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 #ifndef CC_TEST_FAKE_OUTPUT_SURFACE_H_
6 #define CC_TEST_FAKE_OUTPUT_SURFACE_H_
8 #include "base/callback.h"
9 #include "base/logging.h"
10 #include "base/time/time.h"
11 #include "cc/output/begin_frame_args.h"
12 #include "cc/output/compositor_frame.h"
13 #include "cc/output/managed_memory_policy.h"
14 #include "cc/output/output_surface.h"
15 #include "cc/output/software_output_device.h"
16 #include "cc/test/test_context_provider.h"
17 #include "cc/test/test_web_graphics_context_3d.h"
21 class FakeOutputSurface
: public OutputSurface
{
23 ~FakeOutputSurface() override
;
25 static scoped_ptr
<FakeOutputSurface
> Create3d() {
26 return make_scoped_ptr(new FakeOutputSurface(
27 TestContextProvider::Create(), TestContextProvider::Create(), false));
30 static scoped_ptr
<FakeOutputSurface
> Create3d(
31 scoped_refptr
<ContextProvider
> context_provider
) {
32 return make_scoped_ptr(new FakeOutputSurface(
33 context_provider
, TestContextProvider::Create(), false));
36 static scoped_ptr
<FakeOutputSurface
> Create3d(
37 scoped_refptr
<ContextProvider
> context_provider
,
38 scoped_refptr
<ContextProvider
> worker_context_provider
) {
39 return make_scoped_ptr(new FakeOutputSurface(
40 context_provider
, worker_context_provider
, false));
43 static scoped_ptr
<FakeOutputSurface
> Create3d(
44 scoped_ptr
<TestWebGraphicsContext3D
> context
) {
45 return make_scoped_ptr(
46 new FakeOutputSurface(TestContextProvider::Create(context
.Pass()),
47 TestContextProvider::Create(), false));
50 static scoped_ptr
<FakeOutputSurface
> CreateSoftware(
51 scoped_ptr
<SoftwareOutputDevice
> software_device
) {
52 return make_scoped_ptr(new FakeOutputSurface(software_device
.Pass(),
56 static scoped_ptr
<FakeOutputSurface
> CreateDelegating3d() {
57 return make_scoped_ptr(new FakeOutputSurface(
58 TestContextProvider::Create(), TestContextProvider::Create(), true));
61 static scoped_ptr
<FakeOutputSurface
> CreateDelegating3d(
62 scoped_refptr
<TestContextProvider
> context_provider
) {
63 return make_scoped_ptr(new FakeOutputSurface(context_provider
, true));
66 static scoped_ptr
<FakeOutputSurface
> CreateDelegating3d(
67 scoped_ptr
<TestWebGraphicsContext3D
> context
) {
68 return make_scoped_ptr(new FakeOutputSurface(
69 TestContextProvider::Create(context
.Pass()), true));
72 static scoped_ptr
<FakeOutputSurface
> CreateDelegatingSoftware(
73 scoped_ptr
<SoftwareOutputDevice
> software_device
) {
74 return make_scoped_ptr(
75 new FakeOutputSurface(software_device
.Pass(), true));
78 static scoped_ptr
<FakeOutputSurface
> CreateAlwaysDrawAndSwap3d() {
79 scoped_ptr
<FakeOutputSurface
> surface(Create3d());
80 surface
->capabilities_
.draw_and_swap_full_viewport_every_frame
= true;
81 return surface
.Pass();
84 static scoped_ptr
<FakeOutputSurface
> CreateNoRequireSyncPoint(
85 scoped_ptr
<TestWebGraphicsContext3D
> context
) {
86 scoped_ptr
<FakeOutputSurface
> surface(Create3d(context
.Pass()));
87 surface
->capabilities_
.delegated_sync_points_required
= false;
88 return surface
.Pass();
91 static scoped_ptr
<FakeOutputSurface
> CreateOffscreen(
92 scoped_ptr
<TestWebGraphicsContext3D
> context
) {
93 scoped_ptr
<FakeOutputSurface
> surface(new FakeOutputSurface(
94 TestContextProvider::Create(context
.Pass()), false));
95 surface
->capabilities_
.uses_default_gl_framebuffer
= false;
96 return surface
.Pass();
99 CompositorFrame
& last_sent_frame() { return last_sent_frame_
; }
100 size_t num_sent_frames() { return num_sent_frames_
; }
102 void SwapBuffers(CompositorFrame
* frame
) override
;
104 OutputSurfaceClient
* client() { return client_
; }
105 bool BindToClient(OutputSurfaceClient
* client
) override
;
107 void set_framebuffer(unsigned framebuffer
) { framebuffer_
= framebuffer
; }
108 void BindFramebuffer() override
;
110 void SetTreeActivationCallback(const base::Closure
& callback
);
112 const TransferableResourceArray
& resources_held_by_parent() {
113 return resources_held_by_parent_
;
116 void ReturnResource(unsigned id
, CompositorFrameAck
* ack
);
118 bool HasExternalStencilTest() const override
;
120 bool SurfaceIsSuspendForRecycle() const override
;
122 void set_has_external_stencil_test(bool has_test
) {
123 has_external_stencil_test_
= has_test
;
126 void set_suspended_for_recycle(bool suspended
) {
127 suspended_for_recycle_
= suspended
;
130 void SetMemoryPolicyToSetAtBind(
131 scoped_ptr
<ManagedMemoryPolicy
> memory_policy_to_set_at_bind
);
133 gfx::Rect
last_swap_rect() const {
134 return last_swap_rect_
;
139 scoped_refptr
<ContextProvider
> context_provider
,
140 bool delegated_rendering
);
142 FakeOutputSurface(scoped_refptr
<ContextProvider
> context_provider
,
143 scoped_refptr
<ContextProvider
> worker_context_provider
,
144 bool delegated_rendering
);
146 FakeOutputSurface(scoped_ptr
<SoftwareOutputDevice
> software_device
,
147 bool delegated_rendering
);
150 scoped_refptr
<ContextProvider
> context_provider
,
151 scoped_ptr
<SoftwareOutputDevice
> software_device
,
152 bool delegated_rendering
);
154 OutputSurfaceClient
* client_
;
155 CompositorFrame last_sent_frame_
;
156 size_t num_sent_frames_
;
157 bool has_external_stencil_test_
;
158 bool suspended_for_recycle_
;
159 unsigned framebuffer_
;
160 TransferableResourceArray resources_held_by_parent_
;
161 scoped_ptr
<ManagedMemoryPolicy
> memory_policy_to_set_at_bind_
;
162 gfx::Rect last_swap_rect_
;
167 #endif // CC_TEST_FAKE_OUTPUT_SURFACE_H_