OLD | NEW |
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 SurfaceInfo& surface_info, | 27 const SurfaceId& id, |
28 base::WeakPtr<CompositorFrameSinkSupport> compositor_frame_sink_support) | 28 base::WeakPtr<CompositorFrameSinkSupport> compositor_frame_sink_support) |
29 : surface_info_(surface_info), | 29 : surface_id_(id), |
30 previous_frame_surface_id_(surface_info.id()), | 30 previous_frame_surface_id_(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 bool 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 TRACE_EVENT_INSTANT0("cc", "Surface invariants violation", | |
67 TRACE_EVENT_SCOPE_THREAD); | |
68 return false; | |
69 } | |
70 | |
71 if (closed_) { | 61 if (closed_) { |
72 if (compositor_frame_sink_support_) { | 62 if (compositor_frame_sink_support_) { |
73 ReturnedResourceArray resources; | 63 ReturnedResourceArray resources; |
74 TransferableResource::ReturnResources(frame.resource_list, &resources); | 64 TransferableResource::ReturnResources(frame.resource_list, &resources); |
75 compositor_frame_sink_support_->ReturnResources(resources); | 65 compositor_frame_sink_support_->ReturnResources(resources); |
76 } | 66 } |
77 callback.Run(); | 67 callback.Run(); |
78 return true; | 68 return; |
79 } | 69 } |
80 | 70 |
81 TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info); | 71 TakeLatencyInfoFromPendingFrame(&frame.metadata.latency_info); |
82 | 72 |
83 base::Optional<FrameData> previous_pending_frame_data = | 73 base::Optional<FrameData> previous_pending_frame_data = |
84 std::move(pending_frame_data_); | 74 std::move(pending_frame_data_); |
85 pending_frame_data_.reset(); | 75 pending_frame_data_.reset(); |
86 | 76 |
87 UpdateBlockingSurfaces(previous_pending_frame_data.has_value(), frame); | 77 UpdateBlockingSurfaces(previous_pending_frame_data.has_value(), frame); |
88 | 78 |
(...skipping 28 matching lines...) Expand all Loading... |
117 // Ask the surface manager to inform |this| when its dependencies are | 107 // Ask the surface manager to inform |this| when its dependencies are |
118 // resolved. | 108 // resolved. |
119 surface_manager_->RequestSurfaceResolution(this); | 109 surface_manager_->RequestSurfaceResolution(this); |
120 } else { | 110 } else { |
121 // If there are no blockers, then immediately activate the frame. | 111 // If there are no blockers, then immediately activate the frame. |
122 ActivateFrame(FrameData(std::move(frame), callback, will_draw_callback)); | 112 ActivateFrame(FrameData(std::move(frame), callback, will_draw_callback)); |
123 } | 113 } |
124 | 114 |
125 // Returns resources for the previous pending frame. | 115 // Returns resources for the previous pending frame. |
126 UnrefFrameResourcesAndRunDrawCallback(std::move(previous_pending_frame_data)); | 116 UnrefFrameResourcesAndRunDrawCallback(std::move(previous_pending_frame_data)); |
127 | |
128 return true; | |
129 } | 117 } |
130 | 118 |
131 void Surface::RequestCopyOfOutput( | 119 void Surface::RequestCopyOfOutput( |
132 std::unique_ptr<CopyOutputRequest> copy_request) { | 120 std::unique_ptr<CopyOutputRequest> copy_request) { |
133 if (!active_frame_data_) { | 121 if (!active_frame_data_) { |
134 copy_request->SendEmptyResult(); | 122 copy_request->SendEmptyResult(); |
135 return; | 123 return; |
136 } | 124 } |
137 | 125 |
138 std::vector<std::unique_ptr<CopyOutputRequest>>& copy_requests = | 126 std::vector<std::unique_ptr<CopyOutputRequest>>& copy_requests = |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 base::Closure callback = active_frame_data_->draw_callback; | 300 base::Closure callback = active_frame_data_->draw_callback; |
313 active_frame_data_->draw_callback = base::Closure(); | 301 active_frame_data_->draw_callback = base::Closure(); |
314 callback.Run(); | 302 callback.Run(); |
315 } | 303 } |
316 } | 304 } |
317 | 305 |
318 void Surface::RunWillDrawCallback(const gfx::Rect& damage_rect) { | 306 void Surface::RunWillDrawCallback(const gfx::Rect& damage_rect) { |
319 if (!active_frame_data_ || active_frame_data_->will_draw_callback.is_null()) | 307 if (!active_frame_data_ || active_frame_data_->will_draw_callback.is_null()) |
320 return; | 308 return; |
321 | 309 |
322 active_frame_data_->will_draw_callback.Run(surface_id().local_surface_id(), | 310 active_frame_data_->will_draw_callback.Run(surface_id_.local_surface_id(), |
323 damage_rect); | 311 damage_rect); |
324 } | 312 } |
325 | 313 |
326 void Surface::AddDestructionDependency(SurfaceSequence sequence) { | 314 void Surface::AddDestructionDependency(SurfaceSequence sequence) { |
327 destruction_dependencies_.push_back(sequence); | 315 destruction_dependencies_.push_back(sequence); |
328 } | 316 } |
329 | 317 |
330 void Surface::SatisfyDestructionDependencies( | 318 void Surface::SatisfyDestructionDependencies( |
331 std::unordered_set<SurfaceSequence, SurfaceSequenceHash>* sequences, | 319 std::unordered_set<SurfaceSequence, SurfaceSequenceHash>* sequences, |
332 std::unordered_set<FrameSinkId, FrameSinkIdHash>* valid_frame_sink_ids) { | 320 std::unordered_set<FrameSinkId, FrameSinkIdHash>* valid_frame_sink_ids) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 frame->metadata.latency_info.swap(*latency_info); | 366 frame->metadata.latency_info.swap(*latency_info); |
379 return; | 367 return; |
380 } | 368 } |
381 std::copy(frame->metadata.latency_info.begin(), | 369 std::copy(frame->metadata.latency_info.begin(), |
382 frame->metadata.latency_info.end(), | 370 frame->metadata.latency_info.end(), |
383 std::back_inserter(*latency_info)); | 371 std::back_inserter(*latency_info)); |
384 frame->metadata.latency_info.clear(); | 372 frame->metadata.latency_info.clear(); |
385 } | 373 } |
386 | 374 |
387 } // namespace cc | 375 } // namespace cc |
OLD | NEW |