OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_DEBUG_TEST_CONTEXT_PROVIDER_H_ | 5 #ifndef CC_DEBUG_TEST_CONTEXT_PROVIDER_H_ |
6 #define CC_DEBUG_TEST_CONTEXT_PROVIDER_H_ | 6 #define CC_DEBUG_TEST_CONTEXT_PROVIDER_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
11 #include "base/threading/thread_checker.h" | 11 #include "base/threading/thread_checker.h" |
12 #include "cc/base/cc_export.h" | 12 #include "cc/base/cc_export.h" |
13 #include "cc/output/context_provider.h" | 13 #include "cc/output/context_provider.h" |
14 | 14 |
15 namespace WebKit { class WebGraphicsContext3D; } | 15 namespace WebKit { class WebGraphicsContext3D; } |
16 | 16 |
17 namespace cc { | 17 namespace cc { |
18 class TestWebGraphicsContext3D; | 18 class TestWebGraphicsContext3D; |
19 | 19 |
20 class CC_EXPORT TestContextProvider | 20 class CC_EXPORT TestContextProvider |
21 : public NON_EXPORTED_BASE(cc::ContextProvider) { | 21 : public NON_EXPORTED_BASE(cc::ContextProvider) { |
22 public: | 22 public: |
23 typedef base::Callback<scoped_ptr<TestWebGraphicsContext3D>(void)> | 23 typedef base::Callback<scoped_ptr<TestWebGraphicsContext3D>(void)> |
24 CreateCallback; | 24 CreateCallback; |
25 | 25 |
26 static scoped_refptr<TestContextProvider> Create(); | 26 static scoped_refptr<TestContextProvider> Create(); |
27 static scoped_refptr<TestContextProvider> Create( | 27 static scoped_refptr<TestContextProvider> Create( |
28 const CreateCallback& create_callback); | 28 const CreateCallback& create_callback); |
| 29 static scoped_refptr<TestContextProvider> Create( |
| 30 scoped_ptr<TestWebGraphicsContext3D> context); |
29 | 31 |
30 virtual bool BindToCurrentThread() OVERRIDE; | 32 virtual bool BindToCurrentThread() OVERRIDE; |
31 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE; | 33 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE; |
32 virtual class GrContext* GrContext() OVERRIDE; | 34 virtual class GrContext* GrContext() OVERRIDE; |
33 virtual void VerifyContexts() OVERRIDE; | 35 virtual void VerifyContexts() OVERRIDE; |
34 virtual bool DestroyedOnMainThread() OVERRIDE; | 36 virtual bool DestroyedOnMainThread() OVERRIDE; |
35 virtual void SetLostContextCallback(const LostContextCallback& cb) OVERRIDE; | 37 virtual void SetLostContextCallback(const LostContextCallback& cb) OVERRIDE; |
| 38 virtual void SetSwapBuffersCompleteCallback( |
| 39 const SwapBuffersCompleteCallback& cb) OVERRIDE; |
| 40 virtual void SetMemoryPolicyChangedCallback( |
| 41 const MemoryPolicyChangedCallback& cb) OVERRIDE; |
36 | 42 |
37 TestWebGraphicsContext3D* TestContext3d() { return context3d_.get(); } | 43 TestWebGraphicsContext3D* TestContext3d() { return context3d_.get(); } |
38 | 44 |
| 45 void SetMemoryAllocation(const ManagedMemoryPolicy& policy, |
| 46 bool discard_backbuffer_when_not_visible); |
| 47 |
39 protected: | 48 protected: |
40 TestContextProvider(); | 49 TestContextProvider(); |
41 virtual ~TestContextProvider(); | 50 virtual ~TestContextProvider(); |
42 | 51 |
43 bool InitializeOnMainThread(const CreateCallback& create_callback); | 52 bool InitializeOnMainThread(const CreateCallback& create_callback); |
44 | 53 |
| 54 void OnLostContext(); |
| 55 void OnSwapBuffersComplete(); |
| 56 |
45 scoped_ptr<TestWebGraphicsContext3D> context3d_; | 57 scoped_ptr<TestWebGraphicsContext3D> context3d_; |
46 bool bound_; | 58 bool bound_; |
47 | 59 |
48 base::ThreadChecker main_thread_checker_; | 60 base::ThreadChecker main_thread_checker_; |
49 base::ThreadChecker context_thread_checker_; | 61 base::ThreadChecker context_thread_checker_; |
50 | 62 |
51 base::Lock destroyed_lock_; | 63 base::Lock destroyed_lock_; |
52 bool destroyed_; | 64 bool destroyed_; |
| 65 |
| 66 LostContextCallback lost_context_callback_; |
| 67 SwapBuffersCompleteCallback swap_buffers_complete_callback_; |
| 68 MemoryPolicyChangedCallback memory_policy_changed_callback_; |
| 69 |
| 70 class LostContextCallbackProxy; |
| 71 scoped_ptr<LostContextCallbackProxy> lost_context_callback_proxy_; |
| 72 |
| 73 class SwapBuffersCompleteCallbackProxy; |
| 74 scoped_ptr<SwapBuffersCompleteCallbackProxy> |
| 75 swap_buffers_complete_callback_proxy_; |
53 }; | 76 }; |
54 | 77 |
55 } // namespace cc | 78 } // namespace cc |
56 | 79 |
57 #endif // CC_DEBUG_TEST_CONTEXT_PROVIDER_H_ | 80 #endif // CC_DEBUG_TEST_CONTEXT_PROVIDER_H_ |
58 | 81 |
OLD | NEW |