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

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

Issue 2831213004: cc: Reject CompositorFrames to old child surfaces (Closed)
Patch Set: Rebased 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 base::flat_set<FrameSinkId> frame_sink_ids_for_dependencies;
91 for (const SurfaceId& surface_id : frame.metadata.activation_dependencies)
92 frame_sink_ids_for_dependencies.insert(surface_id.frame_sink_id());
93 for (const SurfaceId& surface_id : frame.metadata.referenced_surfaces) {
94 // If this |surface_id| corresponds to a fallback surface referenced by
danakj 2017/05/05 18:06:08 This comment just says what the code below does, w
Fady Samuel 2017/05/05 18:55:11 I've improved the comment, hopefully.
95 // this CompositorFrame, then we close the corresponding surface to avoid
96 // accepting new frames.
97 bool is_fallback_surface =
98 frame_sink_ids_for_dependencies.count(surface_id.frame_sink_id()) > 0;
99 if (is_fallback_surface) {
100 Surface* surface = factory_->manager()->GetSurfaceForId(surface_id);
101 DCHECK(surface);
102 surface->Close();
103 }
104 }
71 pending_frame_data_ = 105 pending_frame_data_ =
72 FrameData(std::move(frame), callback, will_draw_callback); 106 FrameData(std::move(frame), callback, will_draw_callback);
73 // Ask the surface manager to inform |this| when its dependencies are 107 // Ask the surface manager to inform |this| when its dependencies are
74 // resolved. 108 // resolved.
75 factory_->manager()->RequestSurfaceResolution(this); 109 factory_->manager()->RequestSurfaceResolution(this);
76 } else { 110 } else {
77 // If there are no blockers, then immediately activate the frame. 111 // If there are no blockers, then immediately activate the frame.
78 ActivateFrame(FrameData(std::move(frame), callback, will_draw_callback)); 112 ActivateFrame(FrameData(std::move(frame), callback, will_draw_callback));
79 } 113 }
80 114
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 frame->metadata.latency_info.swap(*latency_info); 376 frame->metadata.latency_info.swap(*latency_info);
343 return; 377 return;
344 } 378 }
345 std::copy(frame->metadata.latency_info.begin(), 379 std::copy(frame->metadata.latency_info.begin(),
346 frame->metadata.latency_info.end(), 380 frame->metadata.latency_info.end(),
347 std::back_inserter(*latency_info)); 381 std::back_inserter(*latency_info));
348 frame->metadata.latency_info.clear(); 382 frame->metadata.latency_info.clear();
349 } 383 }
350 384
351 } // namespace cc 385 } // 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