1 // Copyright 2013 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_TEST_CONTEXT_PROVIDER_H_
6 #define CC_TEST_TEST_CONTEXT_PROVIDER_H_
8 #include "base/callback.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/synchronization/lock.h"
11 #include "base/threading/thread_checker.h"
12 #include "cc/output/context_provider.h"
13 #include "cc/test/test_context_support.h"
15 namespace WebKit { class WebGraphicsContext3D; }
18 class TestWebGraphicsContext3D;
20 class TestContextProvider : public cc::ContextProvider {
22 typedef base::Callback<scoped_ptr<TestWebGraphicsContext3D>(void)>
25 static scoped_refptr<TestContextProvider> Create();
26 static scoped_refptr<TestContextProvider> Create(
27 scoped_ptr<TestWebGraphicsContext3D> context);
29 virtual bool BindToCurrentThread() OVERRIDE;
30 virtual Capabilities ContextCapabilities() OVERRIDE;
31 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE;
32 virtual gpu::ContextSupport* ContextSupport() OVERRIDE;
33 virtual class GrContext* GrContext() OVERRIDE;
34 virtual void VerifyContexts() OVERRIDE;
35 virtual bool DestroyedOnMainThread() OVERRIDE;
36 virtual void SetLostContextCallback(const LostContextCallback& cb) OVERRIDE;
37 virtual void SetSwapBuffersCompleteCallback(
38 const SwapBuffersCompleteCallback& cb) OVERRIDE;
39 virtual void SetMemoryPolicyChangedCallback(
40 const MemoryPolicyChangedCallback& cb) OVERRIDE;
42 TestWebGraphicsContext3D* TestContext3d();
44 // This returns the TestWebGraphicsContext3D but is valid to call
45 // before the context is bound to a thread. This is needed to set up
46 // state on the test context before binding. Don't call
47 // makeContextCurrent on the context returned from this method.
48 TestWebGraphicsContext3D* UnboundTestContext3d();
50 void SetMemoryAllocation(const ManagedMemoryPolicy& policy);
52 void SetMaxTransferBufferUsageBytes(size_t max_transfer_buffer_usage_bytes);
55 explicit TestContextProvider(scoped_ptr<TestWebGraphicsContext3D> context);
56 virtual ~TestContextProvider();
59 void OnSwapBuffersComplete();
61 TestContextSupport support_;
63 scoped_ptr<TestWebGraphicsContext3D> context3d_;
66 base::ThreadChecker main_thread_checker_;
67 base::ThreadChecker context_thread_checker_;
69 base::Lock destroyed_lock_;
72 LostContextCallback lost_context_callback_;
73 SwapBuffersCompleteCallback swap_buffers_complete_callback_;
74 MemoryPolicyChangedCallback memory_policy_changed_callback_;
76 class LostContextCallbackProxy;
77 scoped_ptr<LostContextCallbackProxy> lost_context_callback_proxy_;
79 class SwapBuffersCompleteCallbackProxy;
80 scoped_ptr<SwapBuffersCompleteCallbackProxy>
81 swap_buffers_complete_callback_proxy_;
86 #endif // CC_TEST_TEST_CONTEXT_PROVIDER_H_