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

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

Issue 2479563005: Create manager to track OffscreenCanvasSurfaceImpl instances (Closed)
Patch Set: further fix Created 4 years, 1 month 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/browser/renderer_host/offscreen_canvas_surface_manager.h"
11 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
12 #include "mojo/public/cpp/bindings/strong_binding.h" 13 #include "mojo/public/cpp/bindings/strong_binding.h"
13 14
14 namespace content { 15 namespace content {
15 16
16 OffscreenCanvasSurfaceImpl::OffscreenCanvasSurfaceImpl() 17 OffscreenCanvasSurfaceImpl::OffscreenCanvasSurfaceImpl()
17 : id_allocator_(new cc::SurfaceIdAllocator()) {} 18 : id_allocator_(new cc::SurfaceIdAllocator()), weak_factory_(this) {}
18 19
19 OffscreenCanvasSurfaceImpl::~OffscreenCanvasSurfaceImpl() {} 20 OffscreenCanvasSurfaceImpl::~OffscreenCanvasSurfaceImpl() {
21 if (frame_sink_id_.is_valid()) {
22 OffscreenCanvasSurfaceManager::GetInstance()
23 ->UnregisterOffscreenCanvasSurfaceInstance(frame_sink_id_);
24 }
25 }
20 26
21 // static 27 // static
22 void OffscreenCanvasSurfaceImpl::Create( 28 void OffscreenCanvasSurfaceImpl::Create(
23 mojo::InterfaceRequest<blink::mojom::OffscreenCanvasSurface> request) { 29 mojo::InterfaceRequest<blink::mojom::OffscreenCanvasSurface> request) {
24 mojo::MakeStrongBinding(base::MakeUnique<OffscreenCanvasSurfaceImpl>(), 30 mojo::MakeStrongBinding(base::MakeUnique<OffscreenCanvasSurfaceImpl>(),
Fady Samuel 2016/11/15 17:32:45 I'm confused by the lifetime management here. It s
xlai (Olivia) 2016/11/15 17:56:52 I don't understand why this is a problem; this is
Fady Samuel 2016/11/15 18:06:43 I guess the part that I find really confusing is t
xlai (Olivia) 2016/11/15 19:12:18 No I don't think OffscreenCanvasSurfaceManager wil
25 std::move(request)); 31 std::move(request));
26 } 32 }
27 33
28 void OffscreenCanvasSurfaceImpl::GetSurfaceId( 34 void OffscreenCanvasSurfaceImpl::GetSurfaceId(
29 const GetSurfaceIdCallback& callback) { 35 const GetSurfaceIdCallback& callback) {
30 DCHECK_CURRENTLY_ON(BrowserThread::UI); 36 DCHECK_CURRENTLY_ON(BrowserThread::UI);
37 if (frame_sink_id_.is_valid()) {
38 // This IPC should be only called once for each HTMLCanvasElement. In this
39 // case, frame_sink_id_ is still unset.
40 // As the browser makes no assumption of correct behavior of renderer, in
41 // an unwanted situation when this function is invoked twice, we need to
42 // unregister the instance from manager.
43 OffscreenCanvasSurfaceManager::GetInstance()
44 ->UnregisterOffscreenCanvasSurfaceInstance(frame_sink_id_);
45 mojo::ReportBadMessage(
46 "The same OffscreenCanvasSurfaceImpl is registered to "
47 "OffscreenCanvasSurfaceManager twice.");
48 }
31 49
32 cc::LocalFrameId local_frame_id = id_allocator_->GenerateId(); 50 frame_sink_id_ = AllocateFrameSinkId();
33 surface_id_ = cc::SurfaceId(AllocateFrameSinkId(), local_frame_id); 51 cc::SurfaceId surface_id =
52 cc::SurfaceId(frame_sink_id_, id_allocator_->GenerateId());
34 53
35 callback.Run(surface_id_); 54 OffscreenCanvasSurfaceManager::GetInstance()
55 ->RegisterOffscreenCanvasSurfaceInstance(frame_sink_id_, this);
56
57 callback.Run(surface_id);
36 } 58 }
37 59
38 void OffscreenCanvasSurfaceImpl::Require(const cc::SurfaceId& surface_id, 60 void OffscreenCanvasSurfaceImpl::Require(const cc::SurfaceId& surface_id,
39 const cc::SurfaceSequence& sequence) { 61 const cc::SurfaceSequence& sequence) {
40 cc::SurfaceManager* manager = GetSurfaceManager(); 62 cc::SurfaceManager* manager = GetSurfaceManager();
41 cc::Surface* surface = manager->GetSurfaceForId(surface_id); 63 cc::Surface* surface = manager->GetSurfaceForId(surface_id);
42 if (!surface) { 64 if (!surface) {
43 DLOG(ERROR) << "Attempting to require callback on nonexistent surface"; 65 DLOG(ERROR) << "Attempting to require callback on nonexistent surface";
44 return; 66 return;
45 } 67 }
46 surface->AddDestructionDependency(sequence); 68 surface->AddDestructionDependency(sequence);
47 } 69 }
48 70
49 void OffscreenCanvasSurfaceImpl::Satisfy(const cc::SurfaceSequence& sequence) { 71 void OffscreenCanvasSurfaceImpl::Satisfy(const cc::SurfaceSequence& sequence) {
50 std::vector<uint32_t> sequences; 72 std::vector<uint32_t> sequences;
51 sequences.push_back(sequence.sequence); 73 sequences.push_back(sequence.sequence);
52 cc::SurfaceManager* manager = GetSurfaceManager(); 74 cc::SurfaceManager* manager = GetSurfaceManager();
53 manager->DidSatisfySequences(sequence.frame_sink_id, &sequences); 75 manager->DidSatisfySequences(sequence.frame_sink_id, &sequences);
54 } 76 }
55 77
56 } // namespace content 78 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698