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 "cc/output/compositor_frame.h" | 7 #include "cc/output/compositor_frame.h" |
8 #include "cc/output/copy_output_request.h" | 8 #include "cc/output/copy_output_request.h" |
9 #include "cc/surfaces/surface_factory.h" | 9 #include "cc/surfaces/surface_factory.h" |
10 | 10 |
11 namespace cc { | 11 namespace cc { |
12 | 12 |
13 // The frame index starts at 2 so that empty frames will be treated as | 13 // The frame index starts at 2 so that empty frames will be treated as |
14 // completely damaged the first time they're drawn from. | 14 // completely damaged the first time they're drawn from. |
15 static const int kFrameIndexStart = 2; | 15 static const int kFrameIndexStart = 2; |
16 | 16 |
17 Surface::Surface(SurfaceId id, const gfx::Size& size, SurfaceFactory* factory) | 17 Surface::Surface(SurfaceId id, const gfx::Size& size, SurfaceFactory* factory) |
18 : surface_id_(id), | 18 : surface_id_(id), |
19 size_(size), | 19 size_(size), |
20 factory_(factory), | 20 factory_(factory), |
21 frame_index_(kFrameIndexStart) { | 21 frame_index_(kFrameIndexStart) { |
22 } | 22 } |
23 | 23 |
24 Surface::~Surface() { | 24 Surface::~Surface() { |
25 for (ScopedPtrVector<CopyOutputRequest>::iterator it = copy_requests_.begin(); | 25 ClearCopyRequests(); |
26 it != copy_requests_.end(); | |
27 ++it) { | |
28 (*it)->SendEmptyResult(); | |
29 } | |
30 copy_requests_.clear(); | |
31 if (current_frame_) { | 26 if (current_frame_) { |
32 ReturnedResourceArray current_resources; | 27 ReturnedResourceArray current_resources; |
33 TransferableResource::ReturnResources( | 28 TransferableResource::ReturnResources( |
34 current_frame_->delegated_frame_data->resource_list, | 29 current_frame_->delegated_frame_data->resource_list, |
35 ¤t_resources); | 30 ¤t_resources); |
36 factory_->UnrefResources(current_resources); | 31 factory_->UnrefResources(current_resources); |
37 } | 32 } |
38 } | 33 } |
39 | 34 |
40 void Surface::QueueFrame(scoped_ptr<CompositorFrame> frame, | 35 void Surface::QueueFrame(scoped_ptr<CompositorFrame> frame, |
41 const base::Closure& callback) { | 36 const base::Closure& callback) { |
42 for (ScopedPtrVector<CopyOutputRequest>::iterator it = copy_requests_.begin(); | 37 ClearCopyRequests(); |
43 it != copy_requests_.end(); | |
44 ++it) { | |
45 (*it)->SendEmptyResult(); | |
46 } | |
47 copy_requests_.clear(); | |
48 | |
49 TakeLatencyInfo(&frame->metadata.latency_info); | 38 TakeLatencyInfo(&frame->metadata.latency_info); |
50 scoped_ptr<CompositorFrame> previous_frame = current_frame_.Pass(); | 39 scoped_ptr<CompositorFrame> previous_frame = current_frame_.Pass(); |
51 current_frame_ = frame.Pass(); | 40 current_frame_ = frame.Pass(); |
52 factory_->ReceiveFromChild( | 41 factory_->ReceiveFromChild( |
53 current_frame_->delegated_frame_data->resource_list); | 42 current_frame_->delegated_frame_data->resource_list); |
54 ++frame_index_; | 43 ++frame_index_; |
55 | 44 |
56 if (previous_frame) { | 45 if (previous_frame) { |
57 ReturnedResourceArray previous_resources; | 46 ReturnedResourceArray previous_resources; |
58 TransferableResource::ReturnResources( | 47 TransferableResource::ReturnResources( |
59 previous_frame->delegated_frame_data->resource_list, | 48 previous_frame->delegated_frame_data->resource_list, |
60 &previous_resources); | 49 &previous_resources); |
61 factory_->UnrefResources(previous_resources); | 50 factory_->UnrefResources(previous_resources); |
62 } | 51 } |
63 if (!draw_callback_.is_null()) | 52 if (!draw_callback_.is_null()) |
64 draw_callback_.Run(); | 53 draw_callback_.Run(); |
65 draw_callback_ = callback; | 54 draw_callback_ = callback; |
66 } | 55 } |
67 | 56 |
68 void Surface::RequestCopyOfOutput(scoped_ptr<CopyOutputRequest> copy_request) { | 57 void Surface::RequestCopyOfOutput(scoped_ptr<CopyOutputRequest> copy_request) { |
69 copy_requests_.push_back(copy_request.Pass()); | 58 if (current_frame_ && |
| 59 !current_frame_->delegated_frame_data->render_pass_list.empty()) |
| 60 current_frame_->delegated_frame_data->render_pass_list.back() |
| 61 ->copy_requests.push_back(copy_request.Pass()); |
| 62 else |
| 63 copy_request->SendEmptyResult(); |
70 } | 64 } |
71 | 65 |
72 void Surface::TakeCopyOutputRequests( | 66 void Surface::TakeCopyOutputRequests( |
73 ScopedPtrVector<CopyOutputRequest>* copy_requests) { | 67 ScopedPtrVector<ScopedPtrVector<CopyOutputRequest>>* copy_requests) { |
74 DCHECK(copy_requests->empty()); | 68 DCHECK(copy_requests->empty()); |
75 copy_requests->swap(copy_requests_); | 69 if (current_frame_) { |
| 70 for (auto* render_pass : |
| 71 current_frame_->delegated_frame_data->render_pass_list) { |
| 72 copy_requests->push_back( |
| 73 make_scoped_ptr(new ScopedPtrVector<CopyOutputRequest>())); |
| 74 copy_requests->back()->swap(render_pass->copy_requests); |
| 75 } |
| 76 } |
76 } | 77 } |
77 | 78 |
78 const CompositorFrame* Surface::GetEligibleFrame() { | 79 const CompositorFrame* Surface::GetEligibleFrame() { |
79 return current_frame_.get(); | 80 return current_frame_.get(); |
80 } | 81 } |
81 | 82 |
82 void Surface::TakeLatencyInfo(std::vector<ui::LatencyInfo>* latency_info) { | 83 void Surface::TakeLatencyInfo(std::vector<ui::LatencyInfo>* latency_info) { |
83 if (!current_frame_) | 84 if (!current_frame_) |
84 return; | 85 return; |
85 if (latency_info->empty()) { | 86 if (latency_info->empty()) { |
86 current_frame_->metadata.latency_info.swap(*latency_info); | 87 current_frame_->metadata.latency_info.swap(*latency_info); |
87 return; | 88 return; |
88 } | 89 } |
89 std::copy(current_frame_->metadata.latency_info.begin(), | 90 std::copy(current_frame_->metadata.latency_info.begin(), |
90 current_frame_->metadata.latency_info.end(), | 91 current_frame_->metadata.latency_info.end(), |
91 std::back_inserter(*latency_info)); | 92 std::back_inserter(*latency_info)); |
92 current_frame_->metadata.latency_info.clear(); | 93 current_frame_->metadata.latency_info.clear(); |
93 } | 94 } |
94 | 95 |
95 void Surface::RunDrawCallbacks() { | 96 void Surface::RunDrawCallbacks() { |
96 if (!draw_callback_.is_null()) { | 97 if (!draw_callback_.is_null()) { |
97 base::Closure callback = draw_callback_; | 98 base::Closure callback = draw_callback_; |
98 draw_callback_ = base::Closure(); | 99 draw_callback_ = base::Closure(); |
99 callback.Run(); | 100 callback.Run(); |
100 } | 101 } |
101 } | 102 } |
102 | 103 |
| 104 void Surface::ClearCopyRequests() { |
| 105 if (current_frame_) { |
| 106 for (auto* render_pass : |
| 107 current_frame_->delegated_frame_data->render_pass_list) { |
| 108 for (auto* copy_request : render_pass->copy_requests) |
| 109 copy_request->SendEmptyResult(); |
| 110 } |
| 111 } |
| 112 } |
| 113 |
103 } // namespace cc | 114 } // namespace cc |
OLD | NEW |