cc: Implement shared worker contexts.
[chromium-blink-merge.git] / cc / test / fake_output_surface.h
blobd2af2e3d44c7400bf163e7dba965318379b9a862
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"
19 namespace cc {
21 class FakeOutputSurface : public OutputSurface {
22 public:
23 ~FakeOutputSurface() override;
25 static scoped_ptr<FakeOutputSurface> Create3d() {
26 return make_scoped_ptr(
27 new FakeOutputSurface(TestContextProvider::Create(),
28 TestContextProvider::CreateWorker(), false));
31 static scoped_ptr<FakeOutputSurface> Create3d(
32 scoped_refptr<ContextProvider> context_provider) {
33 return make_scoped_ptr(new FakeOutputSurface(
34 context_provider, TestContextProvider::CreateWorker(), false));
37 static scoped_ptr<FakeOutputSurface> Create3d(
38 scoped_refptr<ContextProvider> context_provider,
39 scoped_refptr<ContextProvider> worker_context_provider) {
40 return make_scoped_ptr(new FakeOutputSurface(
41 context_provider, worker_context_provider, false));
44 static scoped_ptr<FakeOutputSurface> Create3d(
45 scoped_ptr<TestWebGraphicsContext3D> context) {
46 return make_scoped_ptr(
47 new FakeOutputSurface(TestContextProvider::Create(context.Pass()),
48 TestContextProvider::CreateWorker(), false));
51 static scoped_ptr<FakeOutputSurface> CreateSoftware(
52 scoped_ptr<SoftwareOutputDevice> software_device) {
53 return make_scoped_ptr(new FakeOutputSurface(software_device.Pass(),
54 false));
57 static scoped_ptr<FakeOutputSurface> CreateDelegating3d() {
58 return make_scoped_ptr(
59 new FakeOutputSurface(TestContextProvider::Create(),
60 TestContextProvider::CreateWorker(), true));
63 static scoped_ptr<FakeOutputSurface> CreateDelegating3d(
64 scoped_refptr<TestContextProvider> context_provider) {
65 return make_scoped_ptr(new FakeOutputSurface(
66 context_provider, TestContextProvider::CreateWorker(), true));
69 static scoped_ptr<FakeOutputSurface> CreateDelegating3d(
70 scoped_ptr<TestWebGraphicsContext3D> context) {
71 return make_scoped_ptr(
72 new FakeOutputSurface(TestContextProvider::Create(context.Pass()),
73 TestContextProvider::CreateWorker(), true));
76 static scoped_ptr<FakeOutputSurface> CreateDelegatingSoftware(
77 scoped_ptr<SoftwareOutputDevice> software_device) {
78 return make_scoped_ptr(
79 new FakeOutputSurface(software_device.Pass(), true));
82 static scoped_ptr<FakeOutputSurface> CreateAlwaysDrawAndSwap3d() {
83 scoped_ptr<FakeOutputSurface> surface(Create3d());
84 surface->capabilities_.draw_and_swap_full_viewport_every_frame = true;
85 return surface.Pass();
88 static scoped_ptr<FakeOutputSurface> CreateNoRequireSyncPoint(
89 scoped_ptr<TestWebGraphicsContext3D> context) {
90 scoped_ptr<FakeOutputSurface> surface(Create3d(context.Pass()));
91 surface->capabilities_.delegated_sync_points_required = false;
92 return surface.Pass();
95 static scoped_ptr<FakeOutputSurface> CreateOffscreen(
96 scoped_ptr<TestWebGraphicsContext3D> context) {
97 scoped_ptr<FakeOutputSurface> surface(new FakeOutputSurface(
98 TestContextProvider::Create(context.Pass()), false));
99 surface->capabilities_.uses_default_gl_framebuffer = false;
100 return surface.Pass();
103 CompositorFrame& last_sent_frame() { return last_sent_frame_; }
104 size_t num_sent_frames() { return num_sent_frames_; }
106 void SwapBuffers(CompositorFrame* frame) override;
108 OutputSurfaceClient* client() { return client_; }
109 bool BindToClient(OutputSurfaceClient* client) override;
111 void set_framebuffer(unsigned framebuffer) { framebuffer_ = framebuffer; }
112 void BindFramebuffer() override;
114 void SetTreeActivationCallback(const base::Closure& callback);
116 const TransferableResourceArray& resources_held_by_parent() {
117 return resources_held_by_parent_;
120 void ReturnResource(unsigned id, CompositorFrameAck* ack);
122 bool HasExternalStencilTest() const override;
124 bool SurfaceIsSuspendForRecycle() const override;
126 void set_has_external_stencil_test(bool has_test) {
127 has_external_stencil_test_ = has_test;
130 void set_suspended_for_recycle(bool suspended) {
131 suspended_for_recycle_ = suspended;
134 void SetMemoryPolicyToSetAtBind(
135 scoped_ptr<ManagedMemoryPolicy> memory_policy_to_set_at_bind);
137 gfx::Rect last_swap_rect() const {
138 return last_swap_rect_;
141 protected:
142 FakeOutputSurface(
143 scoped_refptr<ContextProvider> context_provider,
144 bool delegated_rendering);
146 FakeOutputSurface(scoped_refptr<ContextProvider> context_provider,
147 scoped_refptr<ContextProvider> worker_context_provider,
148 bool delegated_rendering);
150 FakeOutputSurface(scoped_ptr<SoftwareOutputDevice> software_device,
151 bool delegated_rendering);
153 FakeOutputSurface(
154 scoped_refptr<ContextProvider> context_provider,
155 scoped_ptr<SoftwareOutputDevice> software_device,
156 bool delegated_rendering);
158 OutputSurfaceClient* client_;
159 CompositorFrame last_sent_frame_;
160 size_t num_sent_frames_;
161 bool has_external_stencil_test_;
162 bool suspended_for_recycle_;
163 unsigned framebuffer_;
164 TransferableResourceArray resources_held_by_parent_;
165 scoped_ptr<ManagedMemoryPolicy> memory_policy_to_set_at_bind_;
166 gfx::Rect last_swap_rect_;
169 } // namespace cc
171 #endif // CC_TEST_FAKE_OUTPUT_SURFACE_H_