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

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 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 DLOG(ERROR) << "Frame size doesn't match surface size.";
67 NOTREACHED();
68 callback.Run();
Fady Samuel 2017/05/08 20:21:19 Return resources too?
Saman Sami 2017/05/08 20:40:32 Yeah sure.
69 return;
70 }
71
61 if (closed_) { 72 if (closed_) {
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
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 base::Closure callback = active_frame_data_->draw_callback; 310 base::Closure callback = active_frame_data_->draw_callback;
300 active_frame_data_->draw_callback = base::Closure(); 311 active_frame_data_->draw_callback = base::Closure();
301 callback.Run(); 312 callback.Run();
302 } 313 }
303 } 314 }
304 315
305 void Surface::RunWillDrawCallback(const gfx::Rect& damage_rect) { 316 void Surface::RunWillDrawCallback(const gfx::Rect& damage_rect) {
306 if (!active_frame_data_ || active_frame_data_->will_draw_callback.is_null()) 317 if (!active_frame_data_ || active_frame_data_->will_draw_callback.is_null())
307 return; 318 return;
308 319
309 active_frame_data_->will_draw_callback.Run(surface_id_.local_surface_id(), 320 active_frame_data_->will_draw_callback.Run(surface_id().local_surface_id(),
310 damage_rect); 321 damage_rect);
311 } 322 }
312 323
313 void Surface::AddDestructionDependency(SurfaceSequence sequence) { 324 void Surface::AddDestructionDependency(SurfaceSequence sequence) {
314 destruction_dependencies_.push_back(sequence); 325 destruction_dependencies_.push_back(sequence);
315 } 326 }
316 327
317 void Surface::SatisfyDestructionDependencies( 328 void Surface::SatisfyDestructionDependencies(
318 std::unordered_set<SurfaceSequence, SurfaceSequenceHash>* sequences, 329 std::unordered_set<SurfaceSequence, SurfaceSequenceHash>* sequences,
319 std::unordered_set<FrameSinkId, FrameSinkIdHash>* valid_frame_sink_ids) { 330 std::unordered_set<FrameSinkId, FrameSinkIdHash>* valid_frame_sink_ids) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 frame->metadata.latency_info.swap(*latency_info); 376 frame->metadata.latency_info.swap(*latency_info);
366 return; 377 return;
367 } 378 }
368 std::copy(frame->metadata.latency_info.begin(), 379 std::copy(frame->metadata.latency_info.begin(),
369 frame->metadata.latency_info.end(), 380 frame->metadata.latency_info.end(),
370 std::back_inserter(*latency_info)); 381 std::back_inserter(*latency_info));
371 frame->metadata.latency_info.clear(); 382 frame->metadata.latency_info.clear();
372 } 383 }
373 384
374 } // namespace cc 385 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698