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
6 #define CONTENT_COMMON_GPU_CLIENT_CONTEXT_PROVIDER_COMMAND_BUFFER
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/output/context_provider.h"
13 #include "content/common/content_export.h"
14 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
15 #include "webkit/common/gpu/context_provider_web_context.h"
19 class GrContextForWebGraphicsContext3D
;
25 // Implementation of cc::ContextProvider that provides a
26 // WebGraphicsContext3DCommandBufferImpl context and a GrContext.
27 class CONTENT_EXPORT ContextProviderCommandBuffer
28 : NON_EXPORTED_BASE(public webkit::gpu::ContextProviderWebContext
) {
30 static scoped_refptr
<ContextProviderCommandBuffer
> Create(
31 scoped_ptr
<WebGraphicsContext3DCommandBufferImpl
> context3d
,
32 const std::string
& debug_name
);
34 CommandBufferProxyImpl
* GetCommandBufferProxy();
36 // ContextProviderWebContext implementation.
37 virtual WebGraphicsContext3DCommandBufferImpl
* WebContext3D() OVERRIDE
;
39 // cc::ContextProvider implementation.
40 virtual bool BindToCurrentThread() OVERRIDE
;
41 virtual gpu::gles2::GLES2Interface
* ContextGL() OVERRIDE
;
42 virtual gpu::ContextSupport
* ContextSupport() OVERRIDE
;
43 virtual class GrContext
* GrContext() OVERRIDE
;
44 virtual Capabilities
ContextCapabilities() OVERRIDE
;
45 virtual bool IsContextLost() OVERRIDE
;
46 virtual void VerifyContexts() OVERRIDE
;
47 virtual void DeleteCachedResources() OVERRIDE
;
48 virtual bool DestroyedOnMainThread() OVERRIDE
;
49 virtual void SetLostContextCallback(
50 const LostContextCallback
& lost_context_callback
) OVERRIDE
;
51 virtual void SetMemoryPolicyChangedCallback(
52 const MemoryPolicyChangedCallback
& memory_policy_changed_callback
)
56 ContextProviderCommandBuffer(
57 scoped_ptr
<WebGraphicsContext3DCommandBufferImpl
> context3d
,
58 const std::string
& debug_name
);
59 virtual ~ContextProviderCommandBuffer();
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
<webkit::gpu::GrContextForWebGraphicsContext3D
> gr_context_
;
73 cc::ContextProvider::Capabilities capabilities_
;
74 std::string debug_name_
;
76 LostContextCallback lost_context_callback_
;
77 MemoryPolicyChangedCallback memory_policy_changed_callback_
;
79 base::Lock main_thread_lock_
;
82 class LostContextCallbackProxy
;
83 scoped_ptr
<LostContextCallbackProxy
> lost_context_callback_proxy_
;
86 } // namespace content
88 #endif // CONTENT_COMMON_GPU_CLIENT_CONTEXT_PROVIDER_COMMAND_BUFFER