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. | |
19 */ | 17 */ |
| 18 |
20 class SK_API SkGLContext : public SkRefCnt { | 19 class SK_API SkGLContext : public SkRefCnt { |
21 public: | 20 public: |
22 ~SkGLContext() override; | 21 ~SkGLContext() override; |
23 | 22 |
24 bool isValid() const { return NULL != gl(); } | 23 bool isValid() const { return NULL != gl(); } |
25 | 24 |
26 const GrGLInterface* gl() const { return fGL.get(); } | 25 const GrGLInterface* gl() const { return fGL.get(); } |
27 | 26 |
28 bool fenceSyncSupport() const { return SkToBool(fFenceSync); } | 27 bool fenceSyncSupport() const { return SkToBool(fFenceSync); } |
29 | 28 |
30 bool getMaxGpuFrameLag(int* maxFrameLag) const { | 29 bool getMaxGpuFrameLag(int* maxFrameLag) const { |
31 if (!fFenceSync) { | 30 if (!fFenceSync) { |
32 return false; | 31 return false; |
33 } | 32 } |
34 *maxFrameLag = kMaxFrameLag; | 33 *maxFrameLag = kMaxFrameLag; |
35 return true; | 34 return true; |
36 } | 35 } |
37 | 36 |
38 void makeCurrent() const; | 37 void makeCurrent() const; |
39 | 38 |
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 | |
50 /** | 39 /** |
51 * The only purpose of this function it to provide a means of scheduling | 40 * The only purpose of this function it to provide a means of scheduling |
52 * work on the GPU (since all of the subclasses create primary buffers for | 41 * work on the GPU (since all of the subclasses create primary buffers for |
53 * testing that are small and not meant to be rendered to the screen). | 42 * testing that are small and not meant to be rendered to the screen). |
54 * | 43 * |
55 * If the platform supports fence sync (OpenGL 3.2+ or EGL_KHR_fence_sync), | 44 * If the platform supports fence sync (OpenGL 3.2+ or EGL_KHR_fence_sync), |
56 * this will not swap any buffers, but rather emulate triple buffer | 45 * this will not swap any buffers, but rather emulate triple buffer |
57 * synchronization using fences. | 46 * synchronization using fences. |
58 * | 47 * |
59 * Otherwise it will call the platform SwapBuffers method. This may or may | 48 * Otherwise it will call the platform SwapBuffers method. This may or may |
60 * not perform some sort of synchronization, depending on whether the | 49 * not perform some sort of synchronization, depending on whether the |
61 * drawing surface provided by the platform is double buffered. | 50 * drawing surface provided by the platform is double buffered. |
62 */ | 51 */ |
63 void swapBuffers(); | 52 void swapBuffers(); |
64 | 53 |
65 /** | 54 /** |
66 * This notifies the context that we are deliberately testing abandoning | 55 * This notifies the context that we are deliberately testing abandoning |
67 * the context. It is useful for debugging contexts that would otherwise | 56 * the context. It is useful for debugging contexts that would otherwise |
68 * test that GPU resources are properly deleted. It also allows a debugging | 57 * test that GPU resources are properly deleted. It also allows a debugging |
69 * context to test that further GL calls are not made by Skia GPU code. | 58 * context to test that further GL calls are not made by Skia GPU code. |
70 */ | 59 */ |
71 void testAbandon(); | 60 void testAbandon(); |
72 | 61 |
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 | |
79 class GLFenceSync; // SkGpuFenceSync implementation that uses the OpenGL fu
nctionality. | 62 class GLFenceSync; // SkGpuFenceSync implementation that uses the OpenGL fu
nctionality. |
80 | 63 |
81 protected: | 64 protected: |
82 SkGLContext(); | 65 SkGLContext(); |
83 | 66 |
84 /* | 67 /* |
85 * Methods that sublcasses must call from their constructors and destructors
. | 68 * Methods that sublcasses must call from their constructors and destructors
. |
86 */ | 69 */ |
87 void init(const GrGLInterface*, SkGpuFenceSync* = NULL); | 70 void init(const GrGLInterface*, SkGpuFenceSync* = NULL); |
88 void teardown(); | 71 void teardown(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 * SK_GL(glCtx, GenTextures(1, &texID)); | 107 * SK_GL(glCtx, GenTextures(1, &texID)); |
125 */ | 108 */ |
126 #define SK_GL(ctx, X) (ctx).gl()->fFunctions.f ## X; \ | 109 #define SK_GL(ctx, X) (ctx).gl()->fFunctions.f ## X; \ |
127 SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) | 110 SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) |
128 #define SK_GL_RET(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X; \ | 111 #define SK_GL_RET(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X; \ |
129 SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) | 112 SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) |
130 #define SK_GL_NOERRCHECK(ctx, X) (ctx).gl()->fFunctions.f ## X | 113 #define SK_GL_NOERRCHECK(ctx, X) (ctx).gl()->fFunctions.f ## X |
131 #define SK_GL_RET_NOERRCHECK(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X | 114 #define SK_GL_RET_NOERRCHECK(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X |
132 | 115 |
133 #endif | 116 #endif |
OLD | NEW |