Chromium Code Reviews| 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> |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 | 24 |
| 25 Surface::Surface(SurfaceId id, SurfaceFactory* factory) | 25 Surface::Surface(SurfaceId id, SurfaceFactory* factory) |
| 26 : surface_id_(id), | 26 : surface_id_(id), |
| 27 previous_frame_surface_id_(id), | 27 previous_frame_surface_id_(id), |
| 28 factory_(factory->AsWeakPtr()), | 28 factory_(factory->AsWeakPtr()), |
| 29 frame_index_(kFrameIndexStart), | 29 frame_index_(kFrameIndexStart), |
| 30 destroyed_(false) {} | 30 destroyed_(false) {} |
| 31 | 31 |
| 32 Surface::~Surface() { | 32 Surface::~Surface() { |
| 33 ClearCopyRequests(); | 33 ClearCopyRequests(); |
| 34 if (current_frame_ && factory_) { | 34 if (current_frame_.delegated_frame_data && factory_) { |
| 35 UnrefFrameResources(current_frame_->delegated_frame_data.get()); | 35 UnrefFrameResources(current_frame_.delegated_frame_data.get()); |
| 36 } | 36 } |
| 37 if (!draw_callback_.is_null()) | 37 if (!draw_callback_.is_null()) |
| 38 draw_callback_.Run(SurfaceDrawStatus::DRAW_SKIPPED); | 38 draw_callback_.Run(SurfaceDrawStatus::DRAW_SKIPPED); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void Surface::SetPreviousFrameSurface(Surface* surface) { | 41 void Surface::SetPreviousFrameSurface(Surface* surface) { |
| 42 DCHECK(surface); | 42 DCHECK(surface); |
| 43 frame_index_ = surface->frame_index() + 1; | 43 frame_index_ = surface->frame_index() + 1; |
| 44 previous_frame_surface_id_ = surface->surface_id(); | 44 previous_frame_surface_id_ = surface->surface_id(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void Surface::SetGpuMemoryBufferClientId(int gpu_memory_buffer_client_id) { | 47 void Surface::SetGpuMemoryBufferClientId(int gpu_memory_buffer_client_id) { |
| 48 // This should only be set once. | 48 // This should only be set once. |
| 49 DCHECK_EQ(-1, gpu_memory_buffer_client_id_); | 49 DCHECK_EQ(-1, gpu_memory_buffer_client_id_); |
| 50 DCHECK_NE(gpu_memory_buffer_client_id, gpu_memory_buffer_client_id_); | 50 DCHECK_NE(gpu_memory_buffer_client_id, gpu_memory_buffer_client_id_); |
| 51 gpu_memory_buffer_client_id_ = gpu_memory_buffer_client_id; | 51 gpu_memory_buffer_client_id_ = gpu_memory_buffer_client_id; |
| 52 } | 52 } |
| 53 | 53 |
| 54 void Surface::QueueFrame(std::unique_ptr<CompositorFrame> frame, | 54 void Surface::QueueFrame(CompositorFrame frame, const DrawCallback& callback) { |
| 55 const DrawCallback& callback) { | |
| 56 DCHECK(factory_); | 55 DCHECK(factory_); |
| 57 ClearCopyRequests(); | 56 ClearCopyRequests(); |
| 58 | 57 |
| 59 if (frame) { | 58 if (frame.delegated_frame_data) { |
| 60 TakeLatencyInfo(&frame->metadata.latency_info); | 59 TakeLatencyInfo(&frame.metadata.latency_info); |
| 61 } | 60 } |
| 62 | 61 |
| 63 std::unique_ptr<CompositorFrame> previous_frame = std::move(current_frame_); | 62 CompositorFrame previous_frame = std::move(current_frame_); |
| 64 current_frame_ = std::move(frame); | 63 current_frame_ = std::move(frame); |
| 65 | 64 |
| 66 if (current_frame_) { | 65 if (current_frame_.delegated_frame_data) { |
| 67 factory_->ReceiveFromChild( | 66 factory_->ReceiveFromChild( |
| 68 current_frame_->delegated_frame_data->resource_list); | 67 current_frame_.delegated_frame_data->resource_list); |
| 69 } | 68 } |
| 70 | 69 |
| 71 // Empty frames shouldn't be drawn and shouldn't contribute damage, so don't | 70 // Empty frames shouldn't be drawn and shouldn't contribute damage, so don't |
| 72 // increment frame index for them. | 71 // increment frame index for them. |
| 73 if (current_frame_ && | 72 if (current_frame_.delegated_frame_data && |
| 74 !current_frame_->delegated_frame_data->render_pass_list.empty()) | 73 !current_frame_.delegated_frame_data->render_pass_list.empty()) { |
| 75 ++frame_index_; | 74 ++frame_index_; |
| 75 } | |
| 76 | 76 |
| 77 previous_frame_surface_id_ = surface_id(); | 77 previous_frame_surface_id_ = surface_id(); |
| 78 | 78 |
| 79 std::vector<SurfaceId> new_referenced_surfaces; | 79 std::vector<SurfaceId> new_referenced_surfaces; |
| 80 if (current_frame_) { | 80 new_referenced_surfaces = current_frame_.metadata.referenced_surfaces; |
| 81 new_referenced_surfaces = current_frame_->metadata.referenced_surfaces; | |
| 82 } | |
| 83 | 81 |
| 84 if (previous_frame) { | 82 if (previous_frame.delegated_frame_data) |
| 85 UnrefFrameResources(previous_frame->delegated_frame_data.get()); | 83 UnrefFrameResources(previous_frame.delegated_frame_data.get()); |
| 86 } | 84 |
| 87 if (!draw_callback_.is_null()) | 85 if (!draw_callback_.is_null()) |
| 88 draw_callback_.Run(SurfaceDrawStatus::DRAW_SKIPPED); | 86 draw_callback_.Run(SurfaceDrawStatus::DRAW_SKIPPED); |
| 89 draw_callback_ = callback; | 87 draw_callback_ = callback; |
| 90 | 88 |
| 91 bool referenced_surfaces_changed = | 89 bool referenced_surfaces_changed = |
| 92 (referenced_surfaces_ != new_referenced_surfaces); | 90 (referenced_surfaces_ != new_referenced_surfaces); |
| 93 referenced_surfaces_ = new_referenced_surfaces; | 91 referenced_surfaces_ = new_referenced_surfaces; |
| 94 std::vector<uint32_t> satisfies_sequences; | 92 std::vector<uint32_t> satisfies_sequences; |
| 95 if (current_frame_) | 93 current_frame_.metadata.satisfies_sequences.swap(satisfies_sequences); |
|
danakj
2016/06/27 19:53:00
you can use move instead for this, and merge it wi
Fady Samuel
2016/06/28 17:19:10
Done.
| |
| 96 current_frame_->metadata.satisfies_sequences.swap(satisfies_sequences); | 94 |
| 97 if (referenced_surfaces_changed || !satisfies_sequences.empty()) { | 95 if (referenced_surfaces_changed || !satisfies_sequences.empty()) { |
| 98 // Notify the manager that sequences were satisfied either if some new | 96 // Notify the manager that sequences were satisfied either if some new |
| 99 // sequences were satisfied, or if the set of referenced surfaces changed | 97 // sequences were satisfied, or if the set of referenced surfaces changed |
| 100 // to force a GC to happen. | 98 // to force a GC to happen. |
| 101 factory_->manager()->DidSatisfySequences(surface_id_.id_namespace(), | 99 factory_->manager()->DidSatisfySequences(surface_id_.id_namespace(), |
| 102 &satisfies_sequences); | 100 &satisfies_sequences); |
| 103 } | 101 } |
| 104 } | 102 } |
| 105 | 103 |
| 106 void Surface::RequestCopyOfOutput( | 104 void Surface::RequestCopyOfOutput( |
| 107 std::unique_ptr<CopyOutputRequest> copy_request) { | 105 std::unique_ptr<CopyOutputRequest> copy_request) { |
| 108 if (current_frame_ && | 106 if (current_frame_.delegated_frame_data && |
| 109 !current_frame_->delegated_frame_data->render_pass_list.empty()) { | 107 !current_frame_.delegated_frame_data->render_pass_list.empty()) { |
| 110 std::vector<std::unique_ptr<CopyOutputRequest>>& copy_requests = | 108 std::vector<std::unique_ptr<CopyOutputRequest>>& copy_requests = |
| 111 current_frame_->delegated_frame_data->render_pass_list.back() | 109 current_frame_.delegated_frame_data->render_pass_list.back() |
| 112 ->copy_requests; | 110 ->copy_requests; |
| 113 | 111 |
| 114 if (void* source = copy_request->source()) { | 112 if (void* source = copy_request->source()) { |
| 115 // Remove existing CopyOutputRequests made on the Surface by the same | 113 // Remove existing CopyOutputRequests made on the Surface by the same |
| 116 // source. | 114 // source. |
| 117 auto to_remove = | 115 auto to_remove = |
| 118 std::remove_if(copy_requests.begin(), copy_requests.end(), | 116 std::remove_if(copy_requests.begin(), copy_requests.end(), |
| 119 [source](const std::unique_ptr<CopyOutputRequest>& x) { | 117 [source](const std::unique_ptr<CopyOutputRequest>& x) { |
| 120 return x->source() == source; | 118 return x->source() == source; |
| 121 }); | 119 }); |
| 122 copy_requests.erase(to_remove, copy_requests.end()); | 120 copy_requests.erase(to_remove, copy_requests.end()); |
| 123 } | 121 } |
| 124 copy_requests.push_back(std::move(copy_request)); | 122 copy_requests.push_back(std::move(copy_request)); |
| 125 } else { | 123 } else { |
| 126 copy_request->SendEmptyResult(); | 124 copy_request->SendEmptyResult(); |
| 127 } | 125 } |
| 128 } | 126 } |
| 129 | 127 |
| 130 void Surface::TakeCopyOutputRequests( | 128 void Surface::TakeCopyOutputRequests( |
| 131 std::multimap<RenderPassId, std::unique_ptr<CopyOutputRequest>>* | 129 std::multimap<RenderPassId, std::unique_ptr<CopyOutputRequest>>* |
| 132 copy_requests) { | 130 copy_requests) { |
| 133 DCHECK(copy_requests->empty()); | 131 DCHECK(copy_requests->empty()); |
| 134 if (current_frame_) { | 132 if (current_frame_.delegated_frame_data) { |
| 135 for (const auto& render_pass : | 133 for (const auto& render_pass : |
| 136 current_frame_->delegated_frame_data->render_pass_list) { | 134 current_frame_.delegated_frame_data->render_pass_list) { |
| 137 for (auto& request : render_pass->copy_requests) { | 135 for (auto& request : render_pass->copy_requests) { |
| 138 copy_requests->insert( | 136 copy_requests->insert( |
| 139 std::make_pair(render_pass->id, std::move(request))); | 137 std::make_pair(render_pass->id, std::move(request))); |
| 140 } | 138 } |
| 141 render_pass->copy_requests.clear(); | 139 render_pass->copy_requests.clear(); |
| 142 } | 140 } |
| 143 } | 141 } |
| 144 } | 142 } |
| 145 | 143 |
| 146 const CompositorFrame* Surface::GetEligibleFrame() { | 144 const CompositorFrame* Surface::GetEligibleFrame() { |
| 147 return current_frame_.get(); | 145 return ¤t_frame_; |
|
danakj
2016/06/27 19:53:00
There are callers that check if this is null. What
Fady Samuel
2016/06/28 17:19:10
I've let the compiler help me with the analysis. :
danakj
2016/06/28 19:01:09
Ya ok this should work for now. Eventually we're n
Fady Samuel
2016/06/28 19:24:19
The primary goal of this CL is to make Surface hol
| |
| 148 } | 146 } |
| 149 | 147 |
| 150 void Surface::TakeLatencyInfo(std::vector<ui::LatencyInfo>* latency_info) { | 148 void Surface::TakeLatencyInfo(std::vector<ui::LatencyInfo>* latency_info) { |
| 151 if (!current_frame_) | 149 if (!current_frame_.delegated_frame_data) |
| 152 return; | 150 return; |
| 153 if (latency_info->empty()) { | 151 if (latency_info->empty()) { |
| 154 current_frame_->metadata.latency_info.swap(*latency_info); | 152 current_frame_.metadata.latency_info.swap(*latency_info); |
| 155 return; | 153 return; |
| 156 } | 154 } |
| 157 std::copy(current_frame_->metadata.latency_info.begin(), | 155 std::copy(current_frame_.metadata.latency_info.begin(), |
| 158 current_frame_->metadata.latency_info.end(), | 156 current_frame_.metadata.latency_info.end(), |
| 159 std::back_inserter(*latency_info)); | 157 std::back_inserter(*latency_info)); |
| 160 current_frame_->metadata.latency_info.clear(); | 158 current_frame_.metadata.latency_info.clear(); |
| 161 } | 159 } |
| 162 | 160 |
| 163 void Surface::RunDrawCallbacks(SurfaceDrawStatus drawn) { | 161 void Surface::RunDrawCallbacks(SurfaceDrawStatus drawn) { |
| 164 if (!draw_callback_.is_null()) { | 162 if (!draw_callback_.is_null()) { |
| 165 DrawCallback callback = draw_callback_; | 163 DrawCallback callback = draw_callback_; |
| 166 draw_callback_ = DrawCallback(); | 164 draw_callback_ = DrawCallback(); |
| 167 callback.Run(drawn); | 165 callback.Run(drawn); |
| 168 } | 166 } |
| 169 } | 167 } |
| 170 | 168 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 188 void Surface::UnrefFrameResources(DelegatedFrameData* frame_data) { | 186 void Surface::UnrefFrameResources(DelegatedFrameData* frame_data) { |
| 189 ReturnedResourceArray resources; | 187 ReturnedResourceArray resources; |
| 190 TransferableResource::ReturnResources(frame_data->resource_list, &resources); | 188 TransferableResource::ReturnResources(frame_data->resource_list, &resources); |
| 191 // No point in returning same sync token to sender. | 189 // No point in returning same sync token to sender. |
| 192 for (auto& resource : resources) | 190 for (auto& resource : resources) |
| 193 resource.sync_token.Clear(); | 191 resource.sync_token.Clear(); |
| 194 factory_->UnrefResources(resources); | 192 factory_->UnrefResources(resources); |
| 195 } | 193 } |
| 196 | 194 |
| 197 void Surface::ClearCopyRequests() { | 195 void Surface::ClearCopyRequests() { |
| 198 if (current_frame_) { | 196 if (current_frame_.delegated_frame_data) { |
| 199 for (const auto& render_pass : | 197 for (const auto& render_pass : |
| 200 current_frame_->delegated_frame_data->render_pass_list) { | 198 current_frame_.delegated_frame_data->render_pass_list) { |
| 201 for (const auto& copy_request : render_pass->copy_requests) | 199 for (const auto& copy_request : render_pass->copy_requests) |
| 202 copy_request->SendEmptyResult(); | 200 copy_request->SendEmptyResult(); |
| 203 } | 201 } |
| 204 } | 202 } |
| 205 } | 203 } |
| 206 | 204 |
| 207 } // namespace cc | 205 } // namespace cc |
| OLD | NEW |