1 // Copyright 2012 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/test/fake_output_surface.h"
8 #include "base/message_loop/message_loop.h"
9 #include "cc/output/compositor_frame_ack.h"
10 #include "cc/output/output_surface_client.h"
11 #include "cc/resources/returned_resource.h"
12 #include "cc/test/begin_frame_args_test.h"
13 #include "testing/gtest/include/gtest/gtest.h"
17 FakeOutputSurface::FakeOutputSurface(
18 scoped_refptr
<ContextProvider
> context_provider
,
19 scoped_refptr
<ContextProvider
> worker_context_provider
,
20 bool delegated_rendering
)
21 : OutputSurface(context_provider
, worker_context_provider
),
24 has_external_stencil_test_(false),
25 suspended_for_recycle_(false),
27 if (delegated_rendering
) {
28 capabilities_
.delegated_rendering
= true;
29 capabilities_
.max_frames_pending
= 1;
33 FakeOutputSurface::FakeOutputSurface(
34 scoped_refptr
<ContextProvider
> context_provider
,
35 bool delegated_rendering
)
36 : OutputSurface(context_provider
),
39 has_external_stencil_test_(false),
40 suspended_for_recycle_(false),
42 if (delegated_rendering
) {
43 capabilities_
.delegated_rendering
= true;
44 capabilities_
.max_frames_pending
= 1;
48 FakeOutputSurface::FakeOutputSurface(
49 scoped_ptr
<SoftwareOutputDevice
> software_device
,
50 bool delegated_rendering
)
51 : OutputSurface(software_device
.Pass()),
54 has_external_stencil_test_(false),
55 suspended_for_recycle_(false),
57 if (delegated_rendering
) {
58 capabilities_
.delegated_rendering
= true;
59 capabilities_
.max_frames_pending
= 1;
63 FakeOutputSurface::FakeOutputSurface(
64 scoped_refptr
<ContextProvider
> context_provider
,
65 scoped_ptr
<SoftwareOutputDevice
> software_device
,
66 bool delegated_rendering
)
67 : OutputSurface(context_provider
, software_device
.Pass()),
70 has_external_stencil_test_(false),
71 suspended_for_recycle_(false),
73 if (delegated_rendering
) {
74 capabilities_
.delegated_rendering
= true;
75 capabilities_
.max_frames_pending
= 1;
79 FakeOutputSurface::~FakeOutputSurface() {}
81 void FakeOutputSurface::SwapBuffers(CompositorFrame
* frame
) {
82 if (frame
->delegated_frame_data
|| !context_provider()) {
83 frame
->AssignTo(&last_sent_frame_
);
85 if (last_sent_frame_
.delegated_frame_data
) {
86 resources_held_by_parent_
.insert(
87 resources_held_by_parent_
.end(),
88 last_sent_frame_
.delegated_frame_data
->resource_list
.begin(),
89 last_sent_frame_
.delegated_frame_data
->resource_list
.end());
94 last_swap_rect_
= frame
->gl_frame_data
->sub_buffer_rect
;
95 frame
->AssignTo(&last_sent_frame_
);
98 PostSwapBuffersComplete();
99 client_
->DidSwapBuffers();
102 void FakeOutputSurface::BindFramebuffer() {
104 context_provider_
->ContextGL()->BindFramebuffer(GL_FRAMEBUFFER
,
107 OutputSurface::BindFramebuffer();
110 bool FakeOutputSurface::BindToClient(OutputSurfaceClient
* client
) {
111 if (OutputSurface::BindToClient(client
)) {
113 if (memory_policy_to_set_at_bind_
) {
114 client_
->SetMemoryPolicy(*memory_policy_to_set_at_bind_
.get());
115 memory_policy_to_set_at_bind_
= nullptr;
123 void FakeOutputSurface::SetTreeActivationCallback(
124 const base::Closure
& callback
) {
126 client_
->SetTreeActivationCallback(callback
);
129 void FakeOutputSurface::ReturnResource(unsigned id
, CompositorFrameAck
* ack
) {
130 TransferableResourceArray::iterator it
;
131 for (it
= resources_held_by_parent_
.begin();
132 it
!= resources_held_by_parent_
.end();
137 DCHECK(it
!= resources_held_by_parent_
.end());
138 ack
->resources
.push_back(it
->ToReturnedResource());
139 resources_held_by_parent_
.erase(it
);
142 bool FakeOutputSurface::HasExternalStencilTest() const {
143 return has_external_stencil_test_
;
146 bool FakeOutputSurface::SurfaceIsSuspendForRecycle() const {
147 return suspended_for_recycle_
;
150 void FakeOutputSurface::SetMemoryPolicyToSetAtBind(
151 scoped_ptr
<ManagedMemoryPolicy
> memory_policy_to_set_at_bind
) {
152 memory_policy_to_set_at_bind_
.swap(memory_policy_to_set_at_bind
);