Chromium Code Reviews| 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/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 |
|
nyquist
2015/11/24 08:55:43
Nit: Can this class be interacted with from any th
David Trainor- moved to gerrit
2015/11/25 17:56:41
Done.
| |
| 28 // LayerTreeHost (compositor). The rendering surface this compositor draws to | 35 // LayerTreeHost (compositor). The rendering surface this compositor draws to |
|
nyquist
2015/11/24 20:24:47
Nit: It's a little bit confusing having "(composit
David Trainor- moved to gerrit
2015/11/25 17:56:41
Done.
| |
| 29 // is defined by the gfx::AcceleratedWidget returned by | 36 // is defined by the gfx::AcceleratedWidget set by SetAcceleratedWidget(). |
| 30 // BlimpCompositor::GetWindow(). | 37 class BLIMP_CLIENT_EXPORT BlimpCompositor |
| 31 class BlimpCompositor : public cc::LayerTreeHostClient { | 38 : public cc::LayerTreeHostClient, |
| 39 public cc::RemoteProtoChannel, | |
| 40 public RenderWidgetMessageProcessor::RenderWidgetMessageDelegate { | |
| 41 | |
| 32 public: | 42 public: |
| 33 ~BlimpCompositor() override; | 43 ~BlimpCompositor() override; |
| 34 | 44 |
| 45 // Sets whether or not this compositor actually draws to the output surface. | |
| 46 // Setting this to false will make the compositor drop all of it's resources | |
|
nyquist
2015/11/24 08:55:43
Nit: I think we want to refer to things the pronou
David Trainor- moved to gerrit
2015/11/25 17:56:41
Done.
| |
| 47 // and the output surface. Setting it to true again will rebuild the output | |
| 48 // surface from the gfx::AcceleratedWidget (see SetAcceleratedWidget). | |
| 35 void SetVisible(bool visible); | 49 void SetVisible(bool visible); |
| 50 | |
| 51 // Sets the size of the viewport on the compositor. | |
| 52 // TODO(dtrainor): Should this be pulled from the engine all the time? | |
|
nyquist
2015/11/24 08:55:43
Nit: "pulled" for me here has the special meaning
David Trainor- moved to gerrit
2015/11/25 17:56:41
Changed it to set.
| |
| 36 void SetSize(const gfx::Size& size); | 53 void SetSize(const gfx::Size& size); |
| 37 | 54 |
| 55 // Lets this compositor know that it can draw to |widget|. This means that, | |
| 56 // if this compositor is visible, it will build an output surface and GL | |
| 57 // context around |widget| and will draw to it. ReleaseAcceleratedWidget() | |
| 58 // *must* be called before SetAcceleratedWidget() is called with the same | |
| 59 // gfx::AcceleratedWidget on another compositor. | |
| 60 void SetAcceleratedWidget(gfx::AcceleratedWidget widget); | |
| 61 | |
| 62 // Releases the internally stored gfx::AcceleratedWidget and the associated | |
| 63 // output surface. This should be called before calling | |
|
nyquist
2015/11/24 08:55:43
Nit: Should or must? I believe you use 'must' abov
David Trainor- moved to gerrit
2015/11/25 17:56:41
Done.
| |
| 64 // SetAcceleratedWidget() with the same gfx::AcceleratedWidget on another | |
| 65 // compositor. | |
| 66 void ReleaseAcceleratedWidget(); | |
| 67 | |
| 68 protected: | |
| 69 // |dp_to_px| is the scale factor required to move from dp (device pixels) to | |
|
nyquist
2015/11/24 08:55:43
Optional nit: For new readers, would we want to li
David Trainor- moved to gerrit
2015/11/25 17:56:41
Done.
| |
| 70 // px. | |
| 71 explicit BlimpCompositor(float dp_to_px); | |
| 72 | |
| 73 // Populates the cc::LayerTreeSettings used by the cc::LayerTreeHost. Can be | |
| 74 // overridden to provide custom settings parameters. | |
| 75 virtual void GenerateLayerTreeSettings(cc::LayerTreeSettings* settings); | |
| 76 | |
| 77 private: | |
| 38 // LayerTreeHostClient implementation. | 78 // LayerTreeHostClient implementation. |
| 39 void WillBeginMainFrame() override; | 79 void WillBeginMainFrame() override; |
| 40 void DidBeginMainFrame() override; | 80 void DidBeginMainFrame() override; |
| 41 void BeginMainFrame(const cc::BeginFrameArgs& args) override; | 81 void BeginMainFrame(const cc::BeginFrameArgs& args) override; |
| 42 void BeginMainFrameNotExpectedSoon() override; | 82 void BeginMainFrameNotExpectedSoon() override; |
| 43 void UpdateLayerTreeHost() override; | 83 void UpdateLayerTreeHost() override; |
| 44 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, | 84 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, |
| 45 const gfx::Vector2dF& outer_delta, | 85 const gfx::Vector2dF& outer_delta, |
| 46 const gfx::Vector2dF& elastic_overscroll_delta, | 86 const gfx::Vector2dF& elastic_overscroll_delta, |
| 47 float page_scale, | 87 float page_scale, |
| 48 float top_controls_delta) override; | 88 float top_controls_delta) override; |
| 49 void RequestNewOutputSurface() override; | 89 void RequestNewOutputSurface() override; |
| 50 void DidInitializeOutputSurface() override; | 90 void DidInitializeOutputSurface() override; |
| 51 void DidFailToInitializeOutputSurface() override; | 91 void DidFailToInitializeOutputSurface() override; |
| 52 void WillCommit() override; | 92 void WillCommit() override; |
| 53 void DidCommit() override; | 93 void DidCommit() override; |
| 54 void DidCommitAndDrawFrame() override; | 94 void DidCommitAndDrawFrame() override; |
| 55 void DidCompleteSwapBuffers() override; | 95 void DidCompleteSwapBuffers() override; |
| 56 void DidCompletePageScaleAnimation() override; | 96 void DidCompletePageScaleAnimation() override; |
| 57 void RecordFrameTimingEvents( | 97 void RecordFrameTimingEvents( |
| 58 scoped_ptr<cc::FrameTimingTracker::CompositeTimingSet> composite_events, | 98 scoped_ptr<cc::FrameTimingTracker::CompositeTimingSet> composite_events, |
| 59 scoped_ptr<cc::FrameTimingTracker::MainFrameTimingSet> main_frame_events) | 99 scoped_ptr<cc::FrameTimingTracker::MainFrameTimingSet> main_frame_events) |
| 60 override; | 100 override; |
| 61 | 101 |
| 62 protected: | 102 // RemoteProtoChannel implementation. |
| 63 // |dp_to_px| is the scale factor required to move from dp (device pixels) to | 103 void SetProtoReceiver(ProtoReceiver* receiver) override; |
| 64 // px. | 104 void SendCompositorProto(const cc::proto::CompositorMessage& proto) override; |
| 65 explicit BlimpCompositor(float dp_to_px); | |
| 66 | 105 |
| 67 // Returns a widget for use in constructing this compositor's OutputSurface. | 106 // RenderWidgetMessageDelegate implementation. |
| 68 // Will only ever be called while this compositor is visible. | 107 void OnRenderWidgetInitialized() override; |
| 69 virtual gfx::AcceleratedWidget GetWindow() = 0; | 108 void OnCompositorMessageReceived( |
| 109 scoped_ptr<cc::proto::CompositorMessage> message) override; | |
| 70 | 110 |
| 71 // Populates the cc::LayerTreeSettings used by the cc::LayerTreeHost. Can be | 111 // Helper method to build the internal CC compositor instance from |message|. |
| 72 // overridden to provide custom settings parameters. | 112 void CreateLayerTreeHost(scoped_ptr<cc::proto::CompositorMessage> message); |
| 73 virtual void GenerateLayerTreeSettings(cc::LayerTreeSettings* settings); | |
| 74 | 113 |
| 75 private: | |
| 76 // Creates (if necessary) and returns a TaskRunner for a thread meant to run | 114 // Creates (if necessary) and returns a TaskRunner for a thread meant to run |
| 77 // compositor rendering. | 115 // compositor rendering. |
| 116 void HandlePendingOutputSurfaceRequest(); | |
| 78 scoped_refptr<base::SingleThreadTaskRunner> GetCompositorTaskRunner(); | 117 scoped_refptr<base::SingleThreadTaskRunner> GetCompositorTaskRunner(); |
| 79 | 118 |
| 80 gfx::Size viewport_size_; | 119 gfx::Size viewport_size_; |
| 81 | 120 |
| 82 // The scale factor used to convert dp units (device independent pixels) to | 121 // The scale factor used to convert dp units (device independent pixels) to |
| 83 // pixels. | 122 // pixels. |
| 84 float device_scale_factor_; | 123 float device_scale_factor_; |
| 85 scoped_ptr<cc::LayerTreeHost> host_; | 124 scoped_ptr<cc::LayerTreeHost> host_; |
| 86 scoped_ptr<cc::LayerTreeSettings> settings_; | 125 scoped_ptr<cc::LayerTreeSettings> settings_; |
| 87 | 126 |
| 88 // Lazily created thread that will run the compositor rendering tasks. | 127 // Lazily created thread that will run the compositor rendering tasks. |
| 89 scoped_ptr<base::Thread> compositor_thread_; | 128 scoped_ptr<base::Thread> compositor_thread_; |
| 90 | 129 |
| 130 gfx::AcceleratedWidget window_; | |
| 131 | |
| 132 // Whether or not |host_| should be visible. This is stored in case |host_| | |
| 133 // is null when SetVisible() is called or if we don't have a | |
| 134 // gfx::AcceleratedWidget to build an output surface from. | |
| 135 bool host_should_be_visible_; | |
| 136 | |
| 137 // Whether there is an OutputSurface request pending from the current | |
| 138 // |host_|. Becomes |true| if RequestNewOutputSurface is called, and |false| | |
| 139 // if |host_| is deleted or we succeed in creating *and* initializing an | |
| 140 // OutputSurface (which is essentially the contract with cc). | |
| 141 bool output_surface_request_pending_; | |
| 142 | |
| 143 // To be notified of any incoming compositor protos that are specifically sent | |
| 144 // to |render_widget_id_|. | |
| 145 cc::RemoteProtoChannel::ProtoReceiver* remote_proto_channel_receiver_; | |
| 146 | |
| 147 // The bridge to the network layer that does the proto/RenderWidget id work. | |
| 148 // TODO(dtrainor): Move this to a higher level once we start dealing with | |
| 149 // multiple tabs. | |
| 150 RenderWidgetMessageProcessor render_widget_processor_; | |
| 151 | |
| 91 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor); | 152 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor); |
| 92 }; | 153 }; |
| 93 | 154 |
| 94 } // namespace blimp | 155 } // namespace blimp |
| 95 | 156 |
| 96 #endif // BLIMP_CLIENT_COMPOSITOR_BLIMP_COMPOSITOR_H_ | 157 #endif // BLIMP_CLIENT_COMPOSITOR_BLIMP_COMPOSITOR_H_ |
| OLD | NEW |