OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/renderer_host/offscreen_canvas_surface_impl.h" |
| 6 |
| 7 #include "base/bind_helpers.h" |
| 8 #include "cc/surfaces/surface.h" |
| 9 #include "cc/surfaces/surface_manager.h" |
| 10 #include "content/browser/compositor/surface_utils.h" |
| 11 #include "content/public/browser/browser_thread.h" |
| 12 |
| 13 namespace content { |
| 14 |
| 15 // static |
| 16 void OffscreenCanvasSurfaceImpl::Create( |
| 17 mojo::InterfaceRequest<blink::mojom::OffscreenCanvasSurface> request) { |
| 18 // |binding_| will take ownership of OffscreenCanvasSurfaceImpl |
| 19 new OffscreenCanvasSurfaceImpl(std::move(request)); |
| 20 } |
| 21 |
| 22 OffscreenCanvasSurfaceImpl::OffscreenCanvasSurfaceImpl( |
| 23 mojo::InterfaceRequest<blink::mojom::OffscreenCanvasSurface> request) |
| 24 : id_allocator_(CreateSurfaceIdAllocator()), |
| 25 binding_(this, std::move(request)) {} |
| 26 |
| 27 OffscreenCanvasSurfaceImpl::~OffscreenCanvasSurfaceImpl() { |
| 28 if (surface_factory_) { |
| 29 surface_factory_->DestroyAll(); |
| 30 } |
| 31 } |
| 32 |
| 33 void OffscreenCanvasSurfaceImpl::GetSurfaceId( |
| 34 const GetSurfaceIdCallback& callback) { |
| 35 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 36 |
| 37 cc::SurfaceId surface_id = id_allocator_->GenerateId(); |
| 38 |
| 39 callback.Run(surface_id); |
| 40 } |
| 41 |
| 42 void OffscreenCanvasSurfaceImpl::RequestSurfaceCreation( |
| 43 const cc::SurfaceId& surface_id) { |
| 44 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 45 if (!surface_factory_) { |
| 46 surface_factory_ = base::MakeUnique<cc::SurfaceFactory>(manager, this); |
| 47 } |
| 48 surface_factory_->Create(surface_id); |
| 49 } |
| 50 |
| 51 void OffscreenCanvasSurfaceImpl::Require(const cc::SurfaceId& surface_id, |
| 52 const cc::SurfaceSequence& sequence) { |
| 53 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 54 cc::Surface* surface = manager->GetSurfaceForId(surface_id); |
| 55 if (!surface) { |
| 56 DLOG(ERROR) << "Attempting to require callback on nonexistent surface"; |
| 57 return; |
| 58 } |
| 59 surface->AddDestructionDependency(sequence); |
| 60 } |
| 61 |
| 62 void OffscreenCanvasSurfaceImpl::Satisfy(const cc::SurfaceSequence& sequence) { |
| 63 std::vector<uint32_t> sequences; |
| 64 sequences.push_back(sequence.sequence); |
| 65 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 66 manager->DidSatisfySequences(sequence.id_namespace, &sequences); |
| 67 } |
| 68 |
| 69 // TODO(619136): Implement cc::SurfaceFactoryClient functions for resources |
| 70 // return. |
| 71 void OffscreenCanvasSurfaceImpl::ReturnResources( |
| 72 const cc::ReturnedResourceArray& resources) {} |
| 73 |
| 74 void OffscreenCanvasSurfaceImpl::WillDrawSurface(cc::SurfaceId id, |
| 75 const gfx::Rect& damage_rect) { |
| 76 } |
| 77 |
| 78 void OffscreenCanvasSurfaceImpl::SetBeginFrameSource( |
| 79 cc::BeginFrameSource* begin_frame_source) {} |
| 80 |
| 81 } // namespace content |
OLD | NEW |