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_output_surface.h" | 5 #include "content/renderer/android/synchronous_compositor_output_surface.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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 namespace content { | 42 namespace content { |
| 43 | 43 |
| 44 namespace { | 44 namespace { |
| 45 | 45 |
| 46 const int64_t kFallbackTickTimeoutInMilliseconds = 100; | 46 const int64_t kFallbackTickTimeoutInMilliseconds = 100; |
| 47 const uint32_t kCompositorClientId = 1; | 47 const uint32_t kCompositorClientId = 1; |
| 48 | 48 |
| 49 // Do not limit number of resources, so use an unrealistically high value. | 49 // Do not limit number of resources, so use an unrealistically high value. |
| 50 const size_t kNumResourcesLimit = 10 * 1000 * 1000; | 50 const size_t kNumResourcesLimit = 10 * 1000 * 1000; |
| 51 | 51 |
| 52 } // namespace | |
| 53 | |
| 54 class SoftwareDevice : public cc::SoftwareOutputDevice { | 52 class SoftwareDevice : public cc::SoftwareOutputDevice { |
| 55 public: | 53 public: |
| 56 SoftwareDevice(SkCanvas** canvas) : canvas_(canvas) {} | 54 SoftwareDevice(SkCanvas** canvas) : canvas_(canvas) {} |
| 57 | 55 |
| 58 void Resize(const gfx::Size& pixel_size, float scale_factor) override { | 56 void Resize(const gfx::Size& pixel_size, float scale_factor) override { |
| 59 // Intentional no-op: canvas size is controlled by the embedder. | 57 // Intentional no-op: canvas size is controlled by the embedder. |
| 60 } | 58 } |
| 61 SkCanvas* BeginPaint(const gfx::Rect& damage_rect) override { | 59 SkCanvas* BeginPaint(const gfx::Rect& damage_rect) override { |
| 62 DCHECK(*canvas_) << "BeginPaint with no canvas set"; | 60 DCHECK(*canvas_) << "BeginPaint with no canvas set"; |
| 63 return *canvas_; | 61 return *canvas_; |
| 64 } | 62 } |
| 65 void EndPaint() override {} | 63 void EndPaint() override {} |
| 66 | 64 |
| 67 private: | 65 private: |
| 68 SkCanvas** canvas_; | 66 SkCanvas** canvas_; |
| 69 | 67 |
| 70 DISALLOW_COPY_AND_ASSIGN(SoftwareDevice); | 68 DISALLOW_COPY_AND_ASSIGN(SoftwareDevice); |
| 71 }; | 69 }; |
| 72 | 70 |
| 73 class SoftwareOutputSurface : public cc::OutputSurface { | 71 } // namespace |
| 72 | |
| 73 class SynchronousCompositorOutputSurface::SoftwareOutputSurface | |
| 74 : public cc::OutputSurface { | |
| 74 public: | 75 public: |
| 75 SoftwareOutputSurface(std::unique_ptr<SoftwareDevice> software_device) | 76 SoftwareOutputSurface(std::unique_ptr<SoftwareDevice> software_device) |
| 76 : cc::OutputSurface(nullptr, nullptr, std::move(software_device)) {} | 77 : cc::OutputSurface(nullptr, nullptr, std::move(software_device)) {} |
| 77 | 78 |
| 78 // cc::OutputSurface implementation. | 79 // cc::OutputSurface implementation. |
| 79 uint32_t GetFramebufferCopyTextureFormat() override { return 0; } | 80 uint32_t GetFramebufferCopyTextureFormat() override { return 0; } |
| 80 void SwapBuffers(cc::CompositorFrame frame) override {} | 81 void SwapBuffers(cc::CompositorFrame frame) override {} |
| 82 void Reshape(const gfx::Size& size, | |
| 83 float scale_factor, | |
| 84 const gfx::ColorSpace& color_space, | |
| 85 bool has_alpha) override { | |
| 86 // Intentional no-op. Surface size controlled by embedder. | |
| 87 } | |
| 88 | |
| 89 void SetSurfaceSize(const gfx::Size surface_size) { | |
| 90 surface_size_ = surface_size; | |
| 91 } | |
| 81 }; | 92 }; |
| 82 | 93 |
| 83 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( | 94 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( |
| 84 scoped_refptr<cc::ContextProvider> context_provider, | 95 scoped_refptr<cc::ContextProvider> context_provider, |
| 85 scoped_refptr<cc::ContextProvider> worker_context_provider, | 96 scoped_refptr<cc::ContextProvider> worker_context_provider, |
| 86 int routing_id, | 97 int routing_id, |
| 87 uint32_t output_surface_id, | 98 uint32_t output_surface_id, |
| 88 SynchronousCompositorRegistry* registry, | 99 SynchronousCompositorRegistry* registry, |
| 89 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue) | 100 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue) |
| 90 : cc::OutputSurface(std::move(context_provider), | 101 : cc::OutputSurface(std::move(context_provider), |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 base::Unretained(this))); | 153 base::Unretained(this))); |
| 143 registry_->RegisterOutputSurface(routing_id_, this); | 154 registry_->RegisterOutputSurface(routing_id_, this); |
| 144 registered_ = true; | 155 registered_ = true; |
| 145 | 156 |
| 146 surface_manager_->RegisterSurfaceClientId(surface_id_allocator_->client_id()); | 157 surface_manager_->RegisterSurfaceClientId(surface_id_allocator_->client_id()); |
| 147 surface_manager_->RegisterSurfaceFactoryClient( | 158 surface_manager_->RegisterSurfaceFactoryClient( |
| 148 surface_id_allocator_->client_id(), this); | 159 surface_id_allocator_->client_id(), this); |
| 149 | 160 |
| 150 cc::RendererSettings software_renderer_settings; | 161 cc::RendererSettings software_renderer_settings; |
| 151 | 162 |
| 163 std::unique_ptr<SoftwareOutputSurface> output_surface( | |
| 164 new SoftwareOutputSurface( | |
| 165 base::MakeUnique<SoftwareDevice>(¤t_sw_canvas_))); | |
| 166 software_output_surface_ = output_surface.get(); | |
| 167 | |
| 152 // The shared_bitmap_manager and gpu_memory_buffer_manager here are null as | 168 // The shared_bitmap_manager and gpu_memory_buffer_manager here are null as |
| 153 // this Display is only used for resourcesless software draws, where no | 169 // this Display is only used for resourcesless software draws, where no |
| 154 // resources are included in the frame swapped from the compositor. So there | 170 // resources are included in the frame swapped from the compositor. So there |
| 155 // is no need for these. | 171 // is no need for these. |
| 156 display_.reset(new cc::Display( | 172 display_.reset(new cc::Display( |
| 157 nullptr /* shared_bitmap_manager */, | 173 nullptr /* shared_bitmap_manager */, |
| 158 nullptr /* gpu_memory_buffer_manager */, software_renderer_settings, | 174 nullptr /* gpu_memory_buffer_manager */, software_renderer_settings, |
| 159 nullptr /* begin_frame_source */, | 175 nullptr /* begin_frame_source */, std::move(output_surface), |
| 160 base::MakeUnique<SoftwareOutputSurface>( | |
| 161 base::MakeUnique<SoftwareDevice>(¤t_sw_canvas_)), | |
| 162 nullptr /* scheduler */, nullptr /* texture_mailbox_deleter */)); | 176 nullptr /* scheduler */, nullptr /* texture_mailbox_deleter */)); |
| 163 display_->Initialize(&display_client_, surface_manager_.get(), | 177 display_->Initialize(&display_client_, surface_manager_.get(), |
| 164 surface_id_allocator_->client_id()); | 178 surface_id_allocator_->client_id()); |
| 165 return true; | 179 return true; |
| 166 } | 180 } |
| 167 | 181 |
| 168 void SynchronousCompositorOutputSurface::DetachFromClient() { | 182 void SynchronousCompositorOutputSurface::DetachFromClient() { |
| 169 DCHECK(CalledOnValidThread()); | 183 DCHECK(CalledOnValidThread()); |
| 170 if (registered_) { | 184 if (registered_) { |
| 171 registry_->UnregisterOutputSurface(routing_id_, this); | 185 registry_->UnregisterOutputSurface(routing_id_, this); |
| 172 } | 186 } |
| 173 client_->SetTreeActivationCallback(base::Closure()); | 187 client_->SetTreeActivationCallback(base::Closure()); |
| 174 if (!delegated_surface_id_.is_null()) | 188 if (!delegated_surface_id_.is_null()) |
| 175 surface_factory_->Destroy(delegated_surface_id_); | 189 surface_factory_->Destroy(delegated_surface_id_); |
| 176 surface_manager_->UnregisterSurfaceFactoryClient( | 190 surface_manager_->UnregisterSurfaceFactoryClient( |
| 177 surface_id_allocator_->client_id()); | 191 surface_id_allocator_->client_id()); |
| 178 surface_manager_->InvalidateSurfaceClientId( | 192 surface_manager_->InvalidateSurfaceClientId( |
| 179 surface_id_allocator_->client_id()); | 193 surface_id_allocator_->client_id()); |
| 194 software_output_surface_ = nullptr; | |
| 180 display_ = nullptr; | 195 display_ = nullptr; |
| 181 surface_factory_ = nullptr; | 196 surface_factory_ = nullptr; |
| 182 surface_id_allocator_ = nullptr; | 197 surface_id_allocator_ = nullptr; |
| 183 surface_manager_ = nullptr; | 198 surface_manager_ = nullptr; |
| 184 cc::OutputSurface::DetachFromClient(); | 199 cc::OutputSurface::DetachFromClient(); |
| 185 CancelFallbackTick(); | 200 CancelFallbackTick(); |
| 186 } | 201 } |
| 187 | 202 |
| 188 void SynchronousCompositorOutputSurface::Reshape( | 203 void SynchronousCompositorOutputSurface::Reshape( |
| 189 const gfx::Size& size, | 204 const gfx::Size& size, |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 const gfx::Transform& transform, | 306 const gfx::Transform& transform, |
| 292 const gfx::Rect& viewport, | 307 const gfx::Rect& viewport, |
| 293 const gfx::Rect& clip, | 308 const gfx::Rect& clip, |
| 294 const gfx::Rect& viewport_rect_for_tile_priority, | 309 const gfx::Rect& viewport_rect_for_tile_priority, |
| 295 const gfx::Transform& transform_for_tile_priority) { | 310 const gfx::Transform& transform_for_tile_priority) { |
| 296 DCHECK(CalledOnValidThread()); | 311 DCHECK(CalledOnValidThread()); |
| 297 DCHECK(HasClient()); | 312 DCHECK(HasClient()); |
| 298 DCHECK(context_provider_.get()); | 313 DCHECK(context_provider_.get()); |
| 299 CancelFallbackTick(); | 314 CancelFallbackTick(); |
| 300 | 315 |
| 301 surface_size_ = surface_size; | |
| 302 client_->SetExternalTilePriorityConstraints(viewport_rect_for_tile_priority, | 316 client_->SetExternalTilePriorityConstraints(viewport_rect_for_tile_priority, |
| 303 transform_for_tile_priority); | 317 transform_for_tile_priority); |
| 304 InvokeComposite(transform, viewport, clip); | 318 InvokeComposite(transform, viewport, clip); |
| 305 } | 319 } |
| 306 | 320 |
| 307 void SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { | 321 void SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { |
| 308 DCHECK(CalledOnValidThread()); | 322 DCHECK(CalledOnValidThread()); |
| 309 DCHECK(canvas); | 323 DCHECK(canvas); |
| 310 DCHECK(!current_sw_canvas_); | 324 DCHECK(!current_sw_canvas_); |
| 311 CancelFallbackTick(); | 325 CancelFallbackTick(); |
| 312 | 326 |
| 313 base::AutoReset<SkCanvas*> canvas_resetter(¤t_sw_canvas_, canvas); | 327 base::AutoReset<SkCanvas*> canvas_resetter(¤t_sw_canvas_, canvas); |
| 314 | 328 |
| 315 SkIRect canvas_clip; | 329 SkIRect canvas_clip; |
| 316 canvas->getClipDeviceBounds(&canvas_clip); | 330 canvas->getClipDeviceBounds(&canvas_clip); |
| 317 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip); | 331 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip); |
| 318 | 332 |
| 319 gfx::Transform transform(gfx::Transform::kSkipInitialization); | 333 gfx::Transform transform(gfx::Transform::kSkipInitialization); |
| 320 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. | 334 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. |
| 321 | 335 |
| 322 surface_size_ = gfx::Size(canvas->getBaseLayerSize().width(), | |
| 323 canvas->getBaseLayerSize().height()); | |
| 324 base::AutoReset<bool> set_in_software_draw(&in_software_draw_, true); | 336 base::AutoReset<bool> set_in_software_draw(&in_software_draw_, true); |
| 337 display_->SetExternalViewport(clip); | |
| 338 display_->SetExternalClip(clip); | |
| 339 gfx::Size surface_size(canvas->getBaseLayerSize().width(), | |
|
danakj
2016/07/27 22:18:03
nit: You could do s_o_s_->SetSurfaceSize(gfx::SkIS
boliu
2016/07/27 22:22:50
Done.
| |
| 340 canvas->getBaseLayerSize().height()); | |
| 341 software_output_surface_->SetSurfaceSize(surface_size); | |
| 325 InvokeComposite(transform, clip, clip); | 342 InvokeComposite(transform, clip, clip); |
| 326 } | 343 } |
| 327 | 344 |
| 328 void SynchronousCompositorOutputSurface::InvokeComposite( | 345 void SynchronousCompositorOutputSurface::InvokeComposite( |
| 329 const gfx::Transform& transform, | 346 const gfx::Transform& transform, |
| 330 const gfx::Rect& viewport, | 347 const gfx::Rect& viewport, |
| 331 const gfx::Rect& clip) { | 348 const gfx::Rect& clip) { |
| 332 gfx::Transform adjusted_transform = transform; | 349 gfx::Transform adjusted_transform = transform; |
| 333 adjusted_transform.matrix().postTranslate(-viewport.x(), -viewport.y(), 0); | 350 adjusted_transform.matrix().postTranslate(-viewport.x(), -viewport.y(), 0); |
| 334 did_swap_ = false; | 351 did_swap_ = false; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 406 client_->ReclaimResources(resources); | 423 client_->ReclaimResources(resources); |
| 407 } | 424 } |
| 408 | 425 |
| 409 void SynchronousCompositorOutputSurface::SetBeginFrameSource( | 426 void SynchronousCompositorOutputSurface::SetBeginFrameSource( |
| 410 cc::BeginFrameSource* begin_frame_source) { | 427 cc::BeginFrameSource* begin_frame_source) { |
| 411 // Software output is synchronous and doesn't use a BeginFrameSource. | 428 // Software output is synchronous and doesn't use a BeginFrameSource. |
| 412 NOTREACHED(); | 429 NOTREACHED(); |
| 413 } | 430 } |
| 414 | 431 |
| 415 } // namespace content | 432 } // namespace content |
| OLD | NEW |