| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "gl/SkGLContext.h" | 8 #include "gl/SkGLContext.h" |
| 9 | 9 |
| 10 #include <GLES2/gl2.h> | 10 #include <GLES2/gl2.h> |
| 11 | 11 |
| 12 #define EGL_EGLEXT_PROTOTYPES | 12 #define EGL_EGLEXT_PROTOTYPES |
| 13 #include <EGL/egl.h> | 13 #include <EGL/egl.h> |
| 14 #include <EGL/eglext.h> | 14 #include <EGL/eglext.h> |
| 15 | 15 |
| 16 #include "gl/GrGLDefines.h" |
| 17 #include "gl/GrGLUtil.h" |
| 18 |
| 16 namespace { | 19 namespace { |
| 17 | 20 |
| 18 // TODO: Share this class with ANGLE if/when it gets support for EGL_KHR_fence_s
ync. | 21 // TODO: Share this class with ANGLE if/when it gets support for EGL_KHR_fence_s
ync. |
| 19 class SkEGLFenceSync : public SkGpuFenceSync { | 22 class SkEGLFenceSync : public SkGpuFenceSync { |
| 20 public: | 23 public: |
| 21 static SkEGLFenceSync* CreateIfSupported(EGLDisplay); | 24 static SkEGLFenceSync* CreateIfSupported(EGLDisplay); |
| 22 | 25 |
| 23 SkPlatformGpuFence SK_WARN_UNUSED_RESULT insertFence() const override; | 26 SkPlatformGpuFence SK_WARN_UNUSED_RESULT insertFence() const override; |
| 24 bool flushAndWaitFence(SkPlatformGpuFence fence) const override; | 27 bool flushAndWaitFence(SkPlatformGpuFence fence) const override; |
| 25 void deleteFence(SkPlatformGpuFence fence) const override; | 28 void deleteFence(SkPlatformGpuFence fence) const override; |
| 26 | 29 |
| 27 private: | 30 private: |
| 28 SkEGLFenceSync(EGLDisplay display) : fDisplay(display) {} | 31 SkEGLFenceSync(EGLDisplay display) : fDisplay(display) {} |
| 29 | 32 |
| 30 EGLDisplay fDisplay; | 33 EGLDisplay fDisplay; |
| 31 | 34 |
| 32 typedef SkGpuFenceSync INHERITED; | 35 typedef SkGpuFenceSync INHERITED; |
| 33 }; | 36 }; |
| 34 | 37 |
| 35 class EGLGLContext : public SkGLContext { | 38 class EGLGLContext : public SkGLContext { |
| 36 public: | 39 public: |
| 37 EGLGLContext(GrGLStandard forcedGpuAPI); | 40 EGLGLContext(GrGLStandard forcedGpuAPI); |
| 38 ~EGLGLContext() override; | 41 ~EGLGLContext() override; |
| 39 | 42 |
| 43 GrEGLImage texture2DToEGLImage(GrGLuint texID) const override; |
| 44 void destroyEGLImage(GrEGLImage) const override; |
| 45 GrGLuint eglImageToExternalTexture(GrEGLImage) const override; |
| 46 SkGLContext* createNew() const override; |
| 47 |
| 40 private: | 48 private: |
| 41 void destroyGLContext(); | 49 void destroyGLContext(); |
| 42 | 50 |
| 43 void onPlatformMakeCurrent() const override; | 51 void onPlatformMakeCurrent() const override; |
| 44 void onPlatformSwapBuffers() const override; | 52 void onPlatformSwapBuffers() const override; |
| 45 GrGLFuncPtr onPlatformGetProcAddress(const char*) const override; | 53 GrGLFuncPtr onPlatformGetProcAddress(const char*) const override; |
| 46 | 54 |
| 47 EGLContext fContext; | 55 EGLContext fContext; |
| 48 EGLDisplay fDisplay; | 56 EGLDisplay fDisplay; |
| 49 EGLSurface fSurface; | 57 EGLSurface fSurface; |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 if (fSurface) { | 201 if (fSurface) { |
| 194 eglDestroySurface(fDisplay, fSurface); | 202 eglDestroySurface(fDisplay, fSurface); |
| 195 fSurface = EGL_NO_SURFACE; | 203 fSurface = EGL_NO_SURFACE; |
| 196 } | 204 } |
| 197 | 205 |
| 198 //TODO should we close the display? | 206 //TODO should we close the display? |
| 199 fDisplay = EGL_NO_DISPLAY; | 207 fDisplay = EGL_NO_DISPLAY; |
| 200 } | 208 } |
| 201 } | 209 } |
| 202 | 210 |
| 211 GrEGLImage EGLGLContext::texture2DToEGLImage(GrGLuint texID) const { |
| 212 if (!this->gl()->hasExtension("EGL_KHR_gl_texture_2D_image")) { |
| 213 return GR_EGL_NO_IMAGE; |
| 214 } |
| 215 GrEGLImage img; |
| 216 GrEGLint attribs[] = { GR_EGL_GL_TEXTURE_LEVEL, 0, GR_EGL_NONE }; |
| 217 GrEGLClientBuffer clientBuffer = reinterpret_cast<GrEGLClientBuffer>(texID); |
| 218 GR_GL_CALL_RET(this->gl(), img, |
| 219 EGLCreateImage(fDisplay, fContext, GR_EGL_GL_TEXTURE_2D, clie
ntBuffer, attribs)); |
| 220 return img; |
| 221 } |
| 222 |
| 223 void EGLGLContext::destroyEGLImage(GrEGLImage image) const { |
| 224 GR_GL_CALL(this->gl(), EGLDestroyImage(fDisplay, image)); |
| 225 } |
| 226 |
| 227 GrGLuint EGLGLContext::eglImageToExternalTexture(GrEGLImage image) const { |
| 228 GrGLClearErr(this->gl()); |
| 229 if (!this->gl()->hasExtension("GL_OES_EGL_image_external")) { |
| 230 return 0; |
| 231 } |
| 232 GrGLEGLImageTargetTexture2DProc glEGLImageTargetTexture2D = |
| 233 (GrGLEGLImageTargetTexture2DProc) eglGetProcAddress("glEGLImageTarge
tTexture2DOES"); |
| 234 if (!glEGLImageTargetTexture2D) { |
| 235 return 0; |
| 236 } |
| 237 GrGLuint texID; |
| 238 glGenTextures(1, &texID); |
| 239 if (!texID) { |
| 240 return 0; |
| 241 } |
| 242 glBindTexture(GR_GL_TEXTURE_EXTERNAL, texID); |
| 243 if (glGetError() != GR_GL_NO_ERROR) { |
| 244 glDeleteTextures(1, &texID); |
| 245 return 0; |
| 246 } |
| 247 glEGLImageTargetTexture2D(GR_GL_TEXTURE_EXTERNAL, image); |
| 248 if (glGetError() != GR_GL_NO_ERROR) { |
| 249 glDeleteTextures(1, &texID); |
| 250 return 0; |
| 251 } |
| 252 return texID; |
| 253 } |
| 254 |
| 255 SkGLContext* EGLGLContext::createNew() const { |
| 256 SkGLContext* ctx = SkCreatePlatformGLContext(this->gl()->fStandard); |
| 257 if (ctx) { |
| 258 ctx->makeCurrent(); |
| 259 } |
| 260 return ctx; |
| 261 } |
| 203 | 262 |
| 204 void EGLGLContext::onPlatformMakeCurrent() const { | 263 void EGLGLContext::onPlatformMakeCurrent() const { |
| 205 if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { | 264 if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { |
| 206 SkDebugf("Could not set the context.\n"); | 265 SkDebugf("Could not set the context.\n"); |
| 207 } | 266 } |
| 208 } | 267 } |
| 209 | 268 |
| 210 void EGLGLContext::onPlatformSwapBuffers() const { | 269 void EGLGLContext::onPlatformSwapBuffers() const { |
| 211 if (!eglSwapBuffers(fDisplay, fSurface)) { | 270 if (!eglSwapBuffers(fDisplay, fSurface)) { |
| 212 SkDebugf("Could not complete eglSwapBuffers.\n"); | 271 SkDebugf("Could not complete eglSwapBuffers.\n"); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 | 319 |
| 261 SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI) { | 320 SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI) { |
| 262 EGLGLContext* ctx = new EGLGLContext(forcedGpuAPI); | 321 EGLGLContext* ctx = new EGLGLContext(forcedGpuAPI); |
| 263 if (!ctx->isValid()) { | 322 if (!ctx->isValid()) { |
| 264 delete ctx; | 323 delete ctx; |
| 265 return nullptr; | 324 return nullptr; |
| 266 } | 325 } |
| 267 return ctx; | 326 return ctx; |
| 268 } | 327 } |
| 269 | 328 |
| OLD | NEW |