Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: content/browser/renderer_host/offscreen_canvas_surface_impl.cc

Issue 2333133003: Make Surface creation lazy for OffscreenCanvasFrameReceiverImpl (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_(new cc::SurfaceIdAllocator(AllocateSurfaceClientId())), 24 : id_allocator_(new cc::SurfaceIdAllocator(AllocateSurfaceClientId())),
25 binding_(this, std::move(request)) { 25 binding_(this, std::move(request)) {
26 GetSurfaceManager()->RegisterSurfaceClientId(id_allocator_->client_id());
27 } 26 }
28 27
29 OffscreenCanvasSurfaceImpl::~OffscreenCanvasSurfaceImpl() { 28 OffscreenCanvasSurfaceImpl::~OffscreenCanvasSurfaceImpl() {
30 if (!GetSurfaceManager()) {
31 // Inform both members that SurfaceManager's no longer alive to
32 // avoid their destruction errors.
33 if (surface_factory_)
34 surface_factory_->DidDestroySurfaceManager();
35 } else {
36 GetSurfaceManager()->InvalidateSurfaceClientId(id_allocator_->client_id());
37 }
38 surface_factory_->Destroy(surface_id_);
39 } 29 }
40 30
41 void OffscreenCanvasSurfaceImpl::GetSurfaceId( 31 void OffscreenCanvasSurfaceImpl::GetSurfaceId(
42 const GetSurfaceIdCallback& callback) { 32 const GetSurfaceIdCallback& callback) {
43 DCHECK_CURRENTLY_ON(BrowserThread::UI); 33 DCHECK_CURRENTLY_ON(BrowserThread::UI);
44 34
45 surface_id_ = id_allocator_->GenerateId(); 35 surface_id_ = id_allocator_->GenerateId();
46 36
47 callback.Run(surface_id_); 37 callback.Run(surface_id_);
48 } 38 }
49 39
50 void OffscreenCanvasSurfaceImpl::RequestSurfaceCreation(
51 const cc::SurfaceId& surface_id) {
52 cc::SurfaceManager* manager = GetSurfaceManager();
53 if (!surface_factory_) {
54 surface_factory_ = base::MakeUnique<cc::SurfaceFactory>(manager, this);
55 }
56 surface_factory_->Create(surface_id);
57 }
58
59 void OffscreenCanvasSurfaceImpl::Require(const cc::SurfaceId& surface_id, 40 void OffscreenCanvasSurfaceImpl::Require(const cc::SurfaceId& surface_id,
60 const cc::SurfaceSequence& sequence) { 41 const cc::SurfaceSequence& sequence) {
61 cc::SurfaceManager* manager = GetSurfaceManager(); 42 cc::SurfaceManager* manager = GetSurfaceManager();
62 cc::Surface* surface = manager->GetSurfaceForId(surface_id); 43 cc::Surface* surface = manager->GetSurfaceForId(surface_id);
63 if (!surface) { 44 if (!surface) {
64 DLOG(ERROR) << "Attempting to require callback on nonexistent surface"; 45 DLOG(ERROR) << "Attempting to require callback on nonexistent surface";
65 return; 46 return;
66 } 47 }
67 surface->AddDestructionDependency(sequence); 48 surface->AddDestructionDependency(sequence);
68 } 49 }
69 50
70 void OffscreenCanvasSurfaceImpl::Satisfy(const cc::SurfaceSequence& sequence) { 51 void OffscreenCanvasSurfaceImpl::Satisfy(const cc::SurfaceSequence& sequence) {
71 std::vector<uint32_t> sequences; 52 std::vector<uint32_t> sequences;
72 sequences.push_back(sequence.sequence); 53 sequences.push_back(sequence.sequence);
73 cc::SurfaceManager* manager = GetSurfaceManager(); 54 cc::SurfaceManager* manager = GetSurfaceManager();
74 manager->DidSatisfySequences(sequence.client_id, &sequences); 55 manager->DidSatisfySequences(sequence.client_id, &sequences);
75 } 56 }
76 57
77 // TODO(619136): Implement cc::SurfaceFactoryClient functions for resources
78 // return.
79 void OffscreenCanvasSurfaceImpl::ReturnResources(
80 const cc::ReturnedResourceArray& resources) {}
81
82 void OffscreenCanvasSurfaceImpl::WillDrawSurface(const cc::SurfaceId& id,
83 const gfx::Rect& damage_rect) {
84 }
85
86 void OffscreenCanvasSurfaceImpl::SetBeginFrameSource(
87 cc::BeginFrameSource* begin_frame_source) {}
88
89 } // namespace content 58 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698