JSONStringValueSerializer takes a StringPiece instead of std::string&.
[chromium-blink-merge.git] / gpu / command_buffer / service / gles2_cmd_decoder.h
blob0092a9ab7e3dbab3393e3e27c346a093709618df
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 <vector>
12 #include "base/callback.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/time/time.h"
15 #include "build/build_config.h"
16 #include "gpu/command_buffer/common/capabilities.h"
17 #include "gpu/command_buffer/service/common_decoder.h"
18 #include "gpu/command_buffer/service/logger.h"
19 #include "ui/gfx/geometry/size.h"
20 #include "ui/gl/gl_context.h"
22 namespace gfx {
23 class GLContext;
24 class GLSurface;
27 namespace gpu {
29 class AsyncPixelTransferDelegate;
30 class AsyncPixelTransferManager;
31 struct Mailbox;
33 namespace gles2 {
35 class ContextGroup;
36 class ErrorState;
37 class GLES2Util;
38 class ImageManager;
39 class Logger;
40 class QueryManager;
41 class VertexArrayManager;
42 class ValuebufferManager;
43 struct ContextState;
45 struct DisallowedFeatures {
46 DisallowedFeatures()
47 : gpu_memory_manager(false) {
50 bool gpu_memory_manager;
53 typedef base::Callback<void(const std::string& key,
54 const std::string& shader)> ShaderCacheCallback;
56 // This class implements the AsyncAPIInterface interface, decoding GLES2
57 // commands and calling GL.
58 class GPU_EXPORT GLES2Decoder : public base::SupportsWeakPtr<GLES2Decoder>,
59 public CommonDecoder {
60 public:
61 typedef error::Error Error;
62 typedef base::Callback<bool(uint32 id)> WaitSyncPointCallback;
64 // The default stencil mask, which has all bits set. This really should be a
65 // GLuint, but we can't #include gl_bindings.h in this file without causing
66 // macro redefinitions.
67 static const unsigned int kDefaultStencilMask;
69 // Creates a decoder.
70 static GLES2Decoder* Create(ContextGroup* group);
72 ~GLES2Decoder() override;
74 bool initialized() const {
75 return initialized_;
78 void set_initialized() {
79 initialized_ = true;
82 bool unsafe_es3_apis_enabled() const {
83 return unsafe_es3_apis_enabled_;
86 void set_unsafe_es3_apis_enabled(bool enabled) {
87 unsafe_es3_apis_enabled_ = enabled;
90 bool debug() const {
91 return debug_;
94 // Set to true to call glGetError after every command.
95 void set_debug(bool debug) {
96 debug_ = debug;
99 bool log_commands() const {
100 return log_commands_;
103 // Set to true to LOG every command.
104 void set_log_commands(bool log_commands) {
105 log_commands_ = log_commands;
108 // Initializes the graphics context. Can create an offscreen
109 // decoder with a frame buffer that can be referenced from the parent.
110 // Takes ownership of GLContext.
111 // Parameters:
112 // surface: the GL surface to render to.
113 // context: the GL context to render to.
114 // offscreen: whether to make the context offscreen or not. When FBO 0 is
115 // bound, offscreen contexts render to an internal buffer, onscreen ones
116 // to the surface.
117 // size: the size if the GL context is offscreen.
118 // Returns:
119 // true if successful.
120 virtual bool Initialize(const scoped_refptr<gfx::GLSurface>& surface,
121 const scoped_refptr<gfx::GLContext>& context,
122 bool offscreen,
123 const gfx::Size& size,
124 const DisallowedFeatures& disallowed_features,
125 const std::vector<int32>& attribs) = 0;
127 // Destroys the graphics context.
128 virtual void Destroy(bool have_context) = 0;
130 // Set the surface associated with the default FBO.
131 virtual void SetSurface(const scoped_refptr<gfx::GLSurface>& surface) = 0;
133 virtual void ProduceFrontBuffer(const Mailbox& mailbox) = 0;
135 // Resize an offscreen frame buffer.
136 virtual bool ResizeOffscreenFrameBuffer(const gfx::Size& size) = 0;
138 // Make this decoder's GL context current.
139 virtual bool MakeCurrent() = 0;
141 // Gets the GLES2 Util which holds info.
142 virtual GLES2Util* GetGLES2Util() = 0;
144 // Gets the associated GLContext.
145 virtual gfx::GLContext* GetGLContext() = 0;
147 // Gets the associated ContextGroup
148 virtual ContextGroup* GetContextGroup() = 0;
150 virtual Capabilities GetCapabilities() = 0;
152 // Restores all of the decoder GL state.
153 virtual void RestoreState(const ContextState* prev_state) = 0;
155 // Restore States.
156 virtual void RestoreActiveTexture() const = 0;
157 virtual void RestoreAllTextureUnitBindings(
158 const ContextState* prev_state) const = 0;
159 virtual void RestoreActiveTextureUnitBinding(unsigned int target) const = 0;
160 virtual void RestoreBufferBindings() const = 0;
161 virtual void RestoreFramebufferBindings() const = 0;
162 virtual void RestoreRenderbufferBindings() = 0;
163 virtual void RestoreGlobalState() const = 0;
164 virtual void RestoreProgramBindings() const = 0;
165 virtual void RestoreTextureState(unsigned service_id) const = 0;
166 virtual void RestoreTextureUnitBindings(unsigned unit) const = 0;
168 virtual void ClearAllAttributes() const = 0;
169 virtual void RestoreAllAttributes() const = 0;
171 virtual void SetIgnoreCachedStateForTest(bool ignore) = 0;
173 // Gets the QueryManager for this context.
174 virtual QueryManager* GetQueryManager() = 0;
176 // Gets the VertexArrayManager for this context.
177 virtual VertexArrayManager* GetVertexArrayManager() = 0;
179 // Gets the ImageManager for this context.
180 virtual ImageManager* GetImageManager() = 0;
182 // Gets the ValuebufferManager for this context.
183 virtual ValuebufferManager* GetValuebufferManager() = 0;
185 // Process any pending queries. Returns false if there are no pending queries.
186 virtual bool ProcessPendingQueries(bool did_finish) = 0;
188 // Returns false if there are no idle work to be made.
189 virtual bool HasMoreIdleWork() = 0;
191 virtual void PerformIdleWork() = 0;
193 // Sets a callback which is called when a glResizeCHROMIUM command
194 // is processed.
195 virtual void SetResizeCallback(
196 const base::Callback<void(gfx::Size, float)>& callback) = 0;
198 // Interface to performing async pixel transfers.
199 virtual AsyncPixelTransferManager* GetAsyncPixelTransferManager() = 0;
200 virtual void ResetAsyncPixelTransferManagerForTest() = 0;
201 virtual void SetAsyncPixelTransferManagerForTest(
202 AsyncPixelTransferManager* manager) = 0;
204 // Get the service texture ID corresponding to a client texture ID.
205 // If no such record is found then return false.
206 virtual bool GetServiceTextureId(uint32 client_texture_id,
207 uint32* service_texture_id);
209 // Provides detail about a lost context if one occurred.
210 virtual error::ContextLostReason GetContextLostReason() = 0;
212 // Clears a level of a texture
213 // Returns false if a GL error should be generated.
214 virtual bool ClearLevel(
215 unsigned service_id,
216 unsigned bind_target,
217 unsigned target,
218 int level,
219 unsigned internal_format,
220 unsigned format,
221 unsigned type,
222 int width,
223 int height,
224 bool is_texture_immutable) = 0;
226 virtual ErrorState* GetErrorState() = 0;
228 // A callback for messages from the decoder.
229 virtual void SetShaderCacheCallback(const ShaderCacheCallback& callback) = 0;
231 // Sets the callback for waiting on a sync point. The callback returns the
232 // scheduling status (i.e. true if the channel is still scheduled).
233 virtual void SetWaitSyncPointCallback(
234 const WaitSyncPointCallback& callback) = 0;
236 virtual void WaitForReadPixels(base::Closure callback) = 0;
237 virtual uint32 GetTextureUploadCount() = 0;
238 virtual base::TimeDelta GetTotalTextureUploadTime() = 0;
239 virtual base::TimeDelta GetTotalProcessingCommandsTime() = 0;
240 virtual void AddProcessingCommandsTime(base::TimeDelta) = 0;
242 // Returns true if the context was lost either by GL_ARB_robustness, forced
243 // context loss or command buffer parse error.
244 virtual bool WasContextLost() = 0;
246 // Returns true if the context was lost specifically by GL_ARB_robustness.
247 virtual bool WasContextLostByRobustnessExtension() = 0;
249 // Lose this context.
250 virtual void LoseContext(uint32 reset_status) = 0;
252 virtual Logger* GetLogger() = 0;
254 virtual void BeginDecoding();
255 virtual void EndDecoding();
257 virtual const ContextState* GetContextState() = 0;
259 protected:
260 GLES2Decoder();
262 private:
263 bool initialized_;
264 bool debug_;
265 bool log_commands_;
266 bool unsafe_es3_apis_enabled_;
268 DISALLOW_COPY_AND_ASSIGN(GLES2Decoder);
271 } // namespace gles2
272 } // namespace gpu
274 #endif // GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_H_