OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef BLIMP_CLIENT_COMPOSITOR_BLIMP_COMPOSITOR_H_ |
| 6 #define BLIMP_CLIENT_COMPOSITOR_BLIMP_COMPOSITOR_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 12 #include "cc/trees/layer_tree_host_client.h" |
| 13 #include "cc/trees/layer_tree_host_single_thread_client.h" |
| 14 #include "cc/trees/layer_tree_settings.h" |
| 15 #include "ui/gfx/geometry/size.h" |
| 16 #include "ui/gfx/native_widget_types.h" |
| 17 |
| 18 namespace base { |
| 19 class CommandLine; |
| 20 class SingleThreadTaskRunner; |
| 21 class Thread; |
| 22 } |
| 23 |
| 24 namespace cc { |
| 25 class LayerTreeHost; |
| 26 } |
| 27 |
| 28 namespace blimp { |
| 29 |
| 30 // BlimpCompositor provides the basic framework and setup to host a |
| 31 // LayerTreeHost (compositor). The rendering surface this compositor draws to |
| 32 // is defined by the gfx::AcceleratedWidget returned by |
| 33 // BlimpCompositor::GetWindow(). |
| 34 class BlimpCompositor : public cc::LayerTreeHostClient, |
| 35 public cc::LayerTreeHostSingleThreadClient { |
| 36 public: |
| 37 ~BlimpCompositor() override; |
| 38 |
| 39 void SetVisible(bool visible); |
| 40 void SetSize(const gfx::Size& size); |
| 41 |
| 42 // LayerTreeHostClient implementation |
| 43 void WillBeginMainFrame() override; |
| 44 void DidBeginMainFrame() override; |
| 45 void BeginMainFrame(const cc::BeginFrameArgs& args) override; |
| 46 void BeginMainFrameNotExpectedSoon() override; |
| 47 void Layout() override; |
| 48 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, |
| 49 const gfx::Vector2dF& outer_delta, |
| 50 const gfx::Vector2dF& elastic_overscroll_delta, |
| 51 float page_scale, |
| 52 float top_controls_delta) override; |
| 53 void RequestNewOutputSurface() override; |
| 54 void DidInitializeOutputSurface() override; |
| 55 void DidFailToInitializeOutputSurface() override; |
| 56 void WillCommit() override; |
| 57 void DidCommit() override; |
| 58 void DidCommitAndDrawFrame() override; |
| 59 void DidCompleteSwapBuffers() override; |
| 60 void DidCompletePageScaleAnimation() override; |
| 61 void RecordFrameTimingEvents( |
| 62 scoped_ptr<cc::FrameTimingTracker::CompositeTimingSet> composite_events, |
| 63 scoped_ptr<cc::FrameTimingTracker::MainFrameTimingSet> main_frame_events) |
| 64 override; |
| 65 |
| 66 // LayerTreeHostSingleThreadClient implementation |
| 67 void ScheduleComposite() override; |
| 68 void ScheduleAnimation() override; |
| 69 void DidPostSwapBuffers() override; |
| 70 void DidAbortSwapBuffers() override; |
| 71 |
| 72 protected: |
| 73 explicit BlimpCompositor(float device_scale_factor); |
| 74 |
| 75 // Returns a widget for use in constructing this compositor's OutputSurface. |
| 76 // Will only ever be called while this compositor is visible. |
| 77 virtual gfx::AcceleratedWidget GetWindow() = 0; |
| 78 |
| 79 // Populates the cc::LayerTreeSettings used by the cc::LayerTreeHost. Can be |
| 80 // overridden to provide custom settings parameters. |
| 81 virtual void GenerateLayerTreeSettings(cc::LayerTreeSettings* settings, |
| 82 const base::CommandLine& cmd); |
| 83 |
| 84 private: |
| 85 // Creates (if necessary) and returns a TaskRunner for a thread meant to run |
| 86 // compositor rendering. |
| 87 scoped_refptr<base::SingleThreadTaskRunner> GetCompositorTaskRunner(); |
| 88 |
| 89 gfx::Size viewport_size_; |
| 90 |
| 91 // The scale factor used to convert dp units (device independent pixels) to |
| 92 // pixels. |
| 93 float device_scale_factor_; |
| 94 scoped_ptr<cc::LayerTreeHost> host_; |
| 95 scoped_ptr<cc::LayerTreeSettings> settings_; |
| 96 |
| 97 // A lazily created thread that will run the compositor rendering tasks. |
| 98 scoped_ptr<base::Thread> compositor_thread_; |
| 99 |
| 100 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor); |
| 101 }; |
| 102 |
| 103 } // namespace blimp |
| 104 |
| 105 #endif // BLIMP_CLIENT_COMPOSITOR_BLIMP_COMPOSITOR_H_ |
OLD | NEW |