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(
64 context_provider
, TestContextProvider::Create(), true));
67 static scoped_ptr
<FakeOutputSurface
> CreateDelegating3d(
68 scoped_ptr
<TestWebGraphicsContext3D
> context
) {
69 return make_scoped_ptr(
70 new FakeOutputSurface(TestContextProvider::Create(context
.Pass()),
71 TestContextProvider::Create(), true));
74 static scoped_ptr
<FakeOutputSurface
> CreateDelegatingSoftware(
75 scoped_ptr
<SoftwareOutputDevice
> software_device
) {
76 return make_scoped_ptr(
77 new FakeOutputSurface(software_device
.Pass(), true));
80 static scoped_ptr
<FakeOutputSurface
> CreateAlwaysDrawAndSwap3d() {
81 scoped_ptr
<FakeOutputSurface
> surface(Create3d());
82 surface
->capabilities_
.draw_and_swap_full_viewport_every_frame
= true;
83 return surface
.Pass();
86 static scoped_ptr
<FakeOutputSurface
> CreateNoRequireSyncPoint(
87 scoped_ptr
<TestWebGraphicsContext3D
> context
) {
88 scoped_ptr
<FakeOutputSurface
> surface(Create3d(context
.Pass()));
89 surface
->capabilities_
.delegated_sync_points_required
= false;
90 return surface
.Pass();
93 static scoped_ptr
<FakeOutputSurface
> CreateOffscreen(
94 scoped_ptr
<TestWebGraphicsContext3D
> context
) {
95 scoped_ptr
<FakeOutputSurface
> surface(new FakeOutputSurface(
96 TestContextProvider::Create(context
.Pass()), false));
97 surface
->capabilities_
.uses_default_gl_framebuffer
= false;
98 return surface
.Pass();
101 CompositorFrame
& last_sent_frame() { return last_sent_frame_
; }
102 size_t num_sent_frames() { return num_sent_frames_
; }
104 void SwapBuffers(CompositorFrame
* frame
) override
;
106 OutputSurfaceClient
* client() { return client_
; }
107 bool BindToClient(OutputSurfaceClient
* client
) override
;
109 void set_framebuffer(unsigned framebuffer
) { framebuffer_
= framebuffer
; }
110 void BindFramebuffer() override
;
112 void SetTreeActivationCallback(const base::Closure
& callback
);
114 const TransferableResourceArray
& resources_held_by_parent() {
115 return resources_held_by_parent_
;
118 void ReturnResource(unsigned id
, CompositorFrameAck
* ack
);
120 bool HasExternalStencilTest() const override
;
122 bool SurfaceIsSuspendForRecycle() const override
;
124 void set_has_external_stencil_test(bool has_test
) {
125 has_external_stencil_test_
= has_test
;
128 void set_suspended_for_recycle(bool suspended
) {
129 suspended_for_recycle_
= suspended
;
132 void SetMemoryPolicyToSetAtBind(
133 scoped_ptr
<ManagedMemoryPolicy
> memory_policy_to_set_at_bind
);
135 gfx::Rect
last_swap_rect() const {
136 return last_swap_rect_
;
141 scoped_refptr
<ContextProvider
> context_provider
,
142 bool delegated_rendering
);
144 FakeOutputSurface(scoped_refptr
<ContextProvider
> context_provider
,
145 scoped_refptr
<ContextProvider
> worker_context_provider
,
146 bool delegated_rendering
);
148 FakeOutputSurface(scoped_ptr
<SoftwareOutputDevice
> software_device
,
149 bool delegated_rendering
);
152 scoped_refptr
<ContextProvider
> context_provider
,
153 scoped_ptr
<SoftwareOutputDevice
> software_device
,
154 bool delegated_rendering
);
156 OutputSurfaceClient
* client_
;
157 CompositorFrame last_sent_frame_
;
158 size_t num_sent_frames_
;
159 bool has_external_stencil_test_
;
160 bool suspended_for_recycle_
;
161 unsigned framebuffer_
;
162 TransferableResourceArray resources_held_by_parent_
;
163 scoped_ptr
<ManagedMemoryPolicy
> memory_policy_to_set_at_bind_
;
164 gfx::Rect last_swap_rect_
;
169 #endif // CC_TEST_FAKE_OUTPUT_SURFACE_H_