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

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

Issue 2485543004: Make SurfaceFactory lifetime match frame_sink_id registration in OffscreenCanvasCompositorFrameSink (Closed)
Patch Set: 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_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 cc::SurfaceManager* manager = GetSurfaceManager();
19 surface_factory_ = base::MakeUnique<cc::SurfaceFactory>(
20 surface_id_.frame_sink_id(), manager, this);
21 manager->RegisterFrameSinkId(surface_id_.frame_sink_id());
22 surface_factory_->Create(surface_id_.local_frame_id());
23 }
18 24
19 OffscreenCanvasCompositorFrameSink::~OffscreenCanvasCompositorFrameSink() { 25 OffscreenCanvasCompositorFrameSink::~OffscreenCanvasCompositorFrameSink() {
20 if (surface_factory_) { 26 cc::SurfaceManager* manager = GetSurfaceManager();
21 cc::SurfaceManager* manager = GetSurfaceManager(); 27 if (!manager) {
22 if (!manager) { 28 // Inform SurfaceFactory that SurfaceManager's no longer alive to
23 // Inform SurfaceFactory that SurfaceManager's no longer alive to 29 // avoid its destruction error.
24 // avoid its destruction error. 30 surface_factory_->DidDestroySurfaceManager();
25 surface_factory_->DidDestroySurfaceManager(); 31 } else {
26 } else { 32 manager->InvalidateFrameSinkId(surface_id_.frame_sink_id());
27 manager->InvalidateFrameSinkId(surface_id_.frame_sink_id());
28 }
29 surface_factory_->Destroy(surface_id_.local_frame_id());
30 } 33 }
34 surface_factory_->Destroy(surface_id_.local_frame_id());
31 } 35 }
32 36
33 // static 37 // static
34 void OffscreenCanvasCompositorFrameSink::Create( 38 void OffscreenCanvasCompositorFrameSink::Create(
35 const cc::SurfaceId& surface_id, 39 const cc::SurfaceId& surface_id,
36 cc::mojom::MojoCompositorFrameSinkClientPtr client, 40 cc::mojom::MojoCompositorFrameSinkClientPtr client,
37 cc::mojom::MojoCompositorFrameSinkRequest request) { 41 cc::mojom::MojoCompositorFrameSinkRequest request) {
38 mojo::MakeStrongBinding(base::MakeUnique<OffscreenCanvasCompositorFrameSink>( 42 mojo::MakeStrongBinding(base::MakeUnique<OffscreenCanvasCompositorFrameSink>(
39 surface_id, std::move(client)), 43 surface_id, std::move(client)),
40 std::move(request)); 44 std::move(request));
41 } 45 }
42 46
43 void OffscreenCanvasCompositorFrameSink::SubmitCompositorFrame( 47 void OffscreenCanvasCompositorFrameSink::SubmitCompositorFrame(
44 cc::CompositorFrame frame) { 48 cc::CompositorFrame frame) {
45 if (!surface_factory_) {
46 cc::SurfaceManager* manager = GetSurfaceManager();
47 surface_factory_ = base::MakeUnique<cc::SurfaceFactory>(
48 surface_id_.frame_sink_id(), manager, this);
49 surface_factory_->Create(surface_id_.local_frame_id());
50
51 manager->RegisterFrameSinkId(surface_id_.frame_sink_id());
52 }
53 ++ack_pending_count_; 49 ++ack_pending_count_;
54 surface_factory_->SubmitCompositorFrame( 50 surface_factory_->SubmitCompositorFrame(
55 surface_id_.local_frame_id(), std::move(frame), 51 surface_id_.local_frame_id(), std::move(frame),
56 base::Bind( 52 base::Bind(
57 &OffscreenCanvasCompositorFrameSink::DidReceiveCompositorFrameAck, 53 &OffscreenCanvasCompositorFrameSink::DidReceiveCompositorFrameAck,
58 base::Unretained(this))); 54 base::Unretained(this)));
59 } 55 }
60 56
61 void OffscreenCanvasCompositorFrameSink::SetNeedsBeginFrame( 57 void OffscreenCanvasCompositorFrameSink::SetNeedsBeginFrame(
62 bool needs_begin_frame) { 58 bool needs_begin_frame) {
(...skipping 27 matching lines...) Expand all
90 client_->DidReceiveCompositorFrameAck(); 86 client_->DidReceiveCompositorFrameAck();
91 DCHECK_GT(ack_pending_count_, 0); 87 DCHECK_GT(ack_pending_count_, 0);
92 if (!surface_returned_resources_.empty()) { 88 if (!surface_returned_resources_.empty()) {
93 client_->ReclaimResources(surface_returned_resources_); 89 client_->ReclaimResources(surface_returned_resources_);
94 surface_returned_resources_.clear(); 90 surface_returned_resources_.clear();
95 } 91 }
96 ack_pending_count_--; 92 ack_pending_count_--;
97 } 93 }
98 94
99 } // namespace content 95 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698