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 #include "cc/surfaces/surface_manager.h" |
10 | 11 |
11 namespace cc { | 12 namespace cc { |
12 | 13 |
13 // The frame index starts at 2 so that empty frames will be treated as | 14 // The frame index starts at 2 so that empty frames will be treated as |
14 // completely damaged the first time they're drawn from. | 15 // completely damaged the first time they're drawn from. |
15 static const int kFrameIndexStart = 2; | 16 static const int kFrameIndexStart = 2; |
16 | 17 |
17 Surface::Surface(SurfaceId id, const gfx::Size& size, SurfaceFactory* factory) | 18 Surface::Surface(SurfaceId id, const gfx::Size& size, SurfaceFactory* factory) |
18 : surface_id_(id), | 19 : surface_id_(id), |
19 size_(size), | 20 size_(size), |
20 factory_(factory), | 21 factory_(factory->AsWeakPtr()), |
21 frame_index_(kFrameIndexStart) { | 22 frame_index_(kFrameIndexStart) { |
22 } | 23 } |
23 | 24 |
24 Surface::~Surface() { | 25 Surface::~Surface() { |
25 for (ScopedPtrVector<CopyOutputRequest>::iterator it = copy_requests_.begin(); | 26 for (ScopedPtrVector<CopyOutputRequest>::iterator it = copy_requests_.begin(); |
26 it != copy_requests_.end(); | 27 it != copy_requests_.end(); |
27 ++it) { | 28 ++it) { |
28 (*it)->SendEmptyResult(); | 29 (*it)->SendEmptyResult(); |
29 } | 30 } |
30 copy_requests_.clear(); | 31 copy_requests_.clear(); |
31 if (current_frame_) { | 32 if (current_frame_ && factory_) { |
32 ReturnedResourceArray current_resources; | 33 ReturnedResourceArray current_resources; |
33 TransferableResource::ReturnResources( | 34 TransferableResource::ReturnResources( |
34 current_frame_->delegated_frame_data->resource_list, | 35 current_frame_->delegated_frame_data->resource_list, |
35 ¤t_resources); | 36 ¤t_resources); |
36 factory_->UnrefResources(current_resources); | 37 factory_->UnrefResources(current_resources); |
37 } | 38 } |
38 } | 39 } |
39 | 40 |
40 void Surface::QueueFrame(scoped_ptr<CompositorFrame> frame, | 41 void Surface::QueueFrame(scoped_ptr<CompositorFrame> frame, |
41 const base::Closure& callback) { | 42 const base::Closure& callback) { |
| 43 DCHECK(factory_); |
42 for (ScopedPtrVector<CopyOutputRequest>::iterator it = copy_requests_.begin(); | 44 for (ScopedPtrVector<CopyOutputRequest>::iterator it = copy_requests_.begin(); |
43 it != copy_requests_.end(); | 45 it != copy_requests_.end(); |
44 ++it) { | 46 ++it) { |
45 (*it)->SendEmptyResult(); | 47 (*it)->SendEmptyResult(); |
46 } | 48 } |
47 copy_requests_.clear(); | 49 copy_requests_.clear(); |
48 | 50 |
49 TakeLatencyInfo(&frame->metadata.latency_info); | 51 TakeLatencyInfo(&frame->metadata.latency_info); |
50 scoped_ptr<CompositorFrame> previous_frame = current_frame_.Pass(); | 52 scoped_ptr<CompositorFrame> previous_frame = current_frame_.Pass(); |
51 current_frame_ = frame.Pass(); | 53 current_frame_ = frame.Pass(); |
52 factory_->ReceiveFromChild( | 54 factory_->ReceiveFromChild( |
53 current_frame_->delegated_frame_data->resource_list); | 55 current_frame_->delegated_frame_data->resource_list); |
54 ++frame_index_; | 56 ++frame_index_; |
55 | 57 |
56 if (previous_frame) { | 58 if (previous_frame) { |
57 ReturnedResourceArray previous_resources; | 59 ReturnedResourceArray previous_resources; |
58 TransferableResource::ReturnResources( | 60 TransferableResource::ReturnResources( |
59 previous_frame->delegated_frame_data->resource_list, | 61 previous_frame->delegated_frame_data->resource_list, |
60 &previous_resources); | 62 &previous_resources); |
61 factory_->UnrefResources(previous_resources); | 63 factory_->UnrefResources(previous_resources); |
62 } | 64 } |
63 if (!draw_callback_.is_null()) | 65 if (!draw_callback_.is_null()) |
64 draw_callback_.Run(); | 66 draw_callback_.Run(); |
65 draw_callback_ = callback; | 67 draw_callback_ = callback; |
| 68 factory_->manager()->DidSatisfySequences( |
| 69 surface_id_, ¤t_frame_->metadata.satisfies_sequences); |
66 } | 70 } |
67 | 71 |
68 void Surface::RequestCopyOfOutput(scoped_ptr<CopyOutputRequest> copy_request) { | 72 void Surface::RequestCopyOfOutput(scoped_ptr<CopyOutputRequest> copy_request) { |
69 copy_requests_.push_back(copy_request.Pass()); | 73 copy_requests_.push_back(copy_request.Pass()); |
70 } | 74 } |
71 | 75 |
72 void Surface::TakeCopyOutputRequests( | 76 void Surface::TakeCopyOutputRequests( |
73 ScopedPtrVector<CopyOutputRequest>* copy_requests) { | 77 ScopedPtrVector<CopyOutputRequest>* copy_requests) { |
74 DCHECK(copy_requests->empty()); | 78 DCHECK(copy_requests->empty()); |
75 copy_requests->swap(copy_requests_); | 79 copy_requests->swap(copy_requests_); |
(...skipping 18 matching lines...) Expand all Loading... |
94 | 98 |
95 void Surface::RunDrawCallbacks() { | 99 void Surface::RunDrawCallbacks() { |
96 if (!draw_callback_.is_null()) { | 100 if (!draw_callback_.is_null()) { |
97 base::Closure callback = draw_callback_; | 101 base::Closure callback = draw_callback_; |
98 draw_callback_ = base::Closure(); | 102 draw_callback_ = base::Closure(); |
99 callback.Run(); | 103 callback.Run(); |
100 } | 104 } |
101 } | 105 } |
102 | 106 |
103 } // namespace cc | 107 } // namespace cc |
OLD | NEW |