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

Side by Side Diff: cc/surfaces/surface.cc

Issue 2831213004: cc: Reject CompositorFrames to old child surfaces (Closed)
Patch Set: Improved comment Created 3 years, 7 months 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 | « cc/surfaces/surface.h ('k') | cc/surfaces/surface_factory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "cc/surfaces/surface.h" 5 #include "cc/surfaces/surface.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 11
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "cc/output/compositor_frame.h" 13 #include "cc/output/compositor_frame.h"
14 #include "cc/output/copy_output_request.h" 14 #include "cc/output/copy_output_request.h"
15 #include "cc/surfaces/local_surface_id_allocator.h" 15 #include "cc/surfaces/local_surface_id_allocator.h"
16 #include "cc/surfaces/pending_frame_observer.h" 16 #include "cc/surfaces/pending_frame_observer.h"
17 #include "cc/surfaces/surface_factory.h" 17 #include "cc/surfaces/surface_factory.h"
18 #include "cc/surfaces/surface_factory_client.h"
18 #include "cc/surfaces/surface_manager.h" 19 #include "cc/surfaces/surface_manager.h"
20 #include "cc/surfaces/surface_resource_holder_client.h"
19 21
20 namespace cc { 22 namespace cc {
21 23
22 // The frame index starts at 2 so that empty frames will be treated as 24 // The frame index starts at 2 so that empty frames will be treated as
23 // completely damaged the first time they're drawn from. 25 // completely damaged the first time they're drawn from.
24 static const int kFrameIndexStart = 2; 26 static const int kFrameIndexStart = 2;
25 27
26 Surface::Surface(const SurfaceId& id, base::WeakPtr<SurfaceFactory> factory) 28 Surface::Surface(const SurfaceId& id, base::WeakPtr<SurfaceFactory> factory)
27 : surface_id_(id), 29 : surface_id_(id),
28 previous_frame_surface_id_(id), 30 previous_frame_surface_id_(id),
(...skipping 14 matching lines...) Expand all
43 void Surface::SetPreviousFrameSurface(Surface* surface) { 45 void Surface::SetPreviousFrameSurface(Surface* surface) {
44 DCHECK(surface && (HasActiveFrame() || HasPendingFrame())); 46 DCHECK(surface && (HasActiveFrame() || HasPendingFrame()));
45 frame_index_ = surface->frame_index() + 1; 47 frame_index_ = surface->frame_index() + 1;
46 previous_frame_surface_id_ = surface->surface_id(); 48 previous_frame_surface_id_ = surface->surface_id();
47 CompositorFrame& frame = active_frame_data_ ? active_frame_data_->frame 49 CompositorFrame& frame = active_frame_data_ ? active_frame_data_->frame
48 : pending_frame_data_->frame; 50 : pending_frame_data_->frame;
49 surface->TakeLatencyInfo(&frame.metadata.latency_info); 51 surface->TakeLatencyInfo(&frame.metadata.latency_info);
50 surface->TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info); 52 surface->TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info);
51 } 53 }
52 54
55 void Surface::Close() {
56 closed_ = true;
57 }
58
53 void Surface::QueueFrame(CompositorFrame frame, 59 void Surface::QueueFrame(CompositorFrame frame,
54 const DrawCallback& callback, 60 const DrawCallback& callback,
55 const WillDrawCallback& will_draw_callback) { 61 const WillDrawCallback& will_draw_callback) {
62 if (closed_) {
63 if (factory_ && factory_->resource_holder_client()) {
64 ReturnedResourceArray resources;
65 TransferableResource::ReturnResources(frame.resource_list, &resources);
66 factory_->resource_holder_client()->ReturnResources(resources);
67 }
68 callback.Run();
69 return;
70 }
71
56 TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info); 72 TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info);
57 73
58 base::Optional<FrameData> previous_pending_frame_data = 74 base::Optional<FrameData> previous_pending_frame_data =
59 std::move(pending_frame_data_); 75 std::move(pending_frame_data_);
60 pending_frame_data_.reset(); 76 pending_frame_data_.reset();
61 77
62 UpdateBlockingSurfaces(previous_pending_frame_data.has_value(), frame); 78 UpdateBlockingSurfaces(previous_pending_frame_data.has_value(), frame);
63 79
64 // Receive and track the resources referenced from the CompositorFrame 80 // Receive and track the resources referenced from the CompositorFrame
65 // regardless of whether it's pending or active. 81 // regardless of whether it's pending or active.
66 factory_->ReceiveFromChild(frame.resource_list); 82 factory_->ReceiveFromChild(frame.resource_list);
67 83
68 bool is_pending_frame = !blocking_surfaces_.empty(); 84 bool is_pending_frame = !blocking_surfaces_.empty();
69 85
70 if (is_pending_frame) { 86 if (is_pending_frame) {
87 // Reject CompositorFrames submitted to surfaces referenced from this
88 // CompositorFrame as fallbacks. This saves some CPU cycles to allow
89 // children to catch up to the parent.
90 // Note: |activation_dependencies| and |referenced_surfaces| are disjointed
danakj 2017/05/05 19:51:35 This part of the comment seems like it belongs in
Fady Samuel 2017/05/05 20:25:02 Done. Moved this to CompositorFrameMetadata.
91 // sets of surface IDs. If a surface ID is known to exist and can be
92 // used without additional synchronization, then it is placed in
93 // |referenced_surfaces|. |activation_dependencies| are the set of
94 // surface IDs that this |frame| would like to block on until they
95 // become available or a deadline hits.
96 //
97 // A surface ID in |referenced_surfaces| that has a corresponding
danakj 2017/05/05 19:51:35 Thanks, this is what I was looking for. Can you mo
Fady Samuel 2017/05/05 20:25:02 Done.
98 // surface ID in |activation_dependencies| with the same frame sink ID
99 // is said to be a fallback surface that can be used in place of the
100 // primary surface if the deadline passes before the dependency
101 // becomes available.
102 base::flat_set<FrameSinkId> frame_sink_ids_for_dependencies;
103 for (const SurfaceId& surface_id : frame.metadata.activation_dependencies)
104 frame_sink_ids_for_dependencies.insert(surface_id.frame_sink_id());
105 for (const SurfaceId& surface_id : frame.metadata.referenced_surfaces) {
106 // If this |surface_id| corresponds to a fallback surface referenced by
107 // this |frame|, then we close the corresponding surface to avoid
108 // accepting new frames.
109 bool is_fallback_surface =
110 frame_sink_ids_for_dependencies.count(surface_id.frame_sink_id()) > 0;
111 if (is_fallback_surface) {
112 Surface* surface = factory_->manager()->GetSurfaceForId(surface_id);
113 DCHECK(surface);
114 surface->Close();
115 }
116 }
71 pending_frame_data_ = 117 pending_frame_data_ =
72 FrameData(std::move(frame), callback, will_draw_callback); 118 FrameData(std::move(frame), callback, will_draw_callback);
73 // Ask the surface manager to inform |this| when its dependencies are 119 // Ask the surface manager to inform |this| when its dependencies are
74 // resolved. 120 // resolved.
75 factory_->manager()->RequestSurfaceResolution(this); 121 factory_->manager()->RequestSurfaceResolution(this);
76 } else { 122 } else {
77 // If there are no blockers, then immediately activate the frame. 123 // If there are no blockers, then immediately activate the frame.
78 ActivateFrame(FrameData(std::move(frame), callback, will_draw_callback)); 124 ActivateFrame(FrameData(std::move(frame), callback, will_draw_callback));
79 } 125 }
80 126
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 frame->metadata.latency_info.swap(*latency_info); 388 frame->metadata.latency_info.swap(*latency_info);
343 return; 389 return;
344 } 390 }
345 std::copy(frame->metadata.latency_info.begin(), 391 std::copy(frame->metadata.latency_info.begin(),
346 frame->metadata.latency_info.end(), 392 frame->metadata.latency_info.end(),
347 std::back_inserter(*latency_info)); 393 std::back_inserter(*latency_info));
348 frame->metadata.latency_info.clear(); 394 frame->metadata.latency_info.clear();
349 } 395 }
350 396
351 } // namespace cc 397 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/surface.h ('k') | cc/surfaces/surface_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698