| 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_FEATURE_COMPOSITOR_BLIMP_COMPOSITOR_H_ | |
| 6 #define BLIMP_CLIENT_FEATURE_COMPOSITOR_BLIMP_COMPOSITOR_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "blimp/client/core/compositor/blimp_output_surface.h" | |
| 13 #include "blimp/client/feature/compositor/blimp_input_manager.h" | |
| 14 #include "cc/surfaces/surface_factory_client.h" | |
| 15 #include "cc/trees/layer_tree_host.h" | |
| 16 #include "cc/trees/layer_tree_host_client.h" | |
| 17 #include "cc/trees/layer_tree_settings.h" | |
| 18 #include "cc/trees/remote_proto_channel.h" | |
| 19 #include "ui/gfx/geometry/size.h" | |
| 20 #include "ui/gfx/native_widget_types.h" | |
| 21 | |
| 22 namespace base { | |
| 23 class SingleThreadTaskRunner; | |
| 24 class Thread; | |
| 25 } // namespace base | |
| 26 | |
| 27 namespace cc { | |
| 28 namespace proto { | |
| 29 class CompositorMessage; | |
| 30 class InitializeImpl; | |
| 31 } // namespace proto | |
| 32 | |
| 33 class ContextProvider; | |
| 34 class Layer; | |
| 35 class LayerTreeHost; | |
| 36 class LayerTreeSettings; | |
| 37 class Surface; | |
| 38 class SurfaceFactory; | |
| 39 class SurfaceId; | |
| 40 class SurfaceIdAllocator; | |
| 41 } // namespace cc | |
| 42 | |
| 43 namespace blimp { | |
| 44 class BlimpMessage; | |
| 45 | |
| 46 namespace client { | |
| 47 | |
| 48 class BlimpCompositorDependencies; | |
| 49 class CompositorDependencies; | |
| 50 | |
| 51 // The BlimpCompositorClient provides the BlimpCompositor with the necessary | |
| 52 // dependencies for cc::LayerTreeHost owned by this compositor and for | |
| 53 // communicating the compositor and input messages to the corresponding | |
| 54 // render widget of this compositor on the engine. | |
| 55 class BlimpCompositorClient { | |
| 56 public: | |
| 57 // Should send web gesture events which could not be handled locally by the | |
| 58 // compositor to the engine. | |
| 59 virtual void SendWebGestureEvent( | |
| 60 int render_widget_id, | |
| 61 const blink::WebGestureEvent& gesture_event) = 0; | |
| 62 | |
| 63 // Should send the compositor messages from the remote client LayerTreeHost of | |
| 64 // this compositor to the corresponding remote server LayerTreeHost. | |
| 65 virtual void SendCompositorMessage( | |
| 66 int render_widget_id, | |
| 67 const cc::proto::CompositorMessage& message) = 0; | |
| 68 | |
| 69 protected: | |
| 70 virtual ~BlimpCompositorClient() {} | |
| 71 }; | |
| 72 | |
| 73 // BlimpCompositor provides the basic framework and setup to host a | |
| 74 // LayerTreeHost. This class owns the remote client cc::LayerTreeHost, which | |
| 75 // performs the compositing work for the remote server LayerTreeHost. The server | |
| 76 // LayerTreeHost for a BlimpCompositor is owned by the | |
| 77 // content::RenderWidgetCompositor. Thus, each BlimpCompositor is tied to a | |
| 78 // RenderWidget, identified by a custom |render_widget_id| generated on the | |
| 79 // engine. The lifetime of this compositor is controlled by its corresponding | |
| 80 // RenderWidget. | |
| 81 // This class should only be accessed from the main thread. | |
| 82 class BlimpCompositor : public cc::LayerTreeHostClient, | |
| 83 public cc::RemoteProtoChannel, | |
| 84 public BlimpInputManagerClient, | |
| 85 public BlimpOutputSurfaceClient, | |
| 86 public cc::SurfaceFactoryClient { | |
| 87 public: | |
| 88 BlimpCompositor(const int render_widget_id, | |
| 89 BlimpCompositorDependencies* compositor_dependencies, | |
| 90 BlimpCompositorClient* client); | |
| 91 | |
| 92 ~BlimpCompositor() override; | |
| 93 | |
| 94 virtual void SetVisible(bool visible); | |
| 95 | |
| 96 // Forwards the touch event to the |input_manager_|. | |
| 97 // virtual for testing. | |
| 98 virtual bool OnTouchEvent(const ui::MotionEvent& motion_event); | |
| 99 | |
| 100 // Called to forward the compositor message from the remote server | |
| 101 // LayerTreeHost of the render widget for this compositor. | |
| 102 // virtual for testing. | |
| 103 virtual void OnCompositorMessageReceived( | |
| 104 std::unique_ptr<cc::proto::CompositorMessage> message); | |
| 105 | |
| 106 // Called when the a ContextProvider has been created by the | |
| 107 // CompositorDependencies class. If |host_| is waiting on an OutputSurface | |
| 108 // this will build one for it. | |
| 109 void OnContextProviderCreated( | |
| 110 const scoped_refptr<cc::ContextProvider>& provider); | |
| 111 | |
| 112 scoped_refptr<cc::Layer> layer() const { return layer_; } | |
| 113 | |
| 114 int render_widget_id() const { return render_widget_id_; } | |
| 115 | |
| 116 private: | |
| 117 friend class BlimpCompositorForTesting; | |
| 118 | |
| 119 // LayerTreeHostClient implementation. | |
| 120 void WillBeginMainFrame() override {} | |
| 121 void DidBeginMainFrame() override {} | |
| 122 void BeginMainFrame(const cc::BeginFrameArgs& args) override {} | |
| 123 void BeginMainFrameNotExpectedSoon() override {} | |
| 124 void UpdateLayerTreeHost() override {} | |
| 125 void ApplyViewportDeltas(const gfx::Vector2dF& inner_delta, | |
| 126 const gfx::Vector2dF& outer_delta, | |
| 127 const gfx::Vector2dF& elastic_overscroll_delta, | |
| 128 float page_scale, | |
| 129 float top_controls_delta) override {} | |
| 130 void RequestNewOutputSurface() override; | |
| 131 void DidInitializeOutputSurface() override; | |
| 132 // TODO(khushalsagar): Need to handle context initialization failures. | |
| 133 void DidFailToInitializeOutputSurface() override {} | |
| 134 void WillCommit() override {} | |
| 135 void DidCommit() override {} | |
| 136 void DidCommitAndDrawFrame() override; | |
| 137 void DidCompleteSwapBuffers() override {} | |
| 138 void DidCompletePageScaleAnimation() override {} | |
| 139 | |
| 140 // RemoteProtoChannel implementation. | |
| 141 void SetProtoReceiver(ProtoReceiver* receiver) override; | |
| 142 void SendCompositorProto(const cc::proto::CompositorMessage& proto) override; | |
| 143 | |
| 144 // BlimpInputManagerClient implementation. | |
| 145 void SendWebGestureEvent( | |
| 146 const blink::WebGestureEvent& gesture_event) override; | |
| 147 | |
| 148 // BlimpOutputSurfaceClient implementation. | |
| 149 void BindToOutputSurface( | |
| 150 base::WeakPtr<BlimpOutputSurface> output_surface) override; | |
| 151 void SwapCompositorFrame(cc::CompositorFrame frame) override; | |
| 152 void UnbindOutputSurface() override; | |
| 153 | |
| 154 // SurfaceFactoryClient implementation. | |
| 155 void ReturnResources(const cc::ReturnedResourceArray& resources) override; | |
| 156 void SetBeginFrameSource(cc::BeginFrameSource* begin_frame_source) override {} | |
| 157 | |
| 158 // Helper method to get the embedder dependencies. | |
| 159 CompositorDependencies* GetEmbedderDeps(); | |
| 160 | |
| 161 // TODO(khushalsagar): Move all of this to the |DocumentView| or another | |
| 162 // platform specific class. So we use the DelegatedFrameHostAndroid like the | |
| 163 // RenderWidgetHostViewAndroid. | |
| 164 void DestroyDelegatedContent(); | |
| 165 | |
| 166 // Helper method to build the internal CC LayerTreeHost instance from | |
| 167 // |message|. | |
| 168 void CreateLayerTreeHost( | |
| 169 const cc::proto::InitializeImpl& initialize_message); | |
| 170 | |
| 171 // Helper method to destroy the internal CC LayerTreeHost instance and all its | |
| 172 // associated state. | |
| 173 void DestroyLayerTreeHost(); | |
| 174 | |
| 175 // The unique identifier for the render widget for this compositor. | |
| 176 const int render_widget_id_; | |
| 177 | |
| 178 BlimpCompositorClient* client_; | |
| 179 | |
| 180 BlimpCompositorDependencies* compositor_dependencies_; | |
| 181 | |
| 182 std::unique_ptr<cc::LayerTreeHost> host_; | |
| 183 | |
| 184 // Whether or not |host_| should be visible. This is stored in case |host_| | |
| 185 // is null when SetVisible() is called. | |
| 186 bool host_should_be_visible_; | |
| 187 | |
| 188 // The SurfaceFactory is bound to the lifetime of the BlimpOutputSurface. When | |
| 189 // detached, the surface factory will be destroyed. | |
| 190 std::unique_ptr<cc::SurfaceFactory> surface_factory_; | |
| 191 base::WeakPtr<BlimpOutputSurface> output_surface_; | |
| 192 | |
| 193 // Whether or not |host_| has asked for an output surface. | |
| 194 bool output_surface_request_pending_; | |
| 195 | |
| 196 // Data for the current frame. | |
| 197 cc::SurfaceId surface_id_; | |
| 198 gfx::Size current_surface_size_; | |
| 199 | |
| 200 base::ThreadChecker thread_checker_; | |
| 201 | |
| 202 // Surfaces related stuff and layer which holds the delegated content from the | |
| 203 // compositor. | |
| 204 std::unique_ptr<cc::SurfaceIdAllocator> surface_id_allocator_; | |
| 205 scoped_refptr<cc::Layer> layer_; | |
| 206 | |
| 207 // To be notified of any incoming compositor protos that are specifically sent | |
| 208 // to |render_widget_id_|. | |
| 209 cc::RemoteProtoChannel::ProtoReceiver* remote_proto_channel_receiver_; | |
| 210 | |
| 211 // Handles input events for the current render widget. The lifetime of the | |
| 212 // input manager is tied to the lifetime of the |host_| which owns the | |
| 213 // cc::InputHandler. The input events are forwarded to this input handler by | |
| 214 // the manager to be handled by the client compositor for the current render | |
| 215 // widget. | |
| 216 std::unique_ptr<BlimpInputManager> input_manager_; | |
| 217 | |
| 218 base::WeakPtrFactory<BlimpCompositor> weak_ptr_factory_; | |
| 219 | |
| 220 DISALLOW_COPY_AND_ASSIGN(BlimpCompositor); | |
| 221 }; | |
| 222 | |
| 223 } // namespace client | |
| 224 } // namespace blimp | |
| 225 | |
| 226 #endif // BLIMP_CLIENT_FEATURE_COMPOSITOR_BLIMP_COMPOSITOR_H_ | |
| OLD | NEW |