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

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

Issue 2848223003: Enforce constant size and device scale factor for surfaces (Closed)
Patch Set: c 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
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_));
(...skipping 10 matching lines...) Expand all
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 void 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 if (closed_) { 61 bool reject_frame = closed_;
62
63 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size();
64 float device_scale_factor = frame.metadata.device_scale_factor;
65
66 if (frame_size != surface_info_.size_in_pixels() ||
67 device_scale_factor != surface_info_.device_scale_factor()) {
68 DLOG(FATAL) << "Rejected CompositorFrame that violates surface invariants.";
danakj 2017/05/18 15:15:54 can this be a trace event also?
Saman Sami 2017/05/18 20:44:37 Done.
69 reject_frame = true;
danakj 2017/05/17 20:49:36 How will this happen in practice? Why isn't this j
Saman Sami 2017/05/17 20:52:08 If the client misbehaves, for example.
danakj 2017/05/17 21:03:28 Can't we reject that at the IPC boundary instead o
Saman Sami 2017/05/17 21:22:50 We don't know the details of the surface at IPC bo
danakj 2017/05/17 21:25:28 I guess I am asking how far out we can push it the
Saman Sami 2017/05/17 21:39:26 I guess we can do the verification in CFSS but I'm
Fady Samuel 2017/05/18 11:45:25 +1 There isn't a whole lot up the stack in some ca
70 }
71
72 if (reject_frame) {
62 if (compositor_frame_sink_support_) { 73 if (compositor_frame_sink_support_) {
63 ReturnedResourceArray resources; 74 ReturnedResourceArray resources;
64 TransferableResource::ReturnResources(frame.resource_list, &resources); 75 TransferableResource::ReturnResources(frame.resource_list, &resources);
65 compositor_frame_sink_support_->ReturnResources(resources); 76 compositor_frame_sink_support_->ReturnResources(resources);
66 } 77 }
67 callback.Run(); 78 callback.Run();
68 return; 79 return;
69 } 80 }
70 81
71 TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info); 82 TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info);
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 base::Closure callback = active_frame_data_->draw_callback; 311 base::Closure callback = active_frame_data_->draw_callback;
301 active_frame_data_->draw_callback = base::Closure(); 312 active_frame_data_->draw_callback = base::Closure();
302 callback.Run(); 313 callback.Run();
303 } 314 }
304 } 315 }
305 316
306 void Surface::RunWillDrawCallback(const gfx::Rect& damage_rect) { 317 void Surface::RunWillDrawCallback(const gfx::Rect& damage_rect) {
307 if (!active_frame_data_ || active_frame_data_->will_draw_callback.is_null()) 318 if (!active_frame_data_ || active_frame_data_->will_draw_callback.is_null())
308 return; 319 return;
309 320
310 active_frame_data_->will_draw_callback.Run(surface_id_.local_surface_id(), 321 active_frame_data_->will_draw_callback.Run(surface_id().local_surface_id(),
311 damage_rect); 322 damage_rect);
312 } 323 }
313 324
314 void Surface::AddDestructionDependency(SurfaceSequence sequence) { 325 void Surface::AddDestructionDependency(SurfaceSequence sequence) {
315 destruction_dependencies_.push_back(sequence); 326 destruction_dependencies_.push_back(sequence);
316 } 327 }
317 328
318 void Surface::SatisfyDestructionDependencies( 329 void Surface::SatisfyDestructionDependencies(
319 std::unordered_set<SurfaceSequence, SurfaceSequenceHash>* sequences, 330 std::unordered_set<SurfaceSequence, SurfaceSequenceHash>* sequences,
320 std::unordered_set<FrameSinkId, FrameSinkIdHash>* valid_frame_sink_ids) { 331 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); 377 frame->metadata.latency_info.swap(*latency_info);
367 return; 378 return;
368 } 379 }
369 std::copy(frame->metadata.latency_info.begin(), 380 std::copy(frame->metadata.latency_info.begin(),
370 frame->metadata.latency_info.end(), 381 frame->metadata.latency_info.end(),
371 std::back_inserter(*latency_info)); 382 std::back_inserter(*latency_info));
372 frame->metadata.latency_info.clear(); 383 frame->metadata.latency_info.clear();
373 } 384 }
374 385
375 } // namespace cc 386 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698