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 fFenceSync; } |
30 | |
31 bool getGpuFrameLag(int* frameLag) const { | |
bsalomon
2015/06/23 14:09:20
getMaxGpuFrameLag?
I just don't want it to sound
Chris Dalton
2015/06/23 19:34:11
Done.
| |
32 if (!fFenceSync) { | |
33 return false; | |
34 } | |
35 *frameLag = SK_ARRAY_COUNT(fFrameFences) + 1; | |
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 SkAutoTDelete<SkGpuFenceSync> fFenceSync; | |
84 SkPlatformGpuFence fFrameFences[2]; | |
85 | |
53 /** Subclass provides the gl interface object if construction was | 86 /** Subclass provides the gl interface object if construction was |
54 * successful. */ | 87 * successful. */ |
55 SkAutoTUnref<const GrGLInterface> fGL; | 88 SkAutoTUnref<const GrGLInterface> fGL; |
56 | 89 |
90 friend class GLFenceSync; // For onPlatformGetProcAddress. | |
91 | |
57 typedef SkRefCnt INHERITED; | 92 typedef SkRefCnt INHERITED; |
58 }; | 93 }; |
59 | 94 |
60 /** Creates platform-dependent GL context object | 95 /** Creates platform-dependent GL context object |
61 * Returns a valid gl context object or NULL if such can not be created. | 96 * 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 | 97 * Note: If Skia embedder needs a custom GL context that sets up the GL |
63 * interface, this function should be implemented by the embedder. | 98 * interface, this function should be implemented by the embedder. |
64 * Otherwise, the default implementation for the platform should be compiled in | 99 * Otherwise, the default implementation for the platform should be compiled in |
65 * the library. | 100 * the library. |
66 */ | 101 */ |
67 SK_API SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI); | 102 SK_API SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI); |
68 | 103 |
69 /** | 104 /** |
70 * Helper macros for using the GL context through the GrGLInterface. Example: | 105 * Helper macros for using the GL context through the GrGLInterface. Example: |
71 * SK_GL(glCtx, GenTextures(1, &texID)); | 106 * SK_GL(glCtx, GenTextures(1, &texID)); |
72 */ | 107 */ |
73 #define SK_GL(ctx, X) (ctx).gl()->fFunctions.f ## X; \ | 108 #define SK_GL(ctx, X) (ctx).gl()->fFunctions.f ## X; \ |
74 SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) | 109 SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) |
75 #define SK_GL_RET(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X; \ | 110 #define SK_GL_RET(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X; \ |
76 SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) | 111 SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) |
77 #define SK_GL_NOERRCHECK(ctx, X) (ctx).gl()->fFunctions.f ## X | 112 #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 | 113 #define SK_GL_RET_NOERRCHECK(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X |
79 | 114 |
80 #endif | 115 #endif |
OLD | NEW |