• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright 2013 Google Inc.
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 #ifndef SkGLContext_DEFINED
9 #define SkGLContext_DEFINED
10 
11 #include "GrGLInterface.h"
12 
13 /**
14  * Create an offscreen opengl context with an RGBA8 / 8bit stencil FBO.
15  * Provides a GrGLInterface struct of function pointers for the context.
16  */
17 
18 class SK_API SkGLContext : public SkRefCnt {
19 public:
20     SK_DECLARE_INST_COUNT(SkGLContext)
21 
22     ~SkGLContext() override;
23 
isValid()24     bool isValid() const { return NULL != gl(); }
25 
gl()26     const GrGLInterface* gl() const { return fGL.get(); }
27 
28     virtual void makeCurrent() const = 0;
29 
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 
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 
50 protected:
51     SkGLContext();
52 
53     /** Subclass provides the gl interface object if construction was
54      *  successful. */
55     SkAutoTUnref<const GrGLInterface> fGL;
56 
57     typedef SkRefCnt INHERITED;
58 };
59 
60 /** Creates platform-dependent GL context object
61  * 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
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  */
67 SK_API SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI);
68 
69 /**
70  * Helper macros for using the GL context through the GrGLInterface. Example:
71  * SK_GL(glCtx, GenTextures(1, &texID));
72  */
73 #define SK_GL(ctx, X) (ctx).gl()->fFunctions.f ## X;    \
74                       SkASSERT(0 == (ctx).gl()->fFunctions.fGetError())
75 #define SK_GL_RET(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X;    \
76                   SkASSERT(0 == (ctx).gl()->fFunctions.fGetError())
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
79 
80 #endif
81