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"
9 #include "cc/output/compositor_frame.h"
10 #include "cc/output/copy_output_request.h"
11 #include "cc/surfaces/surface_factory.h"
12 #include "cc/surfaces/surface_manager.h"
16 // The frame index starts at 2 so that empty frames will be treated as
17 // completely damaged the first time they're drawn from.
18 static const int kFrameIndexStart
= 2;
20 Surface::Surface(SurfaceId id
, const gfx::Size
& size
, SurfaceFactory
* factory
)
23 factory_(factory
->AsWeakPtr()),
24 frame_index_(kFrameIndexStart
) {
29 if (current_frame_
&& factory_
) {
30 ReturnedResourceArray current_resources
;
31 TransferableResource::ReturnResources(
32 current_frame_
->delegated_frame_data
->resource_list
,
34 factory_
->UnrefResources(current_resources
);
38 void Surface::QueueFrame(scoped_ptr
<CompositorFrame
> frame
,
39 const base::Closure
& callback
) {
42 TakeLatencyInfo(&frame
->metadata
.latency_info
);
43 scoped_ptr
<CompositorFrame
> previous_frame
= current_frame_
.Pass();
44 current_frame_
= frame
.Pass();
45 factory_
->ReceiveFromChild(
46 current_frame_
->delegated_frame_data
->resource_list
);
50 ReturnedResourceArray previous_resources
;
51 TransferableResource::ReturnResources(
52 previous_frame
->delegated_frame_data
->resource_list
,
54 factory_
->UnrefResources(previous_resources
);
56 if (!draw_callback_
.is_null())
58 draw_callback_
= callback
;
59 factory_
->manager()->DidSatisfySequences(
60 surface_id_
, ¤t_frame_
->metadata
.satisfies_sequences
);
63 void Surface::RequestCopyOfOutput(scoped_ptr
<CopyOutputRequest
> copy_request
) {
65 !current_frame_
->delegated_frame_data
->render_pass_list
.empty())
66 current_frame_
->delegated_frame_data
->render_pass_list
.back()
67 ->copy_requests
.push_back(copy_request
.Pass());
69 copy_request
->SendEmptyResult();
72 void Surface::TakeCopyOutputRequests(
73 std::multimap
<RenderPassId
, CopyOutputRequest
*>* copy_requests
) {
74 DCHECK(copy_requests
->empty());
76 for (const auto& render_pass
:
77 current_frame_
->delegated_frame_data
->render_pass_list
) {
78 while (!render_pass
->copy_requests
.empty()) {
79 scoped_ptr
<CopyOutputRequest
> request
=
80 render_pass
->copy_requests
.take_back();
81 render_pass
->copy_requests
.pop_back();
82 copy_requests
->insert(
83 std::make_pair(render_pass
->id
, request
.release()));
89 const CompositorFrame
* Surface::GetEligibleFrame() {
90 return current_frame_
.get();
93 void Surface::TakeLatencyInfo(std::vector
<ui::LatencyInfo
>* latency_info
) {
96 if (latency_info
->empty()) {
97 current_frame_
->metadata
.latency_info
.swap(*latency_info
);
100 std::copy(current_frame_
->metadata
.latency_info
.begin(),
101 current_frame_
->metadata
.latency_info
.end(),
102 std::back_inserter(*latency_info
));
103 current_frame_
->metadata
.latency_info
.clear();
106 void Surface::RunDrawCallbacks() {
107 if (!draw_callback_
.is_null()) {
108 base::Closure callback
= draw_callback_
;
109 draw_callback_
= base::Closure();
114 void Surface::ClearCopyRequests() {
115 if (current_frame_
) {
116 for (const auto& render_pass
:
117 current_frame_
->delegated_frame_data
->render_pass_list
) {
118 for (const auto& copy_request
: render_pass
->copy_requests
)
119 copy_request
->SendEmptyResult();