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(); |
| 26 it != copy_requests_.end(); |
| 27 ++it) { |
| 28 (*it)->SendEmptyResult(); |
| 29 } |
| 30 copy_requests_.clear(); |
25 if (current_frame_) { | 31 if (current_frame_) { |
26 ReturnedResourceArray current_resources; | 32 ReturnedResourceArray current_resources; |
27 TransferableResource::ReturnResources( | 33 TransferableResource::ReturnResources( |
28 current_frame_->delegated_frame_data->resource_list, | 34 current_frame_->delegated_frame_data->resource_list, |
29 ¤t_resources); | 35 ¤t_resources); |
30 factory_->UnrefResources(current_resources); | 36 factory_->UnrefResources(current_resources); |
31 } | 37 } |
32 } | 38 } |
33 | 39 |
34 void Surface::QueueFrame(scoped_ptr<CompositorFrame> frame, | 40 void Surface::QueueFrame(scoped_ptr<CompositorFrame> frame, |
35 const base::Closure& callback) { | 41 const base::Closure& callback) { |
| 42 for (ScopedPtrVector<CopyOutputRequest>::iterator it = copy_requests_.begin(); |
| 43 it != copy_requests_.end(); |
| 44 ++it) { |
| 45 (*it)->SendEmptyResult(); |
| 46 } |
| 47 copy_requests_.clear(); |
| 48 |
36 TakeLatencyInfo(&frame->metadata.latency_info); | 49 TakeLatencyInfo(&frame->metadata.latency_info); |
37 scoped_ptr<CompositorFrame> previous_frame = current_frame_.Pass(); | 50 scoped_ptr<CompositorFrame> previous_frame = current_frame_.Pass(); |
38 current_frame_ = frame.Pass(); | 51 current_frame_ = frame.Pass(); |
39 factory_->ReceiveFromChild( | 52 factory_->ReceiveFromChild( |
40 current_frame_->delegated_frame_data->resource_list); | 53 current_frame_->delegated_frame_data->resource_list); |
41 ++frame_index_; | 54 ++frame_index_; |
42 | 55 |
43 if (previous_frame) { | 56 if (previous_frame) { |
44 ReturnedResourceArray previous_resources; | 57 ReturnedResourceArray previous_resources; |
45 TransferableResource::ReturnResources( | 58 TransferableResource::ReturnResources( |
46 previous_frame->delegated_frame_data->resource_list, | 59 previous_frame->delegated_frame_data->resource_list, |
47 &previous_resources); | 60 &previous_resources); |
48 factory_->UnrefResources(previous_resources); | 61 factory_->UnrefResources(previous_resources); |
49 } | 62 } |
50 if (!draw_callback_.is_null()) | 63 if (!draw_callback_.is_null()) |
51 draw_callback_.Run(); | 64 draw_callback_.Run(); |
52 draw_callback_ = callback; | 65 draw_callback_ = callback; |
53 } | 66 } |
54 | 67 |
55 void Surface::RequestCopyOfOutput(scoped_ptr<CopyOutputRequest> copy_request) { | 68 void Surface::RequestCopyOfOutput(scoped_ptr<CopyOutputRequest> copy_request) { |
56 // TODO(jbauman): Make this work. | 69 copy_requests_.push_back(copy_request.Pass()); |
57 copy_request->SendEmptyResult(); | 70 } |
| 71 |
| 72 void Surface::TakeCopyOutputRequests( |
| 73 ScopedPtrVector<CopyOutputRequest>* copy_requests) { |
| 74 DCHECK(copy_requests->empty()); |
| 75 copy_requests->swap(copy_requests_); |
58 } | 76 } |
59 | 77 |
60 const CompositorFrame* Surface::GetEligibleFrame() { | 78 const CompositorFrame* Surface::GetEligibleFrame() { |
61 return current_frame_.get(); | 79 return current_frame_.get(); |
62 } | 80 } |
63 | 81 |
64 void Surface::TakeLatencyInfo(std::vector<ui::LatencyInfo>* latency_info) { | 82 void Surface::TakeLatencyInfo(std::vector<ui::LatencyInfo>* latency_info) { |
65 if (!current_frame_) | 83 if (!current_frame_) |
66 return; | 84 return; |
67 if (latency_info->empty()) { | 85 if (latency_info->empty()) { |
68 current_frame_->metadata.latency_info.swap(*latency_info); | 86 current_frame_->metadata.latency_info.swap(*latency_info); |
69 return; | 87 return; |
70 } | 88 } |
71 std::copy(current_frame_->metadata.latency_info.begin(), | 89 std::copy(current_frame_->metadata.latency_info.begin(), |
72 current_frame_->metadata.latency_info.end(), | 90 current_frame_->metadata.latency_info.end(), |
73 std::back_inserter(*latency_info)); | 91 std::back_inserter(*latency_info)); |
74 current_frame_->metadata.latency_info.clear(); | 92 current_frame_->metadata.latency_info.clear(); |
75 } | 93 } |
76 | 94 |
77 void Surface::RunDrawCallbacks() { | 95 void Surface::RunDrawCallbacks() { |
78 if (!draw_callback_.is_null()) { | 96 if (!draw_callback_.is_null()) { |
79 base::Closure callback = draw_callback_; | 97 base::Closure callback = draw_callback_; |
80 draw_callback_ = base::Closure(); | 98 draw_callback_ = base::Closure(); |
81 callback.Run(); | 99 callback.Run(); |
82 } | 100 } |
83 } | 101 } |
84 | 102 |
85 } // namespace cc | 103 } // namespace cc |
OLD | NEW |