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),
26 if (delegated_rendering
) {
27 capabilities_
.delegated_rendering
= true;
28 capabilities_
.max_frames_pending
= 1;
32 FakeOutputSurface::FakeOutputSurface(
33 scoped_refptr
<ContextProvider
> context_provider
,
34 bool delegated_rendering
)
35 : OutputSurface(context_provider
),
38 has_external_stencil_test_(false),
40 if (delegated_rendering
) {
41 capabilities_
.delegated_rendering
= true;
42 capabilities_
.max_frames_pending
= 1;
46 FakeOutputSurface::FakeOutputSurface(
47 scoped_ptr
<SoftwareOutputDevice
> software_device
,
48 bool delegated_rendering
)
49 : OutputSurface(software_device
.Pass()),
52 has_external_stencil_test_(false),
54 if (delegated_rendering
) {
55 capabilities_
.delegated_rendering
= true;
56 capabilities_
.max_frames_pending
= 1;
60 FakeOutputSurface::FakeOutputSurface(
61 scoped_refptr
<ContextProvider
> context_provider
,
62 scoped_ptr
<SoftwareOutputDevice
> software_device
,
63 bool delegated_rendering
)
64 : OutputSurface(context_provider
, software_device
.Pass()),
67 has_external_stencil_test_(false),
69 if (delegated_rendering
) {
70 capabilities_
.delegated_rendering
= true;
71 capabilities_
.max_frames_pending
= 1;
75 FakeOutputSurface::~FakeOutputSurface() {}
77 void FakeOutputSurface::SwapBuffers(CompositorFrame
* frame
) {
78 if (frame
->software_frame_data
|| frame
->delegated_frame_data
||
79 !context_provider()) {
80 frame
->AssignTo(&last_sent_frame_
);
82 if (last_sent_frame_
.delegated_frame_data
) {
83 resources_held_by_parent_
.insert(
84 resources_held_by_parent_
.end(),
85 last_sent_frame_
.delegated_frame_data
->resource_list
.begin(),
86 last_sent_frame_
.delegated_frame_data
->resource_list
.end());
91 last_swap_rect_
= frame
->gl_frame_data
->sub_buffer_rect
;
92 frame
->AssignTo(&last_sent_frame_
);
95 PostSwapBuffersComplete();
96 client_
->DidSwapBuffers();
99 void FakeOutputSurface::BindFramebuffer() {
101 context_provider_
->ContextGL()->BindFramebuffer(GL_FRAMEBUFFER
,
104 OutputSurface::BindFramebuffer();
107 bool FakeOutputSurface::BindToClient(OutputSurfaceClient
* client
) {
108 if (OutputSurface::BindToClient(client
)) {
110 if (memory_policy_to_set_at_bind_
) {
111 client_
->SetMemoryPolicy(*memory_policy_to_set_at_bind_
.get());
112 memory_policy_to_set_at_bind_
= nullptr;
120 void FakeOutputSurface::SetTreeActivationCallback(
121 const base::Closure
& callback
) {
123 client_
->SetTreeActivationCallback(callback
);
126 void FakeOutputSurface::ReturnResource(unsigned id
, CompositorFrameAck
* ack
) {
127 TransferableResourceArray::iterator it
;
128 for (it
= resources_held_by_parent_
.begin();
129 it
!= resources_held_by_parent_
.end();
134 DCHECK(it
!= resources_held_by_parent_
.end());
135 ack
->resources
.push_back(it
->ToReturnedResource());
136 resources_held_by_parent_
.erase(it
);
139 bool FakeOutputSurface::HasExternalStencilTest() const {
140 return has_external_stencil_test_
;
143 void FakeOutputSurface::SetMemoryPolicyToSetAtBind(
144 scoped_ptr
<ManagedMemoryPolicy
> memory_policy_to_set_at_bind
) {
145 memory_policy_to_set_at_bind_
.swap(memory_policy_to_set_at_bind
);