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_
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"
29 class AsyncPixelTransferDelegate
;
30 class AsyncPixelTransferManager
;
42 class VertexArrayManager
;
43 class ValuebufferManager
;
46 struct DisallowedFeatures
{
48 : gpu_memory_manager(false) {
51 bool gpu_memory_manager
;
54 typedef base::Callback
<void(const std::string
& key
,
55 const std::string
& shader
)> ShaderCacheCallback
;
57 // This class implements the AsyncAPIInterface interface, decoding GLES2
58 // commands and calling GL.
59 class GPU_EXPORT GLES2Decoder
: public base::SupportsWeakPtr
<GLES2Decoder
>,
60 public CommonDecoder
{
62 typedef error::Error Error
;
63 typedef base::Callback
<bool(uint32 id
)> WaitSyncPointCallback
;
65 // The default stencil mask, which has all bits set. This really should be a
66 // GLuint, but we can't #include gl_bindings.h in this file without causing
67 // macro redefinitions.
68 static const unsigned int kDefaultStencilMask
;
71 static GLES2Decoder
* Create(ContextGroup
* group
);
73 ~GLES2Decoder() override
;
75 bool initialized() const {
79 void set_initialized() {
83 bool unsafe_es3_apis_enabled() const {
84 return unsafe_es3_apis_enabled_
;
87 void set_unsafe_es3_apis_enabled(bool enabled
) {
88 unsafe_es3_apis_enabled_
= enabled
;
95 // Set to true to call glGetError after every command.
96 void set_debug(bool debug
) {
100 bool log_commands() const {
101 return log_commands_
;
104 // Set to true to LOG every command.
105 void set_log_commands(bool log_commands
) {
106 log_commands_
= log_commands
;
109 // Initializes the graphics context. Can create an offscreen
110 // decoder with a frame buffer that can be referenced from the parent.
111 // Takes ownership of GLContext.
113 // surface: the GL surface to render to.
114 // context: the GL context to render to.
115 // offscreen: whether to make the context offscreen or not. When FBO 0 is
116 // bound, offscreen contexts render to an internal buffer, onscreen ones
118 // offscreen_size: the size if the GL context is offscreen.
120 // true if successful.
121 virtual bool Initialize(const scoped_refptr
<gfx::GLSurface
>& surface
,
122 const scoped_refptr
<gfx::GLContext
>& context
,
124 const gfx::Size
& offscreen_size
,
125 const DisallowedFeatures
& disallowed_features
,
126 const std::vector
<int32
>& attribs
) = 0;
128 // Destroys the graphics context.
129 virtual void Destroy(bool have_context
) = 0;
131 // Set the surface associated with the default FBO.
132 virtual void SetSurface(const scoped_refptr
<gfx::GLSurface
>& surface
) = 0;
134 virtual void ProduceFrontBuffer(const Mailbox
& mailbox
) = 0;
136 // Resize an offscreen frame buffer.
137 virtual bool ResizeOffscreenFrameBuffer(const gfx::Size
& size
) = 0;
139 // Make this decoder's GL context current.
140 virtual bool MakeCurrent() = 0;
142 // Gets the GLES2 Util which holds info.
143 virtual GLES2Util
* GetGLES2Util() = 0;
145 // Gets the associated GLContext.
146 virtual gfx::GLContext
* GetGLContext() = 0;
148 // Gets the associated ContextGroup
149 virtual ContextGroup
* GetContextGroup() = 0;
151 virtual Capabilities
GetCapabilities() = 0;
153 // Restores all of the decoder GL state.
154 virtual void RestoreState(const ContextState
* prev_state
) = 0;
157 virtual void RestoreActiveTexture() const = 0;
158 virtual void RestoreAllTextureUnitBindings(
159 const ContextState
* prev_state
) const = 0;
160 virtual void RestoreActiveTextureUnitBinding(unsigned int target
) const = 0;
161 virtual void RestoreBufferBindings() const = 0;
162 virtual void RestoreFramebufferBindings() const = 0;
163 virtual void RestoreRenderbufferBindings() = 0;
164 virtual void RestoreGlobalState() const = 0;
165 virtual void RestoreProgramBindings() const = 0;
166 virtual void RestoreTextureState(unsigned service_id
) const = 0;
167 virtual void RestoreTextureUnitBindings(unsigned unit
) const = 0;
169 virtual void ClearAllAttributes() const = 0;
170 virtual void RestoreAllAttributes() const = 0;
172 virtual void SetIgnoreCachedStateForTest(bool ignore
) = 0;
174 // Gets the QueryManager for this context.
175 virtual QueryManager
* GetQueryManager() = 0;
177 // Gets the VertexArrayManager for this context.
178 virtual VertexArrayManager
* GetVertexArrayManager() = 0;
180 // Gets the ImageManager for this context.
181 virtual ImageManager
* GetImageManager() = 0;
183 // Gets the ValuebufferManager for this context.
184 virtual ValuebufferManager
* GetValuebufferManager() = 0;
186 // Process any pending queries. Returns false if there are no pending queries.
187 virtual bool ProcessPendingQueries(bool did_finish
) = 0;
189 // Returns false if there are no idle work to be made.
190 virtual bool HasMoreIdleWork() = 0;
192 virtual void PerformIdleWork() = 0;
194 // Sets a callback which is called when a glResizeCHROMIUM command
196 virtual void SetResizeCallback(
197 const base::Callback
<void(gfx::Size
, float)>& callback
) = 0;
199 // Interface to performing async pixel transfers.
200 virtual AsyncPixelTransferManager
* GetAsyncPixelTransferManager() = 0;
201 virtual void ResetAsyncPixelTransferManagerForTest() = 0;
202 virtual void SetAsyncPixelTransferManagerForTest(
203 AsyncPixelTransferManager
* manager
) = 0;
205 // Get the service texture ID corresponding to a client texture ID.
206 // If no such record is found then return false.
207 virtual bool GetServiceTextureId(uint32 client_texture_id
,
208 uint32
* service_texture_id
);
210 // Provides detail about a lost context if one occurred.
211 virtual error::ContextLostReason
GetContextLostReason() = 0;
213 // Clears a level of a texture
214 // Returns false if a GL error should be generated.
215 virtual bool ClearLevel(
219 unsigned internal_format
,
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;
266 bool unsafe_es3_apis_enabled_
;
268 DISALLOW_COPY_AND_ASSIGN(GLES2Decoder
);
274 #endif // GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_H_