| 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 #include "mojo/public/cpp/bindings/strong_binding.h" | 12 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 | 15 |
| 16 OffscreenCanvasSurfaceImpl::OffscreenCanvasSurfaceImpl() | 16 OffscreenCanvasSurfaceImpl::OffscreenCanvasSurfaceImpl() |
| 17 : id_allocator_(new cc::SurfaceIdAllocator(AllocateSurfaceClientId())) { | 17 : id_allocator_(new cc::SurfaceIdAllocator(AllocateSurfaceClientId())) {} |
| 18 GetSurfaceManager()->RegisterSurfaceClientId(id_allocator_->client_id()); | |
| 19 } | |
| 20 | 18 |
| 21 OffscreenCanvasSurfaceImpl::~OffscreenCanvasSurfaceImpl() { | 19 OffscreenCanvasSurfaceImpl::~OffscreenCanvasSurfaceImpl() {} |
| 22 if (!GetSurfaceManager()) { | |
| 23 // Inform both members that SurfaceManager's no longer alive to | |
| 24 // avoid their destruction errors. | |
| 25 if (surface_factory_) | |
| 26 surface_factory_->DidDestroySurfaceManager(); | |
| 27 } else { | |
| 28 GetSurfaceManager()->InvalidateSurfaceClientId(id_allocator_->client_id()); | |
| 29 } | |
| 30 surface_factory_->Destroy(surface_id_); | |
| 31 } | |
| 32 | 20 |
| 33 // static | 21 // static |
| 34 void OffscreenCanvasSurfaceImpl::Create( | 22 void OffscreenCanvasSurfaceImpl::Create( |
| 35 mojo::InterfaceRequest<blink::mojom::OffscreenCanvasSurface> request) { | 23 mojo::InterfaceRequest<blink::mojom::OffscreenCanvasSurface> request) { |
| 36 mojo::MakeStrongBinding(base::MakeUnique<OffscreenCanvasSurfaceImpl>(), | 24 mojo::MakeStrongBinding(base::MakeUnique<OffscreenCanvasSurfaceImpl>(), |
| 37 std::move(request)); | 25 std::move(request)); |
| 38 } | 26 } |
| 39 | 27 |
| 40 void OffscreenCanvasSurfaceImpl::GetSurfaceId( | 28 void OffscreenCanvasSurfaceImpl::GetSurfaceId( |
| 41 const GetSurfaceIdCallback& callback) { | 29 const GetSurfaceIdCallback& callback) { |
| 42 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 30 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 43 | 31 |
| 44 surface_id_ = id_allocator_->GenerateId(); | 32 surface_id_ = id_allocator_->GenerateId(); |
| 45 | 33 |
| 46 callback.Run(surface_id_); | 34 callback.Run(surface_id_); |
| 47 } | 35 } |
| 48 | 36 |
| 49 void OffscreenCanvasSurfaceImpl::RequestSurfaceCreation( | |
| 50 const cc::SurfaceId& surface_id) { | |
| 51 cc::SurfaceManager* manager = GetSurfaceManager(); | |
| 52 if (!surface_factory_) { | |
| 53 surface_factory_ = base::MakeUnique<cc::SurfaceFactory>(manager, this); | |
| 54 } | |
| 55 surface_factory_->Create(surface_id); | |
| 56 } | |
| 57 | |
| 58 void OffscreenCanvasSurfaceImpl::Require(const cc::SurfaceId& surface_id, | 37 void OffscreenCanvasSurfaceImpl::Require(const cc::SurfaceId& surface_id, |
| 59 const cc::SurfaceSequence& sequence) { | 38 const cc::SurfaceSequence& sequence) { |
| 60 cc::SurfaceManager* manager = GetSurfaceManager(); | 39 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 61 cc::Surface* surface = manager->GetSurfaceForId(surface_id); | 40 cc::Surface* surface = manager->GetSurfaceForId(surface_id); |
| 62 if (!surface) { | 41 if (!surface) { |
| 63 DLOG(ERROR) << "Attempting to require callback on nonexistent surface"; | 42 DLOG(ERROR) << "Attempting to require callback on nonexistent surface"; |
| 64 return; | 43 return; |
| 65 } | 44 } |
| 66 surface->AddDestructionDependency(sequence); | 45 surface->AddDestructionDependency(sequence); |
| 67 } | 46 } |
| 68 | 47 |
| 69 void OffscreenCanvasSurfaceImpl::Satisfy(const cc::SurfaceSequence& sequence) { | 48 void OffscreenCanvasSurfaceImpl::Satisfy(const cc::SurfaceSequence& sequence) { |
| 70 std::vector<uint32_t> sequences; | 49 std::vector<uint32_t> sequences; |
| 71 sequences.push_back(sequence.sequence); | 50 sequences.push_back(sequence.sequence); |
| 72 cc::SurfaceManager* manager = GetSurfaceManager(); | 51 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 73 manager->DidSatisfySequences(sequence.client_id, &sequences); | 52 manager->DidSatisfySequences(sequence.client_id, &sequences); |
| 74 } | 53 } |
| 75 | 54 |
| 76 // TODO(619136): Implement cc::SurfaceFactoryClient functions for resources | |
| 77 // return. | |
| 78 void OffscreenCanvasSurfaceImpl::ReturnResources( | |
| 79 const cc::ReturnedResourceArray& resources) {} | |
| 80 | |
| 81 void OffscreenCanvasSurfaceImpl::WillDrawSurface(const cc::SurfaceId& id, | |
| 82 const gfx::Rect& damage_rect) { | |
| 83 } | |
| 84 | |
| 85 void OffscreenCanvasSurfaceImpl::SetBeginFrameSource( | |
| 86 cc::BeginFrameSource* begin_frame_source) {} | |
| 87 | |
| 88 } // namespace content | 55 } // namespace content |
| OLD | NEW |