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_compositor_frame_sink.h " | 5 #include "content/browser/renderer_host/offscreen_canvas_compositor_frame_sink.h " |
6 | 6 |
7 #include "cc/surfaces/surface.h" | 7 #include "cc/surfaces/surface.h" |
8 #include "cc/surfaces/surface_manager.h" | 8 #include "cc/surfaces/surface_manager.h" |
9 #include "content/browser/compositor/surface_utils.h" | 9 #include "content/browser/compositor/surface_utils.h" |
10 #include "content/browser/renderer_host/offscreen_canvas_surface_manager.h" | |
10 #include "mojo/public/cpp/bindings/strong_binding.h" | 11 #include "mojo/public/cpp/bindings/strong_binding.h" |
11 | 12 |
12 namespace content { | 13 namespace content { |
13 | 14 |
14 OffscreenCanvasCompositorFrameSink::OffscreenCanvasCompositorFrameSink( | 15 OffscreenCanvasCompositorFrameSink::OffscreenCanvasCompositorFrameSink( |
16 uint32_t canvas_id, | |
15 const cc::SurfaceId& surface_id, | 17 const cc::SurfaceId& surface_id, |
16 cc::mojom::MojoCompositorFrameSinkClientPtr client) | 18 cc::mojom::MojoCompositorFrameSinkClientPtr client) |
17 : surface_id_(surface_id), client_(std::move(client)) {} | 19 : canvas_id_(canvas_id), |
dcheng
2016/11/08 18:30:23
Please make sure that |canvas_id_| and |canvas_id|
xlai (Olivia)
2016/11/10 15:45:11
This canvas_id_ is a unique identifier for this pa
| |
20 surface_id_(surface_id), | |
21 client_(std::move(client)), | |
22 weak_factory_(this) { | |
23 OffscreenCanvasSurfaceManager::GetInstance() | |
24 ->RegisterCompositorFrameSinkInstance(canvas_id_, this); | |
25 } | |
18 | 26 |
19 OffscreenCanvasCompositorFrameSink::~OffscreenCanvasCompositorFrameSink() { | 27 OffscreenCanvasCompositorFrameSink::~OffscreenCanvasCompositorFrameSink() { |
20 if (surface_factory_) { | 28 if (surface_factory_) { |
21 cc::SurfaceManager* manager = GetSurfaceManager(); | 29 cc::SurfaceManager* manager = GetSurfaceManager(); |
22 if (!manager) { | 30 if (!manager) { |
23 // Inform SurfaceFactory that SurfaceManager's no longer alive to | 31 // Inform SurfaceFactory that SurfaceManager's no longer alive to |
24 // avoid its destruction error. | 32 // avoid its destruction error. |
25 surface_factory_->DidDestroySurfaceManager(); | 33 surface_factory_->DidDestroySurfaceManager(); |
26 } else { | 34 } else { |
27 manager->InvalidateFrameSinkId(surface_id_.frame_sink_id()); | 35 manager->InvalidateFrameSinkId(surface_id_.frame_sink_id()); |
28 } | 36 } |
29 surface_factory_->Destroy(surface_id_.local_frame_id()); | 37 surface_factory_->Destroy(surface_id_.local_frame_id()); |
30 } | 38 } |
31 } | 39 } |
32 | 40 |
33 // static | 41 // static |
34 void OffscreenCanvasCompositorFrameSink::Create( | 42 void OffscreenCanvasCompositorFrameSink::Create( |
43 uint32_t canvas_id, | |
35 const cc::SurfaceId& surface_id, | 44 const cc::SurfaceId& surface_id, |
36 cc::mojom::MojoCompositorFrameSinkClientPtr client, | 45 cc::mojom::MojoCompositorFrameSinkClientPtr client, |
37 cc::mojom::MojoCompositorFrameSinkRequest request) { | 46 cc::mojom::MojoCompositorFrameSinkRequest request) { |
38 mojo::MakeStrongBinding(base::MakeUnique<OffscreenCanvasCompositorFrameSink>( | 47 mojo::MakeStrongBinding(base::MakeUnique<OffscreenCanvasCompositorFrameSink>( |
39 surface_id, std::move(client)), | 48 canvas_id, surface_id, std::move(client)), |
40 std::move(request)); | 49 std::move(request)); |
41 } | 50 } |
42 | 51 |
43 void OffscreenCanvasCompositorFrameSink::SubmitCompositorFrame( | 52 void OffscreenCanvasCompositorFrameSink::SubmitCompositorFrame( |
44 cc::CompositorFrame frame) { | 53 cc::CompositorFrame frame) { |
45 if (!surface_factory_) { | 54 if (!surface_factory_) { |
46 cc::SurfaceManager* manager = GetSurfaceManager(); | 55 cc::SurfaceManager* manager = GetSurfaceManager(); |
47 surface_factory_ = base::MakeUnique<cc::SurfaceFactory>( | 56 surface_factory_ = base::MakeUnique<cc::SurfaceFactory>( |
48 surface_id_.frame_sink_id(), manager, this); | 57 surface_id_.frame_sink_id(), manager, this); |
49 surface_factory_->Create(surface_id_.local_frame_id()); | 58 surface_factory_->Create(surface_id_.local_frame_id()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 client_->DidReceiveCompositorFrameAck(); | 99 client_->DidReceiveCompositorFrameAck(); |
91 DCHECK_GT(ack_pending_count_, 0); | 100 DCHECK_GT(ack_pending_count_, 0); |
92 if (!surface_returned_resources_.empty()) { | 101 if (!surface_returned_resources_.empty()) { |
93 client_->ReclaimResources(surface_returned_resources_); | 102 client_->ReclaimResources(surface_returned_resources_); |
94 surface_returned_resources_.clear(); | 103 surface_returned_resources_.clear(); |
95 } | 104 } |
96 ack_pending_count_--; | 105 ack_pending_count_--; |
97 } | 106 } |
98 | 107 |
99 } // namespace content | 108 } // namespace content |
OLD | NEW |