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