Home | History | Annotate | Download | only in gpu
      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 WEBKIT_COMMON_GPU_CONTEXT_PROVIDER_IN_PROCESS_H_
      6 #define WEBKIT_COMMON_GPU_CONTEXT_PROVIDER_IN_PROCESS_H_
      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 "webkit/common/gpu/webkit_gpu_export.h"
     14 
     15 namespace WebKit {
     16 class WebGraphicsContext3D;
     17 }
     18 
     19 namespace webkit {
     20 namespace gpu {
     21 class GrContextForWebGraphicsContext3D;
     22 class WebGraphicsContext3DInProcessCommandBufferImpl;
     23 
     24 class WEBKIT_GPU_EXPORT ContextProviderInProcess
     25     : NON_EXPORTED_BASE(public cc::ContextProvider) {
     26  public:
     27   typedef base::Callback<
     28       scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl>(void)>
     29       CreateCallback;
     30 
     31   static scoped_refptr<ContextProviderInProcess> Create(
     32       const CreateCallback& create_callback);
     33 
     34   // Calls Create() with a default factory method for creating an offscreen
     35   // context.
     36   static scoped_refptr<ContextProviderInProcess> CreateOffscreen();
     37 
     38   virtual bool BindToCurrentThread() OVERRIDE;
     39   virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE;
     40   virtual class GrContext* GrContext() OVERRIDE;
     41   virtual void VerifyContexts() OVERRIDE;
     42   virtual bool DestroyedOnMainThread() OVERRIDE;
     43   virtual void SetLostContextCallback(
     44       const LostContextCallback& lost_context_callback) OVERRIDE;
     45 
     46  protected:
     47   ContextProviderInProcess();
     48   virtual ~ContextProviderInProcess();
     49 
     50   bool InitializeOnMainThread(
     51       const CreateCallback& create_callback);
     52 
     53   void OnLostContext();
     54   void OnMemoryAllocationChanged(bool nonzero_allocation);
     55 
     56  private:
     57   base::ThreadChecker main_thread_checker_;
     58   base::ThreadChecker context_thread_checker_;
     59 
     60   scoped_ptr<WebKit::WebGraphicsContext3D> context3d_;
     61   scoped_ptr<webkit::gpu::GrContextForWebGraphicsContext3D> gr_context_;
     62 
     63   LostContextCallback lost_context_callback_;
     64 
     65   base::Lock destroyed_lock_;
     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 gpu
     76 }  // namespace webkit
     77 
     78 #endif  // WEBKIT_COMMON_GPU_CONTEXT_PROVIDER_IN_PROCESS_H_
     79