| 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_FEATURE_COMPOSITOR_BLIMP_COMPOSITOR_H_ | 5 #ifndef BLIMP_CLIENT_FEATURE_COMPOSITOR_BLIMP_COMPOSITOR_H_ |
| 6 #define BLIMP_CLIENT_FEATURE_COMPOSITOR_BLIMP_COMPOSITOR_H_ | 6 #define BLIMP_CLIENT_FEATURE_COMPOSITOR_BLIMP_COMPOSITOR_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "blimp/client/blimp_client_export.h" | 13 #include "blimp/client/blimp_client_export.h" |
| 14 #include "blimp/client/feature/compositor/blimp_input_manager.h" | 14 #include "blimp/client/feature/compositor/blimp_input_manager.h" |
| 15 #include "blimp/client/feature/render_widget_feature.h" | 15 #include "blimp/client/feature/render_widget_feature.h" |
| 16 #include "cc/layers/layer_settings.h" | 16 #include "cc/layers/layer_settings.h" |
| 17 #include "cc/trees/layer_tree_host.h" |
| 17 #include "cc/trees/layer_tree_host_client.h" | 18 #include "cc/trees/layer_tree_host_client.h" |
| 18 #include "cc/trees/layer_tree_settings.h" | 19 #include "cc/trees/layer_tree_settings.h" |
| 19 #include "cc/trees/remote_proto_channel.h" | 20 #include "cc/trees/remote_proto_channel.h" |
| 20 #include "ui/gfx/geometry/size.h" | 21 #include "ui/gfx/geometry/size.h" |
| 21 #include "ui/gfx/native_widget_types.h" | 22 #include "ui/gfx/native_widget_types.h" |
| 22 | 23 |
| 23 namespace base { | 24 namespace base { |
| 24 class SingleThreadTaskRunner; | 25 class SingleThreadTaskRunner; |
| 25 class Thread; | 26 class Thread; |
| 26 } | 27 } |
| 27 | 28 |
| 28 namespace cc { | 29 namespace cc { |
| 30 namespace proto { |
| 31 class InitializeImpl; |
| 32 } |
| 29 class LayerTreeHost; | 33 class LayerTreeHost; |
| 30 } | 34 } |
| 31 | 35 |
| 32 namespace blimp { | 36 namespace blimp { |
| 33 | 37 |
| 34 class BlimpMessage; | 38 class BlimpMessage; |
| 35 | 39 |
| 36 namespace client { | 40 namespace client { |
| 37 | 41 |
| 38 // BlimpCompositor provides the basic framework and setup to host a | 42 // BlimpCompositor provides the basic framework and setup to host a |
| 39 // LayerTreeHost. The class that owns the LayerTreeHost is usually called the | 43 // LayerTreeHost. The class that owns the LayerTreeHost is usually called the |
| 40 // compositor, but the LayerTreeHost does the compositing work. The rendering | 44 // compositor, but the LayerTreeHost does the compositing work. The rendering |
| 41 // surface this compositor draws to is defined by the gfx::AcceleratedWidget set | 45 // surface this compositor draws to is defined by the gfx::AcceleratedWidget set |
| 42 // by SetAcceleratedWidget(). This class should only be accessed from the main | 46 // by SetAcceleratedWidget(). This class should only be accessed from the main |
| 43 // thread. Any interaction with the compositing thread should happen through | 47 // thread. Any interaction with the compositing thread should happen through |
| 44 // the LayerTreeHost or RemoteChannelImpl. | 48 // the LayerTreeHost. |
| 45 class BLIMP_CLIENT_EXPORT BlimpCompositor | 49 class BLIMP_CLIENT_EXPORT BlimpCompositor |
| 46 : public cc::LayerTreeHostClient, | 50 : public cc::LayerTreeHostClient, |
| 47 public cc::RemoteProtoChannel, | 51 public cc::RemoteProtoChannel, |
| 48 public RenderWidgetFeature::RenderWidgetFeatureDelegate, | 52 public RenderWidgetFeature::RenderWidgetFeatureDelegate, |
| 49 public BlimpInputManagerClient { | 53 public BlimpInputManagerClient { |
| 50 public: | 54 public: |
| 51 // |dp_to_px| is the scale factor required to move from dp (device pixels) to | 55 // |dp_to_px| is the scale factor required to move from dp (device pixels) to |
| 52 // px. See https://developer.android.com/guide/practices/screens_support.html | 56 // px. See https://developer.android.com/guide/practices/screens_support.html |
| 53 // for more details. | 57 // for more details. |
| 54 BlimpCompositor(float dp_to_px, RenderWidgetFeature* render_widget_feature); | 58 BlimpCompositor(float dp_to_px, RenderWidgetFeature* render_widget_feature); |
| 55 | 59 |
| 56 ~BlimpCompositor() override; | 60 ~BlimpCompositor() override; |
| 57 | 61 |
| 58 // Default layer settings for all Blimp layer instances. | |
| 59 static cc::LayerSettings LayerSettings(); | |
| 60 | |
| 61 // Sets whether or not this compositor actually draws to the output surface. | 62 // Sets whether or not this compositor actually draws to the output surface. |
| 62 // Setting this to false will make the compositor drop all of its resources | 63 // Setting this to false will make the compositor drop all of its resources |
| 63 // and the output surface. Setting it to true again will rebuild the output | 64 // and the output surface. Setting it to true again will rebuild the output |
| 64 // surface from the gfx::AcceleratedWidget (see SetAcceleratedWidget). | 65 // surface from the gfx::AcceleratedWidget (see SetAcceleratedWidget). |
| 65 void SetVisible(bool visible); | 66 void SetVisible(bool visible); |
| 66 | 67 |
| 67 // Sets the size of the viewport on the compositor. | |
| 68 // TODO(dtrainor): Should this be set from the engine all the time? | |
| 69 void SetSize(const gfx::Size& size); | |
| 70 | |
| 71 // Lets this compositor know that it can draw to |widget|. This means that, | 68 // Lets this compositor know that it can draw to |widget|. This means that, |
| 72 // if this compositor is visible, it will build an output surface and GL | 69 // if this compositor is visible, it will build an output surface and GL |
| 73 // context around |widget| and will draw to it. ReleaseAcceleratedWidget() | 70 // context around |widget| and will draw to it. ReleaseAcceleratedWidget() |
| 74 // *must* be called before SetAcceleratedWidget() is called with the same | 71 // *must* be called before SetAcceleratedWidget() is called with the same |
| 75 // gfx::AcceleratedWidget on another compositor. | 72 // gfx::AcceleratedWidget on another compositor. |
| 76 void SetAcceleratedWidget(gfx::AcceleratedWidget widget); | 73 void SetAcceleratedWidget(gfx::AcceleratedWidget widget); |
| 77 | 74 |
| 78 // Releases the internally stored gfx::AcceleratedWidget and the associated | 75 // Releases the internally stored gfx::AcceleratedWidget and the associated |
| 79 // output surface. This must be called before calling | 76 // output surface. This must be called before calling |
| 80 // SetAcceleratedWidget() with the same gfx::AcceleratedWidget on another | 77 // SetAcceleratedWidget() with the same gfx::AcceleratedWidget on another |
| 81 // compositor. | 78 // compositor. |
| 82 void ReleaseAcceleratedWidget(); | 79 void ReleaseAcceleratedWidget(); |
| 83 | 80 |
| 84 // Forwards the touch event to the |input_manager_|. | 81 // Forwards the touch event to the |input_manager_|. |
| 85 bool OnTouchEvent(const ui::MotionEvent& motion_event); | 82 bool OnTouchEvent(const ui::MotionEvent& motion_event); |
| 86 | 83 |
| 87 protected: | 84 protected: |
| 88 // Populates the cc::LayerTreeSettings used by the cc::LayerTreeHost. Can be | 85 // Populates the cc::LayerTreeSettings used by the cc::LayerTreeHost. Can be |
| 89 // overridden to provide custom settings parameters. | 86 // overridden to provide custom settings parameters. |
| 90 virtual void GenerateLayerTreeSettings(cc::LayerTreeSettings* settings); | 87 virtual void GenerateLayerTreeSettings(cc::LayerTreeSettings* settings); |
| 91 | 88 |
| 92 private: | 89 private: |
| 90 friend class BlimpCompositorForTesting; |
| 91 |
| 93 // LayerTreeHostClient implementation. | 92 // LayerTreeHostClient implementation. |
| 94 void WillBeginMainFrame() override; | 93 void WillBeginMainFrame() override; |
| 95 void DidBeginMainFrame() override; | 94 void DidBeginMainFrame() override; |
| 96 void BeginMainFrame(const cc::BeginFrameArgs& args) override; | 95 void BeginMainFrame(const cc::BeginFrameArgs& args) override; |
| 97 void BeginMainFrameNotExpectedSoon() override; | 96 void BeginMainFrameNotExpectedSoon() override; |
| 98 void UpdateLayerTreeHost() override; | 97 void UpdateLayerTreeHost() override; |
| 99 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, | 98 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, |
| 100 const gfx::Vector2dF& outer_delta, | 99 const gfx::Vector2dF& outer_delta, |
| 101 const gfx::Vector2dF& elastic_overscroll_delta, | 100 const gfx::Vector2dF& elastic_overscroll_delta, |
| 102 float page_scale, | 101 float page_scale, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 119 void SendCompositorProto(const cc::proto::CompositorMessage& proto) override; | 118 void SendCompositorProto(const cc::proto::CompositorMessage& proto) override; |
| 120 | 119 |
| 121 // RenderWidgetFeatureDelegate implementation. | 120 // RenderWidgetFeatureDelegate implementation. |
| 122 void OnRenderWidgetInitialized() override; | 121 void OnRenderWidgetInitialized() override; |
| 123 void OnCompositorMessageReceived( | 122 void OnCompositorMessageReceived( |
| 124 scoped_ptr<cc::proto::CompositorMessage> message) override; | 123 scoped_ptr<cc::proto::CompositorMessage> message) override; |
| 125 | 124 |
| 126 // BlimpInputManagerClient implementation. | 125 // BlimpInputManagerClient implementation. |
| 127 void SendWebInputEvent(const blink::WebInputEvent& input_event) override; | 126 void SendWebInputEvent(const blink::WebInputEvent& input_event) override; |
| 128 | 127 |
| 128 // Internal method to correctly set the visibility on the |host_|. It will |
| 129 // make the |host_| visible if |visible| is true and we have a valid |window_| |
| 130 // If |visible_| is false, the host will also release its output surface. |
| 131 void SetVisibleInternal(bool visible); |
| 132 |
| 129 // Helper method to build the internal CC compositor instance from |message|. | 133 // Helper method to build the internal CC compositor instance from |message|. |
| 130 void CreateLayerTreeHost(scoped_ptr<cc::proto::CompositorMessage> message); | 134 void CreateLayerTreeHost( |
| 135 const cc::proto::InitializeImpl& initialize_message); |
| 136 |
| 137 // Helper method to destroy the internal CC compositor instance and all its |
| 138 // associated state. |
| 139 void DestroyLayerTreeHost(); |
| 131 | 140 |
| 132 // Creates (if necessary) and returns a TaskRunner for a thread meant to run | 141 // Creates (if necessary) and returns a TaskRunner for a thread meant to run |
| 133 // compositor rendering. | 142 // compositor rendering. |
| 134 void HandlePendingOutputSurfaceRequest(); | 143 void HandlePendingOutputSurfaceRequest(); |
| 135 scoped_refptr<base::SingleThreadTaskRunner> GetCompositorTaskRunner(); | 144 scoped_refptr<base::SingleThreadTaskRunner> GetCompositorTaskRunner(); |
| 136 | 145 |
| 137 gfx::Size viewport_size_; | |
| 138 | |
| 139 // The scale factor used to convert dp units (device independent pixels) to | 146 // The scale factor used to convert dp units (device independent pixels) to |
| 140 // pixels. | 147 // pixels. |
| 141 float device_scale_factor_; | 148 float device_scale_factor_; |
| 142 scoped_ptr<cc::LayerTreeHost> host_; | 149 scoped_ptr<cc::LayerTreeHost> host_; |
| 143 scoped_ptr<cc::LayerTreeSettings> settings_; | 150 scoped_ptr<cc::LayerTreeSettings> settings_; |
| 144 | 151 |
| 145 // Lazily created thread that will run the compositor rendering tasks. | 152 // Lazily created thread that will run the compositor rendering tasks. |
| 146 scoped_ptr<base::Thread> compositor_thread_; | 153 scoped_ptr<base::Thread> compositor_thread_; |
| 147 | 154 |
| 148 gfx::AcceleratedWidget window_; | 155 gfx::AcceleratedWidget window_; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 176 // widget. | 183 // widget. |
| 177 scoped_ptr<BlimpInputManager> input_manager_; | 184 scoped_ptr<BlimpInputManager> input_manager_; |
| 178 | 185 |
| 179 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor); | 186 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor); |
| 180 }; | 187 }; |
| 181 | 188 |
| 182 } // namespace client | 189 } // namespace client |
| 183 } // namespace blimp | 190 } // namespace blimp |
| 184 | 191 |
| 185 #endif // BLIMP_CLIENT_FEATURE_COMPOSITOR_BLIMP_COMPOSITOR_H_ | 192 #endif // BLIMP_CLIENT_FEATURE_COMPOSITOR_BLIMP_COMPOSITOR_H_ |
| OLD | NEW |