Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / gpu / command_buffer / service / gles2_cmd_decoder.h
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.
4
5 // This file contains the GLES2Decoder class.
6
7 #ifndef GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_H_
8 #define GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_H_
9
10 #include <vector>
11
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/size.h"
20 #include "ui/gl/gl_context.h"
21
22 namespace gfx {
23 class GLContext;
24 class GLSurface;
25 }
26
27 namespace gpu {
28
29 class AsyncPixelTransferDelegate;
30 class AsyncPixelTransferManager;
31 struct Mailbox;
32
33 namespace gles2 {
34
35 class ContextGroup;
36 class ErrorState;
37 class GLES2Util;
38 class Logger;
39 class QueryManager;
40 class VertexArrayManager;
41 struct ContextState;
42
43 struct DisallowedFeatures {
44   DisallowedFeatures()
45       : gpu_memory_manager(false) {
46   }
47
48   bool gpu_memory_manager;
49 };
50
51 typedef base::Callback<void(const std::string& key,
52                             const std::string& shader)> ShaderCacheCallback;
53
54 // This class implements the AsyncAPIInterface interface, decoding GLES2
55 // commands and calling GL.
56 class GPU_EXPORT GLES2Decoder : public base::SupportsWeakPtr<GLES2Decoder>,
57                                 public CommonDecoder {
58  public:
59   typedef error::Error Error;
60   typedef base::Callback<bool(uint32 id)> WaitSyncPointCallback;
61
62   // Creates a decoder.
63   static GLES2Decoder* Create(ContextGroup* group);
64
65   virtual ~GLES2Decoder();
66
67   bool initialized() const {
68     return initialized_;
69   }
70
71   void set_initialized() {
72     initialized_ = true;
73   }
74
75   bool debug() const {
76     return debug_;
77   }
78
79   // Set to true to call glGetError after every command.
80   void set_debug(bool debug) {
81     debug_ = debug;
82   }
83
84   bool log_commands() const {
85     return log_commands_;
86   }
87
88   // Set to true to LOG every command.
89   void set_log_commands(bool log_commands) {
90     log_commands_ = log_commands;
91   }
92
93   // Initializes the graphics context. Can create an offscreen
94   // decoder with a frame buffer that can be referenced from the parent.
95   // Takes ownership of GLContext.
96   // Parameters:
97   //  surface: the GL surface to render to.
98   //  context: the GL context to render to.
99   //  offscreen: whether to make the context offscreen or not. When FBO 0 is
100   //      bound, offscreen contexts render to an internal buffer, onscreen ones
101   //      to the surface.
102   //  size: the size if the GL context is offscreen.
103   // Returns:
104   //   true if successful.
105   virtual bool Initialize(const scoped_refptr<gfx::GLSurface>& surface,
106                           const scoped_refptr<gfx::GLContext>& context,
107                           bool offscreen,
108                           const gfx::Size& size,
109                           const DisallowedFeatures& disallowed_features,
110                           const std::vector<int32>& attribs) = 0;
111
112   // Destroys the graphics context.
113   virtual void Destroy(bool have_context) = 0;
114
115   // Set the surface associated with the default FBO.
116   virtual void SetSurface(const scoped_refptr<gfx::GLSurface>& surface) = 0;
117
118   virtual void ProduceFrontBuffer(const Mailbox& mailbox) = 0;
119
120   // Resize an offscreen frame buffer.
121   virtual bool ResizeOffscreenFrameBuffer(const gfx::Size& size) = 0;
122
123   // Make this decoder's GL context current.
124   virtual bool MakeCurrent() = 0;
125
126   // Gets the GLES2 Util which holds info.
127   virtual GLES2Util* GetGLES2Util() = 0;
128
129   // Gets the associated GLContext.
130   virtual gfx::GLContext* GetGLContext() = 0;
131
132   // Gets the associated ContextGroup
133   virtual ContextGroup* GetContextGroup() = 0;
134
135   virtual Capabilities GetCapabilities() = 0;
136
137   // Restores all of the decoder GL state.
138   virtual void RestoreState(const ContextState* prev_state) const = 0;
139
140   // Restore States.
141   virtual void RestoreActiveTexture() const = 0;
142   virtual void RestoreAllTextureUnitBindings(
143       const ContextState* prev_state) const = 0;
144   virtual void RestoreAttribute(unsigned index) const = 0;
145   virtual void RestoreBufferBindings() const = 0;
146   virtual void RestoreFramebufferBindings() const = 0;
147   virtual void RestoreGlobalState() const = 0;
148   virtual void RestoreProgramBindings() const = 0;
149   virtual void RestoreTextureState(unsigned service_id) const = 0;
150   virtual void RestoreTextureUnitBindings(unsigned unit) const = 0;
151
152   virtual void ClearAllAttributes() const = 0;
153   virtual void RestoreAllAttributes() const = 0;
154
155   // Gets the QueryManager for this context.
156   virtual QueryManager* GetQueryManager() = 0;
157
158   // Gets the VertexArrayManager for this context.
159   virtual VertexArrayManager* GetVertexArrayManager() = 0;
160
161   // Process any pending queries. Returns false if there are no pending queries.
162   virtual bool ProcessPendingQueries() = 0;
163
164   // Returns false if there are no idle work to be made.
165   virtual bool HasMoreIdleWork() = 0;
166
167   virtual void PerformIdleWork() = 0;
168
169   // Sets a callback which is called when a glResizeCHROMIUM command
170   // is processed.
171   virtual void SetResizeCallback(
172       const base::Callback<void(gfx::Size, float)>& callback) = 0;
173
174   // Interface to performing async pixel transfers.
175   virtual AsyncPixelTransferManager* GetAsyncPixelTransferManager() = 0;
176   virtual void ResetAsyncPixelTransferManagerForTest() = 0;
177   virtual void SetAsyncPixelTransferManagerForTest(
178       AsyncPixelTransferManager* manager) = 0;
179
180   // Get the service texture ID corresponding to a client texture ID.
181   // If no such record is found then return false.
182   virtual bool GetServiceTextureId(uint32 client_texture_id,
183                                    uint32* service_texture_id);
184
185   // Provides detail about a lost context if one occurred.
186   virtual error::ContextLostReason GetContextLostReason() = 0;
187
188   // Clears a level of a texture
189   // Returns false if a GL error should be generated.
190   virtual bool ClearLevel(
191       unsigned service_id,
192       unsigned bind_target,
193       unsigned target,
194       int level,
195       unsigned format,
196       unsigned type,
197       int width,
198       int height,
199       bool is_texture_immutable) = 0;
200
201   virtual ErrorState* GetErrorState() = 0;
202
203   // A callback for messages from the decoder.
204   virtual void SetShaderCacheCallback(const ShaderCacheCallback& callback) = 0;
205
206   // Sets the callback for waiting on a sync point. The callback returns the
207   // scheduling status (i.e. true if the channel is still scheduled).
208   virtual void SetWaitSyncPointCallback(
209       const WaitSyncPointCallback& callback) = 0;
210
211   virtual void WaitForReadPixels(base::Closure callback) = 0;
212   virtual uint32 GetTextureUploadCount() = 0;
213   virtual base::TimeDelta GetTotalTextureUploadTime() = 0;
214   virtual base::TimeDelta GetTotalProcessingCommandsTime() = 0;
215   virtual void AddProcessingCommandsTime(base::TimeDelta) = 0;
216
217   // Returns true if the context was lost either by GL_ARB_robustness, forced
218   // context loss or command buffer parse error.
219   virtual bool WasContextLost() = 0;
220
221   // Returns true if the context was lost specifically by GL_ARB_robustness.
222   virtual bool WasContextLostByRobustnessExtension() = 0;
223
224   // Lose this context.
225   virtual void LoseContext(uint32 reset_status) = 0;
226
227   virtual Logger* GetLogger() = 0;
228
229   virtual void BeginDecoding();
230   virtual void EndDecoding();
231
232   virtual const ContextState* GetContextState() = 0;
233
234  protected:
235   GLES2Decoder();
236
237  private:
238   bool initialized_;
239   bool debug_;
240   bool log_commands_;
241
242   DISALLOW_COPY_AND_ASSIGN(GLES2Decoder);
243 };
244
245 }  // namespace gles2
246 }  // namespace gpu
247
248 #endif  // GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_H_