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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
gpu / skia_bindings / gles2_implementation_with_grcontext_support.cc [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.
#include "gpu/skia_bindings/gles2_implementation_with_grcontext_support.h"
#include <utility>
#include "gpu/skia_bindings/grcontext_for_gles2_interface.h"
#include "third_party/khronos/GLES2/gl2ext.h"
#include "third_party/skia/include/gpu/ganesh/GrDirectContext.h"
namespace skia_bindings {
GLES2ImplementationWithGrContextSupport::
GLES2ImplementationWithGrContextSupport(
gpu::gles2::GLES2CmdHelper* helper,
scoped_refptr<gpu::gles2::ShareGroup> share_group,
gpu::TransferBufferInterface* transfer_buffer,
bool bind_generates_resource,
bool lose_context_when_out_of_memory,
bool support_client_side_arrays,
gpu::GpuControl* gpu_control)
: GLES2Implementation(helper,
std::move(share_group),
transfer_buffer,
bind_generates_resource,
lose_context_when_out_of_memory,
support_client_side_arrays,
gpu_control) {}
GLES2ImplementationWithGrContextSupport::
~GLES2ImplementationWithGrContextSupport() {}
bool GLES2ImplementationWithGrContextSupport::HasGrContextSupport() const {
return true;
}
void GLES2ImplementationWithGrContextSupport::ResetGrContextIfNeeded(
uint32_t dirty_bits) {
if (gr_context_ && !using_gl_from_skia_) {
gr_context_->resetContext(dirty_bits);
}
}
void GLES2ImplementationWithGrContextSupport::SetGrContext(
GrDirectContext* gr) {
DCHECK(!gr || !gr_context_); // Cant have multiple linked GrContexts
gr_context_ = gr;
}
void GLES2ImplementationWithGrContextSupport::WillCallGLFromSkia() {
using_gl_from_skia_ = true;
}
void GLES2ImplementationWithGrContextSupport::DidCallGLFromSkia() {
using_gl_from_skia_ = false;
}
// Calls that invalidate kRenderTarget_GrGLBackendState
void GLES2ImplementationWithGrContextSupport::BindFramebuffer(
GLenum target,
GLuint framebuffer) {
BaseClass::BindFramebuffer(target, framebuffer);
ResetGrContextIfNeeded(kRenderTarget_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::BindRenderbuffer(
GLenum target,
GLuint renderbuffer) {
BaseClass::BindRenderbuffer(target, renderbuffer);
ResetGrContextIfNeeded(kRenderTarget_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::DiscardFramebufferEXT(
GLenum target,
GLsizei count,
const GLenum* attachments) {
BaseClass::DiscardFramebufferEXT(target, count, attachments);
ResetGrContextIfNeeded(kRenderTarget_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::DeleteFramebuffers(
GLsizei n,
const GLuint* framebuffers) {
BaseClass::DeleteFramebuffers(n, framebuffers);
ResetGrContextIfNeeded(kRenderTarget_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::DeleteRenderbuffers(
GLsizei n,
const GLuint* renderbuffers) {
BaseClass::DeleteRenderbuffers(n, renderbuffers);
ResetGrContextIfNeeded(kRenderTarget_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::FramebufferTexture2D(
GLenum target,
GLenum attachment,
GLenum textarget,
GLuint texture,
GLint level) {
BaseClass::FramebufferTexture2D(target, attachment, textarget, texture,
level);
ResetGrContextIfNeeded(kRenderTarget_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::FramebufferTextureLayer(
GLenum target,
GLenum attachment,
GLuint texture,
GLint level,
GLint layer) {
BaseClass::FramebufferTextureLayer(target, attachment, texture, level, layer);
ResetGrContextIfNeeded(kRenderTarget_GrGLBackendState);
}
// Calls that invalidate kTextureBinding_GrGLBackendState
void GLES2ImplementationWithGrContextSupport::BindTexture(GLenum target,
GLuint texture) {
BaseClass::BindTexture(target, texture);
ResetGrContextIfNeeded(kTextureBinding_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::UnlockDiscardableTextureCHROMIUM(
GLuint texture) {
BaseClass::UnlockDiscardableTextureCHROMIUM(texture);
ResetGrContextIfNeeded(kTextureBinding_GrGLBackendState);
}
bool GLES2ImplementationWithGrContextSupport::LockDiscardableTextureCHROMIUM(
GLuint texture) {
bool result = BaseClass::LockDiscardableTextureCHROMIUM(texture);
ResetGrContextIfNeeded(kTextureBinding_GrGLBackendState);
return result;
}
void GLES2ImplementationWithGrContextSupport::DeleteTextures(
GLsizei n,
const GLuint* textures) {
BaseClass::DeleteTextures(n, textures);
ResetGrContextIfNeeded(kTextureBinding_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::ActiveTexture(GLenum texture) {
BaseClass::ActiveTexture(texture);
ResetGrContextIfNeeded(kTextureBinding_GrGLBackendState);
}
// Calls that invalidate kView_GrGLBackendState
void GLES2ImplementationWithGrContextSupport::Scissor(GLint x,
GLint y,
GLsizei width,
GLsizei height) {
BaseClass::Scissor(x, y, width, height);
ResetGrContextIfNeeded(kView_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::Viewport(GLint x,
GLint y,
GLsizei width,
GLsizei height) {
BaseClass::Viewport(x, y, width, height);
ResetGrContextIfNeeded(kView_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::WindowRectanglesEXT(
GLenum mode,
GLsizei count,
const GLint* box) {
BaseClass::WindowRectanglesEXT(mode, count, box);
ResetGrContextIfNeeded(kView_GrGLBackendState);
}
// Calls that invalidate kBlend_GrGLBackendState
void GLES2ImplementationWithGrContextSupport::BlendColor(GLclampf red,
GLclampf green,
GLclampf blue,
GLclampf alpha) {
BaseClass::BlendColor(red, green, blue, alpha);
ResetGrContextIfNeeded(kBlend_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::BlendEquation(GLenum mode) {
BaseClass::BlendEquation(mode);
ResetGrContextIfNeeded(kBlend_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::BlendEquationSeparate(
GLenum modeRGB,
GLenum modeAlpha) {
BaseClass::BlendEquationSeparate(modeRGB, modeAlpha);
ResetGrContextIfNeeded(kBlend_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::BlendFunc(GLenum sfactor,
GLenum dfactor) {
BaseClass::BlendFunc(sfactor, dfactor);
ResetGrContextIfNeeded(kBlend_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::BlendFuncSeparate(
GLenum srcRGB,
GLenum dstRGB,
GLenum srcAlpha,
GLenum dstAlpha) {
BaseClass::BlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
ResetGrContextIfNeeded(kBlend_GrGLBackendState);
}
// Calls that invalidate kVertex_GrGLBackendState
void GLES2ImplementationWithGrContextSupport::BindVertexArrayOES(GLuint array) {
BaseClass::BindVertexArrayOES(array);
ResetGrContextIfNeeded(kVertex_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::DeleteVertexArraysOES(
GLsizei n,
const GLuint* arrays) {
BaseClass::DeleteVertexArraysOES(n, arrays);
ResetGrContextIfNeeded(kVertex_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::VertexAttribDivisorANGLE(
GLuint index,
GLuint divisor) {
BaseClass::VertexAttribDivisorANGLE(index, divisor);
ResetGrContextIfNeeded(kVertex_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::DisableVertexAttribArray(
GLuint index) {
BaseClass::DisableVertexAttribArray(index);
ResetGrContextIfNeeded(kVertex_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::EnableVertexAttribArray(
GLuint index) {
BaseClass::EnableVertexAttribArray(index);
ResetGrContextIfNeeded(kVertex_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::VertexAttrib1f(GLuint indx,
GLfloat x) {
BaseClass::VertexAttrib1f(indx, x);
ResetGrContextIfNeeded(kVertex_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::VertexAttrib1fv(
GLuint indx,
const GLfloat* values) {
BaseClass::VertexAttrib1fv(indx, values);
ResetGrContextIfNeeded(kVertex_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::VertexAttrib2f(GLuint indx,
GLfloat x,
GLfloat y) {
BaseClass::VertexAttrib2f(indx, x, y);
ResetGrContextIfNeeded(kVertex_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::VertexAttrib2fv(
GLuint indx,
const GLfloat* values) {
BaseClass::VertexAttrib2fv(indx, values);
ResetGrContextIfNeeded(kVertex_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::VertexAttrib3f(GLuint indx,
GLfloat x,
GLfloat y,
GLfloat z) {
BaseClass::VertexAttrib3f(indx, x, y, z);
ResetGrContextIfNeeded(kVertex_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::VertexAttrib3fv(
GLuint indx,
const GLfloat* values) {
BaseClass::VertexAttrib3fv(indx, values);
ResetGrContextIfNeeded(kVertex_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::VertexAttrib4f(GLuint indx,
GLfloat x,
GLfloat y,
GLfloat z,
GLfloat w) {
BaseClass::VertexAttrib4f(indx, x, y, z, w);
ResetGrContextIfNeeded(kVertex_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::VertexAttrib4fv(
GLuint indx,
const GLfloat* values) {
BaseClass::VertexAttrib4fv(indx, values);
ResetGrContextIfNeeded(kVertex_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::VertexAttribI4i(GLuint indx,
GLint x,
GLint y,
GLint z,
GLint w) {
BaseClass::VertexAttribI4i(indx, x, y, z, w);
ResetGrContextIfNeeded(kVertex_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::VertexAttribI4iv(
GLuint indx,
const GLint* values) {
BaseClass::VertexAttribI4iv(indx, values);
ResetGrContextIfNeeded(kVertex_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::VertexAttribI4ui(GLuint indx,
GLuint x,
GLuint y,
GLuint z,
GLuint w) {
BaseClass::VertexAttribI4ui(indx, x, y, z, w);
ResetGrContextIfNeeded(kVertex_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::VertexAttribI4uiv(
GLuint indx,
const GLuint* values) {
BaseClass::VertexAttribI4uiv(indx, values);
ResetGrContextIfNeeded(kVertex_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::VertexAttribIPointer(
GLuint indx,
GLint size,
GLenum type,
GLsizei stride,
const void* ptr) {
BaseClass::VertexAttribIPointer(indx, size, type, stride, ptr);
ResetGrContextIfNeeded(kVertex_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::VertexAttribPointer(
GLuint indx,
GLint size,
GLenum type,
GLboolean normalized,
GLsizei stride,
const void* ptr) {
BaseClass::VertexAttribPointer(indx, size, type, normalized, stride, ptr);
ResetGrContextIfNeeded(kVertex_GrGLBackendState);
}
// Calls that invalidate kStencil_GrGLBackendState
void GLES2ImplementationWithGrContextSupport::StencilFunc(GLenum func,
GLint ref,
GLuint mask) {
BaseClass::StencilFunc(func, ref, mask);
ResetGrContextIfNeeded(kStencil_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::StencilFuncSeparate(GLenum face,
GLenum func,
GLint ref,
GLuint mask) {
BaseClass::StencilFuncSeparate(face, func, ref, mask);
ResetGrContextIfNeeded(kStencil_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::StencilMask(GLuint mask) {
BaseClass::StencilMask(mask);
ResetGrContextIfNeeded(kStencil_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::StencilMaskSeparate(GLenum face,
GLuint mask) {
BaseClass::StencilMaskSeparate(face, mask);
ResetGrContextIfNeeded(kStencil_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::StencilOp(GLenum fail,
GLenum zfail,
GLenum zpass) {
BaseClass::StencilOp(fail, zfail, zpass);
ResetGrContextIfNeeded(kStencil_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::StencilOpSeparate(GLenum face,
GLenum fail,
GLenum zfail,
GLenum zpass) {
BaseClass::StencilOpSeparate(face, fail, zfail, zpass);
ResetGrContextIfNeeded(kStencil_GrGLBackendState);
}
// Calls that invalidate kPixelStore_GrGLBackendState
void GLES2ImplementationWithGrContextSupport::PixelStorei(GLenum pname,
GLint param) {
BaseClass::PixelStorei(pname, param);
ResetGrContextIfNeeded(kPixelStore_GrGLBackendState);
}
// Calls that invalidate kProgram_GrGLBackendState
void GLES2ImplementationWithGrContextSupport::UseProgram(GLuint program) {
BaseClass::UseProgram(program);
ResetGrContextIfNeeded(kProgram_GrGLBackendState);
}
// Calls that invalidate kMisc_GrGLBackendState
void GLES2ImplementationWithGrContextSupport::DepthMask(GLboolean flag) {
BaseClass::DepthMask(flag);
ResetGrContextIfNeeded(kMisc_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::FrontFace(GLenum mode) {
BaseClass::FrontFace(mode);
ResetGrContextIfNeeded(kMisc_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::LineWidth(GLfloat width) {
BaseClass::LineWidth(width);
ResetGrContextIfNeeded(kMisc_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::ColorMask(GLboolean red,
GLboolean green,
GLboolean blue,
GLboolean alpha) {
BaseClass::ColorMask(red, green, blue, alpha);
ResetGrContextIfNeeded(kMisc_GrGLBackendState);
}
// Calls that invalidate many flags
void GLES2ImplementationWithGrContextSupport::BindBuffer(GLenum target,
GLuint buffer) {
WillBindBuffer(target);
BaseClass::BindBuffer(target, buffer);
}
void GLES2ImplementationWithGrContextSupport::BindBufferBase(GLenum target,
GLuint index,
GLuint buffer) {
WillBindBuffer(target);
BaseClass::BindBufferBase(target, index, buffer);
}
void GLES2ImplementationWithGrContextSupport::BindBufferRange(GLenum target,
GLuint index,
GLuint buffer,
GLintptr offset,
GLsizeiptr size) {
WillBindBuffer(target);
BaseClass::BindBufferRange(target, index, buffer, offset, size);
}
void GLES2ImplementationWithGrContextSupport::WillBindBuffer(GLenum target) {
switch (target) {
case GL_ELEMENT_ARRAY_BUFFER:
case GL_ARRAY_BUFFER:
ResetGrContextIfNeeded(kVertex_GrGLBackendState);
break;
case GL_TEXTURE_BUFFER_OES:
// case GL_DRAW_INDIRECT_BUFFER:
case GL_PIXEL_UNPACK_BUFFER:
case GL_PIXEL_PACK_BUFFER:
ResetGrContextIfNeeded(kMisc_GrGLBackendState);
break;
default:
break;
}
}
void GLES2ImplementationWithGrContextSupport::DeleteBuffers(
GLsizei n,
const GLuint* buffers) {
BaseClass::DeleteBuffers(n, buffers);
ResetGrContextIfNeeded(kVertex_GrGLBackendState | kMisc_GrGLBackendState);
}
void GLES2ImplementationWithGrContextSupport::Disable(GLenum cap) {
WillEnableOrDisable(cap);
BaseClass::Disable(cap);
}
void GLES2ImplementationWithGrContextSupport::Enable(GLenum cap) {
WillEnableOrDisable(cap);
BaseClass::Enable(cap);
}
void GLES2ImplementationWithGrContextSupport::WillEnableOrDisable(GLenum cap) {
switch (cap) {
case GL_FRAMEBUFFER_SRGB_EXT:
ResetGrContextIfNeeded(kRenderTarget_GrGLBackendState);
break;
case GL_SCISSOR_TEST:
ResetGrContextIfNeeded(kView_GrGLBackendState);
break;
case GL_BLEND:
ResetGrContextIfNeeded(kBlend_GrGLBackendState);
break;
case GL_MULTISAMPLE_EXT:
ResetGrContextIfNeeded(kMSAAEnable_GrGLBackendState);
break;
case GL_STENCIL_TEST:
ResetGrContextIfNeeded(kStencil_GrGLBackendState);
break;
case GL_PRIMITIVE_RESTART_FIXED_INDEX:
ResetGrContextIfNeeded(kVertex_GrGLBackendState);
break;
case GL_DEPTH_TEST:
case GL_CULL_FACE:
case GL_DITHER:
// Commented-out non-ES bits that skia cares about
// case GL_POINT_SMOOTH:
// case GL_LINE_SMOOTH:
// case GL_POLYGON_SMOOTH:
// case GL_POLYGON_STIPPLE:
// case GL_COLOR_LOGIC_OP:
// case GL_INDEX_LOGIC_OP:
// case GL_COLOR_TABLE:
// case GL_VERTEX_PROGRAM_POINT_SIZE:
case GL_POLYGON_OFFSET_FILL:
case GL_FETCH_PER_SAMPLE_ARM:
ResetGrContextIfNeeded(kMisc_GrGLBackendState);
break;
default:
break;
}
}
} // namespace skia_bindings