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
3 // found in the LICENSE file.
5 #include "cc/surfaces/surface.h"
7 #include "cc/output/compositor_frame.h"
8 #include "cc/output/copy_output_request.h"
9 #include "cc/surfaces/surface_factory.h"
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.
15 static const int kFrameIndexStart
= 2;
17 Surface::Surface(SurfaceId id
, const gfx::Size
& size
, SurfaceFactory
* factory
)
21 frame_index_(kFrameIndexStart
) {
26 ReturnedResourceArray current_resources
;
27 TransferableResource::ReturnResources(
28 current_frame_
->delegated_frame_data
->resource_list
,
30 factory_
->UnrefResources(current_resources
);
34 void Surface::QueueFrame(scoped_ptr
<CompositorFrame
> frame
,
35 const base::Closure
& callback
) {
36 TakeLatencyInfo(&frame
->metadata
.latency_info
);
37 scoped_ptr
<CompositorFrame
> previous_frame
= current_frame_
.Pass();
38 current_frame_
= frame
.Pass();
39 factory_
->ReceiveFromChild(
40 current_frame_
->delegated_frame_data
->resource_list
);
44 ReturnedResourceArray previous_resources
;
45 TransferableResource::ReturnResources(
46 previous_frame
->delegated_frame_data
->resource_list
,
48 factory_
->UnrefResources(previous_resources
);
50 if (!draw_callback_
.is_null())
52 draw_callback_
= callback
;
55 void Surface::RequestCopyOfOutput(scoped_ptr
<CopyOutputRequest
> copy_request
) {
56 // TODO(jbauman): Make this work.
57 copy_request
->SendEmptyResult();
60 const CompositorFrame
* Surface::GetEligibleFrame() {
61 return current_frame_
.get();
64 void Surface::TakeLatencyInfo(std::vector
<ui::LatencyInfo
>* latency_info
) {
67 if (latency_info
->empty()) {
68 current_frame_
->metadata
.latency_info
.swap(*latency_info
);
71 std::copy(current_frame_
->metadata
.latency_info
.begin(),
72 current_frame_
->metadata
.latency_info
.end(),
73 std::back_inserter(*latency_info
));
74 current_frame_
->metadata
.latency_info
.clear();
77 void Surface::RunDrawCallbacks() {
78 if (!draw_callback_
.is_null()) {
79 base::Closure callback
= draw_callback_
;
80 draw_callback_
= base::Closure();