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() { |
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>(), |
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 // This IPC should be only called once for each HTMLCanvasElement. In this | |
38 // case, frame_sink_id_ is still unset. | |
39 DCHECK(!frame_sink_id_.is_valid()); | |
40 if (frame_sink_id_.is_valid()) { | |
xlai (Olivia)
2016/11/11 22:56:56
dcheng@ has asked if the failure of this DCHECK wi
| |
41 // As the browser makes no assumption of correct behavior of renderer, in | |
42 // an unwanted situation when this function is invoked twice, we need to | |
43 // unregister the instance from manager. | |
44 OffscreenCanvasSurfaceManager::GetInstance() | |
45 ->UnregisterOffscreenCanvasSurfaceInstance(frame_sink_id_); | |
46 LOG(ERROR) << "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 |
OLD | NEW |