| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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_MANAGER_H_ | |
| 6 #define BLIMP_CLIENT_FEATURE_COMPOSITOR_BLIMP_COMPOSITOR_MANAGER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "blimp/client/core/compositor/blob_image_serialization_processor.h" | |
| 12 #include "blimp/client/feature/compositor/blimp_compositor.h" | |
| 13 #include "blimp/client/feature/compositor/blimp_gpu_memory_buffer_manager.h" | |
| 14 #include "blimp/client/feature/render_widget_feature.h" | |
| 15 #include "cc/trees/layer_tree_settings.h" | |
| 16 | |
| 17 namespace blimp { | |
| 18 namespace client { | |
| 19 | |
| 20 class BlimpCompositorManagerClient { | |
| 21 public: | |
| 22 virtual void OnSwapBuffersCompleted() = 0; | |
| 23 virtual void DidCommitAndDrawFrame() = 0; | |
| 24 }; | |
| 25 | |
| 26 // The BlimpCompositorManager manages multiple BlimpCompositor instances, each | |
| 27 // mapped to a render widget on the engine. The compositor corresponding to | |
| 28 // the render widget initialized on the engine will be the |active_compositor_|. | |
| 29 // Only the |active_compositor_| holds the accelerated widget and builds the | |
| 30 // output surface from this widget to draw to the view. All events from the | |
| 31 // native view are forwarded to this compositor. | |
| 32 class BlimpCompositorManager | |
| 33 : public RenderWidgetFeature::RenderWidgetFeatureDelegate, | |
| 34 public BlimpCompositorClient { | |
| 35 public: | |
| 36 explicit BlimpCompositorManager(RenderWidgetFeature* render_widget_feature, | |
| 37 BlimpCompositorManagerClient* client); | |
| 38 ~BlimpCompositorManager() override; | |
| 39 | |
| 40 void SetVisible(bool visible); | |
| 41 | |
| 42 void SetAcceleratedWidget(gfx::AcceleratedWidget widget); | |
| 43 | |
| 44 void ReleaseAcceleratedWidget(); | |
| 45 | |
| 46 bool OnTouchEvent(const ui::MotionEvent& motion_event); | |
| 47 | |
| 48 protected: | |
| 49 // Populates the cc::LayerTreeSettings used by the cc::LayerTreeHost of the | |
| 50 // BlimpCompositors created by this manager. Can be overridden to provide | |
| 51 // custom settings parameters. | |
| 52 virtual void GenerateLayerTreeSettings(cc::LayerTreeSettings* settings); | |
| 53 | |
| 54 // virtual for testing. | |
| 55 virtual std::unique_ptr<BlimpCompositor> CreateBlimpCompositor( | |
| 56 int render_widget_id, | |
| 57 BlimpCompositorClient* client); | |
| 58 | |
| 59 // Returns the compositor for the |render_widget_id|. Will return nullptr if | |
| 60 // no compositor is found. | |
| 61 // protected for testing. | |
| 62 BlimpCompositor* GetCompositor(int render_widget_id); | |
| 63 | |
| 64 private: | |
| 65 // RenderWidgetFeatureDelegate implementation. | |
| 66 void OnRenderWidgetCreated(int render_widget_id) override; | |
| 67 void OnRenderWidgetInitialized(int render_widget_id) override; | |
| 68 void OnRenderWidgetDeleted(int render_widget_id) override; | |
| 69 void OnCompositorMessageReceived( | |
| 70 int render_widget_id, | |
| 71 std::unique_ptr<cc::proto::CompositorMessage> message) override; | |
| 72 | |
| 73 // BlimpCompositorClient implementation. | |
| 74 void DidCompleteSwapBuffers() override; | |
| 75 void DidCommitAndDrawFrame() override; | |
| 76 cc::LayerTreeSettings* GetLayerTreeSettings() override; | |
| 77 scoped_refptr<base::SingleThreadTaskRunner> | |
| 78 GetCompositorTaskRunner() override; | |
| 79 cc::TaskGraphRunner* GetTaskGraphRunner() override; | |
| 80 gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override; | |
| 81 cc::ImageSerializationProcessor* GetImageSerializationProcessor() override; | |
| 82 void SendWebGestureEvent( | |
| 83 int render_widget_id, | |
| 84 const blink::WebGestureEvent& gesture_event) override; | |
| 85 void SendCompositorMessage( | |
| 86 int render_widget_id, | |
| 87 const cc::proto::CompositorMessage& message) override; | |
| 88 | |
| 89 bool visible_; | |
| 90 | |
| 91 gfx::AcceleratedWidget window_; | |
| 92 | |
| 93 std::unique_ptr<cc::LayerTreeSettings> settings_; | |
| 94 | |
| 95 std::unique_ptr<BlimpGpuMemoryBufferManager> gpu_memory_buffer_manager_; | |
| 96 | |
| 97 // A map of render_widget_ids to the BlimpCompositor instance. | |
| 98 typedef std::map<int, std::unique_ptr<BlimpCompositor>> CompositorMap; | |
| 99 CompositorMap compositors_; | |
| 100 | |
| 101 // The |active_compositor_| represents the compositor from the CompositorMap | |
| 102 // that is currently visible and has the |window_|. It corresponds to the | |
| 103 // render widget currently initialized on the engine. | |
| 104 BlimpCompositor* active_compositor_; | |
| 105 | |
| 106 // Lazily created thread that will run the compositor rendering tasks and will | |
| 107 // be shared by all compositor instances. | |
| 108 std::unique_ptr<base::Thread> compositor_thread_; | |
| 109 | |
| 110 // The bridge to the network layer that does the proto/RenderWidget id work. | |
| 111 // BlimpCompositorManager does not own this and it is expected to outlive this | |
| 112 // BlimpCompositorManager instance. | |
| 113 RenderWidgetFeature* render_widget_feature_; | |
| 114 BlimpCompositorManagerClient* client_; | |
| 115 | |
| 116 DISALLOW_COPY_AND_ASSIGN(BlimpCompositorManager); | |
| 117 }; | |
| 118 | |
| 119 } // namespace client | |
| 120 } // namespace blimp | |
| 121 | |
| 122 #endif // BLIMP_CLIENT_FEATURE_COMPOSITOR_BLIMP_COMPOSITOR_MANAGER_H_ | |
| OLD | NEW |