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 uint32_t kCompositorClientId = 1; | 48 const cc::FrameSinkId kCompositorFrameSinkId(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(kCompositorClientId)), | 123 surface_id_allocator_(new cc::SurfaceIdAllocator(kCompositorFrameSinkId)), |
124 surface_factory_(new cc::SurfaceFactory(surface_manager_.get(), this)), | 124 surface_factory_(new cc::SurfaceFactory(surface_manager_.get(), this)), |
125 begin_frame_source_(std::move(begin_frame_source)) { | 125 begin_frame_source_(std::move(begin_frame_source)) { |
126 DCHECK(registry_); | 126 DCHECK(registry_); |
127 DCHECK(sender_); | 127 DCHECK(sender_); |
128 DCHECK(begin_frame_source_); | 128 DCHECK(begin_frame_source_); |
129 thread_checker_.DetachFromThread(); | 129 thread_checker_.DetachFromThread(); |
130 memory_policy_.priority_cutoff_when_visible = | 130 memory_policy_.priority_cutoff_when_visible = |
131 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; | 131 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; |
132 } | 132 } |
133 | 133 |
(...skipping 26 matching lines...) Expand all Loading... |
160 | 160 |
161 DCHECK(begin_frame_source_); | 161 DCHECK(begin_frame_source_); |
162 client_->SetBeginFrameSource(begin_frame_source_.get()); | 162 client_->SetBeginFrameSource(begin_frame_source_.get()); |
163 client_->SetMemoryPolicy(memory_policy_); | 163 client_->SetMemoryPolicy(memory_policy_); |
164 client_->SetTreeActivationCallback( | 164 client_->SetTreeActivationCallback( |
165 base::Bind(&SynchronousCompositorFrameSink::DidActivatePendingTree, | 165 base::Bind(&SynchronousCompositorFrameSink::DidActivatePendingTree, |
166 base::Unretained(this))); | 166 base::Unretained(this))); |
167 registry_->RegisterCompositorFrameSink(routing_id_, this); | 167 registry_->RegisterCompositorFrameSink(routing_id_, this); |
168 registered_ = true; | 168 registered_ = true; |
169 | 169 |
170 surface_manager_->RegisterSurfaceClientId(surface_id_allocator_->client_id()); | 170 surface_manager_->RegisterFrameSinkId(surface_id_allocator_->frame_sink_id()); |
171 surface_manager_->RegisterSurfaceFactoryClient( | 171 surface_manager_->RegisterSurfaceFactoryClient( |
172 surface_id_allocator_->client_id(), 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(), |
191 surface_id_allocator_->client_id()); | 191 surface_id_allocator_->frame_sink_id()); |
192 display_->SetVisible(true); | 192 display_->SetVisible(true); |
193 return true; | 193 return true; |
194 } | 194 } |
195 | 195 |
196 void SynchronousCompositorFrameSink::DetachFromClient() { | 196 void SynchronousCompositorFrameSink::DetachFromClient() { |
197 DCHECK(CalledOnValidThread()); | 197 DCHECK(CalledOnValidThread()); |
198 client_->SetBeginFrameSource(nullptr); | 198 client_->SetBeginFrameSource(nullptr); |
199 // Destroy the begin frame source on the same thread it was bound on. | 199 // Destroy the begin frame source on the same thread it was bound on. |
200 begin_frame_source_ = nullptr; | 200 begin_frame_source_ = nullptr; |
201 if (registered_) | 201 if (registered_) |
202 registry_->UnregisterCompositorFrameSink(routing_id_, this); | 202 registry_->UnregisterCompositorFrameSink(routing_id_, this); |
203 client_->SetTreeActivationCallback(base::Closure()); | 203 client_->SetTreeActivationCallback(base::Closure()); |
204 if (!delegated_surface_id_.is_null()) | 204 if (!delegated_surface_id_.is_null()) |
205 surface_factory_->Destroy(delegated_surface_id_); | 205 surface_factory_->Destroy(delegated_surface_id_); |
206 surface_manager_->UnregisterSurfaceFactoryClient( | 206 surface_manager_->UnregisterSurfaceFactoryClient( |
207 surface_id_allocator_->client_id()); | 207 surface_id_allocator_->frame_sink_id()); |
208 surface_manager_->InvalidateSurfaceClientId( | 208 surface_manager_->InvalidateFrameSinkId( |
209 surface_id_allocator_->client_id()); | 209 surface_id_allocator_->frame_sink_id()); |
210 software_compositor_frame_sink_ = nullptr; | 210 software_compositor_frame_sink_ = nullptr; |
211 display_ = nullptr; | 211 display_ = nullptr; |
212 surface_factory_ = nullptr; | 212 surface_factory_ = nullptr; |
213 surface_id_allocator_ = nullptr; | 213 surface_id_allocator_ = nullptr; |
214 surface_manager_ = nullptr; | 214 surface_manager_ = nullptr; |
215 cc::CompositorFrameSink::DetachFromClient(); | 215 cc::CompositorFrameSink::DetachFromClient(); |
216 CancelFallbackTick(); | 216 CancelFallbackTick(); |
217 } | 217 } |
218 | 218 |
219 static void NoOpDrawCallback() {} | 219 static void NoOpDrawCallback() {} |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 client_->ReclaimResources(resources); | 413 client_->ReclaimResources(resources); |
414 } | 414 } |
415 | 415 |
416 void SynchronousCompositorFrameSink::SetBeginFrameSource( | 416 void SynchronousCompositorFrameSink::SetBeginFrameSource( |
417 cc::BeginFrameSource* begin_frame_source) { | 417 cc::BeginFrameSource* begin_frame_source) { |
418 // Software output is synchronous and doesn't use a BeginFrameSource. | 418 // Software output is synchronous and doesn't use a BeginFrameSource. |
419 NOTREACHED(); | 419 NOTREACHED(); |
420 } | 420 } |
421 | 421 |
422 } // namespace content | 422 } // namespace content |
OLD | NEW |