1 // Copyright 2018 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 #include "gpu/skia_bindings/gles2_implementation_with_grcontext_support.h"
6 
7 #include <utility>
8 
9 #include "gpu/skia_bindings/grcontext_for_gles2_interface.h"
10 #include "third_party/khronos/GLES2/gl2ext.h"
11 #include "third_party/skia/include/gpu/GrContext.h"
12 
13 namespace skia_bindings {
14 
15 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)16     GLES2ImplementationWithGrContextSupport(
17         gpu::gles2::GLES2CmdHelper* helper,
18         scoped_refptr<gpu::gles2::ShareGroup> share_group,
19         gpu::TransferBufferInterface* transfer_buffer,
20         bool bind_generates_resource,
21         bool lose_context_when_out_of_memory,
22         bool support_client_side_arrays,
23         gpu::GpuControl* gpu_control)
24     : GLES2Implementation(helper,
25                           std::move(share_group),
26                           transfer_buffer,
27                           bind_generates_resource,
28                           lose_context_when_out_of_memory,
29                           support_client_side_arrays,
30                           gpu_control) {}
31 
32 GLES2ImplementationWithGrContextSupport::
~GLES2ImplementationWithGrContextSupport()33     ~GLES2ImplementationWithGrContextSupport() {}
34 
HasGrContextSupport() const35 bool GLES2ImplementationWithGrContextSupport::HasGrContextSupport() const {
36   return true;
37 }
38 
ResetGrContextIfNeeded(uint32_t dirty_bits)39 void GLES2ImplementationWithGrContextSupport::ResetGrContextIfNeeded(
40     uint32_t dirty_bits) {
41   if (gr_context_ && !using_gl_from_skia_) {
42     gr_context_->resetContext(dirty_bits);
43   }
44 }
45 
SetGrContext(GrContext * gr)46 void GLES2ImplementationWithGrContextSupport::SetGrContext(GrContext* gr) {
47   DCHECK(!gr || !gr_context_);  // Cant have multiple linked GrContexts
48   gr_context_ = gr;
49 }
50 
WillCallGLFromSkia()51 void GLES2ImplementationWithGrContextSupport::WillCallGLFromSkia() {
52   using_gl_from_skia_ = true;
53 }
54 
DidCallGLFromSkia()55 void GLES2ImplementationWithGrContextSupport::DidCallGLFromSkia() {
56   using_gl_from_skia_ = false;
57 }
58 
59 // Calls that invalidate kRenderTarget_GrGLBackendState
BindFramebuffer(GLenum target,GLuint framebuffer)60 void GLES2ImplementationWithGrContextSupport::BindFramebuffer(
61     GLenum target,
62     GLuint framebuffer) {
63   BaseClass::BindFramebuffer(target, framebuffer);
64   ResetGrContextIfNeeded(kRenderTarget_GrGLBackendState);
65 }
BindRenderbuffer(GLenum target,GLuint renderbuffer)66 void GLES2ImplementationWithGrContextSupport::BindRenderbuffer(
67     GLenum target,
68     GLuint renderbuffer) {
69   BaseClass::BindRenderbuffer(target, renderbuffer);
70   ResetGrContextIfNeeded(kRenderTarget_GrGLBackendState);
71 }
DiscardFramebufferEXT(GLenum target,GLsizei count,const GLenum * attachments)72 void GLES2ImplementationWithGrContextSupport::DiscardFramebufferEXT(
73     GLenum target,
74     GLsizei count,
75     const GLenum* attachments) {
76   BaseClass::DiscardFramebufferEXT(target, count, attachments);
77   ResetGrContextIfNeeded(kRenderTarget_GrGLBackendState);
78 }
DeleteFramebuffers(GLsizei n,const GLuint * framebuffers)79 void GLES2ImplementationWithGrContextSupport::DeleteFramebuffers(
80     GLsizei n,
81     const GLuint* framebuffers) {
82   BaseClass::DeleteFramebuffers(n, framebuffers);
83   ResetGrContextIfNeeded(kRenderTarget_GrGLBackendState);
84 }
DeleteRenderbuffers(GLsizei n,const GLuint * renderbuffers)85 void GLES2ImplementationWithGrContextSupport::DeleteRenderbuffers(
86     GLsizei n,
87     const GLuint* renderbuffers) {
88   BaseClass::DeleteRenderbuffers(n, renderbuffers);
89   ResetGrContextIfNeeded(kRenderTarget_GrGLBackendState);
90 }
FramebufferTexture2D(GLenum target,GLenum attachment,GLenum textarget,GLuint texture,GLint level)91 void GLES2ImplementationWithGrContextSupport::FramebufferTexture2D(
92     GLenum target,
93     GLenum attachment,
94     GLenum textarget,
95     GLuint texture,
96     GLint level) {
97   BaseClass::FramebufferTexture2D(target, attachment, textarget, texture,
98                                   level);
99   ResetGrContextIfNeeded(kRenderTarget_GrGLBackendState);
100 }
FramebufferTextureLayer(GLenum target,GLenum attachment,GLuint texture,GLint level,GLint layer)101 void GLES2ImplementationWithGrContextSupport::FramebufferTextureLayer(
102     GLenum target,
103     GLenum attachment,
104     GLuint texture,
105     GLint level,
106     GLint layer) {
107   BaseClass::FramebufferTextureLayer(target, attachment, texture, level, layer);
108   ResetGrContextIfNeeded(kRenderTarget_GrGLBackendState);
109 }
110 
111 // Calls that invalidate kTextureBinding_GrGLBackendState
BindTexture(GLenum target,GLuint texture)112 void GLES2ImplementationWithGrContextSupport::BindTexture(GLenum target,
113                                                           GLuint texture) {
114   BaseClass::BindTexture(target, texture);
115   ResetGrContextIfNeeded(kTextureBinding_GrGLBackendState);
116 }
UnlockDiscardableTextureCHROMIUM(GLuint texture)117 void GLES2ImplementationWithGrContextSupport::UnlockDiscardableTextureCHROMIUM(
118     GLuint texture) {
119   BaseClass::UnlockDiscardableTextureCHROMIUM(texture);
120   ResetGrContextIfNeeded(kTextureBinding_GrGLBackendState);
121 }
LockDiscardableTextureCHROMIUM(GLuint texture)122 bool GLES2ImplementationWithGrContextSupport::LockDiscardableTextureCHROMIUM(
123     GLuint texture) {
124   bool result = BaseClass::LockDiscardableTextureCHROMIUM(texture);
125   ResetGrContextIfNeeded(kTextureBinding_GrGLBackendState);
126   return result;
127 }
DeleteTextures(GLsizei n,const GLuint * textures)128 void GLES2ImplementationWithGrContextSupport::DeleteTextures(
129     GLsizei n,
130     const GLuint* textures) {
131   BaseClass::DeleteTextures(n, textures);
132   ResetGrContextIfNeeded(kTextureBinding_GrGLBackendState);
133 }
ActiveTexture(GLenum texture)134 void GLES2ImplementationWithGrContextSupport::ActiveTexture(GLenum texture) {
135   BaseClass::ActiveTexture(texture);
136   ResetGrContextIfNeeded(kTextureBinding_GrGLBackendState);
137 }
138 
139 // Calls that invalidate kView_GrGLBackendState
Scissor(GLint x,GLint y,GLsizei width,GLsizei height)140 void GLES2ImplementationWithGrContextSupport::Scissor(GLint x,
141                                                       GLint y,
142                                                       GLsizei width,
143                                                       GLsizei height) {
144   BaseClass::Scissor(x, y, width, height);
145   ResetGrContextIfNeeded(kView_GrGLBackendState);
146 }
Viewport(GLint x,GLint y,GLsizei width,GLsizei height)147 void GLES2ImplementationWithGrContextSupport::Viewport(GLint x,
148                                                        GLint y,
149                                                        GLsizei width,
150                                                        GLsizei height) {
151   BaseClass::Viewport(x, y, width, height);
152   ResetGrContextIfNeeded(kView_GrGLBackendState);
153 }
WindowRectanglesEXT(GLenum mode,GLsizei count,const GLint * box)154 void GLES2ImplementationWithGrContextSupport::WindowRectanglesEXT(
155     GLenum mode,
156     GLsizei count,
157     const GLint* box) {
158   BaseClass::WindowRectanglesEXT(mode, count, box);
159   ResetGrContextIfNeeded(kView_GrGLBackendState);
160 }
161 
162 // Calls that invalidate kBlend_GrGLBackendState
BlendColor(GLclampf red,GLclampf green,GLclampf blue,GLclampf alpha)163 void GLES2ImplementationWithGrContextSupport::BlendColor(GLclampf red,
164                                                          GLclampf green,
165                                                          GLclampf blue,
166                                                          GLclampf alpha) {
167   BaseClass::BlendColor(red, green, blue, alpha);
168   ResetGrContextIfNeeded(kBlend_GrGLBackendState);
169 }
BlendEquation(GLenum mode)170 void GLES2ImplementationWithGrContextSupport::BlendEquation(GLenum mode) {
171   BaseClass::BlendEquation(mode);
172   ResetGrContextIfNeeded(kBlend_GrGLBackendState);
173 }
BlendEquationSeparate(GLenum modeRGB,GLenum modeAlpha)174 void GLES2ImplementationWithGrContextSupport::BlendEquationSeparate(
175     GLenum modeRGB,
176     GLenum modeAlpha) {
177   BaseClass::BlendEquationSeparate(modeRGB, modeAlpha);
178   ResetGrContextIfNeeded(kBlend_GrGLBackendState);
179 }
BlendFunc(GLenum sfactor,GLenum dfactor)180 void GLES2ImplementationWithGrContextSupport::BlendFunc(GLenum sfactor,
181                                                         GLenum dfactor) {
182   BaseClass::BlendFunc(sfactor, dfactor);
183   ResetGrContextIfNeeded(kBlend_GrGLBackendState);
184 }
BlendFuncSeparate(GLenum srcRGB,GLenum dstRGB,GLenum srcAlpha,GLenum dstAlpha)185 void GLES2ImplementationWithGrContextSupport::BlendFuncSeparate(
186     GLenum srcRGB,
187     GLenum dstRGB,
188     GLenum srcAlpha,
189     GLenum dstAlpha) {
190   BaseClass::BlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
191   ResetGrContextIfNeeded(kBlend_GrGLBackendState);
192 }
193 
194 // Calls that invalidate kMSAAEnable_GrGLBackendState
CoverageModulationCHROMIUM(GLenum components)195 void GLES2ImplementationWithGrContextSupport::CoverageModulationCHROMIUM(
196     GLenum components) {
197   BaseClass::CoverageModulationCHROMIUM(components);
198   ResetGrContextIfNeeded(kMSAAEnable_GrGLBackendState);
199 }
200 
201 // Calls that invalidate kVertex_GrGLBackendState
BindVertexArrayOES(GLuint array)202 void GLES2ImplementationWithGrContextSupport::BindVertexArrayOES(GLuint array) {
203   BaseClass::BindVertexArrayOES(array);
204   ResetGrContextIfNeeded(kVertex_GrGLBackendState);
205 }
DeleteVertexArraysOES(GLsizei n,const GLuint * arrays)206 void GLES2ImplementationWithGrContextSupport::DeleteVertexArraysOES(
207     GLsizei n,
208     const GLuint* arrays) {
209   BaseClass::DeleteVertexArraysOES(n, arrays);
210   ResetGrContextIfNeeded(kVertex_GrGLBackendState);
211 }
VertexAttribDivisorANGLE(GLuint index,GLuint divisor)212 void GLES2ImplementationWithGrContextSupport::VertexAttribDivisorANGLE(
213     GLuint index,
214     GLuint divisor) {
215   BaseClass::VertexAttribDivisorANGLE(index, divisor);
216   ResetGrContextIfNeeded(kVertex_GrGLBackendState);
217 }
DisableVertexAttribArray(GLuint index)218 void GLES2ImplementationWithGrContextSupport::DisableVertexAttribArray(
219     GLuint index) {
220   BaseClass::DisableVertexAttribArray(index);
221   ResetGrContextIfNeeded(kVertex_GrGLBackendState);
222 }
EnableVertexAttribArray(GLuint index)223 void GLES2ImplementationWithGrContextSupport::EnableVertexAttribArray(
224     GLuint index) {
225   BaseClass::EnableVertexAttribArray(index);
226   ResetGrContextIfNeeded(kVertex_GrGLBackendState);
227 }
VertexAttrib1f(GLuint indx,GLfloat x)228 void GLES2ImplementationWithGrContextSupport::VertexAttrib1f(GLuint indx,
229                                                              GLfloat x) {
230   BaseClass::VertexAttrib1f(indx, x);
231   ResetGrContextIfNeeded(kVertex_GrGLBackendState);
232 }
VertexAttrib1fv(GLuint indx,const GLfloat * values)233 void GLES2ImplementationWithGrContextSupport::VertexAttrib1fv(
234     GLuint indx,
235     const GLfloat* values) {
236   BaseClass::VertexAttrib1fv(indx, values);
237   ResetGrContextIfNeeded(kVertex_GrGLBackendState);
238 }
VertexAttrib2f(GLuint indx,GLfloat x,GLfloat y)239 void GLES2ImplementationWithGrContextSupport::VertexAttrib2f(GLuint indx,
240                                                              GLfloat x,
241                                                              GLfloat y) {
242   BaseClass::VertexAttrib2f(indx, x, y);
243   ResetGrContextIfNeeded(kVertex_GrGLBackendState);
244 }
VertexAttrib2fv(GLuint indx,const GLfloat * values)245 void GLES2ImplementationWithGrContextSupport::VertexAttrib2fv(
246     GLuint indx,
247     const GLfloat* values) {
248   BaseClass::VertexAttrib2fv(indx, values);
249   ResetGrContextIfNeeded(kVertex_GrGLBackendState);
250 }
VertexAttrib3f(GLuint indx,GLfloat x,GLfloat y,GLfloat z)251 void GLES2ImplementationWithGrContextSupport::VertexAttrib3f(GLuint indx,
252                                                              GLfloat x,
253                                                              GLfloat y,
254                                                              GLfloat z) {
255   BaseClass::VertexAttrib3f(indx, x, y, z);
256   ResetGrContextIfNeeded(kVertex_GrGLBackendState);
257 }
VertexAttrib3fv(GLuint indx,const GLfloat * values)258 void GLES2ImplementationWithGrContextSupport::VertexAttrib3fv(
259     GLuint indx,
260     const GLfloat* values) {
261   BaseClass::VertexAttrib3fv(indx, values);
262   ResetGrContextIfNeeded(kVertex_GrGLBackendState);
263 }
VertexAttrib4f(GLuint indx,GLfloat x,GLfloat y,GLfloat z,GLfloat w)264 void GLES2ImplementationWithGrContextSupport::VertexAttrib4f(GLuint indx,
265                                                              GLfloat x,
266                                                              GLfloat y,
267                                                              GLfloat z,
268                                                              GLfloat w) {
269   BaseClass::VertexAttrib4f(indx, x, y, z, w);
270   ResetGrContextIfNeeded(kVertex_GrGLBackendState);
271 }
VertexAttrib4fv(GLuint indx,const GLfloat * values)272 void GLES2ImplementationWithGrContextSupport::VertexAttrib4fv(
273     GLuint indx,
274     const GLfloat* values) {
275   BaseClass::VertexAttrib4fv(indx, values);
276   ResetGrContextIfNeeded(kVertex_GrGLBackendState);
277 }
VertexAttribI4i(GLuint indx,GLint x,GLint y,GLint z,GLint w)278 void GLES2ImplementationWithGrContextSupport::VertexAttribI4i(GLuint indx,
279                                                               GLint x,
280                                                               GLint y,
281                                                               GLint z,
282                                                               GLint w) {
283   BaseClass::VertexAttribI4i(indx, x, y, z, w);
284   ResetGrContextIfNeeded(kVertex_GrGLBackendState);
285 }
VertexAttribI4iv(GLuint indx,const GLint * values)286 void GLES2ImplementationWithGrContextSupport::VertexAttribI4iv(
287     GLuint indx,
288     const GLint* values) {
289   BaseClass::VertexAttribI4iv(indx, values);
290   ResetGrContextIfNeeded(kVertex_GrGLBackendState);
291 }
VertexAttribI4ui(GLuint indx,GLuint x,GLuint y,GLuint z,GLuint w)292 void GLES2ImplementationWithGrContextSupport::VertexAttribI4ui(GLuint indx,
293                                                                GLuint x,
294                                                                GLuint y,
295                                                                GLuint z,
296                                                                GLuint w) {
297   BaseClass::VertexAttribI4ui(indx, x, y, z, w);
298   ResetGrContextIfNeeded(kVertex_GrGLBackendState);
299 }
VertexAttribI4uiv(GLuint indx,const GLuint * values)300 void GLES2ImplementationWithGrContextSupport::VertexAttribI4uiv(
301     GLuint indx,
302     const GLuint* values) {
303   BaseClass::VertexAttribI4uiv(indx, values);
304   ResetGrContextIfNeeded(kVertex_GrGLBackendState);
305 }
VertexAttribIPointer(GLuint indx,GLint size,GLenum type,GLsizei stride,const void * ptr)306 void GLES2ImplementationWithGrContextSupport::VertexAttribIPointer(
307     GLuint indx,
308     GLint size,
309     GLenum type,
310     GLsizei stride,
311     const void* ptr) {
312   BaseClass::VertexAttribIPointer(indx, size, type, stride, ptr);
313   ResetGrContextIfNeeded(kVertex_GrGLBackendState);
314 }
VertexAttribPointer(GLuint indx,GLint size,GLenum type,GLboolean normalized,GLsizei stride,const void * ptr)315 void GLES2ImplementationWithGrContextSupport::VertexAttribPointer(
316     GLuint indx,
317     GLint size,
318     GLenum type,
319     GLboolean normalized,
320     GLsizei stride,
321     const void* ptr) {
322   BaseClass::VertexAttribPointer(indx, size, type, normalized, stride, ptr);
323   ResetGrContextIfNeeded(kVertex_GrGLBackendState);
324 }
325 
326 // Calls that invalidate kStencil_GrGLBackendState
StencilFunc(GLenum func,GLint ref,GLuint mask)327 void GLES2ImplementationWithGrContextSupport::StencilFunc(GLenum func,
328                                                           GLint ref,
329                                                           GLuint mask) {
330   BaseClass::StencilFunc(func, ref, mask);
331   ResetGrContextIfNeeded(kStencil_GrGLBackendState);
332 }
StencilFuncSeparate(GLenum face,GLenum func,GLint ref,GLuint mask)333 void GLES2ImplementationWithGrContextSupport::StencilFuncSeparate(GLenum face,
334                                                                   GLenum func,
335                                                                   GLint ref,
336                                                                   GLuint mask) {
337   BaseClass::StencilFuncSeparate(face, func, ref, mask);
338   ResetGrContextIfNeeded(kStencil_GrGLBackendState);
339 }
StencilMask(GLuint mask)340 void GLES2ImplementationWithGrContextSupport::StencilMask(GLuint mask) {
341   BaseClass::StencilMask(mask);
342   ResetGrContextIfNeeded(kStencil_GrGLBackendState);
343 }
StencilMaskSeparate(GLenum face,GLuint mask)344 void GLES2ImplementationWithGrContextSupport::StencilMaskSeparate(GLenum face,
345                                                                   GLuint mask) {
346   BaseClass::StencilMaskSeparate(face, mask);
347   ResetGrContextIfNeeded(kStencil_GrGLBackendState);
348 }
StencilOp(GLenum fail,GLenum zfail,GLenum zpass)349 void GLES2ImplementationWithGrContextSupport::StencilOp(GLenum fail,
350                                                         GLenum zfail,
351                                                         GLenum zpass) {
352   BaseClass::StencilOp(fail, zfail, zpass);
353   ResetGrContextIfNeeded(kStencil_GrGLBackendState);
354 }
StencilOpSeparate(GLenum face,GLenum fail,GLenum zfail,GLenum zpass)355 void GLES2ImplementationWithGrContextSupport::StencilOpSeparate(GLenum face,
356                                                                 GLenum fail,
357                                                                 GLenum zfail,
358                                                                 GLenum zpass) {
359   BaseClass::StencilOpSeparate(face, fail, zfail, zpass);
360   ResetGrContextIfNeeded(kStencil_GrGLBackendState);
361 }
362 
363 // Calls that invalidate kPixelStore_GrGLBackendState
PixelStorei(GLenum pname,GLint param)364 void GLES2ImplementationWithGrContextSupport::PixelStorei(GLenum pname,
365                                                           GLint param) {
366   BaseClass::PixelStorei(pname, param);
367   ResetGrContextIfNeeded(kPixelStore_GrGLBackendState);
368 }
369 
370 // Calls that invalidate kProgram_GrGLBackendState
UseProgram(GLuint program)371 void GLES2ImplementationWithGrContextSupport::UseProgram(GLuint program) {
372   BaseClass::UseProgram(program);
373   ResetGrContextIfNeeded(kProgram_GrGLBackendState);
374 }
375 
376 // Calls that invalidate kMisc_GrGLBackendState
DepthMask(GLboolean flag)377 void GLES2ImplementationWithGrContextSupport::DepthMask(GLboolean flag) {
378   BaseClass::DepthMask(flag);
379   ResetGrContextIfNeeded(kMisc_GrGLBackendState);
380 }
FrontFace(GLenum mode)381 void GLES2ImplementationWithGrContextSupport::FrontFace(GLenum mode) {
382   BaseClass::FrontFace(mode);
383   ResetGrContextIfNeeded(kMisc_GrGLBackendState);
384 }
LineWidth(GLfloat width)385 void GLES2ImplementationWithGrContextSupport::LineWidth(GLfloat width) {
386   BaseClass::LineWidth(width);
387   ResetGrContextIfNeeded(kMisc_GrGLBackendState);
388 }
ColorMask(GLboolean red,GLboolean green,GLboolean blue,GLboolean alpha)389 void GLES2ImplementationWithGrContextSupport::ColorMask(GLboolean red,
390                                                         GLboolean green,
391                                                         GLboolean blue,
392                                                         GLboolean alpha) {
393   BaseClass::ColorMask(red, green, blue, alpha);
394   ResetGrContextIfNeeded(kMisc_GrGLBackendState);
395 }
396 
397 // Calls that invalidate many flags
BindBuffer(GLenum target,GLuint buffer)398 void GLES2ImplementationWithGrContextSupport::BindBuffer(GLenum target,
399                                                          GLuint buffer) {
400   WillBindBuffer(target);
401   BaseClass::BindBuffer(target, buffer);
402 }
BindBufferBase(GLenum target,GLuint index,GLuint buffer)403 void GLES2ImplementationWithGrContextSupport::BindBufferBase(GLenum target,
404                                                              GLuint index,
405                                                              GLuint buffer) {
406   WillBindBuffer(target);
407   BaseClass::BindBufferBase(target, index, buffer);
408 }
BindBufferRange(GLenum target,GLuint index,GLuint buffer,GLintptr offset,GLsizeiptr size)409 void GLES2ImplementationWithGrContextSupport::BindBufferRange(GLenum target,
410                                                               GLuint index,
411                                                               GLuint buffer,
412                                                               GLintptr offset,
413                                                               GLsizeiptr size) {
414   WillBindBuffer(target);
415   BaseClass::BindBufferRange(target, index, buffer, offset, size);
416 }
WillBindBuffer(GLenum target)417 void GLES2ImplementationWithGrContextSupport::WillBindBuffer(GLenum target) {
418   switch (target) {
419     case GL_ELEMENT_ARRAY_BUFFER:
420     case GL_ARRAY_BUFFER:
421       ResetGrContextIfNeeded(kVertex_GrGLBackendState);
422       break;
423     case GL_TEXTURE_BUFFER_OES:
424     //  case GL_DRAW_INDIRECT_BUFFER:
425     case GL_PIXEL_UNPACK_BUFFER:
426     case GL_PIXEL_PACK_BUFFER:
427       ResetGrContextIfNeeded(kMisc_GrGLBackendState);
428       break;
429     default:
430       break;
431   }
432 }
DeleteBuffers(GLsizei n,const GLuint * buffers)433 void GLES2ImplementationWithGrContextSupport::DeleteBuffers(
434     GLsizei n,
435     const GLuint* buffers) {
436   BaseClass::DeleteBuffers(n, buffers);
437   ResetGrContextIfNeeded(kVertex_GrGLBackendState | kMisc_GrGLBackendState);
438 }
439 
Disable(GLenum cap)440 void GLES2ImplementationWithGrContextSupport::Disable(GLenum cap) {
441   WillEnableOrDisable(cap);
442   BaseClass::Disable(cap);
443 }
444 
Enable(GLenum cap)445 void GLES2ImplementationWithGrContextSupport::Enable(GLenum cap) {
446   WillEnableOrDisable(cap);
447   BaseClass::Enable(cap);
448 }
449 
WillEnableOrDisable(GLenum cap)450 void GLES2ImplementationWithGrContextSupport::WillEnableOrDisable(GLenum cap) {
451   switch (cap) {
452     case GL_FRAMEBUFFER_SRGB_EXT:
453       ResetGrContextIfNeeded(kRenderTarget_GrGLBackendState);
454       break;
455     case GL_SCISSOR_TEST:
456       ResetGrContextIfNeeded(kView_GrGLBackendState);
457       break;
458     case GL_BLEND:
459       ResetGrContextIfNeeded(kBlend_GrGLBackendState);
460       break;
461     case GL_MULTISAMPLE_EXT:
462       ResetGrContextIfNeeded(kMSAAEnable_GrGLBackendState);
463       break;
464     case GL_STENCIL_TEST:
465       ResetGrContextIfNeeded(kStencil_GrGLBackendState);
466       break;
467     case GL_PRIMITIVE_RESTART_FIXED_INDEX:
468       ResetGrContextIfNeeded(kVertex_GrGLBackendState);
469       break;
470     case GL_DEPTH_TEST:
471     case GL_CULL_FACE:
472     case GL_DITHER:
473     //  Commented-out non-ES bits that skia cares about
474     //  case GL_POINT_SMOOTH:
475     //  case GL_LINE_SMOOTH:
476     //  case GL_POLYGON_SMOOTH:
477     //  case GL_POLYGON_STIPPLE:
478     //  case GL_COLOR_LOGIC_OP:
479     //  case GL_INDEX_LOGIC_OP:
480     //  case GL_COLOR_TABLE:
481     //  case GL_VERTEX_PROGRAM_POINT_SIZE:
482     case GL_POLYGON_OFFSET_FILL:
483     case GL_FETCH_PER_SAMPLE_ARM:
484       ResetGrContextIfNeeded(kMisc_GrGLBackendState);
485       break;
486     default:
487       break;
488   }
489 }
490 
491 }  // namespace skia_bindings
492