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 "mojo/public/cpp/bindings/strong_binding.h" | 10 #include "mojo/public/cpp/bindings/strong_binding.h" |
11 | 11 |
12 namespace content { | 12 namespace content { |
13 | 13 |
14 OffscreenCanvasCompositorFrameSink::OffscreenCanvasCompositorFrameSink( | 14 OffscreenCanvasCompositorFrameSink::OffscreenCanvasCompositorFrameSink( |
15 const cc::SurfaceId& surface_id, | 15 const cc::SurfaceId& surface_id, |
16 cc::mojom::MojoCompositorFrameSinkClientPtr client) | 16 cc::mojom::MojoCompositorFrameSinkClientPtr client) |
17 : surface_id_(surface_id), client_(std::move(client)) {} | 17 : surface_id_(surface_id), client_(std::move(client)) {} |
18 | 18 |
19 OffscreenCanvasCompositorFrameSink::~OffscreenCanvasCompositorFrameSink() { | 19 OffscreenCanvasCompositorFrameSink::~OffscreenCanvasCompositorFrameSink() { |
20 if (surface_factory_) { | 20 if (surface_factory_) { |
21 cc::SurfaceManager* manager = GetSurfaceManager(); | 21 cc::SurfaceManager* manager = GetSurfaceManager(); |
22 if (!manager) { | 22 if (!manager) { |
23 // Inform SurfaceFactory that SurfaceManager's no longer alive to | 23 // Inform SurfaceFactory that SurfaceManager's no longer alive to |
24 // avoid its destruction error. | 24 // avoid its destruction error. |
25 surface_factory_->DidDestroySurfaceManager(); | 25 surface_factory_->DidDestroySurfaceManager(); |
26 } else { | 26 } else { |
27 manager->InvalidateFrameSinkId(surface_id_.frame_sink_id()); | 27 manager->InvalidateFrameSinkId(surface_id_.frame_sink_id()); |
28 } | 28 } |
29 surface_factory_->Destroy(surface_id_.local_frame_id()); | |
30 } | 29 } |
31 } | 30 } |
32 | 31 |
33 // static | 32 // static |
34 void OffscreenCanvasCompositorFrameSink::Create( | 33 void OffscreenCanvasCompositorFrameSink::Create( |
35 const cc::SurfaceId& surface_id, | 34 const cc::SurfaceId& surface_id, |
36 cc::mojom::MojoCompositorFrameSinkClientPtr client, | 35 cc::mojom::MojoCompositorFrameSinkClientPtr client, |
37 cc::mojom::MojoCompositorFrameSinkRequest request) { | 36 cc::mojom::MojoCompositorFrameSinkRequest request) { |
38 mojo::MakeStrongBinding(base::MakeUnique<OffscreenCanvasCompositorFrameSink>( | 37 mojo::MakeStrongBinding(base::MakeUnique<OffscreenCanvasCompositorFrameSink>( |
39 surface_id, std::move(client)), | 38 surface_id, std::move(client)), |
40 std::move(request)); | 39 std::move(request)); |
41 } | 40 } |
42 | 41 |
43 void OffscreenCanvasCompositorFrameSink::SubmitCompositorFrame( | 42 void OffscreenCanvasCompositorFrameSink::SubmitCompositorFrame( |
44 cc::CompositorFrame frame) { | 43 cc::CompositorFrame frame) { |
45 if (!surface_factory_) { | 44 if (!surface_factory_) { |
46 cc::SurfaceManager* manager = GetSurfaceManager(); | 45 cc::SurfaceManager* manager = GetSurfaceManager(); |
47 surface_factory_ = base::MakeUnique<cc::SurfaceFactory>( | 46 surface_factory_ = base::MakeUnique<cc::SurfaceFactory>( |
48 surface_id_.frame_sink_id(), manager, this); | 47 surface_id_.frame_sink_id(), manager, this); |
49 surface_factory_->Create(surface_id_.local_frame_id()); | |
50 | 48 |
51 manager->RegisterFrameSinkId(surface_id_.frame_sink_id()); | 49 manager->RegisterFrameSinkId(surface_id_.frame_sink_id()); |
52 } | 50 } |
53 ++ack_pending_count_; | 51 ++ack_pending_count_; |
54 surface_factory_->SubmitCompositorFrame( | 52 surface_factory_->SubmitCompositorFrame( |
55 surface_id_.local_frame_id(), std::move(frame), | 53 surface_id_.local_frame_id(), std::move(frame), |
56 base::Bind( | 54 base::Bind( |
57 &OffscreenCanvasCompositorFrameSink::DidReceiveCompositorFrameAck, | 55 &OffscreenCanvasCompositorFrameSink::DidReceiveCompositorFrameAck, |
58 base::Unretained(this))); | 56 base::Unretained(this))); |
59 } | 57 } |
(...skipping 30 matching lines...) Expand all Loading... |
90 client_->DidReceiveCompositorFrameAck(); | 88 client_->DidReceiveCompositorFrameAck(); |
91 DCHECK_GT(ack_pending_count_, 0); | 89 DCHECK_GT(ack_pending_count_, 0); |
92 if (!surface_returned_resources_.empty()) { | 90 if (!surface_returned_resources_.empty()) { |
93 client_->ReclaimResources(surface_returned_resources_); | 91 client_->ReclaimResources(surface_returned_resources_); |
94 surface_returned_resources_.clear(); | 92 surface_returned_resources_.clear(); |
95 } | 93 } |
96 ack_pending_count_--; | 94 ack_pending_count_--; |
97 } | 95 } |
98 | 96 |
99 } // namespace content | 97 } // namespace content |
OLD | NEW |