Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2035)

Side by Side Diff: content/renderer/android/synchronous_compositor_frame_sink.cc

Issue 2337913003: Fork cc::OutputSurface into cc::CompositorFrameSink. (Closed)
Patch Set: cfsfork: android-vulkan Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_output_surface.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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
15 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
16 #include "cc/output/compositor_frame.h" 16 #include "cc/output/compositor_frame.h"
17 #include "cc/output/compositor_frame_sink_client.h"
17 #include "cc/output/context_provider.h" 18 #include "cc/output/context_provider.h"
18 #include "cc/output/output_surface_client.h" 19 #include "cc/output/output_surface.h"
19 #include "cc/output/renderer_settings.h" 20 #include "cc/output/renderer_settings.h"
20 #include "cc/output/software_output_device.h" 21 #include "cc/output/software_output_device.h"
21 #include "cc/output/texture_mailbox_deleter.h" 22 #include "cc/output/texture_mailbox_deleter.h"
22 #include "cc/surfaces/display.h" 23 #include "cc/surfaces/display.h"
23 #include "cc/surfaces/surface_factory.h" 24 #include "cc/surfaces/surface_factory.h"
24 #include "cc/surfaces/surface_id_allocator.h" 25 #include "cc/surfaces/surface_id_allocator.h"
25 #include "cc/surfaces/surface_manager.h" 26 #include "cc/surfaces/surface_manager.h"
26 #include "content/common/android/sync_compositor_messages.h" 27 #include "content/common/android/sync_compositor_messages.h"
27 #include "content/renderer/android/synchronous_compositor_filter.h" 28 #include "content/renderer/android/synchronous_compositor_filter.h"
28 #include "content/renderer/android/synchronous_compositor_registry.h" 29 #include "content/renderer/android/synchronous_compositor_registry.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 void EndPaint() override {} 64 void EndPaint() override {}
64 65
65 private: 66 private:
66 SkCanvas** canvas_; 67 SkCanvas** canvas_;
67 68
68 DISALLOW_COPY_AND_ASSIGN(SoftwareDevice); 69 DISALLOW_COPY_AND_ASSIGN(SoftwareDevice);
69 }; 70 };
70 71
71 } // namespace 72 } // namespace
72 73
73 class SynchronousCompositorOutputSurface::SoftwareOutputSurface 74 class SynchronousCompositorFrameSink::SoftwareOutputSurface
74 : public cc::OutputSurface { 75 : public cc::OutputSurface {
75 public: 76 public:
76 SoftwareOutputSurface(std::unique_ptr<SoftwareDevice> software_device) 77 SoftwareOutputSurface(std::unique_ptr<SoftwareDevice> software_device)
77 : cc::OutputSurface(nullptr, nullptr, std::move(software_device)) {} 78 : cc::OutputSurface(nullptr, nullptr, std::move(software_device)) {}
78 79
79 // cc::OutputSurface implementation. 80 // cc::OutputSurface implementation.
80 uint32_t GetFramebufferCopyTextureFormat() override { return 0; } 81 uint32_t GetFramebufferCopyTextureFormat() override { return 0; }
81 void SwapBuffers(cc::CompositorFrame frame) override {} 82 void SwapBuffers(cc::CompositorFrame frame) override {}
82 void Reshape(const gfx::Size& size, 83 void Reshape(const gfx::Size& size,
83 float scale_factor, 84 float scale_factor,
84 const gfx::ColorSpace& color_space, 85 const gfx::ColorSpace& color_space,
85 bool has_alpha) override { 86 bool has_alpha) override {
86 // Intentional no-op. Surface size controlled by embedder. 87 // Intentional no-op. Surface size controlled by embedder.
87 } 88 }
88 89
89 void SetSurfaceSize(const gfx::Size surface_size) { 90 void SetSurfaceSize(const gfx::Size surface_size) {
90 surface_size_ = surface_size; 91 surface_size_ = surface_size;
91 } 92 }
92 }; 93 };
93 94
94 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( 95 SynchronousCompositorFrameSink::SynchronousCompositorFrameSink(
95 scoped_refptr<cc::ContextProvider> context_provider, 96 scoped_refptr<cc::ContextProvider> context_provider,
96 scoped_refptr<cc::ContextProvider> worker_context_provider, 97 scoped_refptr<cc::ContextProvider> worker_context_provider,
97 int routing_id, 98 int routing_id,
98 uint32_t output_surface_id, 99 uint32_t compositor_frame_sink_id,
99 std::unique_ptr<cc::BeginFrameSource> begin_frame_source, 100 std::unique_ptr<cc::BeginFrameSource> begin_frame_source,
100 SynchronousCompositorRegistry* registry, 101 SynchronousCompositorRegistry* registry,
101 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue) 102 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue)
102 : cc::OutputSurface(std::move(context_provider), 103 : cc::CompositorFrameSink(std::move(context_provider),
103 std::move(worker_context_provider), 104 std::move(worker_context_provider),
104 nullptr), 105 nullptr),
105 routing_id_(routing_id), 106 routing_id_(routing_id),
106 output_surface_id_(output_surface_id), 107 compositor_frame_sink_id_(compositor_frame_sink_id),
107 registry_(registry), 108 registry_(registry),
108 sender_(RenderThreadImpl::current()->sync_compositor_message_filter()), 109 sender_(RenderThreadImpl::current()->sync_compositor_message_filter()),
109 memory_policy_(0u), 110 memory_policy_(0u),
110 frame_swap_message_queue_(frame_swap_message_queue), 111 frame_swap_message_queue_(frame_swap_message_queue),
111 surface_manager_(new cc::SurfaceManager), 112 surface_manager_(new cc::SurfaceManager),
112 surface_id_allocator_(new cc::SurfaceIdAllocator(kCompositorClientId)), 113 surface_id_allocator_(new cc::SurfaceIdAllocator(kCompositorClientId)),
113 surface_factory_(new cc::SurfaceFactory(surface_manager_.get(), this)), 114 surface_factory_(new cc::SurfaceFactory(surface_manager_.get(), this)),
114 begin_frame_source_(std::move(begin_frame_source)) { 115 begin_frame_source_(std::move(begin_frame_source)) {
115 DCHECK(registry_); 116 DCHECK(registry_);
116 DCHECK(sender_); 117 DCHECK(sender_);
117 DCHECK(begin_frame_source_); 118 DCHECK(begin_frame_source_);
118 thread_checker_.DetachFromThread(); 119 thread_checker_.DetachFromThread();
119 capabilities_.adjust_deadline_for_parent = false; 120 capabilities_.adjust_deadline_for_parent = false;
120 capabilities_.delegated_rendering = true; 121 capabilities_.delegated_rendering = true;
121 memory_policy_.priority_cutoff_when_visible = 122 memory_policy_.priority_cutoff_when_visible =
122 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; 123 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE;
123 } 124 }
124 125
125 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() = 126 SynchronousCompositorFrameSink::~SynchronousCompositorFrameSink() = default;
126 default;
127 127
128 void SynchronousCompositorOutputSurface::SetSyncClient( 128 void SynchronousCompositorFrameSink::SetSyncClient(
129 SynchronousCompositorOutputSurfaceClient* compositor) { 129 SynchronousCompositorFrameSinkClient* compositor) {
130 DCHECK(CalledOnValidThread()); 130 DCHECK(CalledOnValidThread());
131 sync_client_ = compositor; 131 sync_client_ = compositor;
132 if (sync_client_) 132 if (sync_client_)
133 Send(new SyncCompositorHostMsg_OutputSurfaceCreated(routing_id_)); 133 Send(new SyncCompositorHostMsg_CompositorFrameSinkCreated(routing_id_));
134 } 134 }
135 135
136 bool SynchronousCompositorOutputSurface::OnMessageReceived( 136 bool SynchronousCompositorFrameSink::OnMessageReceived(
137 const IPC::Message& message) { 137 const IPC::Message& message) {
138 bool handled = true; 138 bool handled = true;
139 IPC_BEGIN_MESSAGE_MAP(SynchronousCompositorOutputSurface, message) 139 IPC_BEGIN_MESSAGE_MAP(SynchronousCompositorFrameSink, message)
140 IPC_MESSAGE_HANDLER(SyncCompositorMsg_SetMemoryPolicy, SetMemoryPolicy) 140 IPC_MESSAGE_HANDLER(SyncCompositorMsg_SetMemoryPolicy, SetMemoryPolicy)
141 IPC_MESSAGE_HANDLER(SyncCompositorMsg_ReclaimResources, OnReclaimResources) 141 IPC_MESSAGE_HANDLER(SyncCompositorMsg_ReclaimResources, OnReclaimResources)
142 IPC_MESSAGE_UNHANDLED(handled = false) 142 IPC_MESSAGE_UNHANDLED(handled = false)
143 IPC_END_MESSAGE_MAP() 143 IPC_END_MESSAGE_MAP()
144 return handled; 144 return handled;
145 } 145 }
146 146
147 bool SynchronousCompositorOutputSurface::BindToClient( 147 bool SynchronousCompositorFrameSink::BindToClient(
148 cc::OutputSurfaceClient* surface_client) { 148 cc::CompositorFrameSinkClient* sink_client) {
149 DCHECK(CalledOnValidThread()); 149 DCHECK(CalledOnValidThread());
150 if (!cc::OutputSurface::BindToClient(surface_client)) 150 if (!cc::CompositorFrameSink::BindToClient(sink_client))
151 return false; 151 return false;
152 152
153 DCHECK(begin_frame_source_); 153 DCHECK(begin_frame_source_);
154 client_->SetBeginFrameSource(begin_frame_source_.get()); 154 client_->SetBeginFrameSource(begin_frame_source_.get());
155 client_->SetMemoryPolicy(memory_policy_); 155 client_->SetMemoryPolicy(memory_policy_);
156 client_->SetTreeActivationCallback( 156 client_->SetTreeActivationCallback(
157 base::Bind(&SynchronousCompositorOutputSurface::DidActivatePendingTree, 157 base::Bind(&SynchronousCompositorFrameSink::DidActivatePendingTree,
158 base::Unretained(this))); 158 base::Unretained(this)));
159 registry_->RegisterOutputSurface(routing_id_, this); 159 registry_->RegisterCompositorFrameSink(routing_id_, this);
160 registered_ = true; 160 registered_ = true;
161 161
162 surface_manager_->RegisterSurfaceClientId(surface_id_allocator_->client_id()); 162 surface_manager_->RegisterSurfaceClientId(surface_id_allocator_->client_id());
163 surface_manager_->RegisterSurfaceFactoryClient( 163 surface_manager_->RegisterSurfaceFactoryClient(
164 surface_id_allocator_->client_id(), this); 164 surface_id_allocator_->client_id(), this);
165 165
166 cc::RendererSettings software_renderer_settings; 166 cc::RendererSettings software_renderer_settings;
167 167
168 std::unique_ptr<SoftwareOutputSurface> output_surface( 168 std::unique_ptr<SoftwareOutputSurface> compositor_frame_sink(
169 new SoftwareOutputSurface( 169 new SoftwareOutputSurface(
170 base::MakeUnique<SoftwareDevice>(&current_sw_canvas_))); 170 base::MakeUnique<SoftwareDevice>(&current_sw_canvas_)));
171 software_output_surface_ = output_surface.get(); 171 software_compositor_frame_sink_ = compositor_frame_sink.get();
172 172
173 // The shared_bitmap_manager and gpu_memory_buffer_manager here are null as 173 // The shared_bitmap_manager and gpu_memory_buffer_manager here are null as
174 // this Display is only used for resourcesless software draws, where no 174 // this Display is only used for resourcesless software draws, where no
175 // resources are included in the frame swapped from the compositor. So there 175 // resources are included in the frame swapped from the compositor. So there
176 // is no need for these. 176 // is no need for these.
177 display_.reset(new cc::Display( 177 display_.reset(new cc::Display(
178 nullptr /* shared_bitmap_manager */, 178 nullptr /* shared_bitmap_manager */,
179 nullptr /* gpu_memory_buffer_manager */, software_renderer_settings, 179 nullptr /* gpu_memory_buffer_manager */, software_renderer_settings,
180 nullptr /* begin_frame_source */, std::move(output_surface), 180 nullptr /* begin_frame_source */, std::move(compositor_frame_sink),
181 nullptr /* scheduler */, nullptr /* texture_mailbox_deleter */)); 181 nullptr /* scheduler */, nullptr /* texture_mailbox_deleter */));
182 display_->Initialize(&display_client_, surface_manager_.get(), 182 display_->Initialize(&display_client_, surface_manager_.get(),
183 surface_id_allocator_->client_id()); 183 surface_id_allocator_->client_id());
184 display_->SetVisible(true); 184 display_->SetVisible(true);
185 return true; 185 return true;
186 } 186 }
187 187
188 void SynchronousCompositorOutputSurface::DetachFromClient() { 188 void SynchronousCompositorFrameSink::DetachFromClient() {
189 DCHECK(CalledOnValidThread()); 189 DCHECK(CalledOnValidThread());
190 client_->SetBeginFrameSource(nullptr); 190 client_->SetBeginFrameSource(nullptr);
191 // Destroy the begin frame source on the same thread it was bound on. 191 // Destroy the begin frame source on the same thread it was bound on.
192 begin_frame_source_ = nullptr; 192 begin_frame_source_ = nullptr;
193 if (registered_) 193 if (registered_)
194 registry_->UnregisterOutputSurface(routing_id_, this); 194 registry_->UnregisterCompositorFrameSink(routing_id_, this);
195 client_->SetTreeActivationCallback(base::Closure()); 195 client_->SetTreeActivationCallback(base::Closure());
196 if (!delegated_surface_id_.is_null()) 196 if (!delegated_surface_id_.is_null())
197 surface_factory_->Destroy(delegated_surface_id_); 197 surface_factory_->Destroy(delegated_surface_id_);
198 surface_manager_->UnregisterSurfaceFactoryClient( 198 surface_manager_->UnregisterSurfaceFactoryClient(
199 surface_id_allocator_->client_id()); 199 surface_id_allocator_->client_id());
200 surface_manager_->InvalidateSurfaceClientId( 200 surface_manager_->InvalidateSurfaceClientId(
201 surface_id_allocator_->client_id()); 201 surface_id_allocator_->client_id());
202 software_output_surface_ = nullptr; 202 software_compositor_frame_sink_ = nullptr;
203 display_ = nullptr; 203 display_ = nullptr;
204 surface_factory_ = nullptr; 204 surface_factory_ = nullptr;
205 surface_id_allocator_ = nullptr; 205 surface_id_allocator_ = nullptr;
206 surface_manager_ = nullptr; 206 surface_manager_ = nullptr;
207 cc::OutputSurface::DetachFromClient(); 207 cc::CompositorFrameSink::DetachFromClient();
208 CancelFallbackTick(); 208 CancelFallbackTick();
209 } 209 }
210 210
211 void SynchronousCompositorOutputSurface::Reshape( 211 void SynchronousCompositorFrameSink::Reshape(const gfx::Size& size,
212 const gfx::Size& size, 212 float scale_factor,
213 float scale_factor, 213 const gfx::ColorSpace& color_space,
214 const gfx::ColorSpace& color_space, 214 bool has_alpha) {
215 bool has_alpha) {
216 // Intentional no-op: surface size is controlled by the embedder. 215 // Intentional no-op: surface size is controlled by the embedder.
217 } 216 }
218 217
219 static void NoOpDrawCallback() {} 218 static void NoOpDrawCallback() {}
220 219
221 void SynchronousCompositorOutputSurface::SwapBuffers( 220 void SynchronousCompositorFrameSink::SwapBuffers(cc::CompositorFrame frame) {
222 cc::CompositorFrame frame) {
223 DCHECK(CalledOnValidThread()); 221 DCHECK(CalledOnValidThread());
224 DCHECK(sync_client_); 222 DCHECK(sync_client_);
225 223
226 if (fallback_tick_running_) { 224 if (fallback_tick_running_) {
227 DCHECK(frame.delegated_frame_data->resource_list.empty()); 225 DCHECK(frame.delegated_frame_data->resource_list.empty());
228 cc::ReturnedResourceArray return_resources; 226 cc::ReturnedResourceArray return_resources;
229 ReturnResources(return_resources); 227 ReturnResources(return_resources);
230 did_swap_ = true; 228 did_swap_ = true;
231 return; 229 return;
232 } 230 }
(...skipping 19 matching lines...) Expand all
252 250
253 surface_factory_->SubmitCompositorFrame( 251 surface_factory_->SubmitCompositorFrame(
254 delegated_surface_id_, std::move(frame), base::Bind(&NoOpDrawCallback)); 252 delegated_surface_id_, std::move(frame), base::Bind(&NoOpDrawCallback));
255 display_->DrawAndSwap(); 253 display_->DrawAndSwap();
256 } else { 254 } else {
257 // For hardware draws we send the whole frame to the client so it can draw 255 // For hardware draws we send the whole frame to the client so it can draw
258 // the content in it. 256 // the content in it.
259 swap_frame = std::move(frame); 257 swap_frame = std::move(frame);
260 } 258 }
261 259
262 sync_client_->SwapBuffers(output_surface_id_, std::move(swap_frame)); 260 sync_client_->SwapBuffers(compositor_frame_sink_id_, std::move(swap_frame));
263 DeliverMessages(); 261 DeliverMessages();
264 did_swap_ = true; 262 did_swap_ = true;
265 } 263 }
266 264
267 void SynchronousCompositorOutputSurface::CancelFallbackTick() { 265 void SynchronousCompositorFrameSink::CancelFallbackTick() {
268 fallback_tick_.Cancel(); 266 fallback_tick_.Cancel();
269 fallback_tick_pending_ = false; 267 fallback_tick_pending_ = false;
270 } 268 }
271 269
272 void SynchronousCompositorOutputSurface::FallbackTickFired() { 270 void SynchronousCompositorFrameSink::FallbackTickFired() {
273 DCHECK(CalledOnValidThread()); 271 DCHECK(CalledOnValidThread());
274 TRACE_EVENT0("renderer", 272 TRACE_EVENT0("renderer", "SynchronousCompositorFrameSink::FallbackTickFired");
275 "SynchronousCompositorOutputSurface::FallbackTickFired");
276 base::AutoReset<bool> in_fallback_tick(&fallback_tick_running_, true); 273 base::AutoReset<bool> in_fallback_tick(&fallback_tick_running_, true);
277 SkBitmap bitmap; 274 SkBitmap bitmap;
278 bitmap.allocN32Pixels(1, 1); 275 bitmap.allocN32Pixels(1, 1);
279 bitmap.eraseColor(0); 276 bitmap.eraseColor(0);
280 SkCanvas canvas(bitmap); 277 SkCanvas canvas(bitmap);
281 fallback_tick_pending_ = false; 278 fallback_tick_pending_ = false;
282 DemandDrawSw(&canvas); 279 DemandDrawSw(&canvas);
283 } 280 }
284 281
285 void SynchronousCompositorOutputSurface::Invalidate() { 282 void SynchronousCompositorFrameSink::Invalidate() {
286 DCHECK(CalledOnValidThread()); 283 DCHECK(CalledOnValidThread());
287 if (sync_client_) 284 if (sync_client_)
288 sync_client_->Invalidate(); 285 sync_client_->Invalidate();
289 286
290 if (!fallback_tick_pending_) { 287 if (!fallback_tick_pending_) {
291 fallback_tick_.Reset( 288 fallback_tick_.Reset(
292 base::Bind(&SynchronousCompositorOutputSurface::FallbackTickFired, 289 base::Bind(&SynchronousCompositorFrameSink::FallbackTickFired,
293 base::Unretained(this))); 290 base::Unretained(this)));
294 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 291 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
295 FROM_HERE, fallback_tick_.callback(), 292 FROM_HERE, fallback_tick_.callback(),
296 base::TimeDelta::FromMilliseconds(kFallbackTickTimeoutInMilliseconds)); 293 base::TimeDelta::FromMilliseconds(kFallbackTickTimeoutInMilliseconds));
297 fallback_tick_pending_ = true; 294 fallback_tick_pending_ = true;
298 } 295 }
299 } 296 }
300 297
301 void SynchronousCompositorOutputSurface::BindFramebuffer() { 298 void SynchronousCompositorFrameSink::BindFramebuffer() {
302 // This is a delegating output surface, no framebuffer/direct drawing support. 299 // This is a delegating output surface, no framebuffer/direct drawing support.
303 NOTREACHED(); 300 NOTREACHED();
304 } 301 }
305 302
306 uint32_t SynchronousCompositorOutputSurface::GetFramebufferCopyTextureFormat() { 303 uint32_t SynchronousCompositorFrameSink::GetFramebufferCopyTextureFormat() {
307 // This is a delegating output surface, no framebuffer/direct drawing support. 304 // This is a delegating output surface, no framebuffer/direct drawing support.
308 NOTREACHED(); 305 NOTREACHED();
309 return 0; 306 return 0;
310 } 307 }
311 308
312 void SynchronousCompositorOutputSurface::DemandDrawHw( 309 void SynchronousCompositorFrameSink::DemandDrawHw(
313 const gfx::Size& viewport_size, 310 const gfx::Size& viewport_size,
314 const gfx::Rect& viewport_rect_for_tile_priority, 311 const gfx::Rect& viewport_rect_for_tile_priority,
315 const gfx::Transform& transform_for_tile_priority) { 312 const gfx::Transform& transform_for_tile_priority) {
316 DCHECK(CalledOnValidThread()); 313 DCHECK(CalledOnValidThread());
317 DCHECK(HasClient()); 314 DCHECK(HasClient());
318 DCHECK(context_provider_.get()); 315 DCHECK(context_provider_.get());
319 CancelFallbackTick(); 316 CancelFallbackTick();
320 317
321 client_->SetExternalTilePriorityConstraints(viewport_rect_for_tile_priority, 318 client_->SetExternalTilePriorityConstraints(viewport_rect_for_tile_priority,
322 transform_for_tile_priority); 319 transform_for_tile_priority);
323 InvokeComposite(gfx::Transform(), gfx::Rect(viewport_size)); 320 InvokeComposite(gfx::Transform(), gfx::Rect(viewport_size));
324 } 321 }
325 322
326 void SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { 323 void SynchronousCompositorFrameSink::DemandDrawSw(SkCanvas* canvas) {
327 DCHECK(CalledOnValidThread()); 324 DCHECK(CalledOnValidThread());
328 DCHECK(canvas); 325 DCHECK(canvas);
329 DCHECK(!current_sw_canvas_); 326 DCHECK(!current_sw_canvas_);
330 CancelFallbackTick(); 327 CancelFallbackTick();
331 328
332 base::AutoReset<SkCanvas*> canvas_resetter(&current_sw_canvas_, canvas); 329 base::AutoReset<SkCanvas*> canvas_resetter(&current_sw_canvas_, canvas);
333 330
334 SkIRect canvas_clip; 331 SkIRect canvas_clip;
335 canvas->getClipDeviceBounds(&canvas_clip); 332 canvas->getClipDeviceBounds(&canvas_clip);
336 gfx::Rect viewport = gfx::SkIRectToRect(canvas_clip); 333 gfx::Rect viewport = gfx::SkIRectToRect(canvas_clip);
337 334
338 gfx::Transform transform(gfx::Transform::kSkipInitialization); 335 gfx::Transform transform(gfx::Transform::kSkipInitialization);
339 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. 336 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4.
340 337
341 base::AutoReset<bool> set_in_software_draw(&in_software_draw_, true); 338 base::AutoReset<bool> set_in_software_draw(&in_software_draw_, true);
342 display_->SetExternalViewport(viewport); 339 display_->SetExternalViewport(viewport);
343 display_->SetExternalClip(viewport); 340 display_->SetExternalClip(viewport);
344 software_output_surface_->SetSurfaceSize( 341 software_compositor_frame_sink_->SetSurfaceSize(
345 gfx::SkISizeToSize(canvas->getBaseLayerSize())); 342 gfx::SkISizeToSize(canvas->getBaseLayerSize()));
346 InvokeComposite(transform, viewport); 343 InvokeComposite(transform, viewport);
347 } 344 }
348 345
349 void SynchronousCompositorOutputSurface::InvokeComposite( 346 void SynchronousCompositorFrameSink::InvokeComposite(
350 const gfx::Transform& transform, 347 const gfx::Transform& transform,
351 const gfx::Rect& viewport) { 348 const gfx::Rect& viewport) {
352 gfx::Transform adjusted_transform = transform; 349 gfx::Transform adjusted_transform = transform;
353 adjusted_transform.matrix().postTranslate(-viewport.x(), -viewport.y(), 0); 350 adjusted_transform.matrix().postTranslate(-viewport.x(), -viewport.y(), 0);
354 did_swap_ = false; 351 did_swap_ = false;
355 client_->OnDraw(adjusted_transform, viewport, in_software_draw_); 352 client_->OnDraw(adjusted_transform, viewport, in_software_draw_);
356 353
357 if (did_swap_) { 354 if (did_swap_) {
358 // This must happen after unwinding the stack and leaving the compositor. 355 // This must happen after unwinding the stack and leaving the compositor.
359 // Usually it is a separate task but we just defer it until OnDraw completes 356 // Usually it is a separate task but we just defer it until OnDraw completes
360 // instead. 357 // instead.
361 client_->DidSwapBuffersComplete(); 358 client_->DidSwapBuffersComplete();
362 } 359 }
363 } 360 }
364 361
365 void SynchronousCompositorOutputSurface::OnReclaimResources( 362 void SynchronousCompositorFrameSink::OnReclaimResources(
366 uint32_t output_surface_id, 363 uint32_t compositor_frame_sink_id,
367 const cc::ReturnedResourceArray& resources) { 364 const cc::ReturnedResourceArray& resources) {
368 // Ignore message if it's a stale one coming from a different output surface 365 // Ignore message if it's a stale one coming from a different output surface
369 // (e.g. after a lost context). 366 // (e.g. after a lost context).
370 if (output_surface_id != output_surface_id_) 367 if (compositor_frame_sink_id != compositor_frame_sink_id_)
371 return; 368 return;
372 client_->ReclaimResources(resources); 369 client_->ReclaimResources(resources);
373 } 370 }
374 371
375 void SynchronousCompositorOutputSurface::SetMemoryPolicy(size_t bytes_limit) { 372 void SynchronousCompositorFrameSink::SetMemoryPolicy(size_t bytes_limit) {
376 DCHECK(CalledOnValidThread()); 373 DCHECK(CalledOnValidThread());
377 bool became_zero = memory_policy_.bytes_limit_when_visible && !bytes_limit; 374 bool became_zero = memory_policy_.bytes_limit_when_visible && !bytes_limit;
378 bool became_non_zero = 375 bool became_non_zero =
379 !memory_policy_.bytes_limit_when_visible && bytes_limit; 376 !memory_policy_.bytes_limit_when_visible && bytes_limit;
380 memory_policy_.bytes_limit_when_visible = bytes_limit; 377 memory_policy_.bytes_limit_when_visible = bytes_limit;
381 memory_policy_.num_resources_limit = kNumResourcesLimit; 378 memory_policy_.num_resources_limit = kNumResourcesLimit;
382 379
383 if (client_) 380 if (client_)
384 client_->SetMemoryPolicy(memory_policy_); 381 client_->SetMemoryPolicy(memory_policy_);
385 382
386 if (became_zero) { 383 if (became_zero) {
387 // This is small hack to drop context resources without destroying it 384 // This is small hack to drop context resources without destroying it
388 // when this compositor is put into the background. 385 // when this compositor is put into the background.
389 context_provider()->ContextSupport()->SetAggressivelyFreeResources( 386 context_provider()->ContextSupport()->SetAggressivelyFreeResources(
390 true /* aggressively_free_resources */); 387 true /* aggressively_free_resources */);
391 } else if (became_non_zero) { 388 } else if (became_non_zero) {
392 context_provider()->ContextSupport()->SetAggressivelyFreeResources( 389 context_provider()->ContextSupport()->SetAggressivelyFreeResources(
393 false /* aggressively_free_resources */); 390 false /* aggressively_free_resources */);
394 } 391 }
395 } 392 }
396 393
397 void SynchronousCompositorOutputSurface::DidActivatePendingTree() { 394 void SynchronousCompositorFrameSink::DidActivatePendingTree() {
398 DCHECK(CalledOnValidThread()); 395 DCHECK(CalledOnValidThread());
399 if (sync_client_) 396 if (sync_client_)
400 sync_client_->DidActivatePendingTree(); 397 sync_client_->DidActivatePendingTree();
401 DeliverMessages(); 398 DeliverMessages();
402 } 399 }
403 400
404 void SynchronousCompositorOutputSurface::DeliverMessages() { 401 void SynchronousCompositorFrameSink::DeliverMessages() {
405 std::vector<std::unique_ptr<IPC::Message>> messages; 402 std::vector<std::unique_ptr<IPC::Message>> messages;
406 std::unique_ptr<FrameSwapMessageQueue::SendMessageScope> send_message_scope = 403 std::unique_ptr<FrameSwapMessageQueue::SendMessageScope> send_message_scope =
407 frame_swap_message_queue_->AcquireSendMessageScope(); 404 frame_swap_message_queue_->AcquireSendMessageScope();
408 frame_swap_message_queue_->DrainMessages(&messages); 405 frame_swap_message_queue_->DrainMessages(&messages);
409 for (auto& msg : messages) { 406 for (auto& msg : messages) {
410 Send(msg.release()); 407 Send(msg.release());
411 } 408 }
412 } 409 }
413 410
414 bool SynchronousCompositorOutputSurface::Send(IPC::Message* message) { 411 bool SynchronousCompositorFrameSink::Send(IPC::Message* message) {
415 DCHECK(CalledOnValidThread()); 412 DCHECK(CalledOnValidThread());
416 return sender_->Send(message); 413 return sender_->Send(message);
417 } 414 }
418 415
419 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { 416 bool SynchronousCompositorFrameSink::CalledOnValidThread() const {
420 return thread_checker_.CalledOnValidThread(); 417 return thread_checker_.CalledOnValidThread();
421 } 418 }
422 419
423 void SynchronousCompositorOutputSurface::ReturnResources( 420 void SynchronousCompositorFrameSink::ReturnResources(
424 const cc::ReturnedResourceArray& resources) { 421 const cc::ReturnedResourceArray& resources) {
425 DCHECK(resources.empty()); 422 DCHECK(resources.empty());
426 client_->ReclaimResources(resources); 423 client_->ReclaimResources(resources);
427 } 424 }
428 425
429 void SynchronousCompositorOutputSurface::SetBeginFrameSource( 426 void SynchronousCompositorFrameSink::SetBeginFrameSource(
430 cc::BeginFrameSource* begin_frame_source) { 427 cc::BeginFrameSource* begin_frame_source) {
431 // Software output is synchronous and doesn't use a BeginFrameSource. 428 // Software output is synchronous and doesn't use a BeginFrameSource.
432 NOTREACHED(); 429 NOTREACHED();
433 } 430 }
434 431
435 } // namespace content 432 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698