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_TEST_TEST_CONTEXT_PROVIDER_H_ | 5 #ifndef CC_TEST_TEST_CONTEXT_PROVIDER_H_ |
6 #define CC_TEST_TEST_CONTEXT_PROVIDER_H_ | 6 #define CC_TEST_TEST_CONTEXT_PROVIDER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
| 11 #include <memory> |
| 12 |
11 #include "base/callback.h" | 13 #include "base/callback.h" |
12 #include "base/macros.h" | 14 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
15 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
16 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
17 #include "cc/output/context_provider.h" | 18 #include "cc/output/context_provider.h" |
18 #include "cc/test/test_context_support.h" | 19 #include "cc/test/test_context_support.h" |
19 #include "gpu/command_buffer/client/gles2_interface_stub.h" | 20 #include "gpu/command_buffer/client/gles2_interface_stub.h" |
20 #include "skia/ext/refptr.h" | 21 #include "skia/ext/refptr.h" |
21 | 22 |
22 namespace cc { | 23 namespace cc { |
23 class TestWebGraphicsContext3D; | 24 class TestWebGraphicsContext3D; |
24 class TestGLES2Interface; | 25 class TestGLES2Interface; |
25 | 26 |
26 class TestContextProvider : public ContextProvider { | 27 class TestContextProvider : public ContextProvider { |
27 public: | 28 public: |
28 typedef base::Callback<scoped_ptr<TestWebGraphicsContext3D>(void)> | 29 typedef base::Callback<std::unique_ptr<TestWebGraphicsContext3D>(void)> |
29 CreateCallback; | 30 CreateCallback; |
30 | 31 |
31 static scoped_refptr<TestContextProvider> Create(); | 32 static scoped_refptr<TestContextProvider> Create(); |
32 // Creates a worker context provider that can be used on any thread. This is | 33 // Creates a worker context provider that can be used on any thread. This is |
33 // equivalent to: Create(); BindToCurrentThread(); SetupLock(). | 34 // equivalent to: Create(); BindToCurrentThread(); SetupLock(). |
34 static scoped_refptr<TestContextProvider> CreateWorker(); | 35 static scoped_refptr<TestContextProvider> CreateWorker(); |
35 static scoped_refptr<TestContextProvider> Create( | 36 static scoped_refptr<TestContextProvider> Create( |
36 scoped_ptr<TestWebGraphicsContext3D> context); | 37 std::unique_ptr<TestWebGraphicsContext3D> context); |
37 | 38 |
38 bool BindToCurrentThread() override; | 39 bool BindToCurrentThread() override; |
39 void DetachFromThread() override; | 40 void DetachFromThread() override; |
40 Capabilities ContextCapabilities() override; | 41 Capabilities ContextCapabilities() override; |
41 gpu::gles2::GLES2Interface* ContextGL() override; | 42 gpu::gles2::GLES2Interface* ContextGL() override; |
42 gpu::ContextSupport* ContextSupport() override; | 43 gpu::ContextSupport* ContextSupport() override; |
43 class GrContext* GrContext() override; | 44 class GrContext* GrContext() override; |
44 void InvalidateGrContext(uint32_t state) override; | 45 void InvalidateGrContext(uint32_t state) override; |
45 void SetupLock() override; | 46 void SetupLock() override; |
46 base::Lock* GetLock() override; | 47 base::Lock* GetLock() override; |
47 void DeleteCachedResources() override; | 48 void DeleteCachedResources() override; |
48 void SetLostContextCallback(const LostContextCallback& cb) override; | 49 void SetLostContextCallback(const LostContextCallback& cb) override; |
49 | 50 |
50 TestWebGraphicsContext3D* TestContext3d(); | 51 TestWebGraphicsContext3D* TestContext3d(); |
51 | 52 |
52 // This returns the TestWebGraphicsContext3D but is valid to call | 53 // This returns the TestWebGraphicsContext3D but is valid to call |
53 // before the context is bound to a thread. This is needed to set up | 54 // before the context is bound to a thread. This is needed to set up |
54 // state on the test context before binding. Don't call | 55 // state on the test context before binding. Don't call |
55 // InitializeOnCurrentThread on the context returned from this method. | 56 // InitializeOnCurrentThread on the context returned from this method. |
56 TestWebGraphicsContext3D* UnboundTestContext3d(); | 57 TestWebGraphicsContext3D* UnboundTestContext3d(); |
57 | 58 |
58 TestContextSupport* support() { return &support_; } | 59 TestContextSupport* support() { return &support_; } |
59 | 60 |
60 void SetMaxTransferBufferUsageBytes(size_t max_transfer_buffer_usage_bytes); | 61 void SetMaxTransferBufferUsageBytes(size_t max_transfer_buffer_usage_bytes); |
61 | 62 |
62 protected: | 63 protected: |
63 explicit TestContextProvider(scoped_ptr<TestWebGraphicsContext3D> context); | 64 explicit TestContextProvider( |
| 65 std::unique_ptr<TestWebGraphicsContext3D> context); |
64 ~TestContextProvider() override; | 66 ~TestContextProvider() override; |
65 | 67 |
66 private: | 68 private: |
67 void OnLostContext(); | 69 void OnLostContext(); |
68 | 70 |
69 TestContextSupport support_; | 71 TestContextSupport support_; |
70 | 72 |
71 scoped_ptr<TestWebGraphicsContext3D> context3d_; | 73 std::unique_ptr<TestWebGraphicsContext3D> context3d_; |
72 scoped_ptr<TestGLES2Interface> context_gl_; | 74 std::unique_ptr<TestGLES2Interface> context_gl_; |
73 bool bound_; | 75 bool bound_; |
74 | 76 |
75 base::ThreadChecker main_thread_checker_; | 77 base::ThreadChecker main_thread_checker_; |
76 base::ThreadChecker context_thread_checker_; | 78 base::ThreadChecker context_thread_checker_; |
77 | 79 |
78 base::Lock context_lock_; | 80 base::Lock context_lock_; |
79 | 81 |
80 LostContextCallback lost_context_callback_; | 82 LostContextCallback lost_context_callback_; |
81 skia::RefPtr<class GrContext> gr_context_; | 83 skia::RefPtr<class GrContext> gr_context_; |
82 | 84 |
83 base::WeakPtrFactory<TestContextProvider> weak_ptr_factory_; | 85 base::WeakPtrFactory<TestContextProvider> weak_ptr_factory_; |
84 | 86 |
85 DISALLOW_COPY_AND_ASSIGN(TestContextProvider); | 87 DISALLOW_COPY_AND_ASSIGN(TestContextProvider); |
86 }; | 88 }; |
87 | 89 |
88 } // namespace cc | 90 } // namespace cc |
89 | 91 |
90 #endif // CC_TEST_TEST_CONTEXT_PROVIDER_H_ | 92 #endif // CC_TEST_TEST_CONTEXT_PROVIDER_H_ |
91 | 93 |
OLD | NEW |