Chromium Code Reviews| 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 Factory : public ContextProvider::Factory { |
| 40 void DetachFromThread() override; | 37 public: |
| 38 // Creates a context provider with default capabilities. | |
| 39 Factory(); | |
| 40 // Creates a context provider wrapping the given TestWebGraphicsContext3D. | |
| 41 explicit Factory(std::unique_ptr<TestWebGraphicsContext3D> context); | |
| 42 // Creates a context provider with the given capabilities. | |
| 43 explicit Factory(const gpu::Capabilities& capabilities); | |
| 44 // Fails to create a context provider, simulating loss of the gpu channel or | |
| 45 // other such error conditions. | |
| 46 enum FailCreate { kFailCreate = 1 }; | |
| 47 explicit Factory(FailCreate); | |
| 48 | |
| 49 ~Factory(); | |
| 50 scoped_refptr<ContextProvider> CreateContext() override; | |
| 51 | |
| 52 private: | |
|
danakj
2016/05/17 23:17:15
Notably I made these private and added constructor
| |
| 53 const bool fail_create_ = false; | |
| 54 std::unique_ptr<TestWebGraphicsContext3D> context_; | |
| 55 const gpu::Capabilities capabilities_; | |
| 56 | |
| 57 DISALLOW_COPY_AND_ASSIGN(Factory); | |
| 58 }; | |
| 59 | |
| 41 gpu::Capabilities ContextCapabilities() override; | 60 gpu::Capabilities ContextCapabilities() override; |
| 42 gpu::gles2::GLES2Interface* ContextGL() override; | 61 gpu::gles2::GLES2Interface* ContextGL() override; |
| 43 gpu::ContextSupport* ContextSupport() override; | 62 gpu::ContextSupport* ContextSupport() override; |
| 44 class GrContext* GrContext() override; | 63 class GrContext* GrContext() override; |
| 45 void InvalidateGrContext(uint32_t state) override; | 64 void InvalidateGrContext(uint32_t state) override; |
| 46 base::Lock* GetLock() override; | 65 base::Lock* GetLock() override; |
| 47 void DeleteCachedResources() override; | 66 void DeleteCachedResources() override; |
| 48 void SetLostContextCallback(const LostContextCallback& cb) override; | 67 void SetLostContextCallback(const LostContextCallback& cb) override; |
| 68 void DetachFromThread() override; | |
| 49 | 69 |
| 50 TestWebGraphicsContext3D* TestContext3d(); | 70 TestWebGraphicsContext3D* TestContext3d(); |
| 51 | |
| 52 // 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 // state on the test context before binding. Don't call | |
| 55 // InitializeOnCurrentThread on the context returned from this method. | |
| 56 TestWebGraphicsContext3D* UnboundTestContext3d(); | |
| 57 | |
| 58 TestContextSupport* support() { return &support_; } | 71 TestContextSupport* support() { return &support_; } |
| 59 | 72 |
| 60 protected: | 73 protected: |
| 61 explicit TestContextProvider( | 74 explicit TestContextProvider( |
| 62 std::unique_ptr<TestWebGraphicsContext3D> context); | 75 std::unique_ptr<TestWebGraphicsContext3D> context); |
| 63 ~TestContextProvider() override; | 76 ~TestContextProvider() override; |
| 64 | 77 |
| 65 private: | 78 private: |
| 66 void OnLostContext(); | 79 void OnLostContext(); |
| 67 | 80 |
| 68 TestContextSupport support_; | 81 TestContextSupport support_; |
| 69 | 82 |
| 70 std::unique_ptr<TestWebGraphicsContext3D> context3d_; | 83 std::unique_ptr<TestWebGraphicsContext3D> context3d_; |
| 71 std::unique_ptr<TestGLES2Interface> context_gl_; | 84 std::unique_ptr<TestGLES2Interface> context_gl_; |
| 72 bool bound_; | |
| 73 | 85 |
| 74 base::ThreadChecker main_thread_checker_; | 86 base::ThreadChecker thread_checker_; |
| 75 base::ThreadChecker context_thread_checker_; | |
| 76 | 87 |
| 77 base::Lock context_lock_; | 88 base::Lock context_lock_; |
| 78 | 89 |
| 79 LostContextCallback lost_context_callback_; | 90 LostContextCallback lost_context_callback_; |
| 80 sk_sp<class GrContext> gr_context_; | 91 sk_sp<class GrContext> gr_context_; |
| 81 | 92 |
| 82 base::WeakPtrFactory<TestContextProvider> weak_ptr_factory_; | 93 base::WeakPtrFactory<TestContextProvider> weak_ptr_factory_; |
| 83 | 94 |
| 84 DISALLOW_COPY_AND_ASSIGN(TestContextProvider); | 95 DISALLOW_COPY_AND_ASSIGN(TestContextProvider); |
| 85 }; | 96 }; |
| 86 | 97 |
| 87 } // namespace cc | 98 } // namespace cc |
| 88 | 99 |
| 89 #endif // CC_TEST_TEST_CONTEXT_PROVIDER_H_ | 100 #endif // CC_TEST_TEST_CONTEXT_PROVIDER_H_ |
| 90 | 101 |
| OLD | NEW |