| 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) { |
| 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 scoped_ptr<CompositorFrame> previous_frame = current_frame_.Pass(); | 28 scoped_ptr<CompositorFrame> previous_frame = current_frame_.Pass(); |
| 28 current_frame_ = frame.Pass(); | 29 current_frame_ = frame.Pass(); |
| 29 factory_->ReceiveFromChild( | 30 factory_->ReceiveFromChild( |
| 30 current_frame_->delegated_frame_data->resource_list); | 31 current_frame_->delegated_frame_data->resource_list); |
| 31 | 32 |
| 32 if (previous_frame) { | 33 if (previous_frame) { |
| 33 ReturnedResourceArray previous_resources; | 34 ReturnedResourceArray previous_resources; |
| 34 TransferableResource::ReturnResources( | 35 TransferableResource::ReturnResources( |
| 35 previous_frame->delegated_frame_data->resource_list, | 36 previous_frame->delegated_frame_data->resource_list, |
| 36 &previous_resources); | 37 &previous_resources); |
| 37 factory_->UnrefResources(previous_resources); | 38 factory_->UnrefResources(previous_resources); |
| 38 } | 39 } |
| 40 if (!draw_callback_.is_null()) |
| 41 draw_callback_.Run(); |
| 42 draw_callback_ = callback; |
| 39 } | 43 } |
| 40 | 44 |
| 41 const CompositorFrame* Surface::GetEligibleFrame() { | 45 const CompositorFrame* Surface::GetEligibleFrame() { |
| 42 return current_frame_.get(); | 46 return current_frame_.get(); |
| 43 } | 47 } |
| 44 | 48 |
| 49 void Surface::RunDrawCallbacks() { |
| 50 if (!draw_callback_.is_null()) { |
| 51 base::Closure callback = draw_callback_; |
| 52 draw_callback_ = base::Closure(); |
| 53 callback.Run(); |
| 54 } |
| 55 } |
| 56 |
| 45 } // namespace cc | 57 } // namespace cc |
| OLD | NEW |