Home | History | Annotate | Download | only in tests
      1 // Copyright (c) 2012 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 GPU_COMMAND_BUFFER_TESTS_GL_MANAGER_H_
      6 #define GPU_COMMAND_BUFFER_TESTS_GL_MANAGER_H_
      7 
      8 #include "base/containers/scoped_ptr_hash_map.h"
      9 #include "base/memory/ref_counted.h"
     10 #include "base/memory/scoped_ptr.h"
     11 #include "gpu/command_buffer/client/gpu_control.h"
     12 #include "gpu/command_buffer/service/feature_info.h"
     13 #include "ui/gfx/size.h"
     14 
     15 namespace gfx {
     16 
     17 class GLContext;
     18 class GLShareGroup;
     19 class GLSurface;
     20 
     21 }
     22 
     23 namespace gpu {
     24 
     25 class CommandBufferService;
     26 class GpuControlService;
     27 class GpuMemoryBufferFactory;
     28 class GpuScheduler;
     29 class TransferBuffer;
     30 
     31 namespace gles2 {
     32 
     33 class ContextGroup;
     34 class MailboxManager;
     35 class GLES2Decoder;
     36 class GLES2CmdHelper;
     37 class GLES2Implementation;
     38 class ImageFactory;
     39 class ImageManager;
     40 class ShareGroup;
     41 
     42 };
     43 
     44 class GLManager : private GpuControl {
     45  public:
     46   struct Options {
     47     Options();
     48     // The size of the backbuffer.
     49     gfx::Size size;
     50     // If not null will share resources with this context.
     51     GLManager* share_group_manager;
     52     // If not null will share a mailbox manager with this context.
     53     GLManager* share_mailbox_manager;
     54     // If not null will create a virtual manager based on this context.
     55     GLManager* virtual_manager;
     56     // Whether or not glBindXXX generates a resource.
     57     bool bind_generates_resource;
     58     // Whether or not the context is auto-lost when GL_OUT_OF_MEMORY occurs.
     59     bool lose_context_when_out_of_memory;
     60     // Whether or not it's ok to lose the context.
     61     bool context_lost_allowed;
     62     // Image manager to be used.
     63     gles2::ImageManager* image_manager;
     64     // GpuMemoryBuffer factory to be used.
     65     GpuMemoryBufferFactory* gpu_memory_buffer_factory;
     66   };
     67   GLManager();
     68   virtual ~GLManager();
     69 
     70   void Initialize(const Options& options);
     71   void Destroy();
     72 
     73   void MakeCurrent();
     74 
     75   void SetSurface(gfx::GLSurface* surface);
     76 
     77   gles2::GLES2Decoder* decoder() const {
     78     return decoder_.get();
     79   }
     80 
     81   gles2::MailboxManager* mailbox_manager() const {
     82     return mailbox_manager_.get();
     83   }
     84 
     85   gfx::GLShareGroup* share_group() const {
     86     return share_group_.get();
     87   }
     88 
     89   gles2::GLES2Implementation* gles2_implementation() const {
     90     return gles2_implementation_.get();
     91   }
     92 
     93   gfx::GLContext* context() {
     94     return context_.get();
     95   }
     96 
     97   const gpu::gles2::FeatureInfo::Workarounds& workarounds() const;
     98 
     99   // GpuControl implementation.
    100   virtual Capabilities GetCapabilities() OVERRIDE;
    101   virtual gfx::GpuMemoryBuffer* CreateGpuMemoryBuffer(size_t width,
    102                                                       size_t height,
    103                                                       unsigned internalformat,
    104                                                       unsigned usage,
    105                                                       int32* id) OVERRIDE;
    106   virtual void DestroyGpuMemoryBuffer(int32 id) OVERRIDE;
    107   virtual uint32 InsertSyncPoint() OVERRIDE;
    108   virtual void SignalSyncPoint(uint32 sync_point,
    109                                const base::Closure& callback) OVERRIDE;
    110   virtual void SignalQuery(uint32 query,
    111                            const base::Closure& callback) OVERRIDE;
    112   virtual void SetSurfaceVisible(bool visible) OVERRIDE;
    113   virtual void Echo(const base::Closure& callback) OVERRIDE;
    114   virtual uint32 CreateStreamTexture(uint32 texture_id) OVERRIDE;
    115 
    116  private:
    117   void PumpCommands();
    118   bool GetBufferChanged(int32 transfer_buffer_id);
    119   void SetupBaseContext();
    120 
    121   scoped_refptr<gles2::MailboxManager> mailbox_manager_;
    122   scoped_refptr<gfx::GLShareGroup> share_group_;
    123   scoped_ptr<CommandBufferService> command_buffer_;
    124   scoped_ptr<GpuControlService> gpu_control_service_;
    125   scoped_ptr<gles2::GLES2Decoder> decoder_;
    126   scoped_ptr<GpuScheduler> gpu_scheduler_;
    127   scoped_refptr<gfx::GLSurface> surface_;
    128   scoped_refptr<gfx::GLContext> context_;
    129   scoped_ptr<gles2::GLES2CmdHelper> gles2_helper_;
    130   scoped_ptr<TransferBuffer> transfer_buffer_;
    131   scoped_ptr<gles2::GLES2Implementation> gles2_implementation_;
    132   bool context_lost_allowed_;
    133 
    134   // Client GpuControl implementation.
    135   GpuMemoryBufferFactory* gpu_memory_buffer_factory_;
    136   base::ScopedPtrHashMap<int32, gfx::GpuMemoryBuffer> memory_buffers_;
    137 
    138   // Used on Android to virtualize GL for all contexts.
    139   static int use_count_;
    140   static scoped_refptr<gfx::GLShareGroup>* base_share_group_;
    141   static scoped_refptr<gfx::GLSurface>* base_surface_;
    142   static scoped_refptr<gfx::GLContext>* base_context_;
    143 };
    144 
    145 }  // namespace gpu
    146 
    147 #endif  // GPU_COMMAND_BUFFER_TESTS_GL_MANAGER_H_
    148