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_
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"
33 class AsyncPixelTransferManager
;
45 class VertexArrayManager
;
46 class ValuebufferManager
;
49 struct DisallowedFeatures
{
51 : gpu_memory_manager(false),
55 bool gpu_memory_manager
;
59 typedef base::Callback
<void(const std::string
& key
,
60 const std::string
& shader
)> ShaderCacheCallback
;
62 // This class implements the AsyncAPIInterface interface, decoding GLES2
63 // commands and calling GL.
64 class GPU_EXPORT GLES2Decoder
: public base::SupportsWeakPtr
<GLES2Decoder
>,
65 public CommonDecoder
{
67 typedef error::Error Error
;
68 typedef base::Callback
<bool(uint32 id
)> WaitSyncPointCallback
;
70 // The default stencil mask, which has all bits set. This really should be a
71 // GLuint, but we can't #include gl_bindings.h in this file without causing
72 // macro redefinitions.
73 static const unsigned int kDefaultStencilMask
;
76 static GLES2Decoder
* Create(ContextGroup
* group
);
78 ~GLES2Decoder() override
;
80 bool initialized() const {
84 void set_initialized() {
88 bool unsafe_es3_apis_enabled() const {
89 return unsafe_es3_apis_enabled_
;
92 void set_unsafe_es3_apis_enabled(bool enabled
) {
93 unsafe_es3_apis_enabled_
= enabled
;
100 // Set to true to call glGetError after every command.
101 void set_debug(bool debug
) {
105 bool log_commands() const {
106 return log_commands_
;
109 // Set to true to LOG every command.
110 void set_log_commands(bool log_commands
) {
111 log_commands_
= log_commands
;
114 // Initializes the graphics context. Can create an offscreen
115 // decoder with a frame buffer that can be referenced from the parent.
116 // Takes ownership of GLContext.
118 // surface: the GL surface to render to.
119 // context: the GL context to render to.
120 // offscreen: whether to make the context offscreen or not. When FBO 0 is
121 // bound, offscreen contexts render to an internal buffer, onscreen ones
123 // offscreen_size: the size if the GL context is offscreen.
125 // true if successful.
126 virtual bool Initialize(const scoped_refptr
<gfx::GLSurface
>& surface
,
127 const scoped_refptr
<gfx::GLContext
>& context
,
129 const gfx::Size
& offscreen_size
,
130 const DisallowedFeatures
& disallowed_features
,
131 const std::vector
<int32
>& attribs
) = 0;
133 // Destroys the graphics context.
134 virtual void Destroy(bool have_context
) = 0;
136 // Set the surface associated with the default FBO.
137 virtual void SetSurface(const scoped_refptr
<gfx::GLSurface
>& surface
) = 0;
139 virtual void ProduceFrontBuffer(const Mailbox
& mailbox
) = 0;
141 // Resize an offscreen frame buffer.
142 virtual bool ResizeOffscreenFrameBuffer(const gfx::Size
& size
) = 0;
144 // Make this decoder's GL context current.
145 virtual bool MakeCurrent() = 0;
147 // Gets the GLES2 Util which holds info.
148 virtual GLES2Util
* GetGLES2Util() = 0;
150 // Gets the associated GLContext.
151 virtual gfx::GLContext
* GetGLContext() = 0;
153 // Gets the associated ContextGroup
154 virtual ContextGroup
* GetContextGroup() = 0;
156 virtual Capabilities
GetCapabilities() = 0;
158 // Restores all of the decoder GL state.
159 virtual void RestoreState(const ContextState
* prev_state
) = 0;
162 virtual void RestoreActiveTexture() const = 0;
163 virtual void RestoreAllTextureUnitBindings(
164 const ContextState
* prev_state
) const = 0;
165 virtual void RestoreActiveTextureUnitBinding(unsigned int target
) const = 0;
166 virtual void RestoreBufferBindings() const = 0;
167 virtual void RestoreFramebufferBindings() const = 0;
168 virtual void RestoreRenderbufferBindings() = 0;
169 virtual void RestoreGlobalState() const = 0;
170 virtual void RestoreProgramBindings() const = 0;
171 virtual void RestoreTextureState(unsigned service_id
) const = 0;
172 virtual void RestoreTextureUnitBindings(unsigned unit
) const = 0;
174 virtual void ClearAllAttributes() const = 0;
175 virtual void RestoreAllAttributes() const = 0;
177 virtual void SetIgnoreCachedStateForTest(bool ignore
) = 0;
179 // Gets the QueryManager for this context.
180 virtual QueryManager
* GetQueryManager() = 0;
182 // Gets the VertexArrayManager for this context.
183 virtual VertexArrayManager
* GetVertexArrayManager() = 0;
185 // Gets the ImageManager for this context.
186 virtual ImageManager
* GetImageManager() = 0;
188 // Gets the ValuebufferManager for this context.
189 virtual ValuebufferManager
* GetValuebufferManager() = 0;
191 // Process any pending queries. Returns false if there are no pending queries.
192 virtual bool ProcessPendingQueries(bool did_finish
) = 0;
194 // Returns false if there are no idle work to be made.
195 virtual bool HasMoreIdleWork() = 0;
197 virtual void PerformIdleWork() = 0;
199 // Sets a callback which is called when a glResizeCHROMIUM command
201 virtual void SetResizeCallback(
202 const base::Callback
<void(gfx::Size
, float)>& callback
) = 0;
204 // Interface to performing async pixel transfers.
205 virtual AsyncPixelTransferManager
* GetAsyncPixelTransferManager() = 0;
206 virtual void ResetAsyncPixelTransferManagerForTest() = 0;
207 virtual void SetAsyncPixelTransferManagerForTest(
208 AsyncPixelTransferManager
* manager
) = 0;
210 // Get the service texture ID corresponding to a client texture ID.
211 // If no such record is found then return false.
212 virtual bool GetServiceTextureId(uint32 client_texture_id
,
213 uint32
* service_texture_id
);
215 // Provides detail about a lost context if one occurred.
216 virtual error::ContextLostReason
GetContextLostReason() = 0;
218 // Clears a level sub area of a texture
219 // Returns false if a GL error should be generated.
220 virtual bool ClearLevel(Texture
* texture
,
230 virtual ErrorState
* GetErrorState() = 0;
232 // A callback for messages from the decoder.
233 virtual void SetShaderCacheCallback(const ShaderCacheCallback
& callback
) = 0;
235 // Sets the callback for waiting on a sync point. The callback returns the
236 // scheduling status (i.e. true if the channel is still scheduled).
237 virtual void SetWaitSyncPointCallback(
238 const WaitSyncPointCallback
& callback
) = 0;
240 virtual void WaitForReadPixels(base::Closure callback
) = 0;
241 virtual uint32
GetTextureUploadCount() = 0;
242 virtual base::TimeDelta
GetTotalTextureUploadTime() = 0;
243 virtual base::TimeDelta
GetTotalProcessingCommandsTime() = 0;
244 virtual void AddProcessingCommandsTime(base::TimeDelta
) = 0;
246 // Returns true if the context was lost either by GL_ARB_robustness, forced
247 // context loss or command buffer parse error.
248 virtual bool WasContextLost() const = 0;
250 // Returns true if the context was lost specifically by GL_ARB_robustness.
251 virtual bool WasContextLostByRobustnessExtension() const = 0;
253 // Lose this context.
254 virtual void MarkContextLost(error::ContextLostReason reason
) = 0;
256 virtual Logger
* GetLogger() = 0;
258 virtual void BeginDecoding();
259 virtual void EndDecoding();
261 virtual const ContextState
* GetContextState() = 0;
270 bool unsafe_es3_apis_enabled_
;
272 DISALLOW_COPY_AND_ASSIGN(GLES2Decoder
);
278 #endif // GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_H_