1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file contains the GLES2Decoder class.
#ifndef GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_H_
#define GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_H_
#include <stdint.h>
#include <string>
#include <vector>
#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "gpu/command_buffer/common/capabilities.h"
#include "gpu/command_buffer/common/constants.h"
#include "gpu/command_buffer/service/common_decoder.h"
#include "gpu/gpu_export.h"
namespace gfx {
class GLContext;
class GLSurface;
class Size;
}
namespace gpu {
struct Mailbox;
namespace gles2 {
class ContextGroup;
class ErrorState;
class GLES2Util;
class ImageManager;
class Logger;
class QueryManager;
class Texture;
class VertexArrayManager;
class ValuebufferManager;
struct ContextState;
struct DisallowedFeatures {
DisallowedFeatures()
: gpu_memory_manager(false),
npot_support(false) {
}
bool gpu_memory_manager;
bool npot_support;
};
typedef base::Callback<void(const std::string& key,
const std::string& shader)> ShaderCacheCallback;
// This class implements the AsyncAPIInterface interface, decoding GLES2
// commands and calling GL.
class GPU_EXPORT GLES2Decoder : public base::SupportsWeakPtr<GLES2Decoder>,
public CommonDecoder {
public:
typedef error::Error Error;
typedef base::Callback<bool(uint32_t id)> WaitSyncPointCallback;
typedef base::Callback<void(uint64_t release)> FenceSyncReleaseCallback;
typedef base::Callback<bool(gpu::CommandBufferNamespace namespace_id,
uint64_t command_buffer_id,
uint64_t release)> WaitFenceSyncCallback;
// The default stencil mask, which has all bits set. This really should be a
// GLuint, but we can't #include gl_bindings.h in this file without causing
// macro redefinitions.
static const unsigned int kDefaultStencilMask;
// Creates a decoder.
static GLES2Decoder* Create(ContextGroup* group);
~GLES2Decoder() override;
bool initialized() const {
return initialized_;
}
void set_initialized() {
initialized_ = true;
}
bool unsafe_es3_apis_enabled() const {
return unsafe_es3_apis_enabled_;
}
void set_unsafe_es3_apis_enabled(bool enabled) {
unsafe_es3_apis_enabled_ = enabled;
}
bool debug() const {
return debug_;
}
// Set to true to call glGetError after every command.
void set_debug(bool debug) {
debug_ = debug;
}
bool log_commands() const {
return log_commands_;
}
// Set to true to LOG every command.
void set_log_commands(bool log_commands) {
log_commands_ = log_commands;
}
// Initializes the graphics context. Can create an offscreen
// decoder with a frame buffer that can be referenced from the parent.
// Takes ownership of GLContext.
// Parameters:
// surface: the GL surface to render to.
// context: the GL context to render to.
// offscreen: whether to make the context offscreen or not. When FBO 0 is
// bound, offscreen contexts render to an internal buffer, onscreen ones
// to the surface.
// offscreen_size: the size if the GL context is offscreen.
// Returns:
// true if successful.
virtual bool Initialize(const scoped_refptr<gfx::GLSurface>& surface,
const scoped_refptr<gfx::GLContext>& context,
bool offscreen,
const gfx::Size& offscreen_size,
const DisallowedFeatures& disallowed_features,
const std::vector<int32_t>& attribs) = 0;
// Destroys the graphics context.
virtual void Destroy(bool have_context) = 0;
// Set the surface associated with the default FBO.
virtual void SetSurface(const scoped_refptr<gfx::GLSurface>& surface) = 0;
virtual void ProduceFrontBuffer(const Mailbox& mailbox) = 0;
// Resize an offscreen frame buffer.
virtual bool ResizeOffscreenFrameBuffer(const gfx::Size& size) = 0;
// Make this decoder's GL context current.
virtual bool MakeCurrent() = 0;
// Gets the GLES2 Util which holds info.
virtual GLES2Util* GetGLES2Util() = 0;
// Gets the associated GLContext.
virtual gfx::GLContext* GetGLContext() = 0;
// Gets the associated ContextGroup
virtual ContextGroup* GetContextGroup() = 0;
virtual Capabilities GetCapabilities() = 0;
// Restores all of the decoder GL state.
virtual void RestoreState(const ContextState* prev_state) = 0;
// Restore States.
virtual void RestoreActiveTexture() const = 0;
virtual void RestoreAllTextureUnitBindings(
const ContextState* prev_state) const = 0;
virtual void RestoreActiveTextureUnitBinding(unsigned int target) const = 0;
virtual void RestoreBufferBindings() const = 0;
virtual void RestoreFramebufferBindings() const = 0;
virtual void RestoreRenderbufferBindings() = 0;
virtual void RestoreGlobalState() const = 0;
virtual void RestoreProgramBindings() const = 0;
virtual void RestoreTextureState(unsigned service_id) const = 0;
virtual void RestoreTextureUnitBindings(unsigned unit) const = 0;
virtual void RestoreAllExternalTextureBindingsIfNeeded() = 0;
virtual void ClearAllAttributes() const = 0;
virtual void RestoreAllAttributes() const = 0;
virtual void SetIgnoreCachedStateForTest(bool ignore) = 0;
virtual void SetForceShaderNameHashingForTest(bool force) = 0;
virtual uint32_t GetAndClearBackbufferClearBitsForTest();
// Gets the QueryManager for this context.
virtual QueryManager* GetQueryManager() = 0;
// Gets the VertexArrayManager for this context.
virtual VertexArrayManager* GetVertexArrayManager() = 0;
// Gets the ImageManager for this context.
virtual ImageManager* GetImageManager() = 0;
// Gets the ValuebufferManager for this context.
virtual ValuebufferManager* GetValuebufferManager() = 0;
// Returns false if there are no pending queries.
virtual bool HasPendingQueries() const = 0;
// Process any pending queries.
virtual void ProcessPendingQueries(bool did_finish) = 0;
// Returns false if there is no idle work to be made.
virtual bool HasMoreIdleWork() const = 0;
// Perform any idle work that needs to be made.
virtual void PerformIdleWork() = 0;
// Get the service texture ID corresponding to a client texture ID.
// If no such record is found then return false.
virtual bool GetServiceTextureId(uint32_t client_texture_id,
uint32_t* service_texture_id);
// Provides detail about a lost context if one occurred.
virtual error::ContextLostReason GetContextLostReason() = 0;
// Clears a level sub area of a texture
// Returns false if a GL error should be generated.
virtual bool ClearLevel(Texture* texture,
unsigned target,
int level,
unsigned format,
unsigned type,
int xoffset,
int yoffset,
int width,
int height) = 0;
virtual ErrorState* GetErrorState() = 0;
// A callback for messages from the decoder.
virtual void SetShaderCacheCallback(const ShaderCacheCallback& callback) = 0;
// Sets the callback for waiting on a sync point. The callback returns the
// scheduling status (i.e. true if the channel is still scheduled).
virtual void SetWaitSyncPointCallback(
const WaitSyncPointCallback& callback) = 0;
// Sets the callback for fence sync release and wait calls. The wait call
// returns true if the channel is still scheduled.
virtual void SetFenceSyncReleaseCallback(
const FenceSyncReleaseCallback& callback) = 0;
virtual void SetWaitFenceSyncCallback(
const WaitFenceSyncCallback& callback) = 0;
virtual void WaitForReadPixels(base::Closure callback) = 0;
virtual uint32_t GetTextureUploadCount() = 0;
virtual base::TimeDelta GetTotalTextureUploadTime() = 0;
virtual base::TimeDelta GetTotalProcessingCommandsTime() = 0;
virtual void AddProcessingCommandsTime(base::TimeDelta) = 0;
// Returns true if the context was lost either by GL_ARB_robustness, forced
// context loss or command buffer parse error.
virtual bool WasContextLost() const = 0;
// Returns true if the context was lost specifically by GL_ARB_robustness.
virtual bool WasContextLostByRobustnessExtension() const = 0;
// Lose this context.
virtual void MarkContextLost(error::ContextLostReason reason) = 0;
virtual Logger* GetLogger() = 0;
virtual void BeginDecoding();
virtual void EndDecoding();
virtual const ContextState* GetContextState() = 0;
protected:
GLES2Decoder();
private:
bool initialized_;
bool debug_;
bool log_commands_;
bool unsafe_es3_apis_enabled_;
bool force_shader_name_hashing_for_test_;
DISALLOW_COPY_AND_ASSIGN(GLES2Decoder);
};
} // namespace gles2
} // namespace gpu
#endif // GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_DECODER_H_
|