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
gpu / command_buffer / service / decoder_context.h [blame]
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef GPU_COMMAND_BUFFER_SERVICE_DECODER_CONTEXT_H_
#define GPU_COMMAND_BUFFER_SERVICE_DECODER_CONTEXT_H_
#include <stddef.h>
#include <stdint.h>
#include "base/functional/callback.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "build/build_config.h"
#include "gpu/command_buffer/common/capabilities.h"
#include "gpu/command_buffer/common/constants.h"
#include "gpu/command_buffer/common/context_result.h"
#include "gpu/command_buffer/service/async_api_interface.h"
#include "gpu/command_buffer/service/gl_context_virtual_delegate.h"
#include "gpu/gpu_gles2_export.h"
#include "ui/gfx/geometry/rect.h"
namespace gl {
class GLContext;
class GLSurface;
} // namespace gl
namespace gpu {
class TextureBase;
struct ContextCreationAttribs;
namespace gles2 {
class ContextGroup;
class ErrorState;
class FeatureInfo;
class GpuFenceManager;
class Outputter;
class Texture;
struct DisallowedFeatures;
} // namespace gles2
// Abstract interface implemented by {Raster,GLES2}Decoder. It is called a
// DecoderContext because all methods are about decoding commands or
// accessing context/state generated by decoded commands.
class GPU_GLES2_EXPORT DecoderContext : public AsyncAPIInterface,
public GLContextVirtualDelegate {
public:
DecoderContext() = default;
~DecoderContext() override = default;
//
// Methods required by CommandBufferStub.
//
// 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 gpu::ContextResult Initialize(
const scoped_refptr<gl::GLSurface>& surface,
const scoped_refptr<gl::GLContext>& context,
bool offscreen,
const gles2::DisallowedFeatures& disallowed_features,
const ContextCreationAttribs& attrib_helper) = 0;
// Destroys the graphics context.
virtual void Destroy(bool have_context) = 0;
virtual Capabilities GetCapabilities() = 0;
virtual GLCapabilities GetGLCapabilities() = 0;
virtual const gles2::FeatureInfo* GetFeatureInfo() const = 0;
// Gets the associated GLContext.
virtual gl::GLContext* GetGLContext() = 0;
// Gets the associated GLSurface.
virtual gl::GLSurface* GetGLSurface() = 0;
// Make this decoder's GL context current.
virtual bool MakeCurrent() = 0;
// Lose this context.
virtual void MarkContextLost(error::ContextLostReason reason) = 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;
// Updates context lost state and returns true if lost. Most callers can use
// WasContextLost() as the GLES2Decoder will update the state internally. But
// if making GL calls directly, to the context then this state would not be
// updated and the caller can use this to determine if their calls failed due
// to context loss.
virtual bool CheckResetStatus() = 0;
// Set a callback to be called when a query is complete. If the query is
// invalid, the callback must be called immediately.
virtual void SetQueryCallback(unsigned int query_client_id,
base::OnceClosure callback) = 0;
// Cancel and clear all in progress Callbacks.
virtual void CancelAllQueries() = 0;
// Gets the GpuFenceManager for this context.
virtual gles2::GpuFenceManager* GetGpuFenceManager() = 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;
// Whether there is state that needs to be regularly polled.
virtual bool HasPollingWork() const = 0;
// Perform necessary polling.
virtual void PerformPollingWork() = 0;
//
// Methods required by GpuVideoDecodeAccelerator.
//
// Gets the texture object associated with the client ID. null is returned on
// failure or if the texture has not been bound yet.
virtual TextureBase* GetTextureBase(uint32_t client_id) = 0;
virtual void SetLevelInfo(uint32_t client_id,
int level,
unsigned internal_format,
unsigned width,
unsigned height,
unsigned depth,
unsigned format,
unsigned type,
const gfx::Rect& cleared_rect) = 0;
virtual base::WeakPtr<DecoderContext> AsWeakPtr() = 0;
//
// Methods required by GLES2DecoderHelper.
// Only functional for GLES2 Decoders.
//
virtual gles2::ContextGroup* GetContextGroup() = 0;
virtual gles2::ErrorState* GetErrorState() = 0;
//
// Methods required by Texture.
//
// Indicates whether a given internal format is one for a compressed
// texture.
virtual bool IsCompressedTextureFormat(unsigned format) = 0;
// Clears a level sub area of a 2D texture.
// Returns false if a GL error should be generated.
virtual bool ClearLevel(gles2::Texture* texture,
unsigned target,
int level,
unsigned format,
unsigned type,
int xoffset,
int yoffset,
int width,
int height) = 0;
// Clears a level sub area of a compressed 2D texture.
// Returns false if a GL error should be generated.
virtual bool ClearCompressedTextureLevel(gles2::Texture* texture,
unsigned target,
int level,
unsigned format,
int width,
int height) = 0;
// Clears a level sub area of a compressed 3D texture.
// Returns false if a GL error should be generated.
virtual bool ClearCompressedTextureLevel3D(gles2::Texture* texture,
unsigned target,
int level,
unsigned format,
int width,
int height,
int depth) = 0;
// Clears a level of a 3D texture.
// Returns false if a GL error should be generated.
virtual bool ClearLevel3D(gles2::Texture* texture,
unsigned target,
int level,
unsigned format,
unsigned type,
int width,
int height,
int depth) = 0;
//
// Methods required by InProcessCommandBuffer
//
// Set to true to LOG every command.
virtual void SetLogCommands(bool log_commands) = 0;
//
// Methods required by GpuTracer
//
virtual gles2::Outputter* outputter() const = 0;
// Restores all attributs in the gl context state.
virtual void RestoreAllAttributes() const = 0;
// Restores texture states for a given service id.
virtual void RestoreTextureState(unsigned service_id) = 0;
//
// Methods required by ImageDecodeAcceleratorStub
//
// Returns the ID of a RasterDecoder. This is not applicable to other
// implementations and it returns a negative number in that case.
virtual int GetRasterDecoderId() const = 0;
};
} // namespace gpu
#endif // GPU_COMMAND_BUFFER_SERVICE_DECODER_CONTEXT_H_