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