OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BLIMP_CLIENT_COMPOSITOR_BLIMP_COMPOSITOR_H_ | 5 #ifndef BLIMP_CLIENT_COMPOSITOR_BLIMP_COMPOSITOR_H_ |
6 #define BLIMP_CLIENT_COMPOSITOR_BLIMP_COMPOSITOR_H_ | 6 #define BLIMP_CLIENT_COMPOSITOR_BLIMP_COMPOSITOR_H_ |
7 | 7 |
| 8 #include <vector> |
| 9 |
8 #include "base/macros.h" | 10 #include "base/macros.h" |
9 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "blimp/client/blimp_client_export.h" |
| 14 #include "blimp/client/compositor/render_widget_message_processor.h" |
11 #include "cc/trees/layer_tree_host_client.h" | 15 #include "cc/trees/layer_tree_host_client.h" |
12 #include "cc/trees/layer_tree_settings.h" | 16 #include "cc/trees/layer_tree_settings.h" |
| 17 #include "cc/trees/remote_proto_channel.h" |
13 #include "ui/gfx/geometry/size.h" | 18 #include "ui/gfx/geometry/size.h" |
14 #include "ui/gfx/native_widget_types.h" | 19 #include "ui/gfx/native_widget_types.h" |
15 | 20 |
16 namespace base { | 21 namespace base { |
17 class SingleThreadTaskRunner; | 22 class SingleThreadTaskRunner; |
18 class Thread; | 23 class Thread; |
19 } | 24 } |
20 | 25 |
21 namespace cc { | 26 namespace cc { |
22 class LayerTreeHost; | 27 class LayerTreeHost; |
23 } | 28 } |
24 | 29 |
25 namespace blimp { | 30 namespace blimp { |
26 | 31 |
| 32 class BlimpMessage; |
| 33 |
27 // BlimpCompositor provides the basic framework and setup to host a | 34 // BlimpCompositor provides the basic framework and setup to host a |
28 // LayerTreeHost (compositor). The rendering surface this compositor draws to | 35 // LayerTreeHost. The class that owns the LayerTreeHost is usually called the |
29 // is defined by the gfx::AcceleratedWidget returned by | 36 // compositor, but the LayerTreeHost does the compositing work. The rendering |
30 // BlimpCompositor::GetWindow(). | 37 // surface this compositor draws to is defined by the gfx::AcceleratedWidget set |
31 class BlimpCompositor : public cc::LayerTreeHostClient { | 38 // by SetAcceleratedWidget(). This class should only be accessed from the main |
| 39 // thread. Any interaction with the compositing thread should happen through |
| 40 // the LayerTreeHost or RemoteChannelImpl. |
| 41 class BLIMP_CLIENT_EXPORT BlimpCompositor |
| 42 : public cc::LayerTreeHostClient, |
| 43 public cc::RemoteProtoChannel, |
| 44 public RenderWidgetMessageProcessor::RenderWidgetMessageDelegate { |
| 45 |
32 public: | 46 public: |
33 ~BlimpCompositor() override; | 47 ~BlimpCompositor() override; |
34 | 48 |
| 49 // Sets whether or not this compositor actually draws to the output surface. |
| 50 // Setting this to false will make the compositor drop all of its resources |
| 51 // and the output surface. Setting it to true again will rebuild the output |
| 52 // surface from the gfx::AcceleratedWidget (see SetAcceleratedWidget). |
35 void SetVisible(bool visible); | 53 void SetVisible(bool visible); |
| 54 |
| 55 // Sets the size of the viewport on the compositor. |
| 56 // TODO(dtrainor): Should this be set from the engine all the time? |
36 void SetSize(const gfx::Size& size); | 57 void SetSize(const gfx::Size& size); |
37 | 58 |
| 59 // Lets this compositor know that it can draw to |widget|. This means that, |
| 60 // if this compositor is visible, it will build an output surface and GL |
| 61 // context around |widget| and will draw to it. ReleaseAcceleratedWidget() |
| 62 // *must* be called before SetAcceleratedWidget() is called with the same |
| 63 // gfx::AcceleratedWidget on another compositor. |
| 64 void SetAcceleratedWidget(gfx::AcceleratedWidget widget); |
| 65 |
| 66 // Releases the internally stored gfx::AcceleratedWidget and the associated |
| 67 // output surface. This must be called before calling |
| 68 // SetAcceleratedWidget() with the same gfx::AcceleratedWidget on another |
| 69 // compositor. |
| 70 void ReleaseAcceleratedWidget(); |
| 71 |
| 72 protected: |
| 73 // |dp_to_px| is the scale factor required to move from dp (device pixels) to |
| 74 // px. See https://developer.android.com/guide/practices/screens_support.html |
| 75 // for more details. |
| 76 explicit BlimpCompositor(float dp_to_px); |
| 77 |
| 78 // Populates the cc::LayerTreeSettings used by the cc::LayerTreeHost. Can be |
| 79 // overridden to provide custom settings parameters. |
| 80 virtual void GenerateLayerTreeSettings(cc::LayerTreeSettings* settings); |
| 81 |
| 82 private: |
38 // LayerTreeHostClient implementation. | 83 // LayerTreeHostClient implementation. |
39 void WillBeginMainFrame() override; | 84 void WillBeginMainFrame() override; |
40 void DidBeginMainFrame() override; | 85 void DidBeginMainFrame() override; |
41 void BeginMainFrame(const cc::BeginFrameArgs& args) override; | 86 void BeginMainFrame(const cc::BeginFrameArgs& args) override; |
42 void BeginMainFrameNotExpectedSoon() override; | 87 void BeginMainFrameNotExpectedSoon() override; |
43 void UpdateLayerTreeHost() override; | 88 void UpdateLayerTreeHost() override; |
44 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, | 89 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, |
45 const gfx::Vector2dF& outer_delta, | 90 const gfx::Vector2dF& outer_delta, |
46 const gfx::Vector2dF& elastic_overscroll_delta, | 91 const gfx::Vector2dF& elastic_overscroll_delta, |
47 float page_scale, | 92 float page_scale, |
48 float top_controls_delta) override; | 93 float top_controls_delta) override; |
49 void RequestNewOutputSurface() override; | 94 void RequestNewOutputSurface() override; |
50 void DidInitializeOutputSurface() override; | 95 void DidInitializeOutputSurface() override; |
51 void DidFailToInitializeOutputSurface() override; | 96 void DidFailToInitializeOutputSurface() override; |
52 void WillCommit() override; | 97 void WillCommit() override; |
53 void DidCommit() override; | 98 void DidCommit() override; |
54 void DidCommitAndDrawFrame() override; | 99 void DidCommitAndDrawFrame() override; |
55 void DidCompleteSwapBuffers() override; | 100 void DidCompleteSwapBuffers() override; |
56 void DidCompletePageScaleAnimation() override; | 101 void DidCompletePageScaleAnimation() override; |
57 void RecordFrameTimingEvents( | 102 void RecordFrameTimingEvents( |
58 scoped_ptr<cc::FrameTimingTracker::CompositeTimingSet> composite_events, | 103 scoped_ptr<cc::FrameTimingTracker::CompositeTimingSet> composite_events, |
59 scoped_ptr<cc::FrameTimingTracker::MainFrameTimingSet> main_frame_events) | 104 scoped_ptr<cc::FrameTimingTracker::MainFrameTimingSet> main_frame_events) |
60 override; | 105 override; |
61 | 106 |
62 protected: | 107 // RemoteProtoChannel implementation. |
63 // |dp_to_px| is the scale factor required to move from dp (device pixels) to | 108 void SetProtoReceiver(ProtoReceiver* receiver) override; |
64 // px. | 109 void SendCompositorProto(const cc::proto::CompositorMessage& proto) override; |
65 explicit BlimpCompositor(float dp_to_px); | |
66 | 110 |
67 // Returns a widget for use in constructing this compositor's OutputSurface. | 111 // RenderWidgetMessageDelegate implementation. |
68 // Will only ever be called while this compositor is visible. | 112 void OnRenderWidgetInitialized() override; |
69 virtual gfx::AcceleratedWidget GetWindow() = 0; | 113 void OnCompositorMessageReceived( |
| 114 scoped_ptr<cc::proto::CompositorMessage> message) override; |
70 | 115 |
71 // Populates the cc::LayerTreeSettings used by the cc::LayerTreeHost. Can be | 116 // Helper method to build the internal CC compositor instance from |message|. |
72 // overridden to provide custom settings parameters. | 117 void CreateLayerTreeHost(scoped_ptr<cc::proto::CompositorMessage> message); |
73 virtual void GenerateLayerTreeSettings(cc::LayerTreeSettings* settings); | |
74 | 118 |
75 private: | |
76 // Creates (if necessary) and returns a TaskRunner for a thread meant to run | 119 // Creates (if necessary) and returns a TaskRunner for a thread meant to run |
77 // compositor rendering. | 120 // compositor rendering. |
| 121 void HandlePendingOutputSurfaceRequest(); |
78 scoped_refptr<base::SingleThreadTaskRunner> GetCompositorTaskRunner(); | 122 scoped_refptr<base::SingleThreadTaskRunner> GetCompositorTaskRunner(); |
79 | 123 |
80 gfx::Size viewport_size_; | 124 gfx::Size viewport_size_; |
81 | 125 |
82 // The scale factor used to convert dp units (device independent pixels) to | 126 // The scale factor used to convert dp units (device independent pixels) to |
83 // pixels. | 127 // pixels. |
84 float device_scale_factor_; | 128 float device_scale_factor_; |
85 scoped_ptr<cc::LayerTreeHost> host_; | 129 scoped_ptr<cc::LayerTreeHost> host_; |
86 scoped_ptr<cc::LayerTreeSettings> settings_; | 130 scoped_ptr<cc::LayerTreeSettings> settings_; |
87 | 131 |
88 // Lazily created thread that will run the compositor rendering tasks. | 132 // Lazily created thread that will run the compositor rendering tasks. |
89 scoped_ptr<base::Thread> compositor_thread_; | 133 scoped_ptr<base::Thread> compositor_thread_; |
90 | 134 |
| 135 gfx::AcceleratedWidget window_; |
| 136 |
| 137 // Whether or not |host_| should be visible. This is stored in case |host_| |
| 138 // is null when SetVisible() is called or if we don't have a |
| 139 // gfx::AcceleratedWidget to build an output surface from. |
| 140 bool host_should_be_visible_; |
| 141 |
| 142 // Whether there is an OutputSurface request pending from the current |
| 143 // |host_|. Becomes |true| if RequestNewOutputSurface is called, and |false| |
| 144 // if |host_| is deleted or we succeed in creating *and* initializing an |
| 145 // OutputSurface (which is essentially the contract with cc). |
| 146 bool output_surface_request_pending_; |
| 147 |
| 148 // To be notified of any incoming compositor protos that are specifically sent |
| 149 // to |render_widget_id_|. |
| 150 cc::RemoteProtoChannel::ProtoReceiver* remote_proto_channel_receiver_; |
| 151 |
| 152 // The bridge to the network layer that does the proto/RenderWidget id work. |
| 153 // TODO(dtrainor): Move this to a higher level once we start dealing with |
| 154 // multiple tabs. |
| 155 RenderWidgetMessageProcessor render_widget_processor_; |
| 156 |
91 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor); | 157 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor); |
92 }; | 158 }; |
93 | 159 |
94 } // namespace blimp | 160 } // namespace blimp |
95 | 161 |
96 #endif // BLIMP_CLIENT_COMPOSITOR_BLIMP_COMPOSITOR_H_ | 162 #endif // BLIMP_CLIENT_COMPOSITOR_BLIMP_COMPOSITOR_H_ |
OLD | NEW |