gles2_implementation_with_grcontext_support.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. #include "base/memory/raw_ptr.h"
  5. #include "gpu/command_buffer/client/gles2_implementation.h"
  6. #ifndef GPU_SKIA_BINDINGS_GLES2_IMPLEMENTATION_WITH_GRCONTEXT_SUPPORT_H_
  7. #define GPU_SKIA_BINDINGS_GLES2_IMPLEMENTATION_WITH_GRCONTEXT_SUPPORT_H_
  8. class GrDirectContext;
  9. namespace skia_bindings {
  10. class GLES2ImplementationWithGrContextSupport
  11. : public gpu::gles2::GLES2Implementation {
  12. public:
  13. GLES2ImplementationWithGrContextSupport(
  14. gpu::gles2::GLES2CmdHelper* helper,
  15. scoped_refptr<gpu::gles2::ShareGroup> share_group,
  16. gpu::TransferBufferInterface* transfer_buffer,
  17. bool bind_generates_resource,
  18. bool lose_context_when_out_of_memory,
  19. bool support_client_side_arrays,
  20. gpu::GpuControl* gpu_control);
  21. ~GLES2ImplementationWithGrContextSupport() override;
  22. typedef gpu::gles2::GLES2Implementation BaseClass;
  23. void WillCallGLFromSkia() override;
  24. void DidCallGLFromSkia() override;
  25. void SetGrContext(GrDirectContext* gr) override;
  26. bool HasGrContextSupport() const override;
  27. // Overrides for GLES2 calls that invalidate state that is tracked by skia
  28. //=========================================================================
  29. //
  30. // These must be kept in sync with the invalidation defines in
  31. // GrGLGpu::onResetContext()
  32. // Calls that invalidate kRenderTarget_GrGLBackendState
  33. void BindFramebuffer(GLenum target, GLuint framebuffer) override;
  34. void BindRenderbuffer(GLenum target, GLuint renderbuffer) override;
  35. void DiscardFramebufferEXT(GLenum target,
  36. GLsizei count,
  37. const GLenum* attachments) override;
  38. void DeleteFramebuffers(GLsizei n, const GLuint* framebuffers) override;
  39. void DeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers) override;
  40. void FramebufferTexture2D(GLenum target,
  41. GLenum attachment,
  42. GLenum textarget,
  43. GLuint texture,
  44. GLint level) override;
  45. void FramebufferTextureLayer(GLenum target,
  46. GLenum attachment,
  47. GLuint texture,
  48. GLint level,
  49. GLint layer) override;
  50. // Calls that invalidate kTextureBinding_GrGLBackendState
  51. // Note: Deleting a texture may affect the binding if the currently bound
  52. // texture is deleted. Locking and Unlocking discardable textures may
  53. // internally invoke texture deletion, so they too may affect the texture
  54. // binding.
  55. void BindTexture(GLenum target, GLuint texture) override;
  56. void UnlockDiscardableTextureCHROMIUM(GLuint texture) override;
  57. bool LockDiscardableTextureCHROMIUM(GLuint texture) override;
  58. void DeleteTextures(GLsizei n, const GLuint* textures) override;
  59. void ActiveTexture(GLenum texture) override;
  60. // Calls that invalidate kView_GrGLBackendState
  61. void Scissor(GLint x, GLint y, GLsizei width, GLsizei height) override;
  62. void Viewport(GLint x, GLint y, GLsizei width, GLsizei height) override;
  63. void WindowRectanglesEXT(GLenum mode,
  64. GLsizei count,
  65. const GLint* box) override;
  66. // Calls that invalidate kBlend_GrGLBackendState
  67. void BlendColor(GLclampf red,
  68. GLclampf green,
  69. GLclampf blue,
  70. GLclampf alpha) override;
  71. void BlendEquation(GLenum mode) override;
  72. void BlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha) override;
  73. void BlendFunc(GLenum sfactor, GLenum dfactor) override;
  74. void BlendFuncSeparate(GLenum srcRGB,
  75. GLenum dstRGB,
  76. GLenum srcAlpha,
  77. GLenum dstAlpha) override;
  78. // Calls that invalidate kMSAAEnable_GrGLBackendState
  79. void CoverageModulationCHROMIUM(GLenum components) override;
  80. // Calls that invalidate kVertex_GrGLBackendState
  81. void BindVertexArrayOES(GLuint array) override;
  82. void DeleteVertexArraysOES(GLsizei n, const GLuint* arrays) override;
  83. void VertexAttribDivisorANGLE(GLuint index, GLuint divisor) override;
  84. void DisableVertexAttribArray(GLuint index) override;
  85. void EnableVertexAttribArray(GLuint index) override;
  86. void VertexAttrib1f(GLuint indx, GLfloat x) override;
  87. void VertexAttrib1fv(GLuint indx, const GLfloat* values) override;
  88. void VertexAttrib2f(GLuint indx, GLfloat x, GLfloat y) override;
  89. void VertexAttrib2fv(GLuint indx, const GLfloat* values) override;
  90. void VertexAttrib3f(GLuint indx, GLfloat x, GLfloat y, GLfloat z) override;
  91. void VertexAttrib3fv(GLuint indx, const GLfloat* values) override;
  92. void VertexAttrib4f(GLuint indx,
  93. GLfloat x,
  94. GLfloat y,
  95. GLfloat z,
  96. GLfloat w) override;
  97. void VertexAttrib4fv(GLuint indx, const GLfloat* values) override;
  98. void VertexAttribI4i(GLuint indx,
  99. GLint x,
  100. GLint y,
  101. GLint z,
  102. GLint w) override;
  103. void VertexAttribI4iv(GLuint indx, const GLint* values) override;
  104. void VertexAttribI4ui(GLuint indx,
  105. GLuint x,
  106. GLuint y,
  107. GLuint z,
  108. GLuint w) override;
  109. void VertexAttribI4uiv(GLuint indx, const GLuint* values) override;
  110. void VertexAttribIPointer(GLuint indx,
  111. GLint size,
  112. GLenum type,
  113. GLsizei stride,
  114. const void* ptr) override;
  115. void VertexAttribPointer(GLuint indx,
  116. GLint size,
  117. GLenum type,
  118. GLboolean normalized,
  119. GLsizei stride,
  120. const void* ptr) override;
  121. // Calls that invalidate kStencil_GrGLBackendState
  122. void StencilFunc(GLenum func, GLint ref, GLuint mask) override;
  123. void StencilFuncSeparate(GLenum face,
  124. GLenum func,
  125. GLint ref,
  126. GLuint mask) override;
  127. void StencilMask(GLuint mask) override;
  128. void StencilMaskSeparate(GLenum face, GLuint mask) override;
  129. void StencilOp(GLenum fail, GLenum zfail, GLenum zpass) override;
  130. void StencilOpSeparate(GLenum face,
  131. GLenum fail,
  132. GLenum zfail,
  133. GLenum zpass) override;
  134. // Calls that invalidate kPixelStore_GrGLBackendState
  135. void PixelStorei(GLenum pname, GLint param) override;
  136. // Calls that invalidate kProgram_GrGLBackendState
  137. void UseProgram(GLuint program) override;
  138. // Calls that invalidate kMisc_GrGLBackendState
  139. void DepthMask(GLboolean flag) override;
  140. void FrontFace(GLenum mode) override;
  141. void LineWidth(GLfloat width) override;
  142. void ColorMask(GLboolean red,
  143. GLboolean green,
  144. GLboolean blue,
  145. GLboolean alpha) override;
  146. // Calls that invalidate different bits, depending on args
  147. void BindBuffer(GLenum target, GLuint buffer) override;
  148. void BindBufferBase(GLenum target, GLuint index, GLuint buffer) override;
  149. void BindBufferRange(GLenum target,
  150. GLuint index,
  151. GLuint buffer,
  152. GLintptr offset,
  153. GLsizeiptr size) override;
  154. void DeleteBuffers(GLsizei n, const GLuint* buffers) override;
  155. void Disable(GLenum cap) override;
  156. void Enable(GLenum cap) override;
  157. private:
  158. void WillBindBuffer(GLenum target);
  159. void WillEnableOrDisable(GLenum cap);
  160. void ResetGrContextIfNeeded(uint32_t dirty_bits);
  161. raw_ptr<GrDirectContext> gr_context_ = nullptr;
  162. bool using_gl_from_skia_ = false;
  163. };
  164. } // namespace skia_bindings
  165. #endif // GPU_SKIA_BINDINGS_GLES2_IMPLEMENTATION_WITH_GRCONTEXT_SUPPORT_H_