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_service_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 OffscreenCanvasSurfaceServiceImpl::Create( |
| 17 mojo::InterfaceRequest<blink::mojom::OffscreenCanvasSurfaceService> |
| 18 request) { |
| 19 // |binding_| will take ownership of OffscreenCanvasSurfaceServiceImpl |
| 20 new OffscreenCanvasSurfaceServiceImpl(std::move(request)); |
| 21 } |
| 22 |
| 23 OffscreenCanvasSurfaceServiceImpl::OffscreenCanvasSurfaceServiceImpl( |
| 24 mojo::InterfaceRequest<blink::mojom::OffscreenCanvasSurfaceService> request) |
| 25 : binding_(this, std::move(request)) { |
| 26 id_allocator_ = CreateSurfaceIdAllocator(); |
| 27 } |
| 28 |
| 29 OffscreenCanvasSurfaceServiceImpl::~OffscreenCanvasSurfaceServiceImpl() { |
| 30 if (surface_factory_) { |
| 31 surface_factory_->DestroyAll(); |
| 32 } |
| 33 } |
| 34 |
| 35 void OffscreenCanvasSurfaceServiceImpl::GetSurfaceId( |
| 36 const GetSurfaceIdCallback& callback) { |
| 37 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 38 |
| 39 cc::SurfaceId surface_id = id_allocator_->GenerateId(); |
| 40 |
| 41 callback.Run(std::move(surface_id)); |
| 42 } |
| 43 |
| 44 void OffscreenCanvasSurfaceServiceImpl::RequestSurfaceCreation( |
| 45 const cc::SurfaceId& surface_id) { |
| 46 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 47 if (!surface_factory_) { |
| 48 surface_factory_ = base::WrapUnique(new cc::SurfaceFactory(manager, this)); |
| 49 } |
| 50 surface_factory_->Create(surface_id); |
| 51 } |
| 52 |
| 53 void OffscreenCanvasSurfaceServiceImpl::Require( |
| 54 const cc::SurfaceId& surface_id, |
| 55 const cc::SurfaceSequence& sequence) { |
| 56 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 57 cc::Surface* surface = manager->GetSurfaceForId(surface_id); |
| 58 if (!surface) { |
| 59 LOG(ERROR) << "Attempting to require callback on nonexistent surface"; |
| 60 return; |
| 61 } |
| 62 surface->AddDestructionDependency(sequence); |
| 63 } |
| 64 |
| 65 void OffscreenCanvasSurfaceServiceImpl::Satisfy( |
| 66 const cc::SurfaceSequence& sequence) { |
| 67 std::vector<uint32_t> sequences; |
| 68 sequences.push_back(sequence.sequence); |
| 69 cc::SurfaceManager* manager = GetSurfaceManager(); |
| 70 manager->DidSatisfySequences(sequence.id_namespace, &sequences); |
| 71 } |
| 72 |
| 73 // TODO: Implement cc::SurfaceFactoryClient functions for resources return. |
| 74 void OffscreenCanvasSurfaceServiceImpl::ReturnResources( |
| 75 const cc::ReturnedResourceArray& resources) {} |
| 76 |
| 77 void OffscreenCanvasSurfaceServiceImpl::WillDrawSurface( |
| 78 cc::SurfaceId id, |
| 79 const gfx::Rect& damage_rect) {} |
| 80 |
| 81 void OffscreenCanvasSurfaceServiceImpl::SetBeginFrameSource( |
| 82 cc::BeginFrameSource* begin_frame_source) {} |
| 83 |
| 84 } // namespace content |
OLD | NEW |