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/memory/ref_counted.h"
      9 #include "base/memory/scoped_ptr.h"
     10 #include "gpu/command_buffer/service/feature_info.h"
     11 #include "ui/gfx/size.h"
     12 
     13 namespace gfx {
     14 
     15 class GLContext;
     16 class GLShareGroup;
     17 class GLSurface;
     18 
     19 }
     20 
     21 namespace gpu {
     22 
     23 class CommandBufferService;
     24 class TransferBuffer;
     25 class GpuScheduler;
     26 
     27 namespace gles2 {
     28 
     29 class ContextGroup;
     30 class MailboxManager;
     31 class GLES2Decoder;
     32 class GLES2CmdHelper;
     33 class GLES2Implementation;
     34 class ImageFactory;
     35 class ImageManager;
     36 class ShareGroup;
     37 
     38 };
     39 
     40 class GLManager {
     41  public:
     42   struct Options {
     43     Options();
     44     // The size of the backbuffer.
     45     gfx::Size size;
     46     // If not null will share resources with this context.
     47     GLManager* share_group_manager;
     48     // If not null will share a mailbox manager with this context.
     49     GLManager* share_mailbox_manager;
     50     // If not null will create a virtual manager based on this context.
     51     GLManager* virtual_manager;
     52     // Whether or not glBindXXX generates a resource.
     53     bool bind_generates_resource;
     54     // Whether or not it's ok to lose the context.
     55     bool context_lost_allowed;
     56     // Image manager to be used.
     57     gles2::ImageManager* image_manager;
     58     // Image factory to be used.
     59     gles2::ImageFactory* image_factory;
     60   };
     61   GLManager();
     62   ~GLManager();
     63 
     64   void Initialize(const Options& options);
     65   void Destroy();
     66 
     67   void MakeCurrent();
     68 
     69   void SetSurface(gfx::GLSurface* surface);
     70 
     71   gles2::GLES2Decoder* decoder() const {
     72     return decoder_.get();
     73   }
     74 
     75   gles2::MailboxManager* mailbox_manager() const {
     76     return mailbox_manager_.get();
     77   }
     78 
     79   gfx::GLShareGroup* share_group() const {
     80     return share_group_.get();
     81   }
     82 
     83   gles2::GLES2Implementation* gles2_implementation() const {
     84     return gles2_implementation_.get();
     85   }
     86 
     87   gfx::GLContext* context() {
     88     return context_.get();
     89   }
     90 
     91   const gpu::gles2::FeatureInfo::Workarounds& workarounds() const;
     92 
     93  private:
     94   void PumpCommands();
     95   bool GetBufferChanged(int32 transfer_buffer_id);
     96   void SetupBaseContext();
     97 
     98   scoped_refptr<gles2::MailboxManager> mailbox_manager_;
     99   scoped_refptr<gfx::GLShareGroup> share_group_;
    100   scoped_ptr<CommandBufferService> command_buffer_;
    101   scoped_ptr<gles2::GLES2Decoder> decoder_;
    102   scoped_ptr<GpuScheduler> gpu_scheduler_;
    103   scoped_refptr<gfx::GLSurface> surface_;
    104   scoped_refptr<gfx::GLContext> context_;
    105   scoped_ptr<gles2::GLES2CmdHelper> gles2_helper_;
    106   scoped_ptr<TransferBuffer> transfer_buffer_;
    107   scoped_ptr<gles2::GLES2Implementation> gles2_implementation_;
    108   bool context_lost_allowed_;
    109 
    110   // Used on Android to virtualize GL for all contexts.
    111   static int use_count_;
    112   static scoped_refptr<gfx::GLShareGroup>* base_share_group_;
    113   static scoped_refptr<gfx::GLSurface>* base_surface_;
    114   static scoped_refptr<gfx::GLContext>* base_context_;
    115 };
    116 
    117 }  // namespace gpu
    118 
    119 #endif  // GPU_COMMAND_BUFFER_TESTS_GL_MANAGER_H_
    120