OLD | NEW |
---|---|
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() {} |
20 | 21 |
21 // static | 22 // static |
22 void OffscreenCanvasSurfaceImpl::Create( | 23 void OffscreenCanvasSurfaceImpl::Create( |
23 mojo::InterfaceRequest<blink::mojom::OffscreenCanvasSurface> request) { | 24 mojo::InterfaceRequest<blink::mojom::OffscreenCanvasSurface> request) { |
24 mojo::MakeStrongBinding(base::MakeUnique<OffscreenCanvasSurfaceImpl>(), | 25 mojo::MakeStrongBinding(base::MakeUnique<OffscreenCanvasSurfaceImpl>(), |
25 std::move(request)); | 26 std::move(request)); |
26 } | 27 } |
27 | 28 |
28 void OffscreenCanvasSurfaceImpl::GetSurfaceId( | 29 void OffscreenCanvasSurfaceImpl::GetSurfaceId( |
30 uint32_t canvas_id, | |
29 const GetSurfaceIdCallback& callback) { | 31 const GetSurfaceIdCallback& callback) { |
30 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 32 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
31 | 33 |
32 cc::LocalFrameId local_frame_id = id_allocator_->GenerateId(); | 34 cc::LocalFrameId local_frame_id = id_allocator_->GenerateId(); |
35 | |
36 // This IPC should be only called once for each HTMLCanvasElement. In this | |
37 // case, surface_id_ is still unset. | |
38 DCHECK(surface_id_.is_null()); | |
dcheng
2016/11/08 18:30:23
This can't DCHECK, since the renderer could do thi
xlai (Olivia)
2016/11/10 15:45:11
This IPC call is supposed to be called only once f
dcheng
2016/11/11 08:36:40
Right, but this is browser code being invoked by t
| |
33 surface_id_ = cc::SurfaceId(AllocateFrameSinkId(), local_frame_id); | 39 surface_id_ = cc::SurfaceId(AllocateFrameSinkId(), local_frame_id); |
40 canvas_id_ = canvas_id; | |
41 | |
42 OffscreenCanvasSurfaceManager::GetInstance() | |
43 ->RegisterOffscreenCanvasSurfaceInstance(canvas_id_, this); | |
34 | 44 |
35 callback.Run(surface_id_); | 45 callback.Run(surface_id_); |
36 } | 46 } |
37 | 47 |
38 void OffscreenCanvasSurfaceImpl::Require(const cc::SurfaceId& surface_id, | 48 void OffscreenCanvasSurfaceImpl::Require(const cc::SurfaceId& surface_id, |
39 const cc::SurfaceSequence& sequence) { | 49 const cc::SurfaceSequence& sequence) { |
40 cc::SurfaceManager* manager = GetSurfaceManager(); | 50 cc::SurfaceManager* manager = GetSurfaceManager(); |
41 cc::Surface* surface = manager->GetSurfaceForId(surface_id); | 51 cc::Surface* surface = manager->GetSurfaceForId(surface_id); |
42 if (!surface) { | 52 if (!surface) { |
43 DLOG(ERROR) << "Attempting to require callback on nonexistent surface"; | 53 DLOG(ERROR) << "Attempting to require callback on nonexistent surface"; |
44 return; | 54 return; |
45 } | 55 } |
46 surface->AddDestructionDependency(sequence); | 56 surface->AddDestructionDependency(sequence); |
47 } | 57 } |
48 | 58 |
49 void OffscreenCanvasSurfaceImpl::Satisfy(const cc::SurfaceSequence& sequence) { | 59 void OffscreenCanvasSurfaceImpl::Satisfy(const cc::SurfaceSequence& sequence) { |
50 std::vector<uint32_t> sequences; | 60 std::vector<uint32_t> sequences; |
51 sequences.push_back(sequence.sequence); | 61 sequences.push_back(sequence.sequence); |
52 cc::SurfaceManager* manager = GetSurfaceManager(); | 62 cc::SurfaceManager* manager = GetSurfaceManager(); |
53 manager->DidSatisfySequences(sequence.frame_sink_id, &sequences); | 63 manager->DidSatisfySequences(sequence.frame_sink_id, &sequences); |
54 } | 64 } |
55 | 65 |
56 } // namespace content | 66 } // namespace content |
OLD | NEW |