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 | 12 |
13 /** | 13 /** |
14 * Create an offscreen opengl context with an RGBA8 / 8bit stencil FBO. | 14 * Create an offscreen opengl context with an RGBA8 / 8bit stencil FBO. |
15 * Provides a GrGLInterface struct of function pointers for the context. | 15 * Provides a GrGLInterface struct of function pointers for the context. |
16 */ | 16 */ |
17 | 17 |
18 class SK_API SkGLContext : public SkRefCnt { | 18 class SK_API SkGLContext : public SkRefCnt { |
19 public: | 19 public: |
20 SK_DECLARE_INST_COUNT(SkGLContext) | 20 SK_DECLARE_INST_COUNT(SkGLContext) |
21 | 21 |
22 SkGLContext(); | 22 virtual ~SkGLContext() SK_OVERRIDE; |
23 virtual ~SkGLContext(); | |
24 | 23 |
25 /** | 24 bool isValid() const { return NULL != gl(); } |
26 * Initializes the context and makes it current. | |
27 */ | |
28 bool init(GrGLStandard forcedGpuAPI, const int width, const int height); | |
29 | 25 |
30 int getFBOID() const { return fFBO; } | 26 const GrGLInterface* gl() const { return fGL.get(); } |
31 | |
32 const GrGLInterface* gl() const { return fGL; } | |
33 | 27 |
34 virtual void makeCurrent() const = 0; | 28 virtual void makeCurrent() const = 0; |
35 | 29 |
36 /** | 30 /** |
37 * The primary purpose of this function it to provide a means of scheduling | 31 * The primary purpose of this function it to provide a means of scheduling |
38 * work on the GPU (since all of the subclasses create primary buffers for | 32 * work on the GPU (since all of the subclasses create primary buffers for |
39 * testing that are small and not meant to be rendered to the screen). | 33 * testing that are small and not meant to be rendered to the screen). |
40 * | 34 * |
41 * If the drawing surface provided by the platform is double buffered this | 35 * If the drawing surface provided by the platform is double buffered this |
42 * call will cause the platform to swap which buffer is currently being | 36 * call will cause the platform to swap which buffer is currently being |
43 * targeted. If the current surface does not include a back buffer, this | 37 * targeted. If the current surface does not include a back buffer, this |
44 * call has no effect. | 38 * call has no effect. |
45 */ | 39 */ |
46 virtual void swapBuffers() const = 0; | 40 virtual void swapBuffers() const = 0; |
47 | 41 |
48 bool hasExtension(const char* extensionName) const { | |
49 SkASSERT(fGL); | |
50 return fGL->hasExtension(extensionName); | |
51 } | |
52 | |
53 /** | 42 /** |
54 * This notifies the context that we are deliberately testing abandoning | 43 * This notifies the context that we are deliberately testing abandoning |
55 * the context. It is useful for debugging contexts that would otherwise | 44 * the context. It is useful for debugging contexts that would otherwise |
56 * test that GPU resources are properly deleted. It also allows a debugging | 45 * test that GPU resources are properly deleted. It also allows a debugging |
57 * context to test that further GL calls are not made by Skia GPU code. | 46 * context to test that further GL calls are not made by Skia GPU code. |
58 */ | 47 */ |
59 void testAbandon(); | 48 void testAbandon(); |
60 | 49 |
61 protected: | 50 protected: |
62 /** | 51 SkGLContext(); |
63 * Subclass implements this to make a GL context. The returned GrGLInterface | |
64 * should be populated with functions compatible with the context. The | |
65 * format and size of backbuffers does not matter since an FBO will be | |
66 * created. | |
67 */ | |
68 virtual const GrGLInterface* createGLContext(GrGLStandard forcedGpuAPI) = 0; | |
69 | 52 |
70 /** | 53 /** Subclass provides the gl interface object if construction was |
71 * Subclass should destroy the underlying GL context. | 54 * successful. */ |
72 */ | 55 SkAutoTUnref<const GrGLInterface> fGL; |
73 virtual void destroyGLContext() = 0; | |
74 | |
75 private: | |
76 GrGLuint fFBO; | |
77 GrGLuint fColorBufferID; | |
78 GrGLuint fDepthStencilBufferID; | |
79 const GrGLInterface* fGL; | |
80 | 56 |
81 typedef SkRefCnt INHERITED; | 57 typedef SkRefCnt INHERITED; |
82 }; | 58 }; |
83 | 59 |
84 /** Creates platform-dependent GL context object | 60 /** Creates platform-dependent GL context object |
| 61 * Returns a valid gl context object or NULL if such can not be created. |
85 * Note: If Skia embedder needs a custom GL context that sets up the GL | 62 * Note: If Skia embedder needs a custom GL context that sets up the GL |
86 * interface, this function should be implemented by the embedder. | 63 * interface, this function should be implemented by the embedder. |
87 * Otherwise, the default implementation for the platform should be compiled in | 64 * Otherwise, the default implementation for the platform should be compiled in |
88 * the library. | 65 * the library. |
89 */ | 66 */ |
90 SK_API SkGLContext* SkCreatePlatformGLContext(); | 67 SK_API SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI); |
91 | 68 |
92 /** | 69 /** |
93 * Helper macros for using the GL context through the GrGLInterface. Example: | 70 * Helper macros for using the GL context through the GrGLInterface. Example: |
94 * SK_GL(glCtx, GenTextures(1, &texID)); | 71 * SK_GL(glCtx, GenTextures(1, &texID)); |
95 */ | 72 */ |
96 #define SK_GL(ctx, X) (ctx).gl()->fFunctions.f ## X; \ | 73 #define SK_GL(ctx, X) (ctx).gl()->fFunctions.f ## X; \ |
97 SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) | 74 SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) |
98 #define SK_GL_RET(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X; \ | 75 #define SK_GL_RET(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X; \ |
99 SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) | 76 SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) |
100 #define SK_GL_NOERRCHECK(ctx, X) (ctx).gl()->fFunctions.f ## X | 77 #define SK_GL_NOERRCHECK(ctx, X) (ctx).gl()->fFunctions.f ## X |
101 #define SK_GL_RET_NOERRCHECK(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X | 78 #define SK_GL_RET_NOERRCHECK(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X |
102 | 79 |
103 #endif | 80 #endif |
OLD | NEW |