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 GLContext_DEFINED |
9 #define SkGLContext_DEFINED | 9 #define GLContext_DEFINED |
10 | 10 |
11 #include "GrGLInterface.h" | 11 #include "gl/GrGLInterface.h" |
12 #include "../private/SkGpuFenceSync.h" | 12 #include "../private/SkGpuFenceSync.h" |
13 | 13 |
14 | |
15 namespace sk_gpu_test { | |
14 /** | 16 /** |
15 * Create an offscreen opengl context with an RGBA8 / 8bit stencil FBO. | 17 * Create an offscreen Oppengl context. Provides a GrGLInterface struct of funct ion pointers for |
jvanverth1
2016/03/29 14:45:09
OpenGL
bsalomon
2016/03/29 17:07:59
Done.
| |
16 * Provides a GrGLInterface struct of function pointers for the context. | 18 * the context. This class is intended for Skia's internal testing needs and not for general use. |
17 * This class is intended for Skia's testing needs and not for general | |
18 * use. | |
19 */ | 19 */ |
20 class SK_API SkGLContext : public SkNoncopyable { | 20 class GLContext : public SkNoncopyable { |
21 public: | 21 public: |
22 virtual ~SkGLContext(); | 22 virtual ~GLContext(); |
23 | 23 |
24 bool isValid() const { return NULL != gl(); } | 24 bool isValid() const { return NULL != gl(); } |
25 | 25 |
26 const GrGLInterface* gl() const { return fGL.get(); } | 26 const GrGLInterface *gl() const { return fGL.get(); } |
jvanverth1
2016/03/29 14:45:09
Not a big deal, but why did you change this to a C
bsalomon
2016/03/29 17:07:59
Stupid IDE not remembering my code style prefs.
| |
27 | 27 |
28 bool fenceSyncSupport() const { return fFenceSync != nullptr; } | 28 bool fenceSyncSupport() const { return fFenceSync != nullptr; } |
29 | 29 |
30 bool getMaxGpuFrameLag(int* maxFrameLag) const { | 30 bool getMaxGpuFrameLag(int *maxFrameLag) const { |
31 if (!fFenceSync) { | 31 if (!fFenceSync) { |
32 return false; | 32 return false; |
33 } | 33 } |
34 *maxFrameLag = kMaxFrameLag; | 34 *maxFrameLag = kMaxFrameLag; |
35 return true; | 35 return true; |
36 } | 36 } |
37 | 37 |
38 void makeCurrent() const; | 38 void makeCurrent() const; |
39 | 39 |
40 /** Used for testing EGLImage integration. Take a GL_TEXTURE_2D and wraps it in an EGL Image */ | 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; } | 41 virtual GrEGLImage texture2DToEGLImage(GrGLuint /*texID*/) const { return 0; } |
42 virtual void destroyEGLImage(GrEGLImage) const {} | 42 |
43 virtual void destroyEGLImage(GrEGLImage) const { } | |
43 | 44 |
44 /** Used for testing GL_TEXTURE_RECTANGLE integration. */ | 45 /** Used for testing GL_TEXTURE_RECTANGLE integration. */ |
45 GrGLint createTextureRectangle(int width, int height, GrGLenum internalForma t, | 46 GrGLint createTextureRectangle(int width, int height, GrGLenum internalForma t, |
46 GrGLenum externalFormat, GrGLenum externalTyp e, | 47 GrGLenum externalFormat, GrGLenum externalTyp e, |
47 GrGLvoid* data); | 48 GrGLvoid* data); |
48 | 49 |
49 /** | 50 /** |
50 * Used for testing EGLImage integration. Takes a EGLImage and wraps it in a | 51 * Used for testing EGLImage integration. Takes a EGLImage and wraps it in a |
51 * GL_TEXTURE_EXTERNAL_OES. | 52 * GL_TEXTURE_EXTERNAL_OES. |
52 */ | 53 */ |
(...skipping 21 matching lines...) Expand all Loading... | |
74 * the context. It is useful for debugging contexts that would otherwise | 75 * the context. It is useful for debugging contexts that would otherwise |
75 * test that GPU resources are properly deleted. It also allows a debugging | 76 * test that GPU resources are properly deleted. It also allows a debugging |
76 * context to test that further GL calls are not made by Skia GPU code. | 77 * context to test that further GL calls are not made by Skia GPU code. |
77 */ | 78 */ |
78 void testAbandon(); | 79 void testAbandon(); |
79 | 80 |
80 /** | 81 /** |
81 * Creates a new GL context of the same type and makes the returned context current | 82 * Creates a new GL context of the same type and makes the returned context current |
82 * (if not null). | 83 * (if not null). |
83 */ | 84 */ |
84 virtual SkGLContext* createNew() const { return nullptr; } | 85 virtual GLContext *createNew() const { return nullptr; } |
85 | 86 |
86 class GLFenceSync; // SkGpuFenceSync implementation that uses the OpenGL fu nctionality. | 87 class GLFenceSync; // SkGpuFenceSync implementation that uses the OpenGL fu nctionality. |
87 | 88 |
88 /* | 89 /* |
89 * returns the fencesync object owned by this SkGLContext | 90 * returns the fencesync object owned by this GLContext |
90 */ | 91 */ |
91 SkGpuFenceSync* fenceSync() { return fFenceSync.get(); } | 92 SkGpuFenceSync *fenceSync() { return fFenceSync.get(); } |
92 | 93 |
93 protected: | 94 protected: |
94 SkGLContext(); | 95 GLContext(); |
95 | 96 |
96 /* | 97 /* |
97 * Methods that sublcasses must call from their constructors and destructors . | 98 * Methods that sublcasses must call from their constructors and destructors . |
98 */ | 99 */ |
99 void init(const GrGLInterface*, SkGpuFenceSync* = NULL); | 100 void init(const GrGLInterface *, SkGpuFenceSync * = NULL); |
101 | |
100 void teardown(); | 102 void teardown(); |
101 | 103 |
102 /* | 104 /* |
103 * Operations that have a platform-dependent implementation. | 105 * Operations that have a platform-dependent implementation. |
104 */ | 106 */ |
105 virtual void onPlatformMakeCurrent() const = 0; | 107 virtual void onPlatformMakeCurrent() const = 0; |
108 | |
106 virtual void onPlatformSwapBuffers() const = 0; | 109 virtual void onPlatformSwapBuffers() const = 0; |
107 virtual GrGLFuncPtr onPlatformGetProcAddress(const char*) const = 0; | 110 |
111 virtual GrGLFuncPtr onPlatformGetProcAddress(const char *) const = 0; | |
108 | 112 |
109 private: | 113 private: |
110 enum { kMaxFrameLag = 3 }; | 114 enum { kMaxFrameLag = 3 }; |
111 | 115 |
112 SkAutoTDelete<SkGpuFenceSync> fFenceSync; | 116 SkAutoTDelete<SkGpuFenceSync> fFenceSync; |
113 SkPlatformGpuFence fFrameFences[kMaxFrameLag - 1]; | 117 SkPlatformGpuFence fFrameFences[kMaxFrameLag - 1]; |
114 int fCurrentFenceIdx; | 118 int fCurrentFenceIdx; |
115 | 119 |
116 /** Subclass provides the gl interface object if construction was | 120 /** Subclass provides the gl interface object if construction was |
117 * successful. */ | 121 * successful. */ |
118 SkAutoTUnref<const GrGLInterface> fGL; | 122 SkAutoTUnref<const GrGLInterface> fGL; |
119 | 123 |
120 friend class GLFenceSync; // For onPlatformGetProcAddress. | 124 friend class GLFenceSync; // For onPlatformGetProcAddress. |
121 }; | 125 }; |
122 | 126 |
123 /** Creates platform-dependent GL context object. The shareContext parameter is in an optional | 127 /** |
124 * context with which to share display lists. This should be a pointer to an SkG LContext created | 128 * Creates platform-dependent GL context object. The shareContext parameter is in an optional |
125 * with SkCreatePlatformGLContext. NULL indicates that no sharing is to take pl ace. Returns a valid | 129 * context with which to share display lists. This should be a pointer to an GLC ontext created |
126 * gl context object or NULL if such can not be created. | 130 * with CreatePlatformGLContext. nullptr indicates that no sharing is to take pl ace. Returns a valid |
127 * Note: If Skia embedder needs a custom GL context that sets up the GL interfac e, this function | 131 * gl context object or nullptr if such can not be created. |
128 * should be implemented by the embedder. Otherwise, the default implementation for the platform | |
129 * should be compiled in the library. | |
130 */ | 132 */ |
131 SK_API SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI, | 133 GLContext* CreatePlatformGLContext(GrGLStandard forcedGpuAPI, GLContext *shareCo ntext = nullptr); |
132 SkGLContext* shareContext = nullpt r); | |
133 | 134 |
134 /** | 135 } // namespace sk_gpu_test |
135 * Helper macros for using the GL context through the GrGLInterface. Example: | |
136 * SK_GL(glCtx, GenTextures(1, &texID)); | |
137 */ | |
138 #define SK_GL(ctx, X) (ctx).gl()->fFunctions.f ## X; \ | |
139 SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) | |
140 #define SK_GL_RET(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X; \ | |
141 SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) | |
142 #define SK_GL_NOERRCHECK(ctx, X) (ctx).gl()->fFunctions.f ## X | |
143 #define SK_GL_RET_NOERRCHECK(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X | |
144 | |
145 #endif | 136 #endif |
OLD | NEW |