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

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

Issue 2848223003: Enforce constant size and device scale factor for surfaces (Closed)
Patch Set: Address comments 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_aggregator_unittest.cc » ('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/compositor_frame_sink_support.h" 15 #include "cc/surfaces/compositor_frame_sink_support.h"
16 #include "cc/surfaces/local_surface_id_allocator.h" 16 #include "cc/surfaces/local_surface_id_allocator.h"
17 #include "cc/surfaces/surface_manager.h" 17 #include "cc/surfaces/surface_manager.h"
18 #include "cc/surfaces/surface_resource_holder_client.h" 18 #include "cc/surfaces/surface_resource_holder_client.h"
19 19
20 namespace cc { 20 namespace cc {
21 21
22 // The frame index starts at 2 so that empty frames will be treated as 22 // The frame index starts at 2 so that empty frames will be treated as
23 // completely damaged the first time they're drawn from. 23 // completely damaged the first time they're drawn from.
24 static const int kFrameIndexStart = 2; 24 static const int kFrameIndexStart = 2;
25 25
26 Surface::Surface( 26 Surface::Surface(
27 const SurfaceId& id, 27 const SurfaceInfo& surface_info,
28 base::WeakPtr<CompositorFrameSinkSupport> compositor_frame_sink_support) 28 base::WeakPtr<CompositorFrameSinkSupport> compositor_frame_sink_support)
29 : surface_id_(id), 29 : surface_info_(surface_info),
30 previous_frame_surface_id_(id), 30 previous_frame_surface_id_(surface_info.id()),
31 compositor_frame_sink_support_(std::move(compositor_frame_sink_support)), 31 compositor_frame_sink_support_(std::move(compositor_frame_sink_support)),
32 surface_manager_(compositor_frame_sink_support_->surface_manager()), 32 surface_manager_(compositor_frame_sink_support_->surface_manager()),
33 frame_index_(kFrameIndexStart), 33 frame_index_(kFrameIndexStart),
34 destroyed_(false) {} 34 destroyed_(false) {}
35 35
36 Surface::~Surface() { 36 Surface::~Surface() {
37 ClearCopyRequests(); 37 ClearCopyRequests();
38 surface_manager_->SurfaceDiscarded(this); 38 surface_manager_->SurfaceDiscarded(this);
39 39
40 UnrefFrameResourcesAndRunDrawCallback(std::move(pending_frame_data_)); 40 UnrefFrameResourcesAndRunDrawCallback(std::move(pending_frame_data_));
41 UnrefFrameResourcesAndRunDrawCallback(std::move(active_frame_data_)); 41 UnrefFrameResourcesAndRunDrawCallback(std::move(active_frame_data_));
42 } 42 }
43 43
44 void Surface::SetPreviousFrameSurface(Surface* surface) { 44 void Surface::SetPreviousFrameSurface(Surface* surface) {
45 DCHECK(surface && (HasActiveFrame() || HasPendingFrame())); 45 DCHECK(surface && (HasActiveFrame() || HasPendingFrame()));
46 frame_index_ = surface->frame_index() + 1; 46 frame_index_ = surface->frame_index() + 1;
47 previous_frame_surface_id_ = surface->surface_id(); 47 previous_frame_surface_id_ = surface->surface_id();
48 CompositorFrame& frame = active_frame_data_ ? active_frame_data_->frame 48 CompositorFrame& frame = active_frame_data_ ? active_frame_data_->frame
49 : pending_frame_data_->frame; 49 : pending_frame_data_->frame;
50 surface->TakeLatencyInfo(&frame.metadata.latency_info); 50 surface->TakeLatencyInfo(&frame.metadata.latency_info);
51 surface->TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info); 51 surface->TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info);
52 } 52 }
53 53
54 void Surface::Close() { 54 void Surface::Close() {
55 closed_ = true; 55 closed_ = true;
56 } 56 }
57 57
58 void Surface::QueueFrame(CompositorFrame frame, 58 bool Surface::QueueFrame(CompositorFrame frame,
59 const base::Closure& callback, 59 const base::Closure& callback,
60 const WillDrawCallback& will_draw_callback) { 60 const WillDrawCallback& will_draw_callback) {
61 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size();
62 float device_scale_factor = frame.metadata.device_scale_factor;
63
64 if (frame_size != surface_info_.size_in_pixels() ||
65 device_scale_factor != surface_info_.device_scale_factor()) {
66 TRACE_EVENT_INSTANT0("cc", "Surface invariants violation",
67 TRACE_EVENT_SCOPE_THREAD);
68 return false;
69 }
70
61 if (closed_) { 71 if (closed_) {
62 if (compositor_frame_sink_support_) { 72 if (compositor_frame_sink_support_) {
63 ReturnedResourceArray resources; 73 ReturnedResourceArray resources;
64 TransferableResource::ReturnResources(frame.resource_list, &resources); 74 TransferableResource::ReturnResources(frame.resource_list, &resources);
65 compositor_frame_sink_support_->ReturnResources(resources); 75 compositor_frame_sink_support_->ReturnResources(resources);
66 } 76 }
67 callback.Run(); 77 callback.Run();
68 return; 78 return true;
69 } 79 }
70 80
71 TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info); 81 TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info);
72 82
73 base::Optional<FrameData> previous_pending_frame_data = 83 base::Optional<FrameData> previous_pending_frame_data =
74 std::move(pending_frame_data_); 84 std::move(pending_frame_data_);
75 pending_frame_data_.reset(); 85 pending_frame_data_.reset();
76 86
77 UpdateBlockingSurfaces(previous_pending_frame_data.has_value(), frame); 87 UpdateBlockingSurfaces(previous_pending_frame_data.has_value(), frame);
78 88
(...skipping 28 matching lines...) Expand all
107 // Ask the surface manager to inform |this| when its dependencies are 117 // Ask the surface manager to inform |this| when its dependencies are
108 // resolved. 118 // resolved.
109 surface_manager_->RequestSurfaceResolution(this); 119 surface_manager_->RequestSurfaceResolution(this);
110 } else { 120 } else {
111 // If there are no blockers, then immediately activate the frame. 121 // If there are no blockers, then immediately activate the frame.
112 ActivateFrame(FrameData(std::move(frame), callback, will_draw_callback)); 122 ActivateFrame(FrameData(std::move(frame), callback, will_draw_callback));
113 } 123 }
114 124
115 // Returns resources for the previous pending frame. 125 // Returns resources for the previous pending frame.
116 UnrefFrameResourcesAndRunDrawCallback(std::move(previous_pending_frame_data)); 126 UnrefFrameResourcesAndRunDrawCallback(std::move(previous_pending_frame_data));
127
128 return true;
117 } 129 }
118 130
119 void Surface::RequestCopyOfOutput( 131 void Surface::RequestCopyOfOutput(
120 std::unique_ptr<CopyOutputRequest> copy_request) { 132 std::unique_ptr<CopyOutputRequest> copy_request) {
121 if (!active_frame_data_) { 133 if (!active_frame_data_) {
122 copy_request->SendEmptyResult(); 134 copy_request->SendEmptyResult();
123 return; 135 return;
124 } 136 }
125 137
126 std::vector<std::unique_ptr<CopyOutputRequest>>& copy_requests = 138 std::vector<std::unique_ptr<CopyOutputRequest>>& copy_requests =
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 base::Closure callback = active_frame_data_->draw_callback; 312 base::Closure callback = active_frame_data_->draw_callback;
301 active_frame_data_->draw_callback = base::Closure(); 313 active_frame_data_->draw_callback = base::Closure();
302 callback.Run(); 314 callback.Run();
303 } 315 }
304 } 316 }
305 317
306 void Surface::RunWillDrawCallback(const gfx::Rect& damage_rect) { 318 void Surface::RunWillDrawCallback(const gfx::Rect& damage_rect) {
307 if (!active_frame_data_ || active_frame_data_->will_draw_callback.is_null()) 319 if (!active_frame_data_ || active_frame_data_->will_draw_callback.is_null())
308 return; 320 return;
309 321
310 active_frame_data_->will_draw_callback.Run(surface_id_.local_surface_id(), 322 active_frame_data_->will_draw_callback.Run(surface_id().local_surface_id(),
311 damage_rect); 323 damage_rect);
312 } 324 }
313 325
314 void Surface::AddDestructionDependency(SurfaceSequence sequence) { 326 void Surface::AddDestructionDependency(SurfaceSequence sequence) {
315 destruction_dependencies_.push_back(sequence); 327 destruction_dependencies_.push_back(sequence);
316 } 328 }
317 329
318 void Surface::SatisfyDestructionDependencies( 330 void Surface::SatisfyDestructionDependencies(
319 std::unordered_set<SurfaceSequence, SurfaceSequenceHash>* sequences, 331 std::unordered_set<SurfaceSequence, SurfaceSequenceHash>* sequences,
320 std::unordered_set<FrameSinkId, FrameSinkIdHash>* valid_frame_sink_ids) { 332 std::unordered_set<FrameSinkId, FrameSinkIdHash>* valid_frame_sink_ids) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 frame->metadata.latency_info.swap(*latency_info); 378 frame->metadata.latency_info.swap(*latency_info);
367 return; 379 return;
368 } 380 }
369 std::copy(frame->metadata.latency_info.begin(), 381 std::copy(frame->metadata.latency_info.begin(),
370 frame->metadata.latency_info.end(), 382 frame->metadata.latency_info.end(),
371 std::back_inserter(*latency_info)); 383 std::back_inserter(*latency_info));
372 frame->metadata.latency_info.clear(); 384 frame->metadata.latency_info.clear();
373 } 385 }
374 386
375 } // namespace cc 387 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/surface.h ('k') | cc/surfaces/surface_aggregator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698