OLD | NEW |
| 1 |
1 /* | 2 /* |
2 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
3 * | 4 * |
4 * 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 |
5 * found in the LICENSE file. | 6 * found in the LICENSE file. |
6 */ | 7 */ |
7 #include "gl/SkGLContext.h" | 8 #include "gl/GLContext.h" |
8 | 9 |
9 #include <GLES2/gl2.h> | 10 #include <GLES2/gl2.h> |
10 | 11 |
11 #define EGL_EGLEXT_PROTOTYPES | 12 #define EGL_EGLEXT_PROTOTYPES |
12 #include <EGL/egl.h> | 13 #include <EGL/egl.h> |
13 #include <EGL/eglext.h> | 14 #include <EGL/eglext.h> |
14 | 15 |
15 #include "gl/GrGLDefines.h" | 16 #include "gl/GrGLDefines.h" |
16 #include "gl/GrGLUtil.h" | 17 #include "gl/GrGLUtil.h" |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 // 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. |
21 class SkEGLFenceSync : public SkGpuFenceSync { | 22 class SkEGLFenceSync : public SkGpuFenceSync { |
22 public: | 23 public: |
23 static SkEGLFenceSync* CreateIfSupported(EGLDisplay); | 24 static SkEGLFenceSync* CreateIfSupported(EGLDisplay); |
24 | 25 |
25 SkPlatformGpuFence SK_WARN_UNUSED_RESULT insertFence() const override; | 26 SkPlatformGpuFence SK_WARN_UNUSED_RESULT insertFence() const override; |
26 bool waitFence(SkPlatformGpuFence fence, bool flush) const override; | 27 bool waitFence(SkPlatformGpuFence fence, bool flush) const override; |
27 void deleteFence(SkPlatformGpuFence fence) const override; | 28 void deleteFence(SkPlatformGpuFence fence) const override; |
28 | 29 |
29 private: | 30 private: |
30 SkEGLFenceSync(EGLDisplay display) : fDisplay(display) {} | 31 SkEGLFenceSync(EGLDisplay display) : fDisplay(display) {} |
31 | 32 |
32 EGLDisplay fDisplay; | 33 EGLDisplay fDisplay; |
33 | 34 |
34 typedef SkGpuFenceSync INHERITED; | 35 typedef SkGpuFenceSync INHERITED; |
35 }; | 36 }; |
36 | 37 |
37 class EGLGLContext : public SkGLContext { | 38 class EGLGLContext : public sk_gpu_test::GLContext { |
38 public: | 39 public: |
39 EGLGLContext(GrGLStandard forcedGpuAPI); | 40 EGLGLContext(GrGLStandard forcedGpuAPI); |
40 ~EGLGLContext() override; | 41 ~EGLGLContext() override; |
41 | 42 |
42 GrEGLImage texture2DToEGLImage(GrGLuint texID) const override; | 43 GrEGLImage texture2DToEGLImage(GrGLuint texID) const override; |
43 void destroyEGLImage(GrEGLImage) const override; | 44 void destroyEGLImage(GrEGLImage) const override; |
44 GrGLuint eglImageToExternalTexture(GrEGLImage) const override; | 45 GrGLuint eglImageToExternalTexture(GrEGLImage) const override; |
45 SkGLContext* createNew() const override; | 46 sk_gpu_test::GLContext* createNew() const override; |
46 | 47 |
47 private: | 48 private: |
48 void destroyGLContext(); | 49 void destroyGLContext(); |
49 | 50 |
50 void onPlatformMakeCurrent() const override; | 51 void onPlatformMakeCurrent() const override; |
51 void onPlatformSwapBuffers() const override; | 52 void onPlatformSwapBuffers() const override; |
52 GrGLFuncPtr onPlatformGetProcAddress(const char*) const override; | 53 GrGLFuncPtr onPlatformGetProcAddress(const char*) const override; |
53 | 54 |
54 EGLContext fContext; | 55 EGLContext fContext; |
55 EGLDisplay fDisplay; | 56 EGLDisplay fDisplay; |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 return 0; | 247 return 0; |
247 } | 248 } |
248 glEGLImageTargetTexture2D(GR_GL_TEXTURE_EXTERNAL, image); | 249 glEGLImageTargetTexture2D(GR_GL_TEXTURE_EXTERNAL, image); |
249 if (glGetError() != GR_GL_NO_ERROR) { | 250 if (glGetError() != GR_GL_NO_ERROR) { |
250 glDeleteTextures(1, &texID); | 251 glDeleteTextures(1, &texID); |
251 return 0; | 252 return 0; |
252 } | 253 } |
253 return texID; | 254 return texID; |
254 } | 255 } |
255 | 256 |
256 SkGLContext* EGLGLContext::createNew() const { | 257 sk_gpu_test::GLContext* EGLGLContext::createNew() const { |
257 SkGLContext* ctx = SkCreatePlatformGLContext(this->gl()->fStandard); | 258 sk_gpu_test::GLContext* ctx = new EGLGLContext(this->gl()->fStandard); |
258 if (ctx) { | 259 if (ctx) { |
259 ctx->makeCurrent(); | 260 ctx->makeCurrent(); |
260 } | 261 } |
261 return ctx; | 262 return ctx; |
262 } | 263 } |
263 | 264 |
264 void EGLGLContext::onPlatformMakeCurrent() const { | 265 void EGLGLContext::onPlatformMakeCurrent() const { |
265 if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { | 266 if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { |
266 SkDebugf("Could not set the context.\n"); | 267 SkDebugf("Could not set the context.\n"); |
267 } | 268 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 eglsync, | 311 eglsync, |
311 flush ? EGL_SYNC_FLUSH_COMMANDS_BIT_KHR : 0, | 312 flush ? EGL_SYNC_FLUSH_COMMANDS_BIT_KHR : 0, |
312 EGL_FOREVER_KHR); | 313 EGL_FOREVER_KHR); |
313 } | 314 } |
314 | 315 |
315 void SkEGLFenceSync::deleteFence(SkPlatformGpuFence platformFence) const { | 316 void SkEGLFenceSync::deleteFence(SkPlatformGpuFence platformFence) const { |
316 EGLSyncKHR eglsync = static_cast<EGLSyncKHR>(platformFence); | 317 EGLSyncKHR eglsync = static_cast<EGLSyncKHR>(platformFence); |
317 eglDestroySyncKHR(fDisplay, eglsync); | 318 eglDestroySyncKHR(fDisplay, eglsync); |
318 } | 319 } |
319 | 320 |
320 } // anonymous namespace | 321 } // anonymous namespace |
321 | 322 |
322 SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI, SkGLContext* s
hareContext) { | 323 namespace sk_gpu_test { |
| 324 GLContext *CreatePlatformGLContext(GrGLStandard forcedGpuAPI, GLContext *shareCo
ntext) { |
323 SkASSERT(!shareContext); | 325 SkASSERT(!shareContext); |
324 if (shareContext) { | 326 if (shareContext) { |
325 return nullptr; | 327 return nullptr; |
326 } | 328 } |
327 EGLGLContext* ctx = new EGLGLContext(forcedGpuAPI); | 329 EGLGLContext *ctx = new EGLGLContext(forcedGpuAPI); |
328 if (!ctx->isValid()) { | 330 if (!ctx->isValid()) { |
329 delete ctx; | 331 delete ctx; |
330 return nullptr; | 332 return nullptr; |
331 } | 333 } |
332 return ctx; | 334 return ctx; |
333 } | 335 } |
| 336 } // namespace sk_gpu_test |
| 337 |
OLD | NEW |