| 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 "cc/base/container_util.h" | 12 #include "cc/base/container_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/surface_factory.h" | 15 #include "cc/surfaces/surface_factory.h" |
| 16 #include "cc/surfaces/surface_id_allocator.h" | 16 #include "cc/surfaces/surface_id_allocator.h" |
| 17 #include "cc/surfaces/surface_manager.h" | 17 #include "cc/surfaces/surface_manager.h" |
| 18 | 18 |
| 19 namespace cc { | 19 namespace cc { |
| 20 | 20 |
| 21 // The frame index starts at 2 so that empty frames will be treated as | 21 // The frame index starts at 2 so that empty frames will be treated as |
| 22 // completely damaged the first time they're drawn from. | 22 // completely damaged the first time they're drawn from. |
| 23 static const int kFrameIndexStart = 2; | 23 static const int kFrameIndexStart = 2; |
| 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 factory_(factory->AsWeakPtr()), | 28 factory_(factory->AsWeakPtr()), |
| 28 frame_index_(kFrameIndexStart), | 29 frame_index_(kFrameIndexStart), |
| 29 destroyed_(false) {} | 30 destroyed_(false) {} |
| 30 | 31 |
| 31 Surface::~Surface() { | 32 Surface::~Surface() { |
| 32 ClearCopyRequests(); | 33 ClearCopyRequests(); |
| 33 if (current_frame_ && factory_) { | 34 if (current_frame_ && factory_) { |
| 34 ReturnedResourceArray current_resources; | 35 ReturnedResourceArray current_resources; |
| 35 TransferableResource::ReturnResources( | 36 TransferableResource::ReturnResources( |
| 36 current_frame_->delegated_frame_data->resource_list, | 37 current_frame_->delegated_frame_data->resource_list, |
| 37 ¤t_resources); | 38 ¤t_resources); |
| 38 factory_->UnrefResources(current_resources); | 39 factory_->UnrefResources(current_resources); |
| 39 } | 40 } |
| 40 if (!draw_callback_.is_null()) | 41 if (!draw_callback_.is_null()) |
| 41 draw_callback_.Run(SurfaceDrawStatus::DRAW_SKIPPED); | 42 draw_callback_.Run(SurfaceDrawStatus::DRAW_SKIPPED); |
| 42 } | 43 } |
| 43 | 44 |
| 45 void Surface::SetPreviousFrameSurface(Surface* surface) { |
| 46 DCHECK(surface); |
| 47 frame_index_ = surface->frame_index() + 1; |
| 48 previous_frame_surface_id_ = surface->surface_id(); |
| 49 } |
| 50 |
| 44 void Surface::QueueFrame(std::unique_ptr<CompositorFrame> frame, | 51 void Surface::QueueFrame(std::unique_ptr<CompositorFrame> frame, |
| 45 const DrawCallback& callback) { | 52 const DrawCallback& callback) { |
| 46 DCHECK(factory_); | 53 DCHECK(factory_); |
| 47 ClearCopyRequests(); | 54 ClearCopyRequests(); |
| 48 | 55 |
| 49 if (frame) { | 56 if (frame) { |
| 50 TakeLatencyInfo(&frame->metadata.latency_info); | 57 TakeLatencyInfo(&frame->metadata.latency_info); |
| 51 } | 58 } |
| 52 | 59 |
| 53 std::unique_ptr<CompositorFrame> previous_frame = std::move(current_frame_); | 60 std::unique_ptr<CompositorFrame> previous_frame = std::move(current_frame_); |
| 54 current_frame_ = std::move(frame); | 61 current_frame_ = std::move(frame); |
| 55 | 62 |
| 56 if (current_frame_) { | 63 if (current_frame_) { |
| 57 factory_->ReceiveFromChild( | 64 factory_->ReceiveFromChild( |
| 58 current_frame_->delegated_frame_data->resource_list); | 65 current_frame_->delegated_frame_data->resource_list); |
| 59 } | 66 } |
| 60 | 67 |
| 61 // Empty frames shouldn't be drawn and shouldn't contribute damage, so don't | 68 // Empty frames shouldn't be drawn and shouldn't contribute damage, so don't |
| 62 // increment frame index for them. | 69 // increment frame index for them. |
| 63 if (current_frame_ && | 70 if (current_frame_ && |
| 64 !current_frame_->delegated_frame_data->render_pass_list.empty()) | 71 !current_frame_->delegated_frame_data->render_pass_list.empty()) |
| 65 ++frame_index_; | 72 ++frame_index_; |
| 66 | 73 |
| 74 previous_frame_surface_id_ = surface_id(); |
| 75 |
| 67 std::vector<SurfaceId> new_referenced_surfaces; | 76 std::vector<SurfaceId> new_referenced_surfaces; |
| 68 if (current_frame_) { | 77 if (current_frame_) { |
| 69 new_referenced_surfaces = current_frame_->metadata.referenced_surfaces; | 78 new_referenced_surfaces = current_frame_->metadata.referenced_surfaces; |
| 70 } | 79 } |
| 71 | 80 |
| 72 if (previous_frame) { | 81 if (previous_frame) { |
| 73 ReturnedResourceArray previous_resources; | 82 ReturnedResourceArray previous_resources; |
| 74 TransferableResource::ReturnResources( | 83 TransferableResource::ReturnResources( |
| 75 previous_frame->delegated_frame_data->resource_list, | 84 previous_frame->delegated_frame_data->resource_list, |
| 76 &previous_resources); | 85 &previous_resources); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 if (current_frame_) { | 190 if (current_frame_) { |
| 182 for (const auto& render_pass : | 191 for (const auto& render_pass : |
| 183 current_frame_->delegated_frame_data->render_pass_list) { | 192 current_frame_->delegated_frame_data->render_pass_list) { |
| 184 for (const auto& copy_request : render_pass->copy_requests) | 193 for (const auto& copy_request : render_pass->copy_requests) |
| 185 copy_request->SendEmptyResult(); | 194 copy_request->SendEmptyResult(); |
| 186 } | 195 } |
| 187 } | 196 } |
| 188 } | 197 } |
| 189 | 198 |
| 190 } // namespace cc | 199 } // namespace cc |
| OLD | NEW |