Home | History | Annotate | Download | only in output
      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 CC_OUTPUT_CONTEXT_PROVIDER_H_
      6 #define CC_OUTPUT_CONTEXT_PROVIDER_H_
      7 
      8 #include "base/callback.h"
      9 #include "base/memory/ref_counted.h"
     10 #include "cc/base/cc_export.h"
     11 #include "gpu/command_buffer/common/capabilities.h"
     12 
     13 class GrContext;
     14 
     15 namespace blink { class WebGraphicsContext3D; }
     16 namespace gpu {
     17 class ContextSupport;
     18 namespace gles2 { class GLES2Interface; }
     19 }
     20 
     21 namespace cc {
     22 struct ManagedMemoryPolicy;
     23 
     24 class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> {
     25  public:
     26   // Bind the 3d context to the current thread. This should be called before
     27   // accessing the contexts. Calling it more than once should have no effect.
     28   // Once this function has been called, the class should only be accessed
     29   // from the same thread.
     30   virtual bool BindToCurrentThread() = 0;
     31 
     32   virtual blink::WebGraphicsContext3D* Context3d() = 0;
     33   virtual gpu::gles2::GLES2Interface* ContextGL() = 0;
     34   virtual gpu::ContextSupport* ContextSupport() = 0;
     35   virtual class GrContext* GrContext() = 0;
     36   virtual void MakeGrContextCurrent() = 0;
     37 
     38   struct Capabilities {
     39     bool egl_image_external : 1;
     40     bool fast_npot_mo8_textures : 1;
     41     bool iosurface : 1;
     42     bool map_image : 1;
     43     bool post_sub_buffer : 1;
     44     bool texture_format_bgra8888 : 1;
     45     bool texture_format_etc1 : 1;
     46     bool texture_rectangle : 1;
     47     bool texture_storage : 1;
     48     bool texture_usage : 1;
     49     bool discard_framebuffer : 1;
     50     size_t max_transfer_buffer_usage_bytes;
     51 
     52     CC_EXPORT Capabilities();
     53 
     54     // TODO(boliu): Compose a gpu::Capabilities instead and remove this
     55     // constructor.
     56     explicit CC_EXPORT Capabilities(const gpu::Capabilities& gpu_capabilities);
     57   };
     58   // Returns the capabilities of the currently bound 3d context.
     59   virtual Capabilities ContextCapabilities() = 0;
     60 
     61   // Checks if the context is currently known to be lost.
     62   virtual bool IsContextLost() = 0;
     63 
     64   // Ask the provider to check if the contexts are valid or lost. If they are,
     65   // this should invalidate the provider so that it can be replaced with a new
     66   // one.
     67   virtual void VerifyContexts() = 0;
     68 
     69   // A method to be called from the main thread that should return true if
     70   // the context inside the provider is no longer valid.
     71   virtual bool DestroyedOnMainThread() = 0;
     72 
     73   // Sets a callback to be called when the context is lost. This should be
     74   // called from the same thread that the context is bound to. To avoid races,
     75   // it should be called before BindToCurrentThread(), or VerifyContexts()
     76   // should be called after setting the callback.
     77   typedef base::Closure LostContextCallback;
     78   virtual void SetLostContextCallback(
     79       const LostContextCallback& lost_context_callback) = 0;
     80 
     81   // Sets a callback to be called when the memory policy changes. This should be
     82   // called from the same thread that the context is bound to.
     83   typedef base::Callback<void(const ManagedMemoryPolicy& policy)>
     84       MemoryPolicyChangedCallback;
     85   virtual void SetMemoryPolicyChangedCallback(
     86       const MemoryPolicyChangedCallback& memory_policy_changed_callback) = 0;
     87 
     88  protected:
     89   friend class base::RefCountedThreadSafe<ContextProvider>;
     90   virtual ~ContextProvider() {}
     91 };
     92 
     93 }  // namespace cc
     94 
     95 #endif  // CC_OUTPUT_CONTEXT_PROVIDER_H_
     96