1 // Copyright (c) 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 CONTENT_COMMON_GPU_CLIENT_CONTEXT_PROVIDER_COMMAND_BUFFER_H_
6 #define CONTENT_COMMON_GPU_CLIENT_CONTEXT_PROVIDER_COMMAND_BUFFER_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/synchronization/lock.h"
11 #include "base/threading/thread_checker.h"
12 #include "cc/blink/context_provider_web_context.h"
13 #include "cc/output/context_provider.h"
14 #include "content/common/content_export.h"
15 #include "content/common/gpu/client/command_buffer_metrics.h"
16 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
20 class GrContextForWebGraphicsContext3D
;
22 // Implementation of cc::ContextProvider that provides a
23 // WebGraphicsContext3DCommandBufferImpl context and a GrContext.
24 class CONTENT_EXPORT ContextProviderCommandBuffer
25 : NON_EXPORTED_BASE(public cc_blink::ContextProviderWebContext
) {
27 static scoped_refptr
<ContextProviderCommandBuffer
> Create(
28 scoped_ptr
<WebGraphicsContext3DCommandBufferImpl
> context3d
,
29 CommandBufferContextType type
);
31 CommandBufferProxyImpl
* GetCommandBufferProxy();
33 // cc_blink::ContextProviderWebContext implementation.
34 WebGraphicsContext3DCommandBufferImpl
* WebContext3D() override
;
36 // cc::ContextProvider implementation.
37 bool BindToCurrentThread() override
;
38 void DetachFromThread() override
;
39 gpu::gles2::GLES2Interface
* ContextGL() override
;
40 gpu::ContextSupport
* ContextSupport() override
;
41 class GrContext
* GrContext() override
;
42 void InvalidateGrContext(uint32_t state
) override
;
43 void SetupLock() override
;
44 base::Lock
* GetLock() override
;
45 Capabilities
ContextCapabilities() override
;
46 void VerifyContexts() override
;
47 void DeleteCachedResources() override
;
48 bool DestroyedOnMainThread() override
;
49 void SetLostContextCallback(
50 const LostContextCallback
& lost_context_callback
) override
;
51 void SetMemoryPolicyChangedCallback(
52 const MemoryPolicyChangedCallback
& memory_policy_changed_callback
)
56 ContextProviderCommandBuffer(
57 scoped_ptr
<WebGraphicsContext3DCommandBufferImpl
> context3d
,
58 CommandBufferContextType type
);
59 ~ContextProviderCommandBuffer() override
;
62 void OnMemoryAllocationChanged(const gpu::MemoryAllocation
& allocation
);
65 void InitializeCapabilities();
67 base::ThreadChecker main_thread_checker_
;
68 base::ThreadChecker context_thread_checker_
;
70 scoped_ptr
<WebGraphicsContext3DCommandBufferImpl
> context3d_
;
71 scoped_ptr
<GrContextForWebGraphicsContext3D
> gr_context_
;
73 cc::ContextProvider::Capabilities capabilities_
;
74 CommandBufferContextType context_type_
;
75 std::string debug_name_
;
77 LostContextCallback lost_context_callback_
;
78 MemoryPolicyChangedCallback memory_policy_changed_callback_
;
80 base::Lock main_thread_lock_
;
83 base::Lock context_lock_
;
85 class LostContextCallbackProxy
;
86 scoped_ptr
<LostContextCallbackProxy
> lost_context_callback_proxy_
;
89 } // namespace content
91 #endif // CONTENT_COMMON_GPU_CLIENT_CONTEXT_PROVIDER_COMMAND_BUFFER_H_