Chromium Code Reviews| 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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_->RegisterSurfaceClientId(surface_id_allocator_->client_id()); |
| 171 surface_manager_->RegisterSurfaceFactoryClient( | 171 surface_manager_->RegisterSurfaceFactoryClient( |
| 172 surface_id_allocator_->client_id(), this); | 172 surface_id_allocator_->client_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 auto output_surface = base::MakeUnique<SoftwareOutputSurface>( |
| 177 new SoftwareOutputSurface( | 177 base::MakeUnique<SoftwareDevice>(¤t_sw_canvas_)); |
| 178 base::MakeUnique<SoftwareDevice>(¤t_sw_canvas_))); | 178 software_output_surface_ = output_surface.get(); |
| 179 software_compositor_frame_sink_ = compositor_frame_sink.get(); | |
| 180 | 179 |
| 181 // The shared_bitmap_manager and gpu_memory_buffer_manager here are null as | 180 // 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 | 181 // this Display is only used for resourcesless software draws, where no |
| 183 // resources are included in the frame swapped from the compositor. So there | 182 // resources are included in the frame swapped from the compositor. So there |
| 184 // is no need for these. | 183 // is no need for these. |
| 185 display_.reset(new cc::Display( | 184 display_.reset(new cc::Display( |
| 186 nullptr /* shared_bitmap_manager */, | 185 nullptr /* shared_bitmap_manager */, |
| 187 nullptr /* gpu_memory_buffer_manager */, software_renderer_settings, | 186 nullptr /* gpu_memory_buffer_manager */, software_renderer_settings, |
| 188 nullptr /* begin_frame_source */, std::move(compositor_frame_sink), | 187 nullptr /* begin_frame_source */, std::move(output_surface), |
| 189 nullptr /* scheduler */, nullptr /* texture_mailbox_deleter */)); | 188 nullptr /* scheduler */, nullptr /* texture_mailbox_deleter */)); |
| 190 display_->Initialize(&display_client_, surface_manager_.get(), | 189 display_->Initialize(&display_client_, surface_manager_.get(), |
| 191 surface_id_allocator_->client_id()); | 190 surface_id_allocator_->client_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( |
| 207 surface_id_allocator_->client_id()); | 206 surface_id_allocator_->client_id()); |
| 208 surface_manager_->InvalidateSurfaceClientId( | 207 surface_manager_->InvalidateSurfaceClientId( |
| 209 surface_id_allocator_->client_id()); | 208 surface_id_allocator_->client_id()); |
| 210 software_compositor_frame_sink_ = nullptr; | 209 software_output_surface_ = nullptr; |
| 211 display_ = nullptr; | 210 display_ = nullptr; |
| 212 surface_factory_ = nullptr; | 211 surface_factory_ = nullptr; |
| 213 surface_id_allocator_ = nullptr; | 212 surface_id_allocator_ = nullptr; |
| 214 surface_manager_ = nullptr; | 213 surface_manager_ = nullptr; |
| 215 cc::CompositorFrameSink::DetachFromClient(); | 214 cc::CompositorFrameSink::DetachFromClient(); |
| 216 CancelFallbackTick(); | 215 CancelFallbackTick(); |
| 217 } | 216 } |
| 218 | 217 |
| 219 static void NoOpDrawCallback() {} | 218 static void NoOpDrawCallback() {} |
| 220 | 219 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 238 swap_frame.metadata = frame.metadata.Clone(); | 237 swap_frame.metadata = frame.metadata.Clone(); |
| 239 | 238 |
| 240 if (delegated_surface_id_.is_null()) { | 239 if (delegated_surface_id_.is_null()) { |
| 241 delegated_surface_id_ = surface_id_allocator_->GenerateId(); | 240 delegated_surface_id_ = surface_id_allocator_->GenerateId(); |
| 242 surface_factory_->Create(delegated_surface_id_); | 241 surface_factory_->Create(delegated_surface_id_); |
| 243 } | 242 } |
| 244 | 243 |
| 245 display_->SetSurfaceId(delegated_surface_id_, | 244 display_->SetSurfaceId(delegated_surface_id_, |
| 246 frame.metadata.device_scale_factor); | 245 frame.metadata.device_scale_factor); |
| 247 | 246 |
| 248 gfx::Size frame_size = | 247 // This size covers the entire external clip given to DemandDrawSw(). The |
| 249 frame.delegated_frame_data->render_pass_list.back()->output_rect.size(); | 248 // CompositorFrame here could be either smaller than this size (we're |
| 250 display_->Resize(frame_size); | 249 // drawing an enlarged viewport that extends beyond the layer compositor's |
| 250 // concept of the output size) or larger than this size (we're only drawing | |
| 251 // a portion of the layer compositor's usual output size). | |
| 252 display_->Resize(sw_display_size_for_current_draw_); | |
| 251 | 253 |
| 252 surface_factory_->SubmitCompositorFrame( | 254 surface_factory_->SubmitCompositorFrame( |
| 253 delegated_surface_id_, std::move(frame), base::Bind(&NoOpDrawCallback)); | 255 delegated_surface_id_, std::move(frame), base::Bind(&NoOpDrawCallback)); |
| 254 display_->DrawAndSwap(); | 256 display_->DrawAndSwap(); |
| 255 } else { | 257 } else { |
| 256 // For hardware draws we send the whole frame to the client so it can draw | 258 // For hardware draws we send the whole frame to the client so it can draw |
| 257 // the content in it. | 259 // the content in it. |
| 258 swap_frame = std::move(frame); | 260 swap_frame = std::move(frame); |
| 259 } | 261 } |
| 260 | 262 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 | 320 |
| 319 base::AutoReset<SkCanvas*> canvas_resetter(¤t_sw_canvas_, canvas); | 321 base::AutoReset<SkCanvas*> canvas_resetter(¤t_sw_canvas_, canvas); |
| 320 | 322 |
| 321 SkIRect canvas_clip; | 323 SkIRect canvas_clip; |
| 322 canvas->getClipDeviceBounds(&canvas_clip); | 324 canvas->getClipDeviceBounds(&canvas_clip); |
| 323 gfx::Rect viewport = gfx::SkIRectToRect(canvas_clip); | 325 gfx::Rect viewport = gfx::SkIRectToRect(canvas_clip); |
| 324 | 326 |
| 325 gfx::Transform transform(gfx::Transform::kSkipInitialization); | 327 gfx::Transform transform(gfx::Transform::kSkipInitialization); |
| 326 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. | 328 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. |
| 327 | 329 |
| 330 // We will resize the Display to ensure it draws the entire |viewport| given | |
| 331 // here instead of only the layer compositor's idea of what the viewport is. | |
| 332 sw_display_size_for_current_draw_ = | |
| 333 gfx::Size(viewport.right(), viewport.bottom()); | |
| 334 | |
| 328 base::AutoReset<bool> set_in_software_draw(&in_software_draw_, true); | 335 base::AutoReset<bool> set_in_software_draw(&in_software_draw_, true); |
| 329 display_->SetExternalViewport(viewport); | 336 software_output_surface_->SetSurfaceSize( |
| 330 display_->SetExternalClip(viewport); | |
|
boliu
2016/09/27 23:20:48
keep external clip
apparently the assumption that
danakj
2016/09/29 22:55:52
Done.
| |
| 331 software_compositor_frame_sink_->SetSurfaceSize( | |
| 332 gfx::SkISizeToSize(canvas->getBaseLayerSize())); | 337 gfx::SkISizeToSize(canvas->getBaseLayerSize())); |
|
danakj
2016/09/29 22:55:52
I also removed this call, and made Reshape() store
| |
| 333 InvokeComposite(transform, viewport); | 338 InvokeComposite(transform, viewport); |
| 334 } | 339 } |
| 335 | 340 |
| 336 void SynchronousCompositorFrameSink::InvokeComposite( | 341 void SynchronousCompositorFrameSink::InvokeComposite( |
| 337 const gfx::Transform& transform, | 342 const gfx::Transform& transform, |
| 338 const gfx::Rect& viewport) { | 343 const gfx::Rect& viewport) { |
| 339 gfx::Transform adjusted_transform = transform; | 344 gfx::Transform adjusted_transform = transform; |
| 340 adjusted_transform.matrix().postTranslate(-viewport.x(), -viewport.y(), 0); | 345 adjusted_transform.matrix().postTranslate(-viewport.x(), -viewport.y(), 0); |
|
boliu
2016/09/27 23:20:48
drop this "adjustment"
the matrix contains transl
danakj
2016/09/29 22:55:52
Done.
| |
| 341 did_swap_ = false; | 346 did_swap_ = false; |
| 342 client_->OnDraw(adjusted_transform, viewport, in_software_draw_); | 347 client_->OnDraw(adjusted_transform, viewport, in_software_draw_); |
| 343 | 348 |
| 344 if (did_swap_) { | 349 if (did_swap_) { |
| 345 // This must happen after unwinding the stack and leaving the compositor. | 350 // This must happen after unwinding the stack and leaving the compositor. |
| 346 // Usually it is a separate task but we just defer it until OnDraw completes | 351 // Usually it is a separate task but we just defer it until OnDraw completes |
| 347 // instead. | 352 // instead. |
| 348 client_->DidSwapBuffersComplete(); | 353 client_->DidSwapBuffersComplete(); |
| 349 } | 354 } |
| 350 } | 355 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 413 client_->ReclaimResources(resources); | 418 client_->ReclaimResources(resources); |
| 414 } | 419 } |
| 415 | 420 |
| 416 void SynchronousCompositorFrameSink::SetBeginFrameSource( | 421 void SynchronousCompositorFrameSink::SetBeginFrameSource( |
| 417 cc::BeginFrameSource* begin_frame_source) { | 422 cc::BeginFrameSource* begin_frame_source) { |
| 418 // Software output is synchronous and doesn't use a BeginFrameSource. | 423 // Software output is synchronous and doesn't use a BeginFrameSource. |
| 419 NOTREACHED(); | 424 NOTREACHED(); |
| 420 } | 425 } |
| 421 | 426 |
| 422 } // namespace content | 427 } // namespace content |
| OLD | NEW |