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