| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/renderer/android/synchronous_compositor_frame_sink.h" | 5 #include "content/renderer/android/synchronous_compositor_frame_sink.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 #include "third_party/skia/include/core/SkCanvas.h" | 38 #include "third_party/skia/include/core/SkCanvas.h" |
| 39 #include "ui/gfx/geometry/rect_conversions.h" | 39 #include "ui/gfx/geometry/rect_conversions.h" |
| 40 #include "ui/gfx/skia_util.h" | 40 #include "ui/gfx/skia_util.h" |
| 41 #include "ui/gfx/transform.h" | 41 #include "ui/gfx/transform.h" |
| 42 | 42 |
| 43 namespace content { | 43 namespace content { |
| 44 | 44 |
| 45 namespace { | 45 namespace { |
| 46 | 46 |
| 47 const int64_t kFallbackTickTimeoutInMilliseconds = 100; | 47 const int64_t kFallbackTickTimeoutInMilliseconds = 100; |
| 48 const cc::FrameSinkId kCompositorFrameSinkId(1, 1); | 48 const cc::FrameSinkId kFrameSinkId(1, 1); |
| 49 | 49 |
| 50 // Do not limit number of resources, so use an unrealistically high value. | 50 // Do not limit number of resources, so use an unrealistically high value. |
| 51 const size_t kNumResourcesLimit = 10 * 1000 * 1000; | 51 const size_t kNumResourcesLimit = 10 * 1000 * 1000; |
| 52 | 52 |
| 53 class SoftwareDevice : public cc::SoftwareOutputDevice { | 53 class SoftwareDevice : public cc::SoftwareOutputDevice { |
| 54 public: | 54 public: |
| 55 SoftwareDevice(SkCanvas** canvas) : canvas_(canvas) {} | 55 SoftwareDevice(SkCanvas** canvas) : canvas_(canvas) {} |
| 56 | 56 |
| 57 void Resize(const gfx::Size& pixel_size, float scale_factor) override { | 57 void Resize(const gfx::Size& pixel_size, float scale_factor) override { |
| 58 // Intentional no-op: canvas size is controlled by the embedder. | 58 // Intentional no-op: canvas size is controlled by the embedder. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue) | 113 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue) |
| 114 : cc::CompositorFrameSink(std::move(context_provider), | 114 : cc::CompositorFrameSink(std::move(context_provider), |
| 115 std::move(worker_context_provider)), | 115 std::move(worker_context_provider)), |
| 116 routing_id_(routing_id), | 116 routing_id_(routing_id), |
| 117 compositor_frame_sink_id_(compositor_frame_sink_id), | 117 compositor_frame_sink_id_(compositor_frame_sink_id), |
| 118 registry_(registry), | 118 registry_(registry), |
| 119 sender_(RenderThreadImpl::current()->sync_compositor_message_filter()), | 119 sender_(RenderThreadImpl::current()->sync_compositor_message_filter()), |
| 120 memory_policy_(0u), | 120 memory_policy_(0u), |
| 121 frame_swap_message_queue_(frame_swap_message_queue), | 121 frame_swap_message_queue_(frame_swap_message_queue), |
| 122 surface_manager_(new cc::SurfaceManager), | 122 surface_manager_(new cc::SurfaceManager), |
| 123 surface_id_allocator_(new cc::SurfaceIdAllocator(kCompositorFrameSinkId)), | 123 surface_id_allocator_(new cc::SurfaceIdAllocator(kFrameSinkId)), |
| 124 surface_factory_(new cc::SurfaceFactory(surface_manager_.get(), this)), | 124 surface_factory_( |
| 125 new cc::SurfaceFactory(kFrameSinkId, surface_manager_.get(), this)), |
| 125 begin_frame_source_(std::move(begin_frame_source)) { | 126 begin_frame_source_(std::move(begin_frame_source)) { |
| 126 DCHECK(registry_); | 127 DCHECK(registry_); |
| 127 DCHECK(sender_); | 128 DCHECK(sender_); |
| 128 DCHECK(begin_frame_source_); | 129 DCHECK(begin_frame_source_); |
| 129 thread_checker_.DetachFromThread(); | 130 thread_checker_.DetachFromThread(); |
| 130 memory_policy_.priority_cutoff_when_visible = | 131 memory_policy_.priority_cutoff_when_visible = |
| 131 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; | 132 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; |
| 132 } | 133 } |
| 133 | 134 |
| 134 SynchronousCompositorFrameSink::~SynchronousCompositorFrameSink() = default; | 135 SynchronousCompositorFrameSink::~SynchronousCompositorFrameSink() = default; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 160 | 161 |
| 161 DCHECK(begin_frame_source_); | 162 DCHECK(begin_frame_source_); |
| 162 client_->SetBeginFrameSource(begin_frame_source_.get()); | 163 client_->SetBeginFrameSource(begin_frame_source_.get()); |
| 163 client_->SetMemoryPolicy(memory_policy_); | 164 client_->SetMemoryPolicy(memory_policy_); |
| 164 client_->SetTreeActivationCallback( | 165 client_->SetTreeActivationCallback( |
| 165 base::Bind(&SynchronousCompositorFrameSink::DidActivatePendingTree, | 166 base::Bind(&SynchronousCompositorFrameSink::DidActivatePendingTree, |
| 166 base::Unretained(this))); | 167 base::Unretained(this))); |
| 167 registry_->RegisterCompositorFrameSink(routing_id_, this); | 168 registry_->RegisterCompositorFrameSink(routing_id_, this); |
| 168 registered_ = true; | 169 registered_ = true; |
| 169 | 170 |
| 170 surface_manager_->RegisterFrameSinkId(surface_id_allocator_->frame_sink_id()); | 171 surface_manager_->RegisterFrameSinkId(kFrameSinkId); |
| 171 surface_manager_->RegisterSurfaceFactoryClient( | 172 surface_manager_->RegisterSurfaceFactoryClient(kFrameSinkId, this); |
| 172 surface_id_allocator_->frame_sink_id(), this); | |
| 173 | 173 |
| 174 cc::RendererSettings software_renderer_settings; | 174 cc::RendererSettings software_renderer_settings; |
| 175 | 175 |
| 176 std::unique_ptr<SoftwareOutputSurface> compositor_frame_sink( | 176 std::unique_ptr<SoftwareOutputSurface> compositor_frame_sink( |
| 177 new SoftwareOutputSurface( | 177 new SoftwareOutputSurface( |
| 178 base::MakeUnique<SoftwareDevice>(¤t_sw_canvas_))); | 178 base::MakeUnique<SoftwareDevice>(¤t_sw_canvas_))); |
| 179 software_compositor_frame_sink_ = compositor_frame_sink.get(); | 179 software_compositor_frame_sink_ = compositor_frame_sink.get(); |
| 180 | 180 |
| 181 // The shared_bitmap_manager and gpu_memory_buffer_manager here are null as | 181 // The shared_bitmap_manager and gpu_memory_buffer_manager here are null as |
| 182 // this Display is only used for resourcesless software draws, where no | 182 // this Display is only used for resourcesless software draws, where no |
| 183 // resources are included in the frame swapped from the compositor. So there | 183 // resources are included in the frame swapped from the compositor. So there |
| 184 // is no need for these. | 184 // is no need for these. |
| 185 display_.reset(new cc::Display( | 185 display_.reset(new cc::Display( |
| 186 nullptr /* shared_bitmap_manager */, | 186 nullptr /* shared_bitmap_manager */, |
| 187 nullptr /* gpu_memory_buffer_manager */, software_renderer_settings, | 187 nullptr /* gpu_memory_buffer_manager */, software_renderer_settings, |
| 188 nullptr /* begin_frame_source */, std::move(compositor_frame_sink), | 188 nullptr /* begin_frame_source */, std::move(compositor_frame_sink), |
| 189 nullptr /* scheduler */, nullptr /* texture_mailbox_deleter */)); | 189 nullptr /* scheduler */, nullptr /* texture_mailbox_deleter */)); |
| 190 display_->Initialize(&display_client_, surface_manager_.get(), | 190 display_->Initialize(&display_client_, surface_manager_.get(), kFrameSinkId); |
| 191 surface_id_allocator_->frame_sink_id()); | |
| 192 display_->SetVisible(true); | 191 display_->SetVisible(true); |
| 193 return true; | 192 return true; |
| 194 } | 193 } |
| 195 | 194 |
| 196 void SynchronousCompositorFrameSink::DetachFromClient() { | 195 void SynchronousCompositorFrameSink::DetachFromClient() { |
| 197 DCHECK(CalledOnValidThread()); | 196 DCHECK(CalledOnValidThread()); |
| 198 client_->SetBeginFrameSource(nullptr); | 197 client_->SetBeginFrameSource(nullptr); |
| 199 // Destroy the begin frame source on the same thread it was bound on. | 198 // Destroy the begin frame source on the same thread it was bound on. |
| 200 begin_frame_source_ = nullptr; | 199 begin_frame_source_ = nullptr; |
| 201 if (registered_) | 200 if (registered_) |
| 202 registry_->UnregisterCompositorFrameSink(routing_id_, this); | 201 registry_->UnregisterCompositorFrameSink(routing_id_, this); |
| 203 client_->SetTreeActivationCallback(base::Closure()); | 202 client_->SetTreeActivationCallback(base::Closure()); |
| 204 if (!delegated_surface_id_.is_null()) | 203 if (!delegated_surface_id_.is_null()) |
| 205 surface_factory_->Destroy(delegated_surface_id_); | 204 surface_factory_->Destroy(delegated_surface_id_); |
| 206 surface_manager_->UnregisterSurfaceFactoryClient( | 205 surface_manager_->UnregisterSurfaceFactoryClient(kFrameSinkId); |
| 207 surface_id_allocator_->frame_sink_id()); | 206 surface_manager_->InvalidateFrameSinkId(kFrameSinkId); |
| 208 surface_manager_->InvalidateFrameSinkId( | |
| 209 surface_id_allocator_->frame_sink_id()); | |
| 210 software_compositor_frame_sink_ = nullptr; | 207 software_compositor_frame_sink_ = nullptr; |
| 211 display_ = nullptr; | 208 display_ = nullptr; |
| 212 surface_factory_ = nullptr; | 209 surface_factory_ = nullptr; |
| 213 surface_id_allocator_ = nullptr; | 210 surface_id_allocator_ = nullptr; |
| 214 surface_manager_ = nullptr; | 211 surface_manager_ = nullptr; |
| 215 cc::CompositorFrameSink::DetachFromClient(); | 212 cc::CompositorFrameSink::DetachFromClient(); |
| 216 CancelFallbackTick(); | 213 CancelFallbackTick(); |
| 217 } | 214 } |
| 218 | 215 |
| 219 static void NoOpDrawCallback() {} | 216 static void NoOpDrawCallback() {} |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 client_->ReclaimResources(resources); | 410 client_->ReclaimResources(resources); |
| 414 } | 411 } |
| 415 | 412 |
| 416 void SynchronousCompositorFrameSink::SetBeginFrameSource( | 413 void SynchronousCompositorFrameSink::SetBeginFrameSource( |
| 417 cc::BeginFrameSource* begin_frame_source) { | 414 cc::BeginFrameSource* begin_frame_source) { |
| 418 // Software output is synchronous and doesn't use a BeginFrameSource. | 415 // Software output is synchronous and doesn't use a BeginFrameSource. |
| 419 NOTREACHED(); | 416 NOTREACHED(); |
| 420 } | 417 } |
| 421 | 418 |
| 422 } // namespace content | 419 } // namespace content |
| OLD | NEW |