epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 3 | * Copyright 2013 Google Inc. |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
kkinnunen | 9e61bb7 | 2014-10-09 05:24:15 -0700 | [diff] [blame] | 8 | #ifndef SkGLContext_DEFINED |
| 9 | #define SkGLContext_DEFINED |
reed@google.com | c31ce10 | 2010-12-21 16:26:39 +0000 | [diff] [blame] | 10 | |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 11 | #include "GrGLInterface.h" |
reed@google.com | c31ce10 | 2010-12-21 16:26:39 +0000 | [diff] [blame] | 12 | |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 13 | /** |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 14 | * Create an offscreen opengl context with an RGBA8 / 8bit stencil FBO. |
| 15 | * Provides a GrGLInterface struct of function pointers for the context. |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 16 | */ |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 17 | |
kkinnunen | 9e61bb7 | 2014-10-09 05:24:15 -0700 | [diff] [blame] | 18 | class SK_API SkGLContext : public SkRefCnt { |
reed@google.com | c31ce10 | 2010-12-21 16:26:39 +0000 | [diff] [blame] | 19 | public: |
kkinnunen | 9e61bb7 | 2014-10-09 05:24:15 -0700 | [diff] [blame] | 20 | SK_DECLARE_INST_COUNT(SkGLContext) |
robertphillips@google.com | 15e9d3e | 2012-06-21 20:25:03 +0000 | [diff] [blame] | 21 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame^] | 22 | ~SkGLContext() override; |
reed@google.com | c31ce10 | 2010-12-21 16:26:39 +0000 | [diff] [blame] | 23 | |
kkinnunen | 30bc88c | 2014-10-15 23:03:54 -0700 | [diff] [blame] | 24 | bool isValid() const { return NULL != gl(); } |
reed@google.com | c31ce10 | 2010-12-21 16:26:39 +0000 | [diff] [blame] | 25 | |
kkinnunen | 30bc88c | 2014-10-15 23:03:54 -0700 | [diff] [blame] | 26 | const GrGLInterface* gl() const { return fGL.get(); } |
bungeman@google.com | 16bab87 | 2011-05-17 14:24:46 +0000 | [diff] [blame] | 27 | |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 28 | virtual void makeCurrent() const = 0; |
| 29 | |
djsollen@google.com | c9542ca | 2013-10-09 18:25:38 +0000 | [diff] [blame] | 30 | /** |
| 31 | * The primary 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 |
| 33 | * testing that are small and not meant to be rendered to the screen). |
| 34 | * |
| 35 | * If the drawing surface provided by the platform is double buffered this |
| 36 | * call will cause the platform to swap which buffer is currently being |
| 37 | * targeted. If the current surface does not include a back buffer, this |
| 38 | * call has no effect. |
| 39 | */ |
| 40 | virtual void swapBuffers() const = 0; |
| 41 | |
bsalomon | 944bcf0 | 2014-07-29 08:01:52 -0700 | [diff] [blame] | 42 | /** |
| 43 | * This notifies the context that we are deliberately testing abandoning |
| 44 | * the context. It is useful for debugging contexts that would otherwise |
| 45 | * 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. |
| 47 | */ |
| 48 | void testAbandon(); |
| 49 | |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 50 | protected: |
kkinnunen | 30bc88c | 2014-10-15 23:03:54 -0700 | [diff] [blame] | 51 | SkGLContext(); |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 52 | |
kkinnunen | 30bc88c | 2014-10-15 23:03:54 -0700 | [diff] [blame] | 53 | /** Subclass provides the gl interface object if construction was |
| 54 | * successful. */ |
| 55 | SkAutoTUnref<const GrGLInterface> fGL; |
robertphillips@google.com | 15e9d3e | 2012-06-21 20:25:03 +0000 | [diff] [blame] | 56 | |
| 57 | typedef SkRefCnt INHERITED; |
reed@google.com | c31ce10 | 2010-12-21 16:26:39 +0000 | [diff] [blame] | 58 | }; |
| 59 | |
kkinnunen | 9e61bb7 | 2014-10-09 05:24:15 -0700 | [diff] [blame] | 60 | /** Creates platform-dependent GL context object |
kkinnunen | 30bc88c | 2014-10-15 23:03:54 -0700 | [diff] [blame] | 61 | * Returns a valid gl context object or NULL if such can not be created. |
kkinnunen | 9e61bb7 | 2014-10-09 05:24:15 -0700 | [diff] [blame] | 62 | * Note: If Skia embedder needs a custom GL context that sets up the GL |
| 63 | * interface, this function should be implemented by the embedder. |
| 64 | * Otherwise, the default implementation for the platform should be compiled in |
| 65 | * the library. |
| 66 | */ |
kkinnunen | 30bc88c | 2014-10-15 23:03:54 -0700 | [diff] [blame] | 67 | SK_API SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI); |
kkinnunen | 9e61bb7 | 2014-10-09 05:24:15 -0700 | [diff] [blame] | 68 | |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 69 | /** |
robertphillips@google.com | fe1b536 | 2013-02-07 19:45:46 +0000 | [diff] [blame] | 70 | * Helper macros for using the GL context through the GrGLInterface. Example: |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 71 | * SK_GL(glCtx, GenTextures(1, &texID)); |
| 72 | */ |
commit-bot@chromium.org | c72425a | 2014-01-21 16:09:18 +0000 | [diff] [blame] | 73 | #define SK_GL(ctx, X) (ctx).gl()->fFunctions.f ## X; \ |
bsalomon | 9245b7e | 2014-07-01 07:20:11 -0700 | [diff] [blame] | 74 | SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) |
commit-bot@chromium.org | c72425a | 2014-01-21 16:09:18 +0000 | [diff] [blame] | 75 | #define SK_GL_RET(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X; \ |
bsalomon | 9245b7e | 2014-07-01 07:20:11 -0700 | [diff] [blame] | 76 | SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) |
commit-bot@chromium.org | c72425a | 2014-01-21 16:09:18 +0000 | [diff] [blame] | 77 | #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 |
bsalomon@google.com | 373a663 | 2011-10-19 20:43:20 +0000 | [diff] [blame] | 79 | |
reed@google.com | 873cb1e | 2010-12-23 15:00:45 +0000 | [diff] [blame] | 80 | #endif |