gfx/skia/trunk/include/gpu/gl/SkGLContextHelper.h

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2013 Google Inc.
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8 #ifndef SkGLContextHelper_DEFINED
michael@0 9 #define SkGLContextHelper_DEFINED
michael@0 10
michael@0 11 #include "GrGLInterface.h"
michael@0 12
michael@0 13 /**
michael@0 14 * Create an offscreen opengl context with an RGBA8 / 8bit stencil FBO.
michael@0 15 * Provides a GrGLInterface struct of function pointers for the context.
michael@0 16 */
michael@0 17
michael@0 18 class SK_API SkGLContextHelper : public SkRefCnt {
michael@0 19 public:
michael@0 20 SK_DECLARE_INST_COUNT(SkGLContextHelper)
michael@0 21
michael@0 22 SkGLContextHelper();
michael@0 23 virtual ~SkGLContextHelper();
michael@0 24
michael@0 25 /**
michael@0 26 * Initializes the context and makes it current.
michael@0 27 */
michael@0 28 bool init(const int width, const int height);
michael@0 29
michael@0 30 int getFBOID() const { return fFBO; }
michael@0 31
michael@0 32 const GrGLInterface* gl() const { return fGL; }
michael@0 33
michael@0 34 virtual void makeCurrent() const = 0;
michael@0 35
michael@0 36 /**
michael@0 37 * The primary purpose of this function it to provide a means of scheduling
michael@0 38 * work on the GPU (since all of the subclasses create primary buffers for
michael@0 39 * testing that are small and not meant to be rendered to the screen).
michael@0 40 *
michael@0 41 * If the drawing surface provided by the platform is double buffered this
michael@0 42 * call will cause the platform to swap which buffer is currently being
michael@0 43 * targeted. If the current surface does not include a back buffer, this
michael@0 44 * call has no effect.
michael@0 45 */
michael@0 46 virtual void swapBuffers() const = 0;
michael@0 47
michael@0 48 bool hasExtension(const char* extensionName) const {
michael@0 49 SkASSERT(NULL != fGL);
michael@0 50 return fGL->hasExtension(extensionName);
michael@0 51 }
michael@0 52
michael@0 53 protected:
michael@0 54 /**
michael@0 55 * Subclass implements this to make a GL context. The returned GrGLInterface
michael@0 56 * should be populated with functions compatible with the context. The
michael@0 57 * format and size of backbuffers does not matter since an FBO will be
michael@0 58 * created.
michael@0 59 */
michael@0 60 virtual const GrGLInterface* createGLContext() = 0;
michael@0 61
michael@0 62 /**
michael@0 63 * Subclass should destroy the underlying GL context.
michael@0 64 */
michael@0 65 virtual void destroyGLContext() = 0;
michael@0 66
michael@0 67 private:
michael@0 68 GrGLuint fFBO;
michael@0 69 GrGLuint fColorBufferID;
michael@0 70 GrGLuint fDepthStencilBufferID;
michael@0 71 const GrGLInterface* fGL;
michael@0 72
michael@0 73 typedef SkRefCnt INHERITED;
michael@0 74 };
michael@0 75
michael@0 76 /**
michael@0 77 * Helper macros for using the GL context through the GrGLInterface. Example:
michael@0 78 * SK_GL(glCtx, GenTextures(1, &texID));
michael@0 79 */
michael@0 80 #define SK_GL(ctx, X) (ctx).gl()->fFunctions.f ## X; \
michael@0 81 SkASSERT(GR_GL_NO_ERROR == (ctx).gl()->fFunctions.fGetError())
michael@0 82 #define SK_GL_RET(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X; \
michael@0 83 SkASSERT(GR_GL_NO_ERROR == (ctx).gl()->fFunctions.fGetError())
michael@0 84 #define SK_GL_NOERRCHECK(ctx, X) (ctx).gl()->fFunctions.f ## X
michael@0 85 #define SK_GL_RET_NOERRCHECK(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X
michael@0 86
michael@0 87 #endif

mercurial