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_DEBUG_TEST_CONTEXT_PROVIDER_H_
6 #define CC_DEBUG_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/base/cc_export.h"
13 #include "cc/output/context_provider.h"
15 namespace WebKit
{ class WebGraphicsContext3D
; }
18 class TestWebGraphicsContext3D
;
20 class CC_EXPORT TestContextProvider
21 : public NON_EXPORTED_BASE(cc::ContextProvider
) {
23 typedef base::Callback
<scoped_ptr
<TestWebGraphicsContext3D
>(void)>
26 static scoped_refptr
<TestContextProvider
> Create();
27 static scoped_refptr
<TestContextProvider
> Create(
28 scoped_ptr
<TestWebGraphicsContext3D
> context
);
30 virtual bool BindToCurrentThread() OVERRIDE
;
31 virtual Capabilities
ContextCapabilities() OVERRIDE
;
32 virtual WebKit::WebGraphicsContext3D
* Context3d() 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
,
51 bool discard_backbuffer_when_not_visible
);
53 void SetMaxTransferBufferUsageBytes(size_t max_transfer_buffer_usage_bytes
);
56 TestContextProvider(scoped_ptr
<TestWebGraphicsContext3D
> context
);
57 virtual ~TestContextProvider();
60 void OnSwapBuffersComplete();
62 scoped_ptr
<TestWebGraphicsContext3D
> context3d_
;
65 base::ThreadChecker main_thread_checker_
;
66 base::ThreadChecker context_thread_checker_
;
68 base::Lock destroyed_lock_
;
71 LostContextCallback lost_context_callback_
;
72 SwapBuffersCompleteCallback swap_buffers_complete_callback_
;
73 MemoryPolicyChangedCallback memory_policy_changed_callback_
;
75 class LostContextCallbackProxy
;
76 scoped_ptr
<LostContextCallbackProxy
> lost_context_callback_proxy_
;
78 class SwapBuffersCompleteCallbackProxy
;
79 scoped_ptr
<SwapBuffersCompleteCallbackProxy
>
80 swap_buffers_complete_callback_proxy_
;
85 #endif // CC_DEBUG_TEST_CONTEXT_PROVIDER_H_