| 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 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 namespace cc { | 23 namespace cc { |
| 24 class TestWebGraphicsContext3D; | 24 class TestWebGraphicsContext3D; |
| 25 class TestGLES2Interface; | 25 class TestGLES2Interface; |
| 26 | 26 |
| 27 class TestContextProvider : public ContextProvider { | 27 class TestContextProvider : public ContextProvider { |
| 28 public: | 28 public: |
| 29 typedef base::Callback<std::unique_ptr<TestWebGraphicsContext3D>(void)> | 29 typedef base::Callback<std::unique_ptr<TestWebGraphicsContext3D>(void)> |
| 30 CreateCallback; | 30 CreateCallback; |
| 31 | 31 |
| 32 static scoped_refptr<TestContextProvider> Create(); | 32 static scoped_refptr<TestContextProvider> Create(); |
| 33 // Creates a worker context provider that can be used on any thread. This is | |
| 34 // equivalent to: Create(); BindToCurrentThread(). | |
| 35 static scoped_refptr<TestContextProvider> CreateWorker(); | |
| 36 static scoped_refptr<TestContextProvider> Create( | 33 static scoped_refptr<TestContextProvider> Create( |
| 37 std::unique_ptr<TestWebGraphicsContext3D> context); | 34 std::unique_ptr<TestWebGraphicsContext3D> context); |
| 38 | 35 |
| 39 bool BindToCurrentThread() override; | 36 class DeferredCreate : public ContextProvider::DeferredCreate { |
| 40 void DetachFromThread() override; | 37 public: |
| 38 DeferredCreate(); |
| 39 explicit DeferredCreate(std::unique_ptr<TestWebGraphicsContext3D> context); |
| 40 ~DeferredCreate(); |
| 41 scoped_refptr<ContextProvider> CreateContext() override; |
| 42 |
| 43 // If true, CreateContext will return null, simulating failure to make the |
| 44 // context. |
| 45 bool fail_create = false; |
| 46 // If set, this TestWebGraphicsContext3D will back the context provider. |
| 47 std::unique_ptr<TestWebGraphicsContext3D> webcontext; |
| 48 // Set on the new context unless a |webcontext| is specified, since it also |
| 49 // contains capabilities. |
| 50 gpu::Capabilities capabilities; |
| 51 |
| 52 // Set to non-null to have CreateContext give a pointer to the |
| 53 // TestContextProvider it makes. |
| 54 TestContextProvider** created_context = nullptr; |
| 55 }; |
| 56 |
| 41 gpu::Capabilities ContextCapabilities() override; | 57 gpu::Capabilities ContextCapabilities() override; |
| 42 gpu::gles2::GLES2Interface* ContextGL() override; | 58 gpu::gles2::GLES2Interface* ContextGL() override; |
| 43 gpu::ContextSupport* ContextSupport() override; | 59 gpu::ContextSupport* ContextSupport() override; |
| 44 class GrContext* GrContext() override; | 60 class GrContext* GrContext() override; |
| 45 void InvalidateGrContext(uint32_t state) override; | 61 void InvalidateGrContext(uint32_t state) override; |
| 46 base::Lock* GetLock() override; | 62 base::Lock* GetLock() override; |
| 47 void DeleteCachedResources() override; | 63 void DeleteCachedResources() override; |
| 48 void SetLostContextCallback(const LostContextCallback& cb) override; | 64 void SetLostContextCallback(const LostContextCallback& cb) override; |
| 65 void DetachFromThread() override; |
| 49 | 66 |
| 50 TestWebGraphicsContext3D* TestContext3d(); | 67 TestWebGraphicsContext3D* TestContext3d(); |
| 51 | 68 |
| 52 // This returns the TestWebGraphicsContext3D but is valid to call | 69 // This returns the TestWebGraphicsContext3D but is valid to call |
| 53 // before the context is bound to a thread. This is needed to set up | 70 // 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 | 71 // state on the test context before binding. Don't call |
| 55 // InitializeOnCurrentThread on the context returned from this method. | 72 // InitializeOnCurrentThread on the context returned from this method. |
| 73 // TODO(danakj): Delete me. |
| 56 TestWebGraphicsContext3D* UnboundTestContext3d(); | 74 TestWebGraphicsContext3D* UnboundTestContext3d(); |
| 57 | 75 |
| 58 TestContextSupport* support() { return &support_; } | 76 TestContextSupport* support() { return &support_; } |
| 59 | 77 |
| 60 protected: | 78 protected: |
| 61 explicit TestContextProvider( | 79 explicit TestContextProvider( |
| 62 std::unique_ptr<TestWebGraphicsContext3D> context); | 80 std::unique_ptr<TestWebGraphicsContext3D> context); |
| 63 ~TestContextProvider() override; | 81 ~TestContextProvider() override; |
| 64 | 82 |
| 65 private: | 83 private: |
| 66 void OnLostContext(); | 84 void OnLostContext(); |
| 67 | 85 |
| 68 TestContextSupport support_; | 86 TestContextSupport support_; |
| 69 | 87 |
| 70 std::unique_ptr<TestWebGraphicsContext3D> context3d_; | 88 std::unique_ptr<TestWebGraphicsContext3D> context3d_; |
| 71 std::unique_ptr<TestGLES2Interface> context_gl_; | 89 std::unique_ptr<TestGLES2Interface> context_gl_; |
| 72 bool bound_; | |
| 73 | 90 |
| 74 base::ThreadChecker main_thread_checker_; | 91 base::ThreadChecker thread_checker_; |
| 75 base::ThreadChecker context_thread_checker_; | |
| 76 | 92 |
| 77 base::Lock context_lock_; | 93 base::Lock context_lock_; |
| 78 | 94 |
| 79 LostContextCallback lost_context_callback_; | 95 LostContextCallback lost_context_callback_; |
| 80 sk_sp<class GrContext> gr_context_; | 96 sk_sp<class GrContext> gr_context_; |
| 81 | 97 |
| 82 base::WeakPtrFactory<TestContextProvider> weak_ptr_factory_; | 98 base::WeakPtrFactory<TestContextProvider> weak_ptr_factory_; |
| 83 | 99 |
| 84 DISALLOW_COPY_AND_ASSIGN(TestContextProvider); | 100 DISALLOW_COPY_AND_ASSIGN(TestContextProvider); |
| 85 }; | 101 }; |
| 86 | 102 |
| 87 } // namespace cc | 103 } // namespace cc |
| 88 | 104 |
| 89 #endif // CC_TEST_TEST_CONTEXT_PROVIDER_H_ | 105 #endif // CC_TEST_TEST_CONTEXT_PROVIDER_H_ |
| 90 | 106 |
| OLD | NEW |