• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CONTENT_COMMON_GPU_CLIENT_CONTEXT_PROVIDER_COMMAND_BUFFER
6 #define CONTENT_COMMON_GPU_CLIENT_CONTEXT_PROVIDER_COMMAND_BUFFER
7 
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 
16 namespace webkit {
17 namespace gpu {
18 class GrContextForWebGraphicsContext3D;
19 }
20 }
21 
22 namespace content {
23 
24 // Implementation of cc::ContextProvider that provides a
25 // WebGraphicsContext3DCommandBufferImpl context and a GrContext.
26 class CONTENT_EXPORT ContextProviderCommandBuffer
NON_EXPORTED_BASE(public cc::ContextProvider)27     : NON_EXPORTED_BASE(public cc::ContextProvider) {
28  public:
29   static scoped_refptr<ContextProviderCommandBuffer> Create(
30       scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context3d,
31       const std::string& debug_name);
32 
33   virtual bool BindToCurrentThread() OVERRIDE;
34   virtual WebGraphicsContext3DCommandBufferImpl* Context3d() OVERRIDE;
35   virtual gpu::gles2::GLES2Interface* ContextGL() OVERRIDE;
36   virtual gpu::ContextSupport* ContextSupport() OVERRIDE;
37   virtual class GrContext* GrContext() OVERRIDE;
38   virtual void MakeGrContextCurrent() OVERRIDE;
39   virtual Capabilities ContextCapabilities() OVERRIDE;
40   virtual bool IsContextLost() OVERRIDE;
41   virtual void VerifyContexts() OVERRIDE;
42   virtual bool DestroyedOnMainThread() OVERRIDE;
43   virtual void SetLostContextCallback(
44       const LostContextCallback& lost_context_callback) OVERRIDE;
45   virtual void SetMemoryPolicyChangedCallback(
46       const MemoryPolicyChangedCallback& memory_policy_changed_callback)
47       OVERRIDE;
48 
49   void set_leak_on_destroy() {
50     base::AutoLock lock(main_thread_lock_);
51     leak_on_destroy_ = true;
52   }
53 
54  protected:
55   ContextProviderCommandBuffer(
56       scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context3d,
57       const std::string& debug_name);
58   virtual ~ContextProviderCommandBuffer();
59 
60   void OnLostContext();
61   void OnMemoryAllocationChanged(const gpu::MemoryAllocation& allocation);
62 
63  private:
64   void InitializeCapabilities();
65 
66   base::ThreadChecker main_thread_checker_;
67   base::ThreadChecker context_thread_checker_;
68 
69   scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context3d_;
70   scoped_ptr<webkit::gpu::GrContextForWebGraphicsContext3D> gr_context_;
71 
72   cc::ContextProvider::Capabilities capabilities_;
73   std::string debug_name_;
74 
75   LostContextCallback lost_context_callback_;
76   MemoryPolicyChangedCallback memory_policy_changed_callback_;
77 
78   base::Lock main_thread_lock_;
79   bool leak_on_destroy_;
80   bool destroyed_;
81 
82   class LostContextCallbackProxy;
83   scoped_ptr<LostContextCallbackProxy> lost_context_callback_proxy_;
84 };
85 
86 }  // namespace content
87 
88 #endif  // CONTENT_COMMON_GPU_CLIENT_CONTEXT_PROVIDER_COMMAND_BUFFER
89