Roll src/buildtools ea47835:451dcd0
[chromium-blink-merge.git] / cc / test / test_context_provider.h
blob3be8b4365b6278e15ecb413ef6660f4b459058ce
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.
5 #ifndef CC_TEST_TEST_CONTEXT_PROVIDER_H_
6 #define CC_TEST_TEST_CONTEXT_PROVIDER_H_
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"
18 namespace cc {
19 class TestWebGraphicsContext3D;
20 class TestGLES2Interface;
22 class TestContextProvider : public ContextProvider {
23 public:
24 typedef base::Callback<scoped_ptr<TestWebGraphicsContext3D>(void)>
25 CreateCallback;
27 static scoped_refptr<TestContextProvider> Create();
28 static scoped_refptr<TestContextProvider> Create(
29 scoped_ptr<TestWebGraphicsContext3D> context);
31 bool BindToCurrentThread() override;
32 Capabilities ContextCapabilities() override;
33 gpu::gles2::GLES2Interface* ContextGL() override;
34 gpu::ContextSupport* ContextSupport() override;
35 class GrContext* GrContext() override;
36 bool IsContextLost() override;
37 void VerifyContexts() override;
38 void DeleteCachedResources() override;
39 bool DestroyedOnMainThread() override;
40 void SetLostContextCallback(const LostContextCallback& cb) override;
41 void SetMemoryPolicyChangedCallback(
42 const MemoryPolicyChangedCallback& cb) override;
44 TestWebGraphicsContext3D* TestContext3d();
46 // This returns the TestWebGraphicsContext3D but is valid to call
47 // before the context is bound to a thread. This is needed to set up
48 // state on the test context before binding. Don't call
49 // InitializeOnCurrentThread on the context returned from this method.
50 TestWebGraphicsContext3D* UnboundTestContext3d();
52 TestContextSupport* support() { return &support_; }
54 void SetMemoryAllocation(const ManagedMemoryPolicy& policy);
56 void SetMaxTransferBufferUsageBytes(size_t max_transfer_buffer_usage_bytes);
58 protected:
59 explicit TestContextProvider(scoped_ptr<TestWebGraphicsContext3D> context);
60 ~TestContextProvider() override;
62 private:
63 void OnLostContext();
65 TestContextSupport support_;
67 scoped_ptr<TestWebGraphicsContext3D> context3d_;
68 scoped_ptr<TestGLES2Interface> context_gl_;
69 bool bound_;
71 base::ThreadChecker main_thread_checker_;
72 base::ThreadChecker context_thread_checker_;
74 base::Lock destroyed_lock_;
75 bool destroyed_;
77 LostContextCallback lost_context_callback_;
78 MemoryPolicyChangedCallback memory_policy_changed_callback_;
79 skia::RefPtr<class GrContext> gr_context_;
81 base::WeakPtrFactory<TestContextProvider> weak_ptr_factory_;
83 DISALLOW_COPY_AND_ASSIGN(TestContextProvider);
86 } // namespace cc
88 #endif // CC_TEST_TEST_CONTEXT_PROVIDER_H_