gl_bindings_skia_cmd_buffer.cc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. // Copyright 2013 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 "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h"
  5. #include "base/logging.h"
  6. #include "base/memory/raw_ptr.h"
  7. #include "gpu/command_buffer/client/context_support.h"
  8. #include "gpu/command_buffer/client/gles2_interface.h"
  9. #include "third_party/skia/include/gpu/gl/GrGLInterface.h"
  10. using gpu::gles2::GLES2Interface;
  11. using gpu::ContextSupport;
  12. namespace {
  13. class ScopedCallingGLFromSkia {
  14. public:
  15. ScopedCallingGLFromSkia(ContextSupport* context_support)
  16. : context_support_(context_support) {
  17. context_support_->WillCallGLFromSkia();
  18. }
  19. ~ScopedCallingGLFromSkia() { context_support_->DidCallGLFromSkia(); }
  20. private:
  21. raw_ptr<ContextSupport> context_support_;
  22. };
  23. template <typename R, typename... Args>
  24. GrGLFunction<R GR_GL_FUNCTION_TYPE(Args...)> gles_bind(
  25. R (GLES2Interface::*func)(Args...),
  26. GLES2Interface* gles2_interface,
  27. ContextSupport* context_support) {
  28. if (context_support->HasGrContextSupport()) {
  29. return [func, context_support, gles2_interface](Args... args) {
  30. ScopedCallingGLFromSkia guard(context_support);
  31. return (gles2_interface->*func)(args...);
  32. };
  33. }
  34. // This fallback binding should only be used by unit tests which do not care
  35. // about GrContext::resetContext() getting called automatically.
  36. return [func, gles2_interface](Args... args) {
  37. return (gles2_interface->*func)(args...);
  38. };
  39. }
  40. } // namespace
  41. namespace skia_bindings {
  42. sk_sp<GrGLInterface> CreateGLES2InterfaceBindings(
  43. GLES2Interface* impl,
  44. ContextSupport* context_support) {
  45. sk_sp<GrGLInterface> interface(new GrGLInterface);
  46. interface->fStandard = kGLES_GrGLStandard;
  47. // Allowing Skia to use GL ES 3.0 caused a perf test regression (see Issue
  48. // 719572). Until that can be understood we are limiting to ES 2.0 (with
  49. // extensions).
  50. auto get_string = [impl](GLenum name) {
  51. if (name == GL_VERSION)
  52. return reinterpret_cast<const GLubyte*>("OpenGL ES 2.0 Chromium");
  53. return impl->GetString(name);
  54. };
  55. auto get_stringi =
  56. gles_bind(&GLES2Interface::GetStringi, impl, context_support);
  57. auto get_integerv =
  58. gles_bind(&GLES2Interface::GetIntegerv, impl, context_support);
  59. interface->fExtensions.init(kGLES_GrGLStandard, get_string, get_stringi,
  60. get_integerv);
  61. GrGLInterface::Functions* functions = &interface->fFunctions;
  62. functions->fActiveTexture =
  63. gles_bind(&GLES2Interface::ActiveTexture, impl, context_support);
  64. functions->fAttachShader =
  65. gles_bind(&GLES2Interface::AttachShader, impl, context_support);
  66. functions->fBindAttribLocation =
  67. gles_bind(&GLES2Interface::BindAttribLocation, impl, context_support);
  68. functions->fBindBuffer =
  69. gles_bind(&GLES2Interface::BindBuffer, impl, context_support);
  70. functions->fBindTexture =
  71. gles_bind(&GLES2Interface::BindTexture, impl, context_support);
  72. functions->fBindSampler =
  73. gles_bind(&GLES2Interface::BindSampler, impl, context_support);
  74. functions->fBindVertexArray =
  75. gles_bind(&GLES2Interface::BindVertexArrayOES, impl, context_support);
  76. functions->fBlendBarrier =
  77. gles_bind(&GLES2Interface::BlendBarrierKHR, impl, context_support);
  78. functions->fBlendColor =
  79. gles_bind(&GLES2Interface::BlendColor, impl, context_support);
  80. functions->fBlendEquation =
  81. gles_bind(&GLES2Interface::BlendEquation, impl, context_support);
  82. functions->fBlendFunc =
  83. gles_bind(&GLES2Interface::BlendFunc, impl, context_support);
  84. functions->fBufferData =
  85. gles_bind(&GLES2Interface::BufferData, impl, context_support);
  86. functions->fBufferSubData =
  87. gles_bind(&GLES2Interface::BufferSubData, impl, context_support);
  88. functions->fClear = gles_bind(&GLES2Interface::Clear, impl, context_support);
  89. functions->fClearColor =
  90. gles_bind(&GLES2Interface::ClearColor, impl, context_support);
  91. functions->fClearStencil =
  92. gles_bind(&GLES2Interface::ClearStencil, impl, context_support);
  93. functions->fClientWaitSync =
  94. gles_bind(&GLES2Interface::ClientWaitSync, impl, context_support);
  95. functions->fColorMask =
  96. gles_bind(&GLES2Interface::ColorMask, impl, context_support);
  97. functions->fCompileShader =
  98. gles_bind(&GLES2Interface::CompileShader, impl, context_support);
  99. functions->fCompressedTexImage2D =
  100. gles_bind(&GLES2Interface::CompressedTexImage2D, impl, context_support);
  101. functions->fCompressedTexSubImage2D = gles_bind(
  102. &GLES2Interface::CompressedTexSubImage2D, impl, context_support);
  103. functions->fCopyBufferSubData =
  104. gles_bind(&GLES2Interface::CopyBufferSubData, impl, context_support);
  105. functions->fCopyTexSubImage2D =
  106. gles_bind(&GLES2Interface::CopyTexSubImage2D, impl, context_support);
  107. functions->fCreateProgram =
  108. gles_bind(&GLES2Interface::CreateProgram, impl, context_support);
  109. functions->fCreateShader =
  110. gles_bind(&GLES2Interface::CreateShader, impl, context_support);
  111. functions->fCullFace =
  112. gles_bind(&GLES2Interface::CullFace, impl, context_support);
  113. functions->fDeleteBuffers =
  114. gles_bind(&GLES2Interface::DeleteBuffers, impl, context_support);
  115. functions->fDeleteProgram =
  116. gles_bind(&GLES2Interface::DeleteProgram, impl, context_support);
  117. functions->fDeleteSamplers =
  118. gles_bind(&GLES2Interface::DeleteSamplers, impl, context_support);
  119. functions->fDeleteShader =
  120. gles_bind(&GLES2Interface::DeleteShader, impl, context_support);
  121. functions->fDeleteSync =
  122. gles_bind(&GLES2Interface::DeleteSync, impl, context_support);
  123. functions->fDeleteTextures =
  124. gles_bind(&GLES2Interface::DeleteTextures, impl, context_support);
  125. functions->fDeleteVertexArrays =
  126. gles_bind(&GLES2Interface::DeleteVertexArraysOES, impl, context_support);
  127. functions->fDepthMask =
  128. gles_bind(&GLES2Interface::DepthMask, impl, context_support);
  129. functions->fDisable =
  130. gles_bind(&GLES2Interface::Disable, impl, context_support);
  131. functions->fDisableVertexAttribArray = gles_bind(
  132. &GLES2Interface::DisableVertexAttribArray, impl, context_support);
  133. functions->fDiscardFramebuffer =
  134. gles_bind(&GLES2Interface::DiscardFramebufferEXT, impl, context_support);
  135. functions->fDrawArrays =
  136. gles_bind(&GLES2Interface::DrawArrays, impl, context_support);
  137. functions->fDrawArraysInstanced = gles_bind(
  138. &GLES2Interface::DrawArraysInstancedANGLE, impl, context_support);
  139. functions->fDrawBuffers =
  140. gles_bind(&GLES2Interface::DrawBuffersEXT, impl, context_support);
  141. functions->fDrawElements =
  142. gles_bind(&GLES2Interface::DrawElements, impl, context_support);
  143. functions->fDrawElementsInstanced = gles_bind(
  144. &GLES2Interface::DrawElementsInstancedANGLE, impl, context_support);
  145. functions->fDrawRangeElements =
  146. gles_bind(&GLES2Interface::DrawRangeElements, impl, context_support);
  147. functions->fEnable =
  148. gles_bind(&GLES2Interface::Enable, impl, context_support);
  149. functions->fEnableVertexAttribArray = gles_bind(
  150. &GLES2Interface::EnableVertexAttribArray, impl, context_support);
  151. functions->fEndQuery =
  152. gles_bind(&GLES2Interface::EndQueryEXT, impl, context_support);
  153. functions->fFenceSync =
  154. gles_bind(&GLES2Interface::FenceSync, impl, context_support);
  155. functions->fFinish =
  156. gles_bind(&GLES2Interface::Finish, impl, context_support);
  157. functions->fFlush = gles_bind(&GLES2Interface::Flush, impl, context_support);
  158. functions->fFlushMappedBufferRange =
  159. gles_bind(&GLES2Interface::FlushMappedBufferRange, impl, context_support);
  160. functions->fFrontFace =
  161. gles_bind(&GLES2Interface::FrontFace, impl, context_support);
  162. functions->fGenBuffers =
  163. gles_bind(&GLES2Interface::GenBuffers, impl, context_support);
  164. functions->fGenSamplers =
  165. gles_bind(&GLES2Interface::GenSamplers, impl, context_support);
  166. functions->fGenTextures =
  167. gles_bind(&GLES2Interface::GenTextures, impl, context_support);
  168. functions->fGenVertexArrays =
  169. gles_bind(&GLES2Interface::GenVertexArraysOES, impl, context_support);
  170. functions->fGetBufferParameteriv =
  171. gles_bind(&GLES2Interface::GetBufferParameteriv, impl, context_support);
  172. functions->fGetError =
  173. gles_bind(&GLES2Interface::GetError, impl, context_support);
  174. functions->fGetFloatv =
  175. gles_bind(&GLES2Interface::GetFloatv, impl, context_support);
  176. functions->fGetIntegerv = get_integerv;
  177. functions->fGetInternalformativ =
  178. gles_bind(&GLES2Interface::GetInternalformativ, impl, context_support);
  179. functions->fGetProgramInfoLog =
  180. gles_bind(&GLES2Interface::GetProgramInfoLog, impl, context_support);
  181. functions->fGetProgramiv =
  182. gles_bind(&GLES2Interface::GetProgramiv, impl, context_support);
  183. functions->fGetQueryiv =
  184. gles_bind(&GLES2Interface::GetQueryivEXT, impl, context_support);
  185. functions->fGetQueryObjectuiv =
  186. gles_bind(&GLES2Interface::GetQueryObjectuivEXT, impl, context_support);
  187. functions->fGetShaderInfoLog =
  188. gles_bind(&GLES2Interface::GetShaderInfoLog, impl, context_support);
  189. functions->fGetShaderiv =
  190. gles_bind(&GLES2Interface::GetShaderiv, impl, context_support);
  191. functions->fGetShaderPrecisionFormat = gles_bind(
  192. &GLES2Interface::GetShaderPrecisionFormat, impl, context_support);
  193. functions->fGetString = get_string;
  194. functions->fGetStringi = get_stringi;
  195. functions->fGetUniformLocation =
  196. gles_bind(&GLES2Interface::GetUniformLocation, impl, context_support);
  197. functions->fInsertEventMarker =
  198. gles_bind(&GLES2Interface::InsertEventMarkerEXT, impl, context_support);
  199. functions->fInvalidateFramebuffer =
  200. gles_bind(&GLES2Interface::InvalidateFramebuffer, impl, context_support);
  201. functions->fInvalidateSubFramebuffer = gles_bind(
  202. &GLES2Interface::InvalidateSubFramebuffer, impl, context_support);
  203. functions->fIsSync =
  204. gles_bind(&GLES2Interface::IsSync, impl, context_support);
  205. functions->fIsTexture =
  206. gles_bind(&GLES2Interface::IsTexture, impl, context_support);
  207. functions->fLineWidth =
  208. gles_bind(&GLES2Interface::LineWidth, impl, context_support);
  209. functions->fLinkProgram =
  210. gles_bind(&GLES2Interface::LinkProgram, impl, context_support);
  211. functions->fMapBufferRange =
  212. gles_bind(&GLES2Interface::MapBufferRange, impl, context_support);
  213. functions->fMapBufferSubData = gles_bind(
  214. &GLES2Interface::MapBufferSubDataCHROMIUM, impl, context_support);
  215. functions->fMapTexSubImage2D = gles_bind(
  216. &GLES2Interface::MapTexSubImage2DCHROMIUM, impl, context_support);
  217. functions->fPixelStorei =
  218. gles_bind(&GLES2Interface::PixelStorei, impl, context_support);
  219. functions->fPopGroupMarker =
  220. gles_bind(&GLES2Interface::PopGroupMarkerEXT, impl, context_support);
  221. functions->fPushGroupMarker =
  222. gles_bind(&GLES2Interface::PushGroupMarkerEXT, impl, context_support);
  223. functions->fReadBuffer =
  224. gles_bind(&GLES2Interface::ReadBuffer, impl, context_support);
  225. functions->fReadPixels =
  226. gles_bind(&GLES2Interface::ReadPixels, impl, context_support);
  227. functions->fSamplerParameterf =
  228. gles_bind(&GLES2Interface::SamplerParameterf, impl, context_support);
  229. functions->fSamplerParameteri =
  230. gles_bind(&GLES2Interface::SamplerParameteri, impl, context_support);
  231. functions->fSamplerParameteriv =
  232. gles_bind(&GLES2Interface::SamplerParameteriv, impl, context_support);
  233. functions->fScissor =
  234. gles_bind(&GLES2Interface::Scissor, impl, context_support);
  235. functions->fShaderSource =
  236. gles_bind(&GLES2Interface::ShaderSource, impl, context_support);
  237. functions->fStencilFunc =
  238. gles_bind(&GLES2Interface::StencilFunc, impl, context_support);
  239. functions->fStencilFuncSeparate =
  240. gles_bind(&GLES2Interface::StencilFuncSeparate, impl, context_support);
  241. functions->fStencilMask =
  242. gles_bind(&GLES2Interface::StencilMask, impl, context_support);
  243. functions->fStencilMaskSeparate =
  244. gles_bind(&GLES2Interface::StencilMaskSeparate, impl, context_support);
  245. functions->fStencilOp =
  246. gles_bind(&GLES2Interface::StencilOp, impl, context_support);
  247. functions->fStencilOpSeparate =
  248. gles_bind(&GLES2Interface::StencilOpSeparate, impl, context_support);
  249. functions->fTexImage2D =
  250. gles_bind(&GLES2Interface::TexImage2D, impl, context_support);
  251. functions->fTexParameterf =
  252. gles_bind(&GLES2Interface::TexParameterf, impl, context_support);
  253. functions->fTexParameterfv =
  254. gles_bind(&GLES2Interface::TexParameterfv, impl, context_support);
  255. functions->fTexParameteri =
  256. gles_bind(&GLES2Interface::TexParameteri, impl, context_support);
  257. functions->fTexParameteriv =
  258. gles_bind(&GLES2Interface::TexParameteriv, impl, context_support);
  259. functions->fTexStorage2D =
  260. gles_bind(&GLES2Interface::TexStorage2DEXT, impl, context_support);
  261. functions->fTexSubImage2D =
  262. gles_bind(&GLES2Interface::TexSubImage2D, impl, context_support);
  263. functions->fUniform1f =
  264. gles_bind(&GLES2Interface::Uniform1f, impl, context_support);
  265. functions->fUniform1i =
  266. gles_bind(&GLES2Interface::Uniform1i, impl, context_support);
  267. functions->fUniform1fv =
  268. gles_bind(&GLES2Interface::Uniform1fv, impl, context_support);
  269. functions->fUniform1iv =
  270. gles_bind(&GLES2Interface::Uniform1iv, impl, context_support);
  271. functions->fUniform2f =
  272. gles_bind(&GLES2Interface::Uniform2f, impl, context_support);
  273. functions->fUniform2i =
  274. gles_bind(&GLES2Interface::Uniform2i, impl, context_support);
  275. functions->fUniform2fv =
  276. gles_bind(&GLES2Interface::Uniform2fv, impl, context_support);
  277. functions->fUniform2iv =
  278. gles_bind(&GLES2Interface::Uniform2iv, impl, context_support);
  279. functions->fUniform3f =
  280. gles_bind(&GLES2Interface::Uniform3f, impl, context_support);
  281. functions->fUniform3i =
  282. gles_bind(&GLES2Interface::Uniform3i, impl, context_support);
  283. functions->fUniform3fv =
  284. gles_bind(&GLES2Interface::Uniform3fv, impl, context_support);
  285. functions->fUniform3iv =
  286. gles_bind(&GLES2Interface::Uniform3iv, impl, context_support);
  287. functions->fUniform4f =
  288. gles_bind(&GLES2Interface::Uniform4f, impl, context_support);
  289. functions->fUniform4i =
  290. gles_bind(&GLES2Interface::Uniform4i, impl, context_support);
  291. functions->fUniform4fv =
  292. gles_bind(&GLES2Interface::Uniform4fv, impl, context_support);
  293. functions->fUniform4iv =
  294. gles_bind(&GLES2Interface::Uniform4iv, impl, context_support);
  295. functions->fUniformMatrix2fv =
  296. gles_bind(&GLES2Interface::UniformMatrix2fv, impl, context_support);
  297. functions->fUniformMatrix3fv =
  298. gles_bind(&GLES2Interface::UniformMatrix3fv, impl, context_support);
  299. functions->fUniformMatrix4fv =
  300. gles_bind(&GLES2Interface::UniformMatrix4fv, impl, context_support);
  301. functions->fUnmapBufferSubData = gles_bind(
  302. &GLES2Interface::UnmapBufferSubDataCHROMIUM, impl, context_support);
  303. functions->fUnmapTexSubImage2D = gles_bind(
  304. &GLES2Interface::UnmapTexSubImage2DCHROMIUM, impl, context_support);
  305. functions->fUseProgram =
  306. gles_bind(&GLES2Interface::UseProgram, impl, context_support);
  307. functions->fVertexAttrib1f =
  308. gles_bind(&GLES2Interface::VertexAttrib1f, impl, context_support);
  309. functions->fVertexAttrib2fv =
  310. gles_bind(&GLES2Interface::VertexAttrib2fv, impl, context_support);
  311. functions->fVertexAttrib3fv =
  312. gles_bind(&GLES2Interface::VertexAttrib3fv, impl, context_support);
  313. functions->fVertexAttrib4fv =
  314. gles_bind(&GLES2Interface::VertexAttrib4fv, impl, context_support);
  315. functions->fVertexAttribDivisor = gles_bind(
  316. &GLES2Interface::VertexAttribDivisorANGLE, impl, context_support);
  317. functions->fVertexAttribPointer =
  318. gles_bind(&GLES2Interface::VertexAttribPointer, impl, context_support);
  319. functions->fVertexAttribIPointer =
  320. gles_bind(&GLES2Interface::VertexAttribIPointer, impl, context_support);
  321. functions->fViewport =
  322. gles_bind(&GLES2Interface::Viewport, impl, context_support);
  323. functions->fWaitSync =
  324. gles_bind(&GLES2Interface::WaitSync, impl, context_support);
  325. functions->fBindFramebuffer =
  326. gles_bind(&GLES2Interface::BindFramebuffer, impl, context_support);
  327. functions->fBeginQuery =
  328. gles_bind(&GLES2Interface::BeginQueryEXT, impl, context_support);
  329. functions->fBindRenderbuffer =
  330. gles_bind(&GLES2Interface::BindRenderbuffer, impl, context_support);
  331. functions->fCheckFramebufferStatus =
  332. gles_bind(&GLES2Interface::CheckFramebufferStatus, impl, context_support);
  333. functions->fDeleteFramebuffers =
  334. gles_bind(&GLES2Interface::DeleteFramebuffers, impl, context_support);
  335. functions->fDeleteQueries =
  336. gles_bind(&GLES2Interface::DeleteQueriesEXT, impl, context_support);
  337. functions->fDeleteRenderbuffers =
  338. gles_bind(&GLES2Interface::DeleteRenderbuffers, impl, context_support);
  339. functions->fFramebufferRenderbuffer = gles_bind(
  340. &GLES2Interface::FramebufferRenderbuffer, impl, context_support);
  341. functions->fFramebufferTexture2D =
  342. gles_bind(&GLES2Interface::FramebufferTexture2D, impl, context_support);
  343. functions->fFramebufferTexture2DMultisample =
  344. gles_bind(&GLES2Interface::FramebufferTexture2DMultisampleEXT, impl,
  345. context_support);
  346. functions->fGenFramebuffers =
  347. gles_bind(&GLES2Interface::GenFramebuffers, impl, context_support);
  348. functions->fGenRenderbuffers =
  349. gles_bind(&GLES2Interface::GenRenderbuffers, impl, context_support);
  350. functions->fGetFramebufferAttachmentParameteriv =
  351. gles_bind(&GLES2Interface::GetFramebufferAttachmentParameteriv, impl,
  352. context_support);
  353. functions->fGetRenderbufferParameteriv = gles_bind(
  354. &GLES2Interface::GetRenderbufferParameteriv, impl, context_support);
  355. functions->fGenQueries =
  356. gles_bind(&GLES2Interface::GenQueriesEXT, impl, context_support);
  357. functions->fRenderbufferStorage =
  358. gles_bind(&GLES2Interface::RenderbufferStorage, impl, context_support);
  359. functions->fRenderbufferStorageMultisample =
  360. gles_bind(&GLES2Interface::RenderbufferStorageMultisampleCHROMIUM, impl,
  361. context_support);
  362. functions->fRenderbufferStorageMultisampleES2EXT =
  363. gles_bind(&GLES2Interface::RenderbufferStorageMultisampleEXT, impl,
  364. context_support);
  365. functions->fBindFragDataLocation = gles_bind(
  366. &GLES2Interface::BindFragDataLocationEXT, impl, context_support);
  367. functions->fBindFragDataLocationIndexed = gles_bind(
  368. &GLES2Interface::BindFragDataLocationIndexedEXT, impl, context_support);
  369. functions->fBindUniformLocation = gles_bind(
  370. &GLES2Interface::BindUniformLocationCHROMIUM, impl, context_support);
  371. functions->fBlitFramebuffer = gles_bind(
  372. &GLES2Interface::BlitFramebufferCHROMIUM, impl, context_support);
  373. functions->fGenerateMipmap =
  374. gles_bind(&GLES2Interface::GenerateMipmap, impl, context_support);
  375. functions->fCoverageModulation = gles_bind(
  376. &GLES2Interface::CoverageModulationCHROMIUM, impl, context_support);
  377. functions->fWindowRectangles =
  378. gles_bind(&GLES2Interface::WindowRectanglesEXT, impl, context_support);
  379. // Skia should not use program binaries over the command buffer. Allowing
  380. // clients to submit them would be unsafe, and we already cache program
  381. // binaries internally anyway.
  382. functions->fGetProgramBinary = [](GLuint, GLsizei, GLsizei*, GLenum*, void*) {
  383. LOG(FATAL) << "Skia shouldn't use program binaries over the command buffer";
  384. };
  385. functions->fProgramBinary = [](GLuint, GLenum, const void*, GLsizei) {
  386. LOG(FATAL) << "Skia shouldn't use program binaries over the command buffer";
  387. };
  388. functions->fProgramParameteri = [](GLuint, GLenum pname, GLint) {
  389. // This method is only used for GL_PROGRAM_BINARY_RETRIEVABLE_HINT in ES3.
  390. LOG(FATAL) << "Skia shouldn't use program binaries over the command buffer";
  391. };
  392. return interface;
  393. }
  394. } // namespace skia_bindings