| 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> | 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/compositor/render_widget_message_processor.h" | 14 #include "blimp/client/compositor/render_widget_message_processor.h" |
| 15 #include "blimp/client/input/blimp_input_manager.h" |
| 15 #include "cc/layers/layer_settings.h" | 16 #include "cc/layers/layer_settings.h" |
| 16 #include "cc/trees/layer_tree_host_client.h" | 17 #include "cc/trees/layer_tree_host_client.h" |
| 17 #include "cc/trees/layer_tree_settings.h" | 18 #include "cc/trees/layer_tree_settings.h" |
| 18 #include "cc/trees/remote_proto_channel.h" | 19 #include "cc/trees/remote_proto_channel.h" |
| 19 #include "ui/gfx/geometry/size.h" | 20 #include "ui/gfx/geometry/size.h" |
| 20 #include "ui/gfx/native_widget_types.h" | 21 #include "ui/gfx/native_widget_types.h" |
| 21 | 22 |
| 22 namespace base { | 23 namespace base { |
| 23 class SingleThreadTaskRunner; | 24 class SingleThreadTaskRunner; |
| 24 class Thread; | 25 class Thread; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 35 // BlimpCompositor provides the basic framework and setup to host a | 36 // BlimpCompositor provides the basic framework and setup to host a |
| 36 // LayerTreeHost. The class that owns the LayerTreeHost is usually called the | 37 // LayerTreeHost. The class that owns the LayerTreeHost is usually called the |
| 37 // compositor, but the LayerTreeHost does the compositing work. The rendering | 38 // compositor, but the LayerTreeHost does the compositing work. The rendering |
| 38 // surface this compositor draws to is defined by the gfx::AcceleratedWidget set | 39 // surface this compositor draws to is defined by the gfx::AcceleratedWidget set |
| 39 // by SetAcceleratedWidget(). This class should only be accessed from the main | 40 // by SetAcceleratedWidget(). This class should only be accessed from the main |
| 40 // thread. Any interaction with the compositing thread should happen through | 41 // thread. Any interaction with the compositing thread should happen through |
| 41 // the LayerTreeHost or RemoteChannelImpl. | 42 // the LayerTreeHost or RemoteChannelImpl. |
| 42 class BLIMP_CLIENT_EXPORT BlimpCompositor | 43 class BLIMP_CLIENT_EXPORT BlimpCompositor |
| 43 : public cc::LayerTreeHostClient, | 44 : public cc::LayerTreeHostClient, |
| 44 public cc::RemoteProtoChannel, | 45 public cc::RemoteProtoChannel, |
| 45 public RenderWidgetMessageProcessor::RenderWidgetMessageDelegate { | 46 public RenderWidgetMessageProcessor::RenderWidgetMessageDelegate, |
| 46 | 47 public BlimpInputManagerClient { |
| 47 public: | 48 public: |
| 48 ~BlimpCompositor() override; | 49 ~BlimpCompositor() override; |
| 49 | 50 |
| 50 // Default layer settings for all Blimp layer instances. | 51 // Default layer settings for all Blimp layer instances. |
| 51 static cc::LayerSettings LayerSettings(); | 52 static cc::LayerSettings LayerSettings(); |
| 52 | 53 |
| 53 // Sets whether or not this compositor actually draws to the output surface. | 54 // Sets whether or not this compositor actually draws to the output surface. |
| 54 // Setting this to false will make the compositor drop all of its resources | 55 // Setting this to false will make the compositor drop all of its resources |
| 55 // and the output surface. Setting it to true again will rebuild the output | 56 // and the output surface. Setting it to true again will rebuild the output |
| 56 // surface from the gfx::AcceleratedWidget (see SetAcceleratedWidget). | 57 // surface from the gfx::AcceleratedWidget (see SetAcceleratedWidget). |
| 57 void SetVisible(bool visible); | 58 void SetVisible(bool visible); |
| 58 | 59 |
| 59 // Sets the size of the viewport on the compositor. | 60 // Sets the size of the viewport on the compositor. |
| 60 // TODO(dtrainor): Should this be set from the engine all the time? | 61 // TODO(dtrainor): Should this be set from the engine all the time? |
| 61 void SetSize(const gfx::Size& size); | 62 void SetSize(const gfx::Size& size); |
| 62 | 63 |
| 63 // Lets this compositor know that it can draw to |widget|. This means that, | 64 // Lets this compositor know that it can draw to |widget|. This means that, |
| 64 // if this compositor is visible, it will build an output surface and GL | 65 // if this compositor is visible, it will build an output surface and GL |
| 65 // context around |widget| and will draw to it. ReleaseAcceleratedWidget() | 66 // context around |widget| and will draw to it. ReleaseAcceleratedWidget() |
| 66 // *must* be called before SetAcceleratedWidget() is called with the same | 67 // *must* be called before SetAcceleratedWidget() is called with the same |
| 67 // gfx::AcceleratedWidget on another compositor. | 68 // gfx::AcceleratedWidget on another compositor. |
| 68 void SetAcceleratedWidget(gfx::AcceleratedWidget widget); | 69 void SetAcceleratedWidget(gfx::AcceleratedWidget widget); |
| 69 | 70 |
| 70 // Releases the internally stored gfx::AcceleratedWidget and the associated | 71 // Releases the internally stored gfx::AcceleratedWidget and the associated |
| 71 // output surface. This must be called before calling | 72 // output surface. This must be called before calling |
| 72 // SetAcceleratedWidget() with the same gfx::AcceleratedWidget on another | 73 // SetAcceleratedWidget() with the same gfx::AcceleratedWidget on another |
| 73 // compositor. | 74 // compositor. |
| 74 void ReleaseAcceleratedWidget(); | 75 void ReleaseAcceleratedWidget(); |
| 75 | 76 |
| 77 // Forwards the touch event to the |input_manager_|. |
| 78 bool OnTouchEvent(const ui::MotionEvent& motion_event); |
| 79 |
| 76 protected: | 80 protected: |
| 77 // |dp_to_px| is the scale factor required to move from dp (device pixels) to | 81 // |dp_to_px| is the scale factor required to move from dp (device pixels) to |
| 78 // px. See https://developer.android.com/guide/practices/screens_support.html | 82 // px. See https://developer.android.com/guide/practices/screens_support.html |
| 79 // for more details. | 83 // for more details. |
| 80 explicit BlimpCompositor(float dp_to_px); | 84 explicit BlimpCompositor(float dp_to_px); |
| 81 | 85 |
| 82 // Populates the cc::LayerTreeSettings used by the cc::LayerTreeHost. Can be | 86 // Populates the cc::LayerTreeSettings used by the cc::LayerTreeHost. Can be |
| 83 // overridden to provide custom settings parameters. | 87 // overridden to provide custom settings parameters. |
| 84 virtual void GenerateLayerTreeSettings(cc::LayerTreeSettings* settings); | 88 virtual void GenerateLayerTreeSettings(cc::LayerTreeSettings* settings); |
| 85 | 89 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 110 | 114 |
| 111 // RemoteProtoChannel implementation. | 115 // RemoteProtoChannel implementation. |
| 112 void SetProtoReceiver(ProtoReceiver* receiver) override; | 116 void SetProtoReceiver(ProtoReceiver* receiver) override; |
| 113 void SendCompositorProto(const cc::proto::CompositorMessage& proto) override; | 117 void SendCompositorProto(const cc::proto::CompositorMessage& proto) override; |
| 114 | 118 |
| 115 // RenderWidgetMessageDelegate implementation. | 119 // RenderWidgetMessageDelegate implementation. |
| 116 void OnRenderWidgetInitialized() override; | 120 void OnRenderWidgetInitialized() override; |
| 117 void OnCompositorMessageReceived( | 121 void OnCompositorMessageReceived( |
| 118 scoped_ptr<cc::proto::CompositorMessage> message) override; | 122 scoped_ptr<cc::proto::CompositorMessage> message) override; |
| 119 | 123 |
| 124 // BlimpInputManagerClient implementation. |
| 125 void SendWebInputEvent(const blink::WebInputEvent& input_event) override; |
| 126 |
| 120 // Helper method to build the internal CC compositor instance from |message|. | 127 // Helper method to build the internal CC compositor instance from |message|. |
| 121 void CreateLayerTreeHost(scoped_ptr<cc::proto::CompositorMessage> message); | 128 void CreateLayerTreeHost(scoped_ptr<cc::proto::CompositorMessage> message); |
| 122 | 129 |
| 123 // Creates (if necessary) and returns a TaskRunner for a thread meant to run | 130 // Creates (if necessary) and returns a TaskRunner for a thread meant to run |
| 124 // compositor rendering. | 131 // compositor rendering. |
| 125 void HandlePendingOutputSurfaceRequest(); | 132 void HandlePendingOutputSurfaceRequest(); |
| 126 scoped_refptr<base::SingleThreadTaskRunner> GetCompositorTaskRunner(); | 133 scoped_refptr<base::SingleThreadTaskRunner> GetCompositorTaskRunner(); |
| 127 | 134 |
| 128 gfx::Size viewport_size_; | 135 gfx::Size viewport_size_; |
| 129 | 136 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 151 | 158 |
| 152 // To be notified of any incoming compositor protos that are specifically sent | 159 // To be notified of any incoming compositor protos that are specifically sent |
| 153 // to |render_widget_id_|. | 160 // to |render_widget_id_|. |
| 154 cc::RemoteProtoChannel::ProtoReceiver* remote_proto_channel_receiver_; | 161 cc::RemoteProtoChannel::ProtoReceiver* remote_proto_channel_receiver_; |
| 155 | 162 |
| 156 // The bridge to the network layer that does the proto/RenderWidget id work. | 163 // The bridge to the network layer that does the proto/RenderWidget id work. |
| 157 // TODO(dtrainor): Move this to a higher level once we start dealing with | 164 // TODO(dtrainor): Move this to a higher level once we start dealing with |
| 158 // multiple tabs. | 165 // multiple tabs. |
| 159 RenderWidgetMessageProcessor render_widget_processor_; | 166 RenderWidgetMessageProcessor render_widget_processor_; |
| 160 | 167 |
| 168 // Handles input events for the current render widget. The lifetime of the |
| 169 // input manager is tied to the lifetime of the |host_| which owns the |
| 170 // cc::InputHandler. The input events are forwarded to this input handler by |
| 171 // the manager to be handled by the client compositor for the current render |
| 172 // widget. |
| 173 scoped_ptr<BlimpInputManager> input_manager_; |
| 174 |
| 161 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor); | 175 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor); |
| 162 }; | 176 }; |
| 163 | 177 |
| 164 } // namespace blimp | 178 } // namespace blimp |
| 165 | 179 |
| 166 #endif // BLIMP_CLIENT_COMPOSITOR_BLIMP_COMPOSITOR_H_ | 180 #endif // BLIMP_CLIENT_COMPOSITOR_BLIMP_COMPOSITOR_H_ |
| OLD | NEW |