1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/include/gpu/gl/SkGLContextHelper.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,87 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2013 Google Inc. 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 +#ifndef SkGLContextHelper_DEFINED 1.12 +#define SkGLContextHelper_DEFINED 1.13 + 1.14 +#include "GrGLInterface.h" 1.15 + 1.16 +/** 1.17 + * Create an offscreen opengl context with an RGBA8 / 8bit stencil FBO. 1.18 + * Provides a GrGLInterface struct of function pointers for the context. 1.19 + */ 1.20 + 1.21 +class SK_API SkGLContextHelper : public SkRefCnt { 1.22 +public: 1.23 + SK_DECLARE_INST_COUNT(SkGLContextHelper) 1.24 + 1.25 + SkGLContextHelper(); 1.26 + virtual ~SkGLContextHelper(); 1.27 + 1.28 + /** 1.29 + * Initializes the context and makes it current. 1.30 + */ 1.31 + bool init(const int width, const int height); 1.32 + 1.33 + int getFBOID() const { return fFBO; } 1.34 + 1.35 + const GrGLInterface* gl() const { return fGL; } 1.36 + 1.37 + virtual void makeCurrent() const = 0; 1.38 + 1.39 + /** 1.40 + * The primary purpose of this function it to provide a means of scheduling 1.41 + * work on the GPU (since all of the subclasses create primary buffers for 1.42 + * testing that are small and not meant to be rendered to the screen). 1.43 + * 1.44 + * If the drawing surface provided by the platform is double buffered this 1.45 + * call will cause the platform to swap which buffer is currently being 1.46 + * targeted. If the current surface does not include a back buffer, this 1.47 + * call has no effect. 1.48 + */ 1.49 + virtual void swapBuffers() const = 0; 1.50 + 1.51 + bool hasExtension(const char* extensionName) const { 1.52 + SkASSERT(NULL != fGL); 1.53 + return fGL->hasExtension(extensionName); 1.54 + } 1.55 + 1.56 +protected: 1.57 + /** 1.58 + * Subclass implements this to make a GL context. The returned GrGLInterface 1.59 + * should be populated with functions compatible with the context. The 1.60 + * format and size of backbuffers does not matter since an FBO will be 1.61 + * created. 1.62 + */ 1.63 + virtual const GrGLInterface* createGLContext() = 0; 1.64 + 1.65 + /** 1.66 + * Subclass should destroy the underlying GL context. 1.67 + */ 1.68 + virtual void destroyGLContext() = 0; 1.69 + 1.70 +private: 1.71 + GrGLuint fFBO; 1.72 + GrGLuint fColorBufferID; 1.73 + GrGLuint fDepthStencilBufferID; 1.74 + const GrGLInterface* fGL; 1.75 + 1.76 + typedef SkRefCnt INHERITED; 1.77 +}; 1.78 + 1.79 +/** 1.80 + * Helper macros for using the GL context through the GrGLInterface. Example: 1.81 + * SK_GL(glCtx, GenTextures(1, &texID)); 1.82 + */ 1.83 +#define SK_GL(ctx, X) (ctx).gl()->fFunctions.f ## X; \ 1.84 + SkASSERT(GR_GL_NO_ERROR == (ctx).gl()->fFunctions.fGetError()) 1.85 +#define SK_GL_RET(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X; \ 1.86 + SkASSERT(GR_GL_NO_ERROR == (ctx).gl()->fFunctions.fGetError()) 1.87 +#define SK_GL_NOERRCHECK(ctx, X) (ctx).gl()->fFunctions.f ## X 1.88 +#define SK_GL_RET_NOERRCHECK(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X 1.89 + 1.90 +#endif