| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/browser/renderer_host/offscreen_canvas_surface_impl.h" | 5 #include "content/browser/renderer_host/offscreen_canvas_surface_impl.h" |
| 6 | 6 |
| 7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
| 8 #include "cc/surfaces/surface.h" | 8 #include "cc/surfaces/surface.h" |
| 9 #include "cc/surfaces/surface_manager.h" | 9 #include "cc/surfaces/surface_manager.h" |
| 10 #include "content/browser/compositor/surface_utils.h" | 10 #include "content/browser/compositor/surface_utils.h" |
| 11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 | 14 |
| 15 // static | 15 // static |
| 16 void OffscreenCanvasSurfaceImpl::Create( | 16 void OffscreenCanvasSurfaceImpl::Create( |
| 17 mojo::InterfaceRequest<blink::mojom::OffscreenCanvasSurface> request) { | 17 mojo::InterfaceRequest<blink::mojom::OffscreenCanvasSurface> request) { |
| 18 // |binding_| will take ownership of OffscreenCanvasSurfaceImpl | 18 // |binding_| will take ownership of OffscreenCanvasSurfaceImpl |
| 19 new OffscreenCanvasSurfaceImpl(std::move(request)); | 19 new OffscreenCanvasSurfaceImpl(std::move(request)); |
| 20 } | 20 } |
| 21 | 21 |
| 22 OffscreenCanvasSurfaceImpl::OffscreenCanvasSurfaceImpl( | 22 OffscreenCanvasSurfaceImpl::OffscreenCanvasSurfaceImpl( |
| 23 mojo::InterfaceRequest<blink::mojom::OffscreenCanvasSurface> request) | 23 mojo::InterfaceRequest<blink::mojom::OffscreenCanvasSurface> request) |
| 24 : id_allocator_(CreateSurfaceIdAllocator()), | 24 : id_allocator_(new cc::SurfaceIdAllocator(AllocateSurfaceClientId())), |
| 25 binding_(this, std::move(request)) {} | 25 binding_(this, std::move(request)) {} |
| 26 | 26 |
| 27 OffscreenCanvasSurfaceImpl::~OffscreenCanvasSurfaceImpl() { | 27 OffscreenCanvasSurfaceImpl::~OffscreenCanvasSurfaceImpl() { |
| 28 if (!GetSurfaceManager()) { | 28 if (!GetSurfaceManager()) { |
| 29 // Inform both members that SurfaceManager's no longer alive to | 29 // Inform both members that SurfaceManager's no longer alive to |
| 30 // avoid their destruction errors. | 30 // avoid their destruction errors. |
| 31 if (surface_factory_) | 31 if (surface_factory_) |
| 32 surface_factory_->DidDestroySurfaceManager(); | 32 surface_factory_->DidDestroySurfaceManager(); |
| 33 if (id_allocator_) | |
| 34 id_allocator_->DidDestroySurfaceManager(); | |
| 35 } | 33 } |
| 36 surface_factory_->Destroy(surface_id_); | 34 surface_factory_->Destroy(surface_id_); |
| 37 } | 35 } |
| 38 | 36 |
| 39 void OffscreenCanvasSurfaceImpl::GetSurfaceId( | 37 void OffscreenCanvasSurfaceImpl::GetSurfaceId( |
| 40 const GetSurfaceIdCallback& callback) { | 38 const GetSurfaceIdCallback& callback) { |
| 41 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 39 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 42 | 40 |
| 43 surface_id_ = id_allocator_->GenerateId(); | 41 surface_id_ = id_allocator_->GenerateId(); |
| 44 | 42 |
| 45 callback.Run(surface_id_); | 43 callback.Run(surface_id_); |
| 46 } | 44 } |
| 47 | 45 |
| 48 void OffscreenCanvasSurfaceImpl::RequestSurfaceCreation( | 46 void OffscreenCanvasSurfaceImpl::RequestSurfaceCreation( |
| 49 const cc::SurfaceId& surface_id) { | 47 const cc::SurfaceId& surface_id) { |
| 50 cc::SurfaceManager* manager = GetSurfaceManager(); | 48 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 51 if (!surface_factory_) { | 49 if (!surface_factory_) { |
| 52 surface_factory_ = base::MakeUnique<cc::SurfaceFactory>(manager, this); | 50 surface_factory_ = base::MakeUnique<cc::SurfaceFactory>( |
| 51 surface_id.client_id(), manager, this); |
| 53 } | 52 } |
| 54 surface_factory_->Create(surface_id); | 53 surface_factory_->Create(surface_id); |
| 55 } | 54 } |
| 56 | 55 |
| 57 void OffscreenCanvasSurfaceImpl::Require(const cc::SurfaceId& surface_id, | 56 void OffscreenCanvasSurfaceImpl::Require(const cc::SurfaceId& surface_id, |
| 58 const cc::SurfaceSequence& sequence) { | 57 const cc::SurfaceSequence& sequence) { |
| 59 cc::SurfaceManager* manager = GetSurfaceManager(); | 58 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 60 cc::Surface* surface = manager->GetSurfaceForId(surface_id); | 59 cc::Surface* surface = manager->GetSurfaceForId(surface_id); |
| 61 if (!surface) { | 60 if (!surface) { |
| 62 DLOG(ERROR) << "Attempting to require callback on nonexistent surface"; | 61 DLOG(ERROR) << "Attempting to require callback on nonexistent surface"; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 78 const cc::ReturnedResourceArray& resources) {} | 77 const cc::ReturnedResourceArray& resources) {} |
| 79 | 78 |
| 80 void OffscreenCanvasSurfaceImpl::WillDrawSurface(const cc::SurfaceId& id, | 79 void OffscreenCanvasSurfaceImpl::WillDrawSurface(const cc::SurfaceId& id, |
| 81 const gfx::Rect& damage_rect) { | 80 const gfx::Rect& damage_rect) { |
| 82 } | 81 } |
| 83 | 82 |
| 84 void OffscreenCanvasSurfaceImpl::SetBeginFrameSource( | 83 void OffscreenCanvasSurfaceImpl::SetBeginFrameSource( |
| 85 cc::BeginFrameSource* begin_frame_source) {} | 84 cc::BeginFrameSource* begin_frame_source) {} |
| 86 | 85 |
| 87 } // namespace content | 86 } // namespace content |
| OLD | NEW |