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/surfaces/surface_factory.h" | 8 #include "cc/surfaces/surface_factory.h" |
9 | 9 |
10 namespace cc { | 10 namespace cc { |
11 | 11 |
12 Surface::Surface(SurfaceId id, const gfx::Size& size, SurfaceFactory* factory) | 12 Surface::Surface(SurfaceId id, const gfx::Size& size, SurfaceFactory* factory) |
13 : surface_id_(id), size_(size), factory_(factory) { | 13 : surface_id_(id), size_(size), factory_(factory), frame_index_(2) { |
jamesr
2014/08/26 22:06:22
why 2? just for debugging?
| |
14 } | 14 } |
15 | 15 |
16 Surface::~Surface() { | 16 Surface::~Surface() { |
17 if (current_frame_) { | 17 if (current_frame_) { |
18 ReturnedResourceArray current_resources; | 18 ReturnedResourceArray current_resources; |
19 TransferableResource::ReturnResources( | 19 TransferableResource::ReturnResources( |
20 current_frame_->delegated_frame_data->resource_list, | 20 current_frame_->delegated_frame_data->resource_list, |
21 ¤t_resources); | 21 ¤t_resources); |
22 factory_->UnrefResources(current_resources); | 22 factory_->UnrefResources(current_resources); |
23 } | 23 } |
24 } | 24 } |
25 | 25 |
26 void Surface::QueueFrame(scoped_ptr<CompositorFrame> frame, | 26 void Surface::QueueFrame(scoped_ptr<CompositorFrame> frame, |
27 const base::Closure& callback) { | 27 const base::Closure& callback) { |
28 scoped_ptr<CompositorFrame> previous_frame = current_frame_.Pass(); | 28 scoped_ptr<CompositorFrame> previous_frame = current_frame_.Pass(); |
29 current_frame_ = frame.Pass(); | 29 current_frame_ = frame.Pass(); |
30 factory_->ReceiveFromChild( | 30 factory_->ReceiveFromChild( |
31 current_frame_->delegated_frame_data->resource_list); | 31 current_frame_->delegated_frame_data->resource_list); |
32 ++frame_index_; | |
32 | 33 |
33 if (previous_frame) { | 34 if (previous_frame) { |
34 ReturnedResourceArray previous_resources; | 35 ReturnedResourceArray previous_resources; |
35 TransferableResource::ReturnResources( | 36 TransferableResource::ReturnResources( |
36 previous_frame->delegated_frame_data->resource_list, | 37 previous_frame->delegated_frame_data->resource_list, |
37 &previous_resources); | 38 &previous_resources); |
38 factory_->UnrefResources(previous_resources); | 39 factory_->UnrefResources(previous_resources); |
39 } | 40 } |
40 if (!draw_callback_.is_null()) | 41 if (!draw_callback_.is_null()) |
41 draw_callback_.Run(); | 42 draw_callback_.Run(); |
42 draw_callback_ = callback; | 43 draw_callback_ = callback; |
43 } | 44 } |
44 | 45 |
45 const CompositorFrame* Surface::GetEligibleFrame() { | 46 const CompositorFrame* Surface::GetEligibleFrame() { |
46 return current_frame_.get(); | 47 return current_frame_.get(); |
47 } | 48 } |
48 | 49 |
49 void Surface::RunDrawCallbacks() { | 50 void Surface::RunDrawCallbacks() { |
50 if (!draw_callback_.is_null()) { | 51 if (!draw_callback_.is_null()) { |
51 base::Closure callback = draw_callback_; | 52 base::Closure callback = draw_callback_; |
52 draw_callback_ = base::Closure(); | 53 draw_callback_ = base::Closure(); |
53 callback.Run(); | 54 callback.Run(); |
54 } | 55 } |
55 } | 56 } |
56 | 57 |
57 } // namespace cc | 58 } // namespace cc |
OLD | NEW |