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/memory/scoped_ptr.h" 9 #include "base/synchronization/lock.h" 10 #include "base/threading/thread_checker.h" 11 #include "cc/output/context_provider.h" 12 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" 13 14 namespace webkit { 15 namespace gpu { 16 class GrContextForWebGraphicsContext3D; 17 } 18 } 19 20 namespace content { 21 22 // Implementation of cc::ContextProvider that provides a 23 // WebGraphicsContext3DCommandBufferImpl context and a GrContext. 24 class ContextProviderCommandBuffer : public cc::ContextProvider { 25 public: 26 typedef base::Callback< 27 scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(void)> CreateCallback; 28 static scoped_refptr<ContextProviderCommandBuffer> Create( 29 const CreateCallback& create_callback); 30 31 virtual bool BindToCurrentThread() OVERRIDE; 32 virtual WebGraphicsContext3DCommandBufferImpl* Context3d() OVERRIDE; 33 virtual class GrContext* GrContext() OVERRIDE; 34 virtual void VerifyContexts() OVERRIDE; 35 virtual bool DestroyedOnMainThread() OVERRIDE; 36 virtual void SetLostContextCallback( 37 const LostContextCallback& lost_context_callback) OVERRIDE; 38 39 void set_leak_on_destroy() { 40 base::AutoLock lock(main_thread_lock_); 41 leak_on_destroy_ = true; 42 } 43 44 protected: 45 ContextProviderCommandBuffer(); 46 virtual ~ContextProviderCommandBuffer(); 47 48 // This must be called immedately after creating this object, and it should 49 // be thrown away if this returns false. 50 bool InitializeOnMainThread(const CreateCallback& create_callback); 51 52 void OnLostContext(); 53 void OnMemoryAllocationChanged(bool nonzero_allocation); 54 55 private: 56 base::ThreadChecker main_thread_checker_; 57 base::ThreadChecker context_thread_checker_; 58 59 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context3d_; 60 scoped_ptr<webkit::gpu::GrContextForWebGraphicsContext3D> gr_context_; 61 62 LostContextCallback lost_context_callback_; 63 64 base::Lock main_thread_lock_; 65 bool leak_on_destroy_; 66 bool destroyed_; 67 68 class LostContextCallbackProxy; 69 scoped_ptr<LostContextCallbackProxy> lost_context_callback_proxy_; 70 71 class MemoryAllocationCallbackProxy; 72 scoped_ptr<MemoryAllocationCallbackProxy> memory_allocation_callback_proxy_; 73 }; 74 75 } // namespace content 76 77 #endif // CONTENT_COMMON_GPU_CLIENT_CONTEXT_PROVIDER_COMMAND_BUFFER 78