OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 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 #ifndef SkGLContext_DEFINED | 8 #ifndef SkGLContext_DEFINED |
9 #define SkGLContext_DEFINED | 9 #define SkGLContext_DEFINED |
10 | 10 |
11 #include "GrGLInterface.h" | 11 #include "GrGLInterface.h" |
12 #include "../private/SkGpuFenceSync.h" | 12 #include "../private/SkGpuFenceSync.h" |
13 | 13 |
14 /** | 14 /** |
15 * Create an offscreen opengl context with an RGBA8 / 8bit stencil FBO. | 15 * Create an offscreen opengl context with an RGBA8 / 8bit stencil FBO. |
16 * Provides a GrGLInterface struct of function pointers for the context. | 16 * Provides a GrGLInterface struct of function pointers for the context. |
| 17 * This class is intended for Skia's testing needs and not for general |
| 18 * use. |
17 */ | 19 */ |
18 | |
19 class SK_API SkGLContext : public SkRefCnt { | 20 class SK_API SkGLContext : public SkRefCnt { |
20 public: | 21 public: |
21 ~SkGLContext() override; | 22 ~SkGLContext() override; |
22 | 23 |
23 bool isValid() const { return NULL != gl(); } | 24 bool isValid() const { return NULL != gl(); } |
24 | 25 |
25 const GrGLInterface* gl() const { return fGL.get(); } | 26 const GrGLInterface* gl() const { return fGL.get(); } |
26 | 27 |
27 bool fenceSyncSupport() const { return SkToBool(fFenceSync); } | 28 bool fenceSyncSupport() const { return SkToBool(fFenceSync); } |
28 | 29 |
29 bool getMaxGpuFrameLag(int* maxFrameLag) const { | 30 bool getMaxGpuFrameLag(int* maxFrameLag) const { |
30 if (!fFenceSync) { | 31 if (!fFenceSync) { |
31 return false; | 32 return false; |
32 } | 33 } |
33 *maxFrameLag = kMaxFrameLag; | 34 *maxFrameLag = kMaxFrameLag; |
34 return true; | 35 return true; |
35 } | 36 } |
36 | 37 |
37 void makeCurrent() const; | 38 void makeCurrent() const; |
38 | 39 |
| 40 /** Used for testing EGLImage integration. Take a GL_TEXTURE_2D and wraps it
in an EGL Image */ |
| 41 virtual GrEGLImage texture2DToEGLImage(GrGLuint /*texID*/) const { return 0;
} |
| 42 virtual void destroyEGLImage(GrEGLImage) const {} |
| 43 |
| 44 /** |
| 45 * Used for testing EGLImage integration. Takes a EGLImage and wraps it in a |
| 46 * GL_TEXTURE_EXTERNAL_OES. |
| 47 */ |
| 48 virtual GrGLuint eglImageToExternalTexture(GrEGLImage) const { return 0; } |
| 49 |
39 /** | 50 /** |
40 * The only purpose of this function it to provide a means of scheduling | 51 * The only purpose of this function it to provide a means of scheduling |
41 * work on the GPU (since all of the subclasses create primary buffers for | 52 * work on the GPU (since all of the subclasses create primary buffers for |
42 * testing that are small and not meant to be rendered to the screen). | 53 * testing that are small and not meant to be rendered to the screen). |
43 * | 54 * |
44 * If the platform supports fence sync (OpenGL 3.2+ or EGL_KHR_fence_sync), | 55 * If the platform supports fence sync (OpenGL 3.2+ or EGL_KHR_fence_sync), |
45 * this will not swap any buffers, but rather emulate triple buffer | 56 * this will not swap any buffers, but rather emulate triple buffer |
46 * synchronization using fences. | 57 * synchronization using fences. |
47 * | 58 * |
48 * Otherwise it will call the platform SwapBuffers method. This may or may | 59 * Otherwise it will call the platform SwapBuffers method. This may or may |
49 * not perform some sort of synchronization, depending on whether the | 60 * not perform some sort of synchronization, depending on whether the |
50 * drawing surface provided by the platform is double buffered. | 61 * drawing surface provided by the platform is double buffered. |
51 */ | 62 */ |
52 void swapBuffers(); | 63 void swapBuffers(); |
53 | 64 |
54 /** | 65 /** |
55 * This notifies the context that we are deliberately testing abandoning | 66 * This notifies the context that we are deliberately testing abandoning |
56 * the context. It is useful for debugging contexts that would otherwise | 67 * the context. It is useful for debugging contexts that would otherwise |
57 * test that GPU resources are properly deleted. It also allows a debugging | 68 * test that GPU resources are properly deleted. It also allows a debugging |
58 * context to test that further GL calls are not made by Skia GPU code. | 69 * context to test that further GL calls are not made by Skia GPU code. |
59 */ | 70 */ |
60 void testAbandon(); | 71 void testAbandon(); |
61 | 72 |
| 73 /** |
| 74 * Creates a new GL context of the same type and makes the returned context
current |
| 75 * (if not null). |
| 76 */ |
| 77 virtual SkGLContext* createNew() const { return nullptr; } |
| 78 |
62 class GLFenceSync; // SkGpuFenceSync implementation that uses the OpenGL fu
nctionality. | 79 class GLFenceSync; // SkGpuFenceSync implementation that uses the OpenGL fu
nctionality. |
63 | 80 |
64 protected: | 81 protected: |
65 SkGLContext(); | 82 SkGLContext(); |
66 | 83 |
67 /* | 84 /* |
68 * Methods that sublcasses must call from their constructors and destructors
. | 85 * Methods that sublcasses must call from their constructors and destructors
. |
69 */ | 86 */ |
70 void init(const GrGLInterface*, SkGpuFenceSync* = NULL); | 87 void init(const GrGLInterface*, SkGpuFenceSync* = NULL); |
71 void teardown(); | 88 void teardown(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 * SK_GL(glCtx, GenTextures(1, &texID)); | 124 * SK_GL(glCtx, GenTextures(1, &texID)); |
108 */ | 125 */ |
109 #define SK_GL(ctx, X) (ctx).gl()->fFunctions.f ## X; \ | 126 #define SK_GL(ctx, X) (ctx).gl()->fFunctions.f ## X; \ |
110 SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) | 127 SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) |
111 #define SK_GL_RET(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X; \ | 128 #define SK_GL_RET(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X; \ |
112 SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) | 129 SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) |
113 #define SK_GL_NOERRCHECK(ctx, X) (ctx).gl()->fFunctions.f ## X | 130 #define SK_GL_NOERRCHECK(ctx, X) (ctx).gl()->fFunctions.f ## X |
114 #define SK_GL_RET_NOERRCHECK(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X | 131 #define SK_GL_RET_NOERRCHECK(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X |
115 | 132 |
116 #endif | 133 #endif |
OLD | NEW |