| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 #include "blimp/client/feature/compositor/blimp_compositor_manager.h" | 5 #include "blimp/client/feature/compositor/blimp_compositor_manager.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "blimp/client/core/compositor/blob_image_serialization_processor.h" | 9 #include "blimp/client/core/compositor/blob_image_serialization_processor.h" |
| 10 #include "blimp/client/feature/compositor/blimp_gpu_memory_buffer_manager.h" |
| 10 #include "blimp/client/feature/compositor/blimp_layer_tree_settings.h" | 11 #include "blimp/client/feature/compositor/blimp_layer_tree_settings.h" |
| 11 #include "blimp/common/compositor/blimp_task_graph_runner.h" | 12 #include "blimp/common/compositor/blimp_task_graph_runner.h" |
| 12 #include "cc/proto/compositor_message.pb.h" | 13 #include "cc/proto/compositor_message.pb.h" |
| 13 | 14 |
| 14 namespace blimp { | 15 namespace blimp { |
| 15 namespace client { | 16 namespace client { |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 base::LazyInstance<blimp::BlimpTaskGraphRunner> g_task_graph_runner = | 19 base::LazyInstance<blimp::BlimpTaskGraphRunner> g_task_graph_runner = |
| 19 LAZY_INSTANCE_INITIALIZER; | 20 LAZY_INSTANCE_INITIALIZER; |
| 20 | 21 |
| 21 const int kDummyTabId = 0; | 22 const int kDummyTabId = 0; |
| 22 } // namespace | 23 } // namespace |
| 23 | 24 |
| 24 BlimpCompositorManager::BlimpCompositorManager( | 25 BlimpCompositorManager::BlimpCompositorManager( |
| 25 RenderWidgetFeature* render_widget_feature, | 26 RenderWidgetFeature* render_widget_feature, |
| 26 BlimpCompositorManagerClient* client) | 27 cc::SurfaceManager* surface_manager, |
| 27 : visible_(false), | 28 BlimpGpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 28 window_(gfx::kNullAcceleratedWidget), | 29 SurfaceIdAllocationCallback callback) |
| 29 gpu_memory_buffer_manager_(new BlimpGpuMemoryBufferManager), | 30 : render_widget_feature_(render_widget_feature), |
| 30 active_compositor_(nullptr), | 31 surface_manager_(surface_manager), |
| 31 render_widget_feature_(render_widget_feature), | 32 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), |
| 32 client_(client) { | 33 surface_id_allocation_callback_(callback), |
| 34 visible_(false), |
| 35 layer_(cc::Layer::Create()), |
| 36 active_compositor_(nullptr) { |
| 33 DCHECK(render_widget_feature_); | 37 DCHECK(render_widget_feature_); |
| 38 DCHECK(surface_manager_); |
| 39 DCHECK(gpu_memory_buffer_manager_); |
| 40 DCHECK(!surface_id_allocation_callback_.is_null()); |
| 41 |
| 34 render_widget_feature_->SetDelegate(kDummyTabId, this); | 42 render_widget_feature_->SetDelegate(kDummyTabId, this); |
| 35 } | 43 } |
| 36 | 44 |
| 37 BlimpCompositorManager::~BlimpCompositorManager() { | 45 BlimpCompositorManager::~BlimpCompositorManager() { |
| 38 render_widget_feature_->RemoveDelegate(kDummyTabId); | 46 render_widget_feature_->RemoveDelegate(kDummyTabId); |
| 39 if (compositor_thread_) | 47 if (compositor_thread_) |
| 40 compositor_thread_->Stop(); | 48 compositor_thread_->Stop(); |
| 41 } | 49 } |
| 42 | 50 |
| 43 void BlimpCompositorManager::SetVisible(bool visible) { | 51 void BlimpCompositorManager::SetVisible(bool visible) { |
| 44 visible_ = visible; | 52 visible_ = visible; |
| 45 if (active_compositor_) | 53 if (active_compositor_) |
| 46 active_compositor_->SetVisible(visible); | 54 active_compositor_->SetVisible(visible_); |
| 47 } | |
| 48 | |
| 49 void BlimpCompositorManager::SetAcceleratedWidget( | |
| 50 gfx::AcceleratedWidget widget) { | |
| 51 window_ = widget; | |
| 52 if (active_compositor_) | |
| 53 active_compositor_->SetAcceleratedWidget(widget); | |
| 54 } | |
| 55 | |
| 56 void BlimpCompositorManager::ReleaseAcceleratedWidget() { | |
| 57 window_ = gfx::kNullAcceleratedWidget; | |
| 58 if (active_compositor_) | |
| 59 active_compositor_->ReleaseAcceleratedWidget(); | |
| 60 } | 55 } |
| 61 | 56 |
| 62 bool BlimpCompositorManager::OnTouchEvent(const ui::MotionEvent& motion_event) { | 57 bool BlimpCompositorManager::OnTouchEvent(const ui::MotionEvent& motion_event) { |
| 63 if (active_compositor_) | 58 if (active_compositor_) |
| 64 return active_compositor_->OnTouchEvent(motion_event); | 59 return active_compositor_->OnTouchEvent(motion_event); |
| 65 return false; | 60 return false; |
| 66 } | 61 } |
| 67 | 62 |
| 68 void BlimpCompositorManager::GenerateLayerTreeSettings( | 63 void BlimpCompositorManager::GenerateLayerTreeSettings( |
| 69 cc::LayerTreeSettings* settings) { | 64 cc::LayerTreeSettings* settings) { |
| 70 PopulateCommonLayerTreeSettings(settings); | 65 PopulateCommonLayerTreeSettings(settings); |
| 71 } | 66 } |
| 72 | 67 |
| 73 std::unique_ptr<BlimpCompositor> BlimpCompositorManager::CreateBlimpCompositor( | 68 std::unique_ptr<BlimpCompositor> BlimpCompositorManager::CreateBlimpCompositor( |
| 74 int render_widget_id, | 69 int render_widget_id, |
| 70 cc::SurfaceManager* surface_manager, |
| 71 uint32_t surface_client_id, |
| 75 BlimpCompositorClient* client) { | 72 BlimpCompositorClient* client) { |
| 76 return base::WrapUnique(new BlimpCompositor(render_widget_id, client)); | 73 return base::WrapUnique(new BlimpCompositor(render_widget_id, surface_manager, |
| 74 surface_client_id, client)); |
| 77 } | 75 } |
| 78 | 76 |
| 79 void BlimpCompositorManager::OnRenderWidgetCreated(int render_widget_id) { | 77 void BlimpCompositorManager::OnRenderWidgetCreated(int render_widget_id) { |
| 80 CHECK(!GetCompositor(render_widget_id)); | 78 CHECK(!GetCompositor(render_widget_id)); |
| 81 | 79 |
| 82 compositors_[render_widget_id] = CreateBlimpCompositor(render_widget_id, | 80 compositors_[render_widget_id] = |
| 83 this); | 81 CreateBlimpCompositor(render_widget_id, surface_manager_, |
| 82 surface_id_allocation_callback_.Run(), this); |
| 84 } | 83 } |
| 85 | 84 |
| 86 void BlimpCompositorManager::OnRenderWidgetInitialized(int render_widget_id) { | 85 void BlimpCompositorManager::OnRenderWidgetInitialized(int render_widget_id) { |
| 87 if (active_compositor_ && | 86 if (active_compositor_ && |
| 88 active_compositor_->render_widget_id() == render_widget_id) | 87 active_compositor_->render_widget_id() == render_widget_id) |
| 89 return; | 88 return; |
| 90 | 89 |
| 90 // Detach the content layer from the old compositor. |
| 91 layer_->RemoveAllChildren(); |
| 92 |
| 91 if (active_compositor_) { | 93 if (active_compositor_) { |
| 92 VLOG(1) << "Hiding currently active compositor for render widget: " | 94 VLOG(1) << "Hiding currently active compositor for render widget: " |
| 93 << active_compositor_->render_widget_id(); | 95 << active_compositor_->render_widget_id(); |
| 94 active_compositor_->SetVisible(false); | 96 active_compositor_->SetVisible(false); |
| 95 active_compositor_->ReleaseAcceleratedWidget(); | |
| 96 } | 97 } |
| 97 | 98 |
| 98 active_compositor_ = GetCompositor(render_widget_id); | 99 active_compositor_ = GetCompositor(render_widget_id); |
| 99 CHECK(active_compositor_); | 100 CHECK(active_compositor_); |
| 100 | 101 |
| 101 active_compositor_->SetVisible(visible_); | 102 active_compositor_->SetVisible(visible_); |
| 102 active_compositor_->SetAcceleratedWidget(window_); | 103 layer_->AddChild(active_compositor_->layer()); |
| 103 } | 104 } |
| 104 | 105 |
| 105 void BlimpCompositorManager::OnRenderWidgetDeleted(int render_widget_id) { | 106 void BlimpCompositorManager::OnRenderWidgetDeleted(int render_widget_id) { |
| 106 CompositorMap::const_iterator it = compositors_.find(render_widget_id); | 107 CompositorMap::const_iterator it = compositors_.find(render_widget_id); |
| 107 CHECK(it != compositors_.end()); | 108 CHECK(it != compositors_.end()); |
| 108 | 109 |
| 109 // Reset the |active_compositor_| if that is what we're destroying right now. | 110 // Reset the |active_compositor_| if that is what we're destroying right now. |
| 110 if (active_compositor_ == it->second.get()) | 111 if (active_compositor_ == it->second.get()) { |
| 112 layer_->RemoveAllChildren(); |
| 111 active_compositor_ = nullptr; | 113 active_compositor_ = nullptr; |
| 114 } |
| 112 | 115 |
| 113 compositors_.erase(it); | 116 compositors_.erase(it); |
| 114 } | 117 } |
| 115 | 118 |
| 116 void BlimpCompositorManager::OnCompositorMessageReceived( | 119 void BlimpCompositorManager::OnCompositorMessageReceived( |
| 117 int render_widget_id, | 120 int render_widget_id, |
| 118 std::unique_ptr<cc::proto::CompositorMessage> message) { | 121 std::unique_ptr<cc::proto::CompositorMessage> message) { |
| 119 BlimpCompositor* compositor = GetCompositor(render_widget_id); | 122 BlimpCompositor* compositor = GetCompositor(render_widget_id); |
| 120 CHECK(compositor); | 123 CHECK(compositor); |
| 121 | 124 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 134 settings_ | 137 settings_ |
| 135 ->abort_commit_before_output_surface_creation = false; | 138 ->abort_commit_before_output_surface_creation = false; |
| 136 settings_->renderer_settings.buffer_to_texture_target_map = | 139 settings_->renderer_settings.buffer_to_texture_target_map = |
| 137 BlimpGpuMemoryBufferManager::GetDefaultBufferToTextureTargetMap(); | 140 BlimpGpuMemoryBufferManager::GetDefaultBufferToTextureTargetMap(); |
| 138 settings_->use_output_surface_begin_frame_source = true; | 141 settings_->use_output_surface_begin_frame_source = true; |
| 139 } | 142 } |
| 140 | 143 |
| 141 return settings_.get(); | 144 return settings_.get(); |
| 142 } | 145 } |
| 143 | 146 |
| 144 void BlimpCompositorManager::DidCompleteSwapBuffers() { | |
| 145 DCHECK(client_); | |
| 146 client_->OnSwapBuffersCompleted(); | |
| 147 } | |
| 148 | |
| 149 void BlimpCompositorManager::DidCommitAndDrawFrame() { | |
| 150 DCHECK(client_); | |
| 151 client_->DidCommitAndDrawFrame(); | |
| 152 } | |
| 153 | |
| 154 scoped_refptr<base::SingleThreadTaskRunner> | 147 scoped_refptr<base::SingleThreadTaskRunner> |
| 155 BlimpCompositorManager::GetCompositorTaskRunner() { | 148 BlimpCompositorManager::GetCompositorTaskRunner() { |
| 156 if (compositor_thread_) | 149 if (compositor_thread_) |
| 157 return compositor_thread_->task_runner(); | 150 return compositor_thread_->task_runner(); |
| 158 | 151 |
| 159 base::Thread::Options thread_options; | 152 base::Thread::Options thread_options; |
| 160 #if defined(OS_ANDROID) | 153 #if defined(OS_ANDROID) |
| 161 thread_options.priority = base::ThreadPriority::DISPLAY; | 154 thread_options.priority = base::ThreadPriority::DISPLAY; |
| 162 #endif | 155 #endif |
| 163 compositor_thread_.reset(new base::Thread("Compositor")); | 156 compositor_thread_.reset(new base::Thread("Compositor")); |
| 164 compositor_thread_->StartWithOptions(thread_options); | 157 compositor_thread_->StartWithOptions(thread_options); |
| 165 | 158 |
| 166 scoped_refptr<base::SingleThreadTaskRunner> task_runner = | 159 scoped_refptr<base::SingleThreadTaskRunner> task_runner = |
| 167 compositor_thread_->task_runner(); | 160 compositor_thread_->task_runner(); |
| 168 task_runner->PostTask( | 161 task_runner->PostTask( |
| 169 FROM_HERE, | 162 FROM_HERE, |
| 170 base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed), | 163 base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed), |
| 171 false)); | 164 false)); |
| 172 // TODO(dtrainor): Determine whether or not we can disallow waiting. | 165 // TODO(dtrainor): Determine whether or not we can disallow waiting. |
| 173 | 166 |
| 174 return task_runner; | 167 return task_runner; |
| 175 } | 168 } |
| 176 | 169 |
| 177 cc::TaskGraphRunner* BlimpCompositorManager::GetTaskGraphRunner() { | 170 cc::TaskGraphRunner* BlimpCompositorManager::GetTaskGraphRunner() { |
| 178 return g_task_graph_runner.Pointer(); | 171 return g_task_graph_runner.Pointer(); |
| 179 } | 172 } |
| 180 | 173 |
| 181 gpu::GpuMemoryBufferManager* | 174 gpu::GpuMemoryBufferManager* |
| 182 BlimpCompositorManager::GetGpuMemoryBufferManager() { | 175 BlimpCompositorManager::GetGpuMemoryBufferManager() { |
| 183 return gpu_memory_buffer_manager_.get(); | 176 return gpu_memory_buffer_manager_; |
| 184 } | 177 } |
| 185 | 178 |
| 186 cc::ImageSerializationProcessor* | 179 cc::ImageSerializationProcessor* |
| 187 BlimpCompositorManager::GetImageSerializationProcessor() { | 180 BlimpCompositorManager::GetImageSerializationProcessor() { |
| 188 return BlobImageSerializationProcessor::current(); | 181 return BlobImageSerializationProcessor::current(); |
| 189 } | 182 } |
| 190 | 183 |
| 191 void BlimpCompositorManager::SendWebGestureEvent( | 184 void BlimpCompositorManager::SendWebGestureEvent( |
| 192 int render_widget_id, | 185 int render_widget_id, |
| 193 const blink::WebGestureEvent& gesture_event) { | 186 const blink::WebGestureEvent& gesture_event) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 206 | 199 |
| 207 BlimpCompositor* BlimpCompositorManager::GetCompositor(int render_widget_id) { | 200 BlimpCompositor* BlimpCompositorManager::GetCompositor(int render_widget_id) { |
| 208 CompositorMap::const_iterator it = compositors_.find(render_widget_id); | 201 CompositorMap::const_iterator it = compositors_.find(render_widget_id); |
| 209 if (it == compositors_.end()) | 202 if (it == compositors_.end()) |
| 210 return nullptr; | 203 return nullptr; |
| 211 return it->second.get(); | 204 return it->second.get(); |
| 212 } | 205 } |
| 213 | 206 |
| 214 } // namespace client | 207 } // namespace client |
| 215 } // namespace blimp | 208 } // namespace blimp |
| OLD | NEW |