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 "../../src/gpu/SkGpuFenceSync.h" |
12 | 13 |
13 /** | 14 /** |
14 * Create an offscreen opengl context with an RGBA8 / 8bit stencil FBO. | 15 * Create an offscreen opengl context with an RGBA8 / 8bit stencil FBO. |
15 * Provides a GrGLInterface struct of function pointers for the context. | 16 * Provides a GrGLInterface struct of function pointers for the context. |
16 */ | 17 */ |
17 | 18 |
18 class SK_API SkGLContext : public SkRefCnt { | 19 class SK_API SkGLContext : public SkRefCnt { |
19 public: | 20 public: |
20 SK_DECLARE_INST_COUNT(SkGLContext) | 21 SK_DECLARE_INST_COUNT(SkGLContext) |
21 | 22 |
22 ~SkGLContext() override; | 23 ~SkGLContext() override; |
23 | 24 |
24 bool isValid() const { return NULL != gl(); } | 25 bool isValid() const { return NULL != gl(); } |
25 | 26 |
26 const GrGLInterface* gl() const { return fGL.get(); } | 27 const GrGLInterface* gl() const { return fGL.get(); } |
27 | 28 |
28 virtual void makeCurrent() const = 0; | 29 bool fenceSyncSupport() const { return SkToBool(fFenceSync); } |
| 30 |
| 31 bool getMaxGpuFrameLag(int* maxFrameLag) const { |
| 32 if (!fFenceSync) { |
| 33 return false; |
| 34 } |
| 35 *maxFrameLag = kMaxFrameLag; |
| 36 return true; |
| 37 } |
| 38 |
| 39 void makeCurrent() const; |
29 | 40 |
30 /** | 41 /** |
31 * The primary purpose of this function it to provide a means of scheduling | 42 * The only purpose of this function it to provide a means of scheduling |
32 * work on the GPU (since all of the subclasses create primary buffers for | 43 * work on the GPU (since all of the subclasses create primary buffers for |
33 * testing that are small and not meant to be rendered to the screen). | 44 * testing that are small and not meant to be rendered to the screen). |
34 * | 45 * |
35 * If the drawing surface provided by the platform is double buffered this | 46 * If the platform supports fence sync (OpenGL 3.2+ or EGL_KHR_fence_sync), |
36 * call will cause the platform to swap which buffer is currently being | 47 * this will not swap any buffers, but rather emulate triple buffer |
37 * targeted. If the current surface does not include a back buffer, this | 48 * synchronization using fences. |
38 * call has no effect. | 49 * |
| 50 * Otherwise it will call the platform SwapBuffers method. This may or may |
| 51 * not perform some sort of synchronization, depending on whether the |
| 52 * drawing surface provided by the platform is double buffered. |
39 */ | 53 */ |
40 virtual void swapBuffers() const = 0; | 54 void swapBuffers(); |
41 | 55 |
42 /** | 56 /** |
43 * This notifies the context that we are deliberately testing abandoning | 57 * This notifies the context that we are deliberately testing abandoning |
44 * the context. It is useful for debugging contexts that would otherwise | 58 * the context. It is useful for debugging contexts that would otherwise |
45 * test that GPU resources are properly deleted. It also allows a debugging | 59 * test that GPU resources are properly deleted. It also allows a debugging |
46 * context to test that further GL calls are not made by Skia GPU code. | 60 * context to test that further GL calls are not made by Skia GPU code. |
47 */ | 61 */ |
48 void testAbandon(); | 62 void testAbandon(); |
49 | 63 |
| 64 class GLFenceSync; // SkGpuFenceSync implementation that uses the OpenGL fu
nctionality. |
| 65 |
50 protected: | 66 protected: |
51 SkGLContext(); | 67 SkGLContext(); |
52 | 68 |
| 69 /* |
| 70 * Methods that sublcasses must call from their constructors and destructors
. |
| 71 */ |
| 72 void init(const GrGLInterface*, SkGpuFenceSync* = NULL); |
| 73 void teardown(); |
| 74 |
| 75 /* |
| 76 * Operations that have a platform-dependent implementation. |
| 77 */ |
| 78 virtual void onPlatformMakeCurrent() const = 0; |
| 79 virtual void onPlatformSwapBuffers() const = 0; |
| 80 virtual GrGLFuncPtr onPlatformGetProcAddress(const char*) const = 0; |
| 81 |
| 82 private: |
| 83 enum { kMaxFrameLag = 3 }; |
| 84 |
| 85 SkAutoTDelete<SkGpuFenceSync> fFenceSync; |
| 86 SkPlatformGpuFence fFrameFences[kMaxFrameLag - 1]; |
| 87 int fCurrentFenceIdx; |
| 88 |
53 /** Subclass provides the gl interface object if construction was | 89 /** Subclass provides the gl interface object if construction was |
54 * successful. */ | 90 * successful. */ |
55 SkAutoTUnref<const GrGLInterface> fGL; | 91 SkAutoTUnref<const GrGLInterface> fGL; |
56 | 92 |
| 93 friend class GLFenceSync; // For onPlatformGetProcAddress. |
| 94 |
57 typedef SkRefCnt INHERITED; | 95 typedef SkRefCnt INHERITED; |
58 }; | 96 }; |
59 | 97 |
60 /** Creates platform-dependent GL context object | 98 /** Creates platform-dependent GL context object |
61 * Returns a valid gl context object or NULL if such can not be created. | 99 * Returns a valid gl context object or NULL if such can not be created. |
62 * Note: If Skia embedder needs a custom GL context that sets up the GL | 100 * Note: If Skia embedder needs a custom GL context that sets up the GL |
63 * interface, this function should be implemented by the embedder. | 101 * interface, this function should be implemented by the embedder. |
64 * Otherwise, the default implementation for the platform should be compiled in | 102 * Otherwise, the default implementation for the platform should be compiled in |
65 * the library. | 103 * the library. |
66 */ | 104 */ |
67 SK_API SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI); | 105 SK_API SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI); |
68 | 106 |
69 /** | 107 /** |
70 * Helper macros for using the GL context through the GrGLInterface. Example: | 108 * Helper macros for using the GL context through the GrGLInterface. Example: |
71 * SK_GL(glCtx, GenTextures(1, &texID)); | 109 * SK_GL(glCtx, GenTextures(1, &texID)); |
72 */ | 110 */ |
73 #define SK_GL(ctx, X) (ctx).gl()->fFunctions.f ## X; \ | 111 #define SK_GL(ctx, X) (ctx).gl()->fFunctions.f ## X; \ |
74 SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) | 112 SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) |
75 #define SK_GL_RET(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X; \ | 113 #define SK_GL_RET(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X; \ |
76 SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) | 114 SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) |
77 #define SK_GL_NOERRCHECK(ctx, X) (ctx).gl()->fFunctions.f ## X | 115 #define SK_GL_NOERRCHECK(ctx, X) (ctx).gl()->fFunctions.f ## X |
78 #define SK_GL_RET_NOERRCHECK(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X | 116 #define SK_GL_RET_NOERRCHECK(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X |
79 | 117 |
80 #endif | 118 #endif |
OLD | NEW |