• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 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 ImageManager;
37 class ShareGroup;
38 
39 };
40 
41 class GLManager : private GpuControl {
42  public:
43   struct Options {
44     Options();
45     // The size of the backbuffer.
46     gfx::Size size;
47     // If not null will share resources with this context.
48     GLManager* share_group_manager;
49     // If not null will share a mailbox manager with this context.
50     GLManager* share_mailbox_manager;
51     // If not null will create a virtual manager based on this context.
52     GLManager* virtual_manager;
53     // Whether or not glBindXXX generates a resource.
54     bool bind_generates_resource;
55     // Whether or not the context is auto-lost when GL_OUT_OF_MEMORY occurs.
56     bool lose_context_when_out_of_memory;
57     // Whether or not it's ok to lose the context.
58     bool context_lost_allowed;
59   };
60   GLManager();
61   virtual ~GLManager();
62 
63   void Initialize(const Options& options);
64   void Destroy();
65 
66   void MakeCurrent();
67 
68   void SetSurface(gfx::GLSurface* surface);
69 
decoder()70   gles2::GLES2Decoder* decoder() const {
71     return decoder_.get();
72   }
73 
mailbox_manager()74   gles2::MailboxManager* mailbox_manager() const {
75     return mailbox_manager_.get();
76   }
77 
share_group()78   gfx::GLShareGroup* share_group() const {
79     return share_group_.get();
80   }
81 
gles2_implementation()82   gles2::GLES2Implementation* gles2_implementation() const {
83     return gles2_implementation_.get();
84   }
85 
context()86   gfx::GLContext* context() {
87     return context_.get();
88   }
89 
90   const gpu::gles2::FeatureInfo::Workarounds& workarounds() const;
91 
92   // GpuControl implementation.
93   virtual Capabilities GetCapabilities() OVERRIDE;
94   virtual gfx::GpuMemoryBuffer* CreateGpuMemoryBuffer(size_t width,
95                                                       size_t height,
96                                                       unsigned internalformat,
97                                                       unsigned usage,
98                                                       int32* id) OVERRIDE;
99   virtual void DestroyGpuMemoryBuffer(int32 id) OVERRIDE;
100   virtual uint32 InsertSyncPoint() OVERRIDE;
101   virtual uint32 InsertFutureSyncPoint() OVERRIDE;
102   virtual void RetireSyncPoint(uint32 sync_point) OVERRIDE;
103   virtual void SignalSyncPoint(uint32 sync_point,
104                                const base::Closure& callback) OVERRIDE;
105   virtual void SignalQuery(uint32 query,
106                            const base::Closure& callback) OVERRIDE;
107   virtual void SetSurfaceVisible(bool visible) OVERRIDE;
108   virtual void Echo(const base::Closure& callback) OVERRIDE;
109   virtual uint32 CreateStreamTexture(uint32 texture_id) OVERRIDE;
110 
111  private:
112   void PumpCommands();
113   bool GetBufferChanged(int32 transfer_buffer_id);
114   void SetupBaseContext();
115 
116   scoped_refptr<gles2::MailboxManager> mailbox_manager_;
117   scoped_refptr<gfx::GLShareGroup> share_group_;
118   scoped_ptr<CommandBufferService> command_buffer_;
119   scoped_ptr<gles2::GLES2Decoder> decoder_;
120   scoped_ptr<GpuScheduler> gpu_scheduler_;
121   scoped_refptr<gfx::GLSurface> surface_;
122   scoped_refptr<gfx::GLContext> context_;
123   scoped_ptr<gles2::GLES2CmdHelper> gles2_helper_;
124   scoped_ptr<TransferBuffer> transfer_buffer_;
125   scoped_ptr<gles2::GLES2Implementation> gles2_implementation_;
126   bool context_lost_allowed_;
127 
128   // Client GpuControl implementation.
129   base::ScopedPtrHashMap<int32, gfx::GpuMemoryBuffer> gpu_memory_buffers_;
130 
131   // Used on Android to virtualize GL for all contexts.
132   static int use_count_;
133   static scoped_refptr<gfx::GLShareGroup>* base_share_group_;
134   static scoped_refptr<gfx::GLSurface>* base_surface_;
135   static scoped_refptr<gfx::GLContext>* base_context_;
136 };
137 
138 }  // namespace gpu
139 
140 #endif  // GPU_COMMAND_BUFFER_TESTS_GL_MANAGER_H_
141