Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / gpu / command_buffer / service / gles2_cmd_decoder.h
blob0fb4882c76d8a57f7977d9fd99ca1219fad31229
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 // This file contains the GLES2Decoder class.
7 #ifndef GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_H_
8 #define GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_H_
10 #include <string>
11 #include <vector>
13 #include "base/basictypes.h"
14 #include "base/callback_forward.h"
15 #include "base/macros.h"
16 #include "base/memory/ref_counted.h"
17 #include "base/memory/weak_ptr.h"
18 #include "base/time/time.h"
19 #include "build/build_config.h"
20 #include "gpu/command_buffer/common/capabilities.h"
21 #include "gpu/command_buffer/common/constants.h"
22 #include "gpu/command_buffer/service/common_decoder.h"
23 #include "gpu/gpu_export.h"
25 namespace gfx {
26 class GLContext;
27 class GLSurface;
28 class Size;
31 namespace gpu {
33 struct Mailbox;
35 namespace gles2 {
37 class ContextGroup;
38 class ErrorState;
39 class GLES2Util;
40 class ImageManager;
41 class Logger;
42 class QueryManager;
43 class Texture;
44 class VertexArrayManager;
45 class ValuebufferManager;
46 struct ContextState;
48 struct DisallowedFeatures {
49 DisallowedFeatures()
50 : gpu_memory_manager(false),
51 npot_support(false) {
54 bool gpu_memory_manager;
55 bool npot_support;
58 typedef base::Callback<void(const std::string& key,
59 const std::string& shader)> ShaderCacheCallback;
61 // This class implements the AsyncAPIInterface interface, decoding GLES2
62 // commands and calling GL.
63 class GPU_EXPORT GLES2Decoder : public base::SupportsWeakPtr<GLES2Decoder>,
64 public CommonDecoder {
65 public:
66 typedef error::Error Error;
67 typedef base::Callback<bool(uint32 id)> WaitSyncPointCallback;
69 // The default stencil mask, which has all bits set. This really should be a
70 // GLuint, but we can't #include gl_bindings.h in this file without causing
71 // macro redefinitions.
72 static const unsigned int kDefaultStencilMask;
74 // Creates a decoder.
75 static GLES2Decoder* Create(ContextGroup* group);
77 ~GLES2Decoder() override;
79 bool initialized() const {
80 return initialized_;
83 void set_initialized() {
84 initialized_ = true;
87 bool unsafe_es3_apis_enabled() const {
88 return unsafe_es3_apis_enabled_;
91 void set_unsafe_es3_apis_enabled(bool enabled) {
92 unsafe_es3_apis_enabled_ = enabled;
95 bool debug() const {
96 return debug_;
99 // Set to true to call glGetError after every command.
100 void set_debug(bool debug) {
101 debug_ = debug;
104 bool log_commands() const {
105 return log_commands_;
108 // Set to true to LOG every command.
109 void set_log_commands(bool log_commands) {
110 log_commands_ = log_commands;
113 // Initializes the graphics context. Can create an offscreen
114 // decoder with a frame buffer that can be referenced from the parent.
115 // Takes ownership of GLContext.
116 // Parameters:
117 // surface: the GL surface to render to.
118 // context: the GL context to render to.
119 // offscreen: whether to make the context offscreen or not. When FBO 0 is
120 // bound, offscreen contexts render to an internal buffer, onscreen ones
121 // to the surface.
122 // offscreen_size: the size if the GL context is offscreen.
123 // Returns:
124 // true if successful.
125 virtual bool Initialize(const scoped_refptr<gfx::GLSurface>& surface,
126 const scoped_refptr<gfx::GLContext>& context,
127 bool offscreen,
128 const gfx::Size& offscreen_size,
129 const DisallowedFeatures& disallowed_features,
130 const std::vector<int32>& attribs) = 0;
132 // Destroys the graphics context.
133 virtual void Destroy(bool have_context) = 0;
135 // Set the surface associated with the default FBO.
136 virtual void SetSurface(const scoped_refptr<gfx::GLSurface>& surface) = 0;
138 virtual void ProduceFrontBuffer(const Mailbox& mailbox) = 0;
140 // Resize an offscreen frame buffer.
141 virtual bool ResizeOffscreenFrameBuffer(const gfx::Size& size) = 0;
143 // Make this decoder's GL context current.
144 virtual bool MakeCurrent() = 0;
146 // Gets the GLES2 Util which holds info.
147 virtual GLES2Util* GetGLES2Util() = 0;
149 // Gets the associated GLContext.
150 virtual gfx::GLContext* GetGLContext() = 0;
152 // Gets the associated ContextGroup
153 virtual ContextGroup* GetContextGroup() = 0;
155 virtual Capabilities GetCapabilities() = 0;
157 // Restores all of the decoder GL state.
158 virtual void RestoreState(const ContextState* prev_state) = 0;
160 // Restore States.
161 virtual void RestoreActiveTexture() const = 0;
162 virtual void RestoreAllTextureUnitBindings(
163 const ContextState* prev_state) const = 0;
164 virtual void RestoreActiveTextureUnitBinding(unsigned int target) const = 0;
165 virtual void RestoreBufferBindings() const = 0;
166 virtual void RestoreFramebufferBindings() const = 0;
167 virtual void RestoreRenderbufferBindings() = 0;
168 virtual void RestoreGlobalState() const = 0;
169 virtual void RestoreProgramBindings() const = 0;
170 virtual void RestoreTextureState(unsigned service_id) const = 0;
171 virtual void RestoreTextureUnitBindings(unsigned unit) const = 0;
173 virtual void ClearAllAttributes() const = 0;
174 virtual void RestoreAllAttributes() const = 0;
176 virtual void SetIgnoreCachedStateForTest(bool ignore) = 0;
178 // Gets the QueryManager for this context.
179 virtual QueryManager* GetQueryManager() = 0;
181 // Gets the VertexArrayManager for this context.
182 virtual VertexArrayManager* GetVertexArrayManager() = 0;
184 // Gets the ImageManager for this context.
185 virtual ImageManager* GetImageManager() = 0;
187 // Gets the ValuebufferManager for this context.
188 virtual ValuebufferManager* GetValuebufferManager() = 0;
190 // Returns false if there are no pending queries.
191 virtual bool HasPendingQueries() const = 0;
193 // Process any pending queries.
194 virtual void ProcessPendingQueries(bool did_finish) = 0;
196 // Returns false if there is no idle work to be made.
197 virtual bool HasMoreIdleWork() const = 0;
199 // Perform any idle work that needs to be made.
200 virtual void PerformIdleWork() = 0;
202 // Sets a callback which is called when a glResizeCHROMIUM command
203 // is processed.
204 virtual void SetResizeCallback(
205 const base::Callback<void(gfx::Size, float)>& callback) = 0;
207 // Get the service texture ID corresponding to a client texture ID.
208 // If no such record is found then return false.
209 virtual bool GetServiceTextureId(uint32 client_texture_id,
210 uint32* service_texture_id);
212 // Provides detail about a lost context if one occurred.
213 virtual error::ContextLostReason GetContextLostReason() = 0;
215 // Clears a level sub area of a texture
216 // Returns false if a GL error should be generated.
217 virtual bool ClearLevel(Texture* texture,
218 unsigned target,
219 int level,
220 unsigned format,
221 unsigned type,
222 int xoffset,
223 int yoffset,
224 int width,
225 int height) = 0;
227 virtual ErrorState* GetErrorState() = 0;
229 // A callback for messages from the decoder.
230 virtual void SetShaderCacheCallback(const ShaderCacheCallback& callback) = 0;
232 // Sets the callback for waiting on a sync point. The callback returns the
233 // scheduling status (i.e. true if the channel is still scheduled).
234 virtual void SetWaitSyncPointCallback(
235 const WaitSyncPointCallback& callback) = 0;
237 virtual void WaitForReadPixels(base::Closure callback) = 0;
238 virtual uint32 GetTextureUploadCount() = 0;
239 virtual base::TimeDelta GetTotalTextureUploadTime() = 0;
240 virtual base::TimeDelta GetTotalProcessingCommandsTime() = 0;
241 virtual void AddProcessingCommandsTime(base::TimeDelta) = 0;
243 // Returns true if the context was lost either by GL_ARB_robustness, forced
244 // context loss or command buffer parse error.
245 virtual bool WasContextLost() const = 0;
247 // Returns true if the context was lost specifically by GL_ARB_robustness.
248 virtual bool WasContextLostByRobustnessExtension() const = 0;
250 // Lose this context.
251 virtual void MarkContextLost(error::ContextLostReason reason) = 0;
253 virtual Logger* GetLogger() = 0;
255 virtual void BeginDecoding();
256 virtual void EndDecoding();
258 virtual const ContextState* GetContextState() = 0;
260 protected:
261 GLES2Decoder();
263 private:
264 bool initialized_;
265 bool debug_;
266 bool log_commands_;
267 bool unsafe_es3_apis_enabled_;
269 DISALLOW_COPY_AND_ASSIGN(GLES2Decoder);
272 } // namespace gles2
273 } // namespace gpu
275 #endif // GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_H_