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 bool delegated_rendering
)
20 : OutputSurface(context_provider
),
23 has_external_stencil_test_(false) {
24 if (delegated_rendering
) {
25 capabilities_
.delegated_rendering
= true;
26 capabilities_
.max_frames_pending
= 1;
30 FakeOutputSurface::FakeOutputSurface(
31 scoped_ptr
<SoftwareOutputDevice
> software_device
,
32 bool delegated_rendering
)
33 : OutputSurface(software_device
.Pass()),
36 has_external_stencil_test_(false) {
37 if (delegated_rendering
) {
38 capabilities_
.delegated_rendering
= true;
39 capabilities_
.max_frames_pending
= 1;
43 FakeOutputSurface::FakeOutputSurface(
44 scoped_refptr
<ContextProvider
> context_provider
,
45 scoped_ptr
<SoftwareOutputDevice
> software_device
,
46 bool delegated_rendering
)
47 : OutputSurface(context_provider
, software_device
.Pass()),
50 has_external_stencil_test_(false) {
51 if (delegated_rendering
) {
52 capabilities_
.delegated_rendering
= true;
53 capabilities_
.max_frames_pending
= 1;
57 FakeOutputSurface::~FakeOutputSurface() {}
59 void FakeOutputSurface::SwapBuffers(CompositorFrame
* frame
) {
60 if (frame
->software_frame_data
|| frame
->delegated_frame_data
||
61 !context_provider()) {
62 frame
->AssignTo(&last_sent_frame_
);
64 if (last_sent_frame_
.delegated_frame_data
) {
65 resources_held_by_parent_
.insert(
66 resources_held_by_parent_
.end(),
67 last_sent_frame_
.delegated_frame_data
->resource_list
.begin(),
68 last_sent_frame_
.delegated_frame_data
->resource_list
.end());
73 last_swap_rect_
= frame
->gl_frame_data
->sub_buffer_rect
;
74 frame
->AssignTo(&last_sent_frame_
);
77 PostSwapBuffersComplete();
78 client_
->DidSwapBuffers();
81 bool FakeOutputSurface::BindToClient(OutputSurfaceClient
* client
) {
82 if (OutputSurface::BindToClient(client
)) {
84 if (memory_policy_to_set_at_bind_
) {
85 client_
->SetMemoryPolicy(*memory_policy_to_set_at_bind_
.get());
86 memory_policy_to_set_at_bind_
= nullptr;
94 void FakeOutputSurface::SetTreeActivationCallback(
95 const base::Closure
& callback
) {
97 client_
->SetTreeActivationCallback(callback
);
100 void FakeOutputSurface::ReturnResource(unsigned id
, CompositorFrameAck
* ack
) {
101 TransferableResourceArray::iterator it
;
102 for (it
= resources_held_by_parent_
.begin();
103 it
!= resources_held_by_parent_
.end();
108 DCHECK(it
!= resources_held_by_parent_
.end());
109 ack
->resources
.push_back(it
->ToReturnedResource());
110 resources_held_by_parent_
.erase(it
);
113 bool FakeOutputSurface::HasExternalStencilTest() const {
114 return has_external_stencil_test_
;
117 void FakeOutputSurface::SetMemoryPolicyToSetAtBind(
118 scoped_ptr
<ManagedMemoryPolicy
> memory_policy_to_set_at_bind
) {
119 memory_policy_to_set_at_bind_
.swap(memory_policy_to_set_at_bind
);