Elim cr-checkbox
[chromium-blink-merge.git] / gpu / command_buffer / tests / gl_manager.h
blob4c1c72f5709dba4f9d08f49564159e73cc914c4d
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.
5 #ifndef GPU_COMMAND_BUFFER_TESTS_GL_MANAGER_H_
6 #define GPU_COMMAND_BUFFER_TESTS_GL_MANAGER_H_
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/geometry/size.h"
14 #include "ui/gfx/gpu_memory_buffer.h"
16 namespace base {
17 class CommandLine;
20 namespace gfx {
22 class GLContext;
23 class GLShareGroup;
24 class GLSurface;
28 namespace gpu {
30 class CommandBufferService;
31 class GpuScheduler;
32 class TransferBuffer;
34 namespace gles2 {
36 class ContextGroup;
37 class MailboxManager;
38 class GLES2Decoder;
39 class GLES2CmdHelper;
40 class GLES2Implementation;
41 class ImageManager;
42 class ShareGroup;
46 class GLManager : private GpuControl {
47 public:
48 struct Options {
49 Options();
50 // The size of the backbuffer.
51 gfx::Size size;
52 // If not null will share resources with this context.
53 GLManager* share_group_manager;
54 // If not null will share a mailbox manager with this context.
55 GLManager* share_mailbox_manager;
56 // If not null will create a virtual manager based on this context.
57 GLManager* virtual_manager;
58 // Whether or not glBindXXX generates a resource.
59 bool bind_generates_resource;
60 // Whether or not the context is auto-lost when GL_OUT_OF_MEMORY occurs.
61 bool lose_context_when_out_of_memory;
62 // Whether or not it's ok to lose the context.
63 bool context_lost_allowed;
64 // 0 indicates not WebGL context - default.
65 // 1 indicates WebGL 1 context.
66 // 2 indicates WebGL 2 context.
67 unsigned webgl_version;
69 GLManager();
70 ~GLManager() override;
72 static scoped_ptr<gfx::GpuMemoryBuffer> CreateGpuMemoryBuffer(
73 const gfx::Size& size,
74 gfx::BufferFormat format);
76 void Initialize(const Options& options);
77 void InitializeWithCommandLine(const Options& options,
78 base::CommandLine* command_line);
79 void Destroy();
81 void MakeCurrent();
83 void SetSurface(gfx::GLSurface* surface);
85 gles2::GLES2Decoder* decoder() const {
86 return decoder_.get();
89 gles2::MailboxManager* mailbox_manager() const {
90 return mailbox_manager_.get();
93 gfx::GLShareGroup* share_group() const {
94 return share_group_.get();
97 gles2::GLES2Implementation* gles2_implementation() const {
98 return gles2_implementation_.get();
101 gfx::GLContext* context() {
102 return context_.get();
105 const gpu::gles2::FeatureInfo::Workarounds& workarounds() const;
107 // GpuControl implementation.
108 Capabilities GetCapabilities() override;
109 int32 CreateImage(ClientBuffer buffer,
110 size_t width,
111 size_t height,
112 unsigned internalformat) override;
113 void DestroyImage(int32 id) override;
114 int32 CreateGpuMemoryBufferImage(size_t width,
115 size_t height,
116 unsigned internalformat,
117 unsigned usage) override;
118 uint32 InsertSyncPoint() override;
119 uint32 InsertFutureSyncPoint() override;
120 void RetireSyncPoint(uint32 sync_point) override;
121 void SignalSyncPoint(uint32 sync_point,
122 const base::Closure& callback) override;
123 void SignalQuery(uint32 query, const base::Closure& callback) override;
124 void SetSurfaceVisible(bool visible) override;
125 uint32 CreateStreamTexture(uint32 texture_id) override;
126 void SetLock(base::Lock*) override;
127 bool IsGpuChannelLost() override;
128 gpu::CommandBufferNamespace GetNamespaceID() const override;
129 uint64_t GetCommandBufferID() const override;
131 private:
132 void PumpCommands();
133 bool GetBufferChanged(int32 transfer_buffer_id);
134 void SetupBaseContext();
136 scoped_refptr<gles2::MailboxManager> mailbox_manager_;
137 scoped_refptr<gfx::GLShareGroup> share_group_;
138 scoped_ptr<CommandBufferService> command_buffer_;
139 scoped_ptr<gles2::GLES2Decoder> decoder_;
140 scoped_ptr<GpuScheduler> gpu_scheduler_;
141 scoped_refptr<gfx::GLSurface> surface_;
142 scoped_refptr<gfx::GLContext> context_;
143 scoped_ptr<gles2::GLES2CmdHelper> gles2_helper_;
144 scoped_ptr<TransferBuffer> transfer_buffer_;
145 scoped_ptr<gles2::GLES2Implementation> gles2_implementation_;
146 bool context_lost_allowed_;
148 // Used on Android to virtualize GL for all contexts.
149 static int use_count_;
150 static scoped_refptr<gfx::GLShareGroup>* base_share_group_;
151 static scoped_refptr<gfx::GLSurface>* base_surface_;
152 static scoped_refptr<gfx::GLContext>* base_context_;
155 } // namespace gpu
157 #endif // GPU_COMMAND_BUFFER_TESTS_GL_MANAGER_H_