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