* found in the LICENSE file.
*/
#include "BenchGpuTimer_gl.h"
-#include "gl/SkGLContext.h"
+#include "gl/SkGLContextHelper.h"
#include "gl/GrGLUtil.h"
-BenchGpuTimer::BenchGpuTimer(const SkGLContext* glctx) {
+BenchGpuTimer::BenchGpuTimer(const SkGLContextHelper* glctx) {
fContext = glctx;
glctx->ref();
glctx->makeCurrent();
#ifndef SkBenchGpuTimer_DEFINED
#define SkBenchGpuTimer_DEFINED
-class SkGLContext;
+class SkGLContextHelper;
class BenchGpuTimer {
public:
- BenchGpuTimer(const SkGLContext* glctx);
+ BenchGpuTimer(const SkGLContextHelper* glctx);
~BenchGpuTimer();
void startGpu();
double endGpu();
private:
unsigned fQuery;
int fStarted;
- const SkGLContext* fContext;
+ const SkGLContextHelper* fContext;
bool fSupported;
};
#include "BenchGpuTimer_gl.h"
#endif
-BenchTimer::BenchTimer(SkGLContext* gl)
+BenchTimer::BenchTimer(SkGLContextHelper* gl)
: fCpu(-1.0)
, fWall(-1.0)
, fTruncatedCpu(-1.0)
class BenchSysTimer;
class BenchGpuTimer;
-class SkGLContext;
+class SkGLContextHelper;
/**
* SysTimers and GpuTimers are implemented orthogonally.
*/
class BenchTimer {
public:
- BenchTimer(SkGLContext* gl = NULL);
+ BenchTimer(SkGLContextHelper* gl = NULL);
~BenchTimer();
void start();
void end();
SkTArray<BenchTimer*> timers(SK_ARRAY_COUNT(gConfigs));
for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); ++i) {
#if SK_SUPPORT_GPU
- SkGLContext* ctx = NULL;
+ SkGLContextHelper* ctx = NULL;
if (kGPU_Backend == gConfigs[i].fBackend) {
ctx = gContextFactory.getGLContext(gConfigs[i].fContextType);
}
configName = gConfigs[configIndex].fName;
backend = gConfigs[configIndex].fBackend;
GrContext* context = NULL;
- SkGLContext* glContext = NULL;
+ SkGLContextHelper* glContext = NULL;
BenchTimer* timer = timers[configIndex];
#if SK_SUPPORT_GPU
'<(skia_src_path)/gpu/gl/GrGLBufferImpl.h',
'<(skia_src_path)/gpu/gl/GrGLCaps.cpp',
'<(skia_src_path)/gpu/gl/GrGLCaps.h',
- '<(skia_src_path)/gpu/gl/GrGLContextInfo.cpp',
- '<(skia_src_path)/gpu/gl/GrGLContextInfo.h',
+ '<(skia_src_path)/gpu/gl/GrGLContext.cpp',
+ '<(skia_src_path)/gpu/gl/GrGLContext.h',
'<(skia_src_path)/gpu/gl/GrGLCreateNativeInterface_none.cpp',
'<(skia_src_path)/gpu/gl/GrGLDefaultInterface_none.cpp',
'<(skia_src_path)/gpu/gl/GrGLDefines.h',
'<(skia_include_path)/gpu/SkGrPixelRef.h',
'<(skia_include_path)/gpu/SkGrTexturePixelRef.h',
- '<(skia_include_path)/gpu/gl/SkGLContext.h',
+ '<(skia_include_path)/gpu/gl/SkGLContextHelper.h',
'<(skia_src_path)/gpu/SkGpuDevice.cpp',
'<(skia_src_path)/gpu/SkGr.cpp',
'<(skia_src_path)/image/SkImage_Gpu.cpp',
'<(skia_src_path)/image/SkSurface_Gpu.cpp',
- '<(skia_src_path)/gpu/gl/SkGLContext.cpp'
+ '<(skia_src_path)/gpu/gl/SkGLContextHelper.cpp'
],
'skgr_native_gl_sources': [
'<(skia_include_path)/gpu/gl/SkNativeGLContext.h',
return fContexts[i].fGrContext;
}
}
- SkAutoTUnref<SkGLContext> glCtx;
+ SkAutoTUnref<SkGLContextHelper> glCtx;
SkAutoTUnref<GrContext> grCtx;
switch (type) {
case kNative_GLContextType:
// Returns the GLContext of the given type. If it has not been created yet,
// NULL is returned instead.
- SkGLContext* getGLContext(GLContextType type) {
+ SkGLContextHelper* getGLContext(GLContextType type) {
for (int i = 0; i < fContexts.count(); ++i) {
if (fContexts[i].fType == type) {
return fContexts[i].fGLContext;
private:
struct GPUContext {
GLContextType fType;
- SkGLContext* fGLContext;
+ SkGLContextHelper* fGLContext;
GrContext* fGrContext;
};
SkTArray<GPUContext, true> fContexts;
#if SK_ANGLE
-#include "SkGLContext.h"
+#include "SkGLContextHelper.h"
#include <GLES2/gl2.h>
#include <EGL/egl.h>
-class SkANGLEGLContext : public SkGLContext {
+class SkANGLEGLContext : public SkGLContextHelper {
public:
SkANGLEGLContext();
#ifndef SkDebugGLContext_DEFINED
#define SkDebugGLContext_DEFINED
-#include "SkGLContext.h"
+#include "SkGLContextHelper.h"
-class SkDebugGLContext : public SkGLContext {
+class SkDebugGLContext : public SkGLContextHelper {
public:
SkDebugGLContext() {};
+++ /dev/null
-
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#ifndef SkGLContext_DEFINED
-#define SkGLContext_DEFINED
-
-#include "GrGLExtensions.h"
-#include "GrGLInterface.h"
-
-/**
- * Create an offscreen opengl context with an RGBA8 / 8bit stencil FBO.
- * Provides a GrGLInterface struct of function pointers for the context.
- */
-
-class SkGLContext : public SkRefCnt {
-public:
- SK_DECLARE_INST_COUNT(SkGLContext)
-
- SkGLContext();
- virtual ~SkGLContext();
-
- /**
- * Initializes the context and makes it current.
- */
- bool init(const int width, const int height);
-
- int getFBOID() const { return fFBO; }
-
- const GrGLInterface* gl() const { return fGL; }
-
- virtual void makeCurrent() const = 0;
-
- bool hasExtension(const char* extensionName) const {
- GrAssert(NULL != fGL);
- return fExtensions.has(extensionName);
- }
-
-protected:
- /**
- * Subclass implements this to make a GL context. The returned GrGLInterface
- * should be populated with functions compatible with the context. The
- * format and size of backbuffers does not matter since an FBO will be
- * created.
- */
- virtual const GrGLInterface* createGLContext() = 0;
-
- /**
- * Subclass should destroy the underlying GL context.
- */
- virtual void destroyGLContext() = 0;
-
-private:
- GrGLExtensions fExtensions;
- GrGLuint fFBO;
- GrGLuint fColorBufferID;
- GrGLuint fDepthStencilBufferID;
- const GrGLInterface* fGL;
-
- typedef SkRefCnt INHERITED;
-};
-
-/**
- * Helper macros for using the GL context through the GrGLInterface. Example:
- * SK_GL(glCtx, GenTextures(1, &texID));
- */
-#define SK_GL(ctx, X) (ctx).gl()->f ## X; \
- SkASSERT(GR_GL_NO_ERROR == (ctx).gl()->fGetError())
-#define SK_GL_RET(ctx, RET, X) (RET) = (ctx).gl()->f ## X; \
- SkASSERT(GR_GL_NO_ERROR == (ctx).gl()->fGetError())
-#define SK_GL_NOERRCHECK(ctx, X) (ctx).gl()->f ## X
-#define SK_GL_RET_NOERRCHECK(ctx, RET, X) (RET) = (ctx).gl()->f ## X
-
-#endif
--- /dev/null
+
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#ifndef SkGLContextHelper_DEFINED
+#define SkGLContextHelper_DEFINED
+
+#include "GrGLExtensions.h"
+#include "GrGLInterface.h"
+
+/**
+ * Create an offscreen opengl context with an RGBA8 / 8bit stencil FBO.
+ * Provides a GrGLInterface struct of function pointers for the context.
+ */
+
+class SkGLContextHelper : public SkRefCnt {
+public:
+ SK_DECLARE_INST_COUNT(SkGLContextHelper)
+
+ SkGLContextHelper();
+ virtual ~SkGLContextHelper();
+
+ /**
+ * Initializes the context and makes it current.
+ */
+ bool init(const int width, const int height);
+
+ int getFBOID() const { return fFBO; }
+
+ const GrGLInterface* gl() const { return fGL; }
+
+ virtual void makeCurrent() const = 0;
+
+ bool hasExtension(const char* extensionName) const {
+ GrAssert(NULL != fGL);
+ return fExtensions.has(extensionName);
+ }
+
+protected:
+ /**
+ * Subclass implements this to make a GL context. The returned GrGLInterface
+ * should be populated with functions compatible with the context. The
+ * format and size of backbuffers does not matter since an FBO will be
+ * created.
+ */
+ virtual const GrGLInterface* createGLContext() = 0;
+
+ /**
+ * Subclass should destroy the underlying GL context.
+ */
+ virtual void destroyGLContext() = 0;
+
+private:
+ GrGLExtensions fExtensions;
+ GrGLuint fFBO;
+ GrGLuint fColorBufferID;
+ GrGLuint fDepthStencilBufferID;
+ const GrGLInterface* fGL;
+
+ typedef SkRefCnt INHERITED;
+};
+
+/**
+ * Helper macros for using the GL context through the GrGLInterface. Example:
+ * SK_GL(glCtx, GenTextures(1, &texID));
+ */
+#define SK_GL(ctx, X) (ctx).gl()->f ## X; \
+ SkASSERT(GR_GL_NO_ERROR == (ctx).gl()->fGetError())
+#define SK_GL_RET(ctx, RET, X) (RET) = (ctx).gl()->f ## X; \
+ SkASSERT(GR_GL_NO_ERROR == (ctx).gl()->fGetError())
+#define SK_GL_NOERRCHECK(ctx, X) (ctx).gl()->f ## X
+#define SK_GL_RET_NOERRCHECK(ctx, RET, X) (RET) = (ctx).gl()->f ## X
+
+#endif
#ifndef SkMesaGLContext_DEFINED
#define SkMesaGLContext_DEFINED
-#include "SkGLContext.h"
+#include "SkGLContextHelper.h"
#if SK_MESA
-class SkMesaGLContext : public SkGLContext {
+class SkMesaGLContext : public SkGLContextHelper {
private:
typedef intptr_t Context;
#ifndef SkNativeGLContext_DEFINED
#define SkNativeGLContext_DEFINED
-#include "SkGLContext.h"
+#include "SkGLContextHelper.h"
#if defined(SK_BUILD_FOR_MAC)
#include <OpenGL/OpenGL.h>
#include <GL/GL.h>
#endif
-class SkNativeGLContext : public SkGLContext {
+class SkNativeGLContext : public SkGLContextHelper {
public:
SkNativeGLContext();
#ifndef SkNullGLContext_DEFINED
#define SkNullGLContext_DEFINED
-#include "SkGLContext.h"
+#include "SkGLContextHelper.h"
-class SkNullGLContext : public SkGLContext {
+class SkNullGLContext : public SkGLContextHelper {
public:
SkNullGLContext() {};
#endif
return NULL;
}
- GrGLContextInfo ctxInfo(glInterface);
- if (ctxInfo.isInitialized()) {
- return SkNEW_ARGS(GrGpuGL, (ctxInfo, context));
+ GrGLContext ctx(glInterface);
+ if (ctx.isInitialized()) {
+ return SkNEW_ARGS(GrGpuGL, (ctx, context));
}
}
return NULL;
#include "GrGLCaps.h"
-#include "GrGLContextInfo.h"
+#include "GrGLContext.h"
#include "SkTSearch.h"
GrGLCaps::GrGLCaps() {
return *this;
}
-void GrGLCaps::init(const GrGLContextInfo& ctxInfo) {
+void GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
this->reset();
if (!ctxInfo.isInitialized()) {
return;
}
- const GrGLInterface* gli = ctxInfo.interface();
GrGLBinding binding = ctxInfo.binding();
GrGLVersion version = ctxInfo.version();
fUseNonVBOVertexAndIndexDynamicData = true;
}
- this->initFSAASupport(ctxInfo);
+ this->initFSAASupport(ctxInfo, gli);
this->initStencilFormats(ctxInfo);
}
}
}
-void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo) {
+void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) {
fMSFBOType = kNone_MSFBOType;
if (kDesktop_GrGLBinding != ctxInfo.binding()) {
if (ctxInfo.hasExtension("GL_NV_framebuffer_multisample_coverage")) {
fCoverageAAType = kNVDesktop_CoverageAAType;
GrGLint count;
- GR_GL_GetIntegerv(ctxInfo.interface(),
+ GR_GL_GetIntegerv(gli,
GR_GL_MAX_MULTISAMPLE_COVERAGE_MODES,
&count);
fMSAACoverageModes.setCount(count);
- GR_GL_GetIntegerv(ctxInfo.interface(),
+ GR_GL_GetIntegerv(gli,
GR_GL_MULTISAMPLE_COVERAGE_MODES,
(int*)&fMSAACoverageModes[0]);
// The NV driver seems to return the modes already sorted but the
}
}
if (kNone_MSFBOType != fMSFBOType) {
- GR_GL_GetIntegerv(ctxInfo.interface(),
- GR_GL_MAX_SAMPLES,
- &fMaxSampleCount);
+ GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount);
}
}
* Initializes the GrGLCaps to the set of features supported in the current
* OpenGL context accessible via ctxInfo.
*/
- void init(const GrGLContextInfo& ctxInfo);
+ void init(const GrGLContextInfo& ctxInfo, const GrGLInterface* interface);
/**
* Call to note that a color config has been verified as a valid color
}
};
- void initFSAASupport(const GrGLContextInfo& ctxInfo);
+ void initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli);
void initStencilFormats(const GrGLContextInfo& ctxInfo);
// tracks configs that have been verified to pass the FBO completeness when
--- /dev/null
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "GrGLContext.h"
+
+////////////////////////////////////////////////////////////////////////////////
+GrGLContextInfo& GrGLContextInfo::operator= (const GrGLContextInfo& ctxInfo) {
+ fBindingInUse = ctxInfo.fBindingInUse;
+ fGLVersion = ctxInfo.fGLVersion;
+ fGLSLGeneration = ctxInfo.fGLSLGeneration;
+ fVendor = ctxInfo.fVendor;
+ fExtensions = ctxInfo.fExtensions;
+ fGLCaps = ctxInfo.fGLCaps;
+ return *this;
+}
+
+bool GrGLContextInfo::initialize(const GrGLInterface* interface) {
+ this->reset();
+ // We haven't validated the GrGLInterface yet, so check for GetString
+ // function pointer
+ if (interface->fGetString) {
+ const GrGLubyte* verUByte;
+ GR_GL_CALL_RET(interface, verUByte, GetString(GR_GL_VERSION));
+ const char* ver = reinterpret_cast<const char*>(verUByte);
+ GrGLBinding binding = GrGLGetBindingInUseFromString(ver);
+
+ if (0 != binding && interface->validate(binding) && fExtensions.init(binding, interface)) {
+ fBindingInUse = binding;
+
+ fGLVersion = GrGLGetVersionFromString(ver);
+
+ fGLSLGeneration = GrGetGLSLGeneration(fBindingInUse, interface);
+
+ fVendor = GrGLGetVendor(interface);
+ fGLCaps.init(*this, interface);
+ return true;
+ }
+ }
+ return false;
+}
+
+bool GrGLContextInfo::isInitialized() const {
+ return kNone_GrGLBinding != fBindingInUse;
+}
+
+void GrGLContextInfo::reset() {
+ fBindingInUse = kNone_GrGLBinding;
+ fGLVersion = GR_GL_VER(0, 0);
+ fGLSLGeneration = static_cast<GrGLSLGeneration>(0);
+ fVendor = kOther_GrGLVendor;
+ fExtensions.reset();
+ fGLCaps.reset();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+GrGLContext::GrGLContext(const GrGLInterface* interface) {
+ fInterface = NULL;
+ this->initialize(interface);
+}
+
+GrGLContext::GrGLContext(const GrGLContext& ctx) {
+ fInterface = NULL;
+ *this = ctx;
+}
+
+GrGLContext& GrGLContext::operator = (const GrGLContext& ctx) {
+ GrSafeAssign(fInterface, ctx.fInterface);
+ fInfo = ctx.fInfo;
+ return *this;
+}
+
+void GrGLContext::reset() {
+ GrSafeSetNull(fInterface);
+ fInfo.reset();
+}
+
+bool GrGLContext::initialize(const GrGLInterface* interface) {
+ if (fInfo.initialize(interface)) {
+ fInterface = interface;
+ interface->ref();
+ return true;
+ }
+ return false;
+}
--- /dev/null
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+
+#ifndef GrGLContext_DEFINED
+#define GrGLContext_DEFINED
+
+#include "gl/GrGLExtensions.h"
+#include "gl/GrGLInterface.h"
+#include "GrGLCaps.h"
+#include "GrGLSL.h"
+#include "GrGLUtil.h"
+
+#include "SkString.h"
+
+/**
+ * Encapsulates information about an OpenGL context including the OpenGL
+ * version, the GrGLBinding type of the context, and GLSL version.
+ */
+class GrGLContextInfo {
+public:
+ /**
+ * Default constructor
+ */
+ GrGLContextInfo() { this->reset(); }
+
+ /**
+ * Copies a GrGLContextInfo
+ */
+ GrGLContextInfo& operator= (const GrGLContextInfo& ctxInfo);
+
+ /**
+ * Initializes a GrGLContextInfo from a GrGLInterface and the currently
+ * bound OpenGL context accessible by the GrGLInterface.
+ */
+ bool initialize(const GrGLInterface* interface);
+ bool isInitialized() const;
+
+ GrGLBinding binding() const { return fBindingInUse; }
+ GrGLVersion version() const { return fGLVersion; }
+ GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; }
+ GrGLVendor vendor() const { return fVendor; }
+ const GrGLCaps& caps() const { return fGLCaps; }
+ GrGLCaps& caps() { return fGLCaps; }
+
+ /**
+ * Checks for extension support using a cached copy of the GL_EXTENSIONS
+ * string.
+ */
+ bool hasExtension(const char* ext) const {
+ if (!this->isInitialized()) {
+ return false;
+ }
+ return fExtensions.has(ext);
+ }
+
+ /**
+ * Reset the information
+ */
+ void reset();
+
+private:
+
+ GrGLBinding fBindingInUse;
+ GrGLVersion fGLVersion;
+ GrGLSLGeneration fGLSLGeneration;
+ GrGLVendor fVendor;
+ GrGLExtensions fExtensions;
+ GrGLCaps fGLCaps;
+};
+
+/**
+ * Encapsulates the GrGLInterface used to make GL calls plus information
+ * about the context (via GrGLContextInfo).
+ */
+class GrGLContext {
+public:
+ /**
+ * Default constructor
+ */
+ GrGLContext() { this->reset(); }
+
+ /**
+ * Creates a GrGLContext from a GrGLInterface and the currently
+ * bound OpenGL context accessible by the GrGLInterface.
+ */
+ explicit GrGLContext(const GrGLInterface* interface);
+
+ /**
+ * Copies a GrGLContext
+ */
+ GrGLContext(const GrGLContext& ctx);
+
+ ~GrGLContext() { GrSafeUnref(fInterface); }
+
+ /**
+ * Copies a GrGLContext
+ */
+ GrGLContext& operator= (const GrGLContext& ctx);
+
+ /**
+ * Initializes a GrGLContext from a GrGLInterface and the currently
+ * bound OpenGL context accessible by the GrGLInterface.
+ */
+ bool initialize(const GrGLInterface* interface);
+ bool isInitialized() const { return fInfo.isInitialized(); }
+
+ const GrGLInterface* interface() const { return fInterface; }
+ const GrGLContextInfo& info() const { return fInfo; }
+ GrGLContextInfo& info() { return fInfo; }
+
+private:
+ void reset();
+
+ const GrGLInterface* fInterface;
+ GrGLContextInfo fInfo;
+};
+
+#endif
+++ /dev/null
-/*
- * Copyright 2012 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "GrGLContextInfo.h"
-
-GrGLContextInfo::~GrGLContextInfo() {
- GrSafeUnref(fInterface);
-}
-
-GrGLContextInfo::GrGLContextInfo() {
- this->reset();
-}
-
-GrGLContextInfo::GrGLContextInfo(const GrGLInterface* interface) {
- fInterface = NULL;
- this->initialize(interface);
-}
-
-GrGLContextInfo::GrGLContextInfo(const GrGLContextInfo& ctx) {
- fInterface = NULL;
- *this = ctx;
-}
-
-GrGLContextInfo& GrGLContextInfo::operator = (const GrGLContextInfo& ctx) {
- GrSafeAssign(fInterface, ctx.fInterface);
- fBindingInUse = ctx.fBindingInUse;
- fGLVersion = ctx.fGLVersion;
- fGLSLGeneration = ctx.fGLSLGeneration;
- fVendor = ctx.fVendor;
- fExtensions = ctx.fExtensions;
- fGLCaps = ctx.fGLCaps;
- return *this;
-}
-
-void GrGLContextInfo::reset() {
- GrSafeSetNull(fInterface);
- fBindingInUse = kNone_GrGLBinding;
- fGLVersion = GR_GL_VER(0, 0);
- fGLSLGeneration = static_cast<GrGLSLGeneration>(0);
- fVendor = kOther_GrGLVendor;
- fExtensions.reset();
- fGLCaps.reset();
-}
-
-bool GrGLContextInfo::initialize(const GrGLInterface* interface) {
- this->reset();
- // We haven't validated the GrGLInterface yet, so check for GetString
- // function pointer
- if (interface->fGetString) {
- const GrGLubyte* verUByte;
- GR_GL_CALL_RET(interface, verUByte, GetString(GR_GL_VERSION));
- const char* ver = reinterpret_cast<const char*>(verUByte);
- GrGLBinding binding = GrGLGetBindingInUseFromString(ver);
-
- if (0 != binding && interface->validate(binding) && fExtensions.init(binding, interface)) {
-
- fInterface = interface;
- interface->ref();
-
- fBindingInUse = binding;
-
- fGLVersion = GrGLGetVersionFromString(ver);
-
- fGLSLGeneration = GrGetGLSLGeneration(fBindingInUse,
- this->interface());
-
- fVendor = GrGLGetVendor(interface);
- fGLCaps.init(*this);
- return true;
- }
- }
- return false;
-}
-
-bool GrGLContextInfo::isInitialized() const {
- return kNone_GrGLBinding != fBindingInUse;
-}
+++ /dev/null
-/*
- * Copyright 2012 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-
-#ifndef GrGLContextInfo_DEFINED
-#define GrGLContextInfo_DEFINED
-
-#include "gl/GrGLExtensions.h"
-#include "gl/GrGLInterface.h"
-#include "GrGLCaps.h"
-#include "GrGLSL.h"
-#include "GrGLUtil.h"
-
-#include "SkString.h"
-
-/**
- * Encapsulates information about an OpenGL context including the GrGLInterface
- * used to make GL calls, the OpenGL version, the GrGLBinding type of the
- * context, and GLSL version.
- */
-class GrGLContextInfo {
-public:
-
- /**
- * Default constructor, creates an uninitialized GrGLContextInfo
- */
- GrGLContextInfo();
-
- /**
- * Creates a GrGLContextInfo from a GrGLInterface and the currently
- * bound OpenGL context accessible by the GrGLInterface.
- */
- explicit GrGLContextInfo(const GrGLInterface* interface);
-
- /**
- * Copies a GrGLContextInfo
- */
- GrGLContextInfo(const GrGLContextInfo& ctx);
-
- ~GrGLContextInfo();
-
- /**
- * Copies a GrGLContextInfo
- */
- GrGLContextInfo& operator = (const GrGLContextInfo& ctx);
-
- /**
- * Initializes a GrGLContextInfo from a GrGLInterface and the currently
- * bound OpenGL context accessible by the GrGLInterface.
- */
- bool initialize(const GrGLInterface* interface);
- bool isInitialized() const;
-
- const GrGLInterface* interface() const { return fInterface; }
- GrGLBinding binding() const { return fBindingInUse; }
- GrGLVersion version() const { return fGLVersion; }
- GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; }
- GrGLVendor vendor() const { return fVendor; }
- const GrGLCaps& caps() const { return fGLCaps; }
- GrGLCaps& caps() { return fGLCaps; }
-
- /**
- * Checks for extension support using a cached copy of the GL_EXTENSIONS
- * string.
- */
- bool hasExtension(const char* ext) const {
- if (!this->isInitialized()) {
- return false;
- }
- return fExtensions.has(ext);
- }
-
-private:
- void reset();
-
- const GrGLInterface* fInterface;
- GrGLBinding fBindingInUse;
- GrGLVersion fGLVersion;
- GrGLSLGeneration fGLSLGeneration;
- GrGLVendor fVendor;
- GrGLExtensions fExtensions;
- GrGLCaps fGLCaps;
-};
-
-#endif
SK_DEFINE_INST_COUNT(GrGLProgram)
-#define GL_CALL(X) GR_GL_CALL(fContextInfo.interface(), X)
-#define GL_CALL_RET(R, X) GR_GL_CALL_RET(fContextInfo.interface(), R, X)
+#define GL_CALL(X) GR_GL_CALL(fContext.interface(), X)
+#define GL_CALL_RET(R, X) GR_GL_CALL_RET(fContext.interface(), R, X)
SK_CONF_DECLARE(bool, c_PrintShaders, "gpu.printShaders", false, "Print the source code for all shaders generated.");
#endif
}
-GrGLProgram* GrGLProgram::Create(const GrGLContextInfo& gl,
+GrGLProgram* GrGLProgram::Create(const GrGLContext& gl,
const Desc& desc,
const GrEffectStage* stages[]) {
GrGLProgram* program = SkNEW_ARGS(GrGLProgram, (gl, desc, stages));
return program;
}
-GrGLProgram::GrGLProgram(const GrGLContextInfo& gl,
+GrGLProgram::GrGLProgram(const GrGLContext& gl,
const Desc& desc,
const GrEffectStage* stages[])
-: fContextInfo(gl)
+: fContext(gl)
, fUniformManager(gl) {
fDesc = desc;
fVShaderID = 0;
builder->fFSCode.appendf("\t\tedgeAlpha = (%s.x*%s.x - %s.y);\n", fsName, fsName, fsName);
builder->fFSCode.append("\t\tedgeAlpha = clamp(0.5 - edgeAlpha / length(gF), 0.0, 1.0);\n"
"\t}\n");
- if (kES2_GrGLBinding == fContextInfo.binding()) {
+ if (kES2_GrGLBinding == fContext.info().binding()) {
builder->fHeader.printf("#extension GL_OES_standard_derivatives: enable\n");
}
break;
builder->fFSCode.appendf("\tfloat edgeAlpha = (%s.x*%s.x - %s.y);\n", fsName, fsName, fsName);
builder->fFSCode.append("\tedgeAlpha = sqrt(edgeAlpha*edgeAlpha / dot(gF, gF));\n");
builder->fFSCode.append("\tedgeAlpha = max(1.0 - edgeAlpha, 0.0);\n");
- if (kES2_GrGLBinding == fContextInfo.binding()) {
+ if (kES2_GrGLBinding == fContext.info().binding()) {
builder->fHeader.printf("#extension GL_OES_standard_derivatives: enable\n");
}
break;
void GrGLProgram::genGeometryShader(GrGLShaderBuilder* segments) const {
#if GR_GL_EXPERIMENTAL_GS
if (fDesc.fExperimentalGS) {
- GrAssert(fContextInfo.glslGeneration() >= k150_GrGLSLGeneration);
+ GrAssert(fContext.info().glslGeneration() >= k150_GrGLSLGeneration);
segments->fGSHeader.append("layout(triangles) in;\n"
"layout(triangle_strip, max_vertices = 6) out;\n");
segments->fGSCode.append("\tfor (int i = 0; i < 3; ++i) {\n"
}
// Compiles a GL shader, returns shader ID or 0 if failed params have same meaning as glShaderSource
-GrGLuint compile_shader(const GrGLContextInfo& gl,
+GrGLuint compile_shader(const GrGLContext& gl,
GrGLenum type,
int stringCnt,
const char** strings,
}
// helper version of above for when shader is already flattened into a single SkString
-GrGLuint compile_shader(const GrGLContextInfo& gl, GrGLenum type, const SkString& shader) {
+GrGLuint compile_shader(const GrGLContext& gl, GrGLenum type, const SkString& shader) {
const GrGLchar* str = shader.c_str();
int length = shader.size();
return compile_shader(gl, type, 1, &str, &length);
GrPrintf("\n");
}
- if (!(fVShaderID = compile_shader(fContextInfo, GR_GL_VERTEX_SHADER, shader))) {
+ if (!(fVShaderID = compile_shader(fContext, GR_GL_VERTEX_SHADER, shader))) {
return false;
}
GrPrintf(shader.c_str());
GrPrintf("\n");
}
- if (!(fGShaderID = compile_shader(fContextInfo, GR_GL_GEOMETRY_SHADER, shader))) {
+ if (!(fGShaderID = compile_shader(fContext, GR_GL_GEOMETRY_SHADER, shader))) {
return false;
}
} else {
GrPrintf(shader.c_str());
GrPrintf("\n");
}
- if (!(fFShaderID = compile_shader(fContextInfo, GR_GL_FRAGMENT_SHADER, shader))) {
+ if (!(fFShaderID = compile_shader(fContext, GR_GL_FRAGMENT_SHADER, shader))) {
return false;
}
bool GrGLProgram::genProgram(const GrEffectStage* stages[]) {
GrAssert(0 == fProgramID);
- GrGLShaderBuilder builder(fContextInfo, fUniformManager);
+ GrGLShaderBuilder builder(fContext.info(), fUniformManager);
const GrAttribBindings& attribBindings = fDesc.fAttribBindings;
#if GR_GL_EXPERIMENTAL_GS
// the dual source output has no canonical var name, have to
// declare an output, which is incompatible with gl_FragColor/gl_FragData.
bool dualSourceOutputWritten = false;
- builder.fHeader.append(GrGetGLSLVersionDecl(fContextInfo.binding(),
- fContextInfo.glslGeneration()));
+ builder.fHeader.append(GrGetGLSLVersionDecl(fContext.info().binding(),
+ fContext.info().glslGeneration()));
GrGLShaderVar colorOutput;
- bool isColorDeclared = GrGLSLSetupFSColorOuput(fContextInfo.glslGeneration(),
+ bool isColorDeclared = GrGLSLSetupFSColorOuput(fContext.info().glslGeneration(),
declared_color_output_name(),
&colorOutput);
if (isColorDeclared) {
#include "GrDrawState.h"
#include "GrGLEffect.h"
-#include "GrGLContextInfo.h"
+#include "GrGLContext.h"
#include "GrGLSL.h"
#include "GrGLTexture.h"
#include "GrGLUniformManager.h"
const GrGpuGL* gpu,
Desc* outDesc);
- static GrGLProgram* Create(const GrGLContextInfo& gl,
+ static GrGLProgram* Create(const GrGLContext& gl,
const Desc& desc,
const GrEffectStage* stages[]);
static const AttribLayout kAttribLayouts[kGrVertexAttribTypeCount];
private:
- GrGLProgram(const GrGLContextInfo& gl,
+ GrGLProgram(const GrGLContext& gl,
const Desc& desc,
const GrEffectStage* stages[]);
GrGLEffect* fEffects[GrDrawState::kNumStages];
Desc fDesc;
- const GrGLContextInfo& fContextInfo;
+ const GrGLContext& fContext;
GrGLUniformManager fUniformManager;
UniformHandles fUniformHandles;
// varying by stage, if we use 1D textures for gradients!
//const int GrGLShaderBuilder::fCoordDims = 2;
-GrGLShaderBuilder::GrGLShaderBuilder(const GrGLContextInfo& ctx, GrGLUniformManager& uniformManager)
+GrGLShaderBuilder::GrGLShaderBuilder(const GrGLContextInfo& ctxInfo,
+ GrGLUniformManager& uniformManager)
: fUniforms(kVarsPerBlock)
, fVSAttrs(kVarsPerBlock)
, fVSOutputs(kVarsPerBlock)
, fFSInputs(kVarsPerBlock)
, fFSOutputs(kMaxFSOutputs)
, fUsesGS(false)
- , fContext(ctx)
+ , fCtxInfo(ctxInfo)
, fUniformManager(uniformManager)
, fCurrentStageIdx(kNonStageIdx)
, fSetupFragPosition(false)
sample_function_name(varyingType),
this->getUniformCStr(sampler.fSamplerUniform),
coordName);
- append_swizzle(out, *sampler.textureAccess(), fContext.caps());
+ append_swizzle(out, *sampler.textureAccess(), fCtxInfo.caps());
}
void GrGLShaderBuilder::appendTextureLookupAndModulate(
const char* GrGLShaderBuilder::fragmentPosition() {
#if 1
- if (fContext.caps().fragCoordConventionsSupport()) {
+ if (fCtxInfo.caps().fragCoordConventionsSupport()) {
if (!fSetupFragPosition) {
fFSHeader.append("#extension GL_ARB_fragment_coord_conventions: require\n");
fFSInputs.push_back().set(kVec4f_GrSLType,
fFSFunctions.append(*outName);
fFSFunctions.append("(");
for (int i = 0; i < argCnt; ++i) {
- args[i].appendDecl(fContext, &fFSFunctions);
+ args[i].appendDecl(fCtxInfo, &fFSFunctions);
if (i < argCnt - 1) {
fFSFunctions.append(", ");
}
void GrGLShaderBuilder::appendDecls(const VarArray& vars, SkString* out) const {
for (int i = 0; i < vars.count(); ++i) {
- vars[i].appendDecl(fContext, out);
+ vars[i].appendDecl(fCtxInfo, out);
out->append(";\n");
}
}
void GrGLShaderBuilder::appendUniformDecls(ShaderType stype, SkString* out) const {
for (int i = 0; i < fUniforms.count(); ++i) {
if (fUniforms[i].fVisibility & stype) {
- fUniforms[i].fVariable.appendDecl(fContext, out);
+ fUniforms[i].fVariable.appendDecl(fCtxInfo, out);
out->append(";\n");
}
}
case kFragment_ShaderType:
*shaderStr = fHeader;
append_default_precision_qualifier(kDefaultFragmentPrecision,
- fContext.binding(),
+ fCtxInfo.binding(),
shaderStr);
shaderStr->append(fFSHeader);
this->appendUniformDecls(kFragment_ShaderType, shaderStr);
this->appendDecls(fFSInputs, shaderStr);
// We shouldn't have declared outputs on 1.10
- GrAssert(k110_GrGLSLGeneration != fContext.glslGeneration() || fFSOutputs.empty());
+ GrAssert(k110_GrGLSLGeneration != fCtxInfo.glslGeneration() || fFSOutputs.empty());
this->appendDecls(fFSOutputs, shaderStr);
shaderStr->append(fFSFunctions);
shaderStr->append("void main() {\n");
kNonStageIdx = -1,
};
- const GrGLContextInfo& fContext;
+ const GrGLContextInfo& fCtxInfo;
GrGLUniformManager& fUniformManager;
int fCurrentStageIdx;
SkString fFSFunctions;
#ifndef GrGLShaderVar_DEFINED
#define GrGLShaderVar_DEFINED
-#include "GrGLContextInfo.h"
+#include "GrGLContext.h"
#include "GrGLSL.h"
#include "SkString.h"
/**
* Write a declaration of this variable to out.
*/
- void appendDecl(const GrGLContextInfo& gl, SkString* out) const {
+ void appendDecl(const GrGLContextInfo& ctxInfo, SkString* out) const {
if (kUpperLeft_Origin == fOrigin) {
// this is the only place where we specify a layout modifier. If we use other layout
// modifiers in the future then they should be placed in a list.
}
if (this->getTypeModifier() != kNone_TypeModifier) {
out->append(TypeModifierString(this->getTypeModifier(),
- gl.glslGeneration()));
+ ctxInfo.glslGeneration()));
out->append(" ");
}
- out->append(PrecisionString(fPrecision, gl.binding()));
+ out->append(PrecisionString(fPrecision, ctxInfo.binding()));
GrSLType effectiveType = this->getType();
if (this->isArray()) {
if (this->isUnsizedArray()) {
#include "SkTArray.h"
-class GrGLContextInfo;
+class GrGLContext;
class SkMatrix;
/** Manages a program's uniforms.
typedef int UniformHandle;
static const UniformHandle kInvalidUniformHandle = 0;
- GrGLUniformManager(const GrGLContextInfo& context) : fContext(context) {}
+ GrGLUniformManager(const GrGLContext& context) : fContext(context) {}
UniformHandle appendUniform(GrSLType type, int arrayCount = GrGLShaderVar::kNonArray);
};
SkTArray<Uniform, true> fUniforms;
- const GrGLContextInfo& fContext;
+ const GrGLContext& fContext;
};
#endif
return status == GR_GL_FRAMEBUFFER_COMPLETE;
}
-GrGpuGL::GrGpuGL(const GrGLContextInfo& ctxInfo, GrContext* context)
+GrGpuGL::GrGpuGL(const GrGLContext& ctx, GrContext* context)
: GrGpu(context)
- , fGLContextInfo(ctxInfo) {
+ , fGLContext(ctx) {
- GrAssert(ctxInfo.isInitialized());
+ GrAssert(ctx.isInitialized());
fillInConfigRenderableTable();
fPrintedCaps = false;
- GrGLClearErr(fGLContextInfo.interface());
+ GrGLClearErr(fGLContext.interface());
if (gPrintStartupSpew) {
const GrGLubyte* ext;
this->initCaps();
- fProgramCache = SkNEW_ARGS(ProgramCache, (this->glContextInfo()));
+ fProgramCache = SkNEW_ARGS(ProgramCache, (this->glContext()));
fHWGeometryState.setMaxAttribArrays(this->glCaps().maxVertexAttributes());
}
namespace {
-bool renderbuffer_storage_msaa(GrGLContextInfo& ctxInfo,
+bool renderbuffer_storage_msaa(GrGLContext& ctx,
int sampleCount,
GrGLenum format,
int width, int height) {
- CLEAR_ERROR_BEFORE_ALLOC(ctxInfo.interface());
- GrAssert(GrGLCaps::kNone_MSFBOType != ctxInfo.caps().msFBOType());
+ CLEAR_ERROR_BEFORE_ALLOC(ctx.interface());
+ GrAssert(GrGLCaps::kNone_MSFBOType != ctx.info().caps().msFBOType());
bool created = false;
if (GrGLCaps::kNVDesktop_CoverageAAType ==
- ctxInfo.caps().coverageAAType()) {
+ ctx.info().caps().coverageAAType()) {
const GrGLCaps::MSAACoverageMode& mode =
- ctxInfo.caps().getMSAACoverageMode(sampleCount);
- GL_ALLOC_CALL(ctxInfo.interface(),
+ ctx.info().caps().getMSAACoverageMode(sampleCount);
+ GL_ALLOC_CALL(ctx.interface(),
RenderbufferStorageMultisampleCoverage(GR_GL_RENDERBUFFER,
mode.fCoverageSampleCnt,
mode.fColorSampleCnt,
format,
width, height));
- created = (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(ctxInfo.interface()));
+ created = (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(ctx.interface()));
}
if (!created) {
// glRBMS will fail if requested samples is > max samples.
- sampleCount = GrMin(sampleCount, ctxInfo.caps().maxSampleCount());
- GL_ALLOC_CALL(ctxInfo.interface(),
+ sampleCount = GrMin(sampleCount, ctx.info().caps().maxSampleCount());
+ GL_ALLOC_CALL(ctx.interface(),
RenderbufferStorageMultisample(GR_GL_RENDERBUFFER,
sampleCount,
format,
width, height));
- created = (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(ctxInfo.interface()));
+ created = (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(ctx.interface()));
}
return created;
}
GrAssert(desc->fSampleCnt > 0);
GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER,
desc->fMSColorRenderbufferID));
- if (!renderbuffer_storage_msaa(fGLContextInfo,
+ if (!renderbuffer_storage_msaa(fGLContext,
desc->fSampleCnt,
msColorFormat,
width, height)) {
if (status != GR_GL_FRAMEBUFFER_COMPLETE) {
goto FAILED;
}
- fGLContextInfo.caps().markConfigAsValidColorAttachment(
+ fGLContext.info().caps().markConfigAsValidColorAttachment(
desc->fConfig);
}
}
if (status != GR_GL_FRAMEBUFFER_COMPLETE) {
goto FAILED;
}
- fGLContextInfo.caps().markConfigAsValidColorAttachment(desc->fConfig);
+ fGLContext.info().caps().markConfigAsValidColorAttachment(desc->fConfig);
}
return true;
// version on a GL that doesn't have an MSAA extension.
bool created;
if (samples > 0) {
- created = renderbuffer_storage_msaa(fGLContextInfo,
+ created = renderbuffer_storage_msaa(fGLContext,
samples,
sFmt.fInternalFormat,
width, height);
}
return false;
} else {
- fGLContextInfo.caps().markColorConfigAndStencilFormatAsVerified(
+ fGLContext.info().caps().markColorConfigAndStencilFormatAsVerified(
rt->config(),
glsb->format());
}
#include "GrBinHashKey.h"
#include "GrDrawState.h"
#include "GrGpu.h"
-#include "GrGLContextInfo.h"
+#include "GrGLContext.h"
#include "GrGLIndexBuffer.h"
#include "GrGLIRect.h"
#include "GrGLProgram.h"
class GrGpuGL : public GrGpu {
public:
- GrGpuGL(const GrGLContextInfo& ctxInfo, GrContext* context);
+ GrGpuGL(const GrGLContext& ctx, GrContext* context);
virtual ~GrGpuGL();
- const GrGLInterface* glInterface() const {
- return fGLContextInfo.interface();
- }
- GrGLBinding glBinding() const { return fGLContextInfo.binding(); }
- GrGLVersion glVersion() const { return fGLContextInfo.version(); }
- GrGLSLGeneration glslGeneration() const {
- return fGLContextInfo.glslGeneration();
- }
+ const GrGLInterface* glInterface() const { return fGLContext.interface(); }
+ GrGLBinding glBinding() const { return fGLContext.info().binding(); }
+ GrGLVersion glVersion() const { return fGLContext.info().version(); }
+ GrGLSLGeneration glslGeneration() const { return fGLContext.info().glslGeneration(); }
// Used by GrGLProgram to bind necessary textures for GrGLEffects.
void bindTexture(int unitIdx, const GrTextureParams& params, GrGLTexture* texture);
virtual void abandonResources() SK_OVERRIDE;
- const GrGLCaps& glCaps() const { return fGLContextInfo.caps(); }
+ const GrGLCaps& glCaps() const { return fGLContext.info().caps(); }
// Callbacks to update state tracking when related GL objects are bound or deleted
void notifyVertexBufferBind(GrGLuint id);
// have been accounted for).
void flushBlend(bool isLines, GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff);
- bool hasExtension(const char* ext) const {
- return fGLContextInfo.hasExtension(ext);
- }
+ bool hasExtension(const char* ext) const { return fGLContext.info().hasExtension(ext); }
- const GrGLContextInfo& glContextInfo() const { return fGLContextInfo; }
+ const GrGLContext& glContext() const { return fGLContext; }
static bool BlendCoeffReferencesConstant(GrBlendCoeff coeff);
class ProgramCache : public ::GrNoncopyable {
public:
- ProgramCache(const GrGLContextInfo& gl);
+ ProgramCache(const GrGLContext& gl);
void abandon();
GrGLProgram* getProgram(const GrGLProgram::Desc& desc, const GrEffectStage* stages[]);
Entry fEntries[kMaxEntries];
int fCount;
unsigned int fCurrLRUStamp;
- const GrGLContextInfo& fGL;
+ const GrGLContext& fGL;
};
// sets the matrix for path stenciling (uses the GL fixed pipe matrices)
void fillInConfigRenderableTable();
- GrGLContextInfo fGLContextInfo;
+ GrGLContext fGLContext;
// GL program-related state
ProgramCache* fProgramCache;
#define SKIP_CACHE_CHECK true
#define GR_UINT32_MAX static_cast<uint32_t>(-1)
-GrGpuGL::ProgramCache::ProgramCache(const GrGLContextInfo& gl)
+GrGpuGL::ProgramCache::ProgramCache(const GrGLContext& gl)
: fCount(0)
, fCurrLRUStamp(0)
, fGL(gl) {
+++ /dev/null
-
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#include "gl/SkGLContext.h"
-#include "GrGLUtil.h"
-
-SK_DEFINE_INST_COUNT(SkGLContext)
-
-SkGLContext::SkGLContext()
- : fFBO(0)
- , fColorBufferID(0)
- , fDepthStencilBufferID(0)
- , fGL(NULL) {
-}
-
-SkGLContext::~SkGLContext() {
-
- if (fGL) {
- // TODO: determine why DeleteFramebuffers is generating a GL error in tests
- SK_GL_NOERRCHECK(*this, DeleteFramebuffers(1, &fFBO));
- SK_GL_NOERRCHECK(*this, DeleteRenderbuffers(1, &fColorBufferID));
- SK_GL_NOERRCHECK(*this, DeleteRenderbuffers(1, &fDepthStencilBufferID));
- }
-
- SkSafeUnref(fGL);
-}
-
-bool SkGLContext::init(int width, int height) {
- if (fGL) {
- fGL->unref();
- this->destroyGLContext();
- }
-
- fGL = this->createGLContext();
- if (fGL) {
- const GrGLubyte* temp;
-
- GrGLBinding bindingInUse = GrGLGetBindingInUse(this->gl());
-
- if (!fGL->validate(bindingInUse) || !fExtensions.init(bindingInUse, fGL)) {
- fGL = NULL;
- this->destroyGLContext();
- return false;
- }
-
- SK_GL_RET(*this, temp, GetString(GR_GL_VERSION));
- const char* versionStr = reinterpret_cast<const char*>(temp);
- GrGLVersion version = GrGLGetVersionFromString(versionStr);
-
- // clear any existing GL erorrs
- GrGLenum error;
- do {
- SK_GL_RET(*this, error, GetError());
- } while (GR_GL_NO_ERROR != error);
-
- SK_GL(*this, GenFramebuffers(1, &fFBO));
- SK_GL(*this, BindFramebuffer(GR_GL_FRAMEBUFFER, fFBO));
- SK_GL(*this, GenRenderbuffers(1, &fColorBufferID));
- SK_GL(*this, BindRenderbuffer(GR_GL_RENDERBUFFER, fColorBufferID));
- if (kES2_GrGLBinding == bindingInUse) {
- SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER,
- GR_GL_RGBA8,
- width, height));
- } else {
- SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER,
- GR_GL_RGBA,
- width, height));
- }
- SK_GL(*this, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
- GR_GL_COLOR_ATTACHMENT0,
- GR_GL_RENDERBUFFER,
- fColorBufferID));
- SK_GL(*this, GenRenderbuffers(1, &fDepthStencilBufferID));
- SK_GL(*this, BindRenderbuffer(GR_GL_RENDERBUFFER, fDepthStencilBufferID));
-
- // Some drivers that support packed depth stencil will only succeed
- // in binding a packed format an FBO. However, we can't rely on packed
- // depth stencil being available.
- bool supportsPackedDepthStencil;
- if (kES2_GrGLBinding == bindingInUse) {
- supportsPackedDepthStencil = this->hasExtension("GL_OES_packed_depth_stencil");
- } else {
- supportsPackedDepthStencil = version >= GR_GL_VER(3,0) ||
- this->hasExtension("GL_EXT_packed_depth_stencil") ||
- this->hasExtension("GL_ARB_framebuffer_object");
- }
-
- if (supportsPackedDepthStencil) {
- // ES2 requires sized internal formats for RenderbufferStorage
- // On Desktop we let the driver decide.
- GrGLenum format = kES2_GrGLBinding == bindingInUse ?
- GR_GL_DEPTH24_STENCIL8 :
- GR_GL_DEPTH_STENCIL;
- SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER,
- format,
- width, height));
- SK_GL(*this, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
- GR_GL_DEPTH_ATTACHMENT,
- GR_GL_RENDERBUFFER,
- fDepthStencilBufferID));
- } else {
- GrGLenum format = kES2_GrGLBinding == bindingInUse ?
- GR_GL_STENCIL_INDEX8 :
- GR_GL_STENCIL_INDEX;
- SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER,
- format,
- width, height));
- }
- SK_GL(*this, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
- GR_GL_STENCIL_ATTACHMENT,
- GR_GL_RENDERBUFFER,
- fDepthStencilBufferID));
- SK_GL(*this, Viewport(0, 0, width, height));
- SK_GL(*this, ClearStencil(0));
- SK_GL(*this, Clear(GR_GL_STENCIL_BUFFER_BIT));
-
- SK_GL_RET(*this, error, GetError());
- GrGLenum status;
- SK_GL_RET(*this, status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
-
- if (GR_GL_FRAMEBUFFER_COMPLETE != status ||
- GR_GL_NO_ERROR != error) {
- fFBO = 0;
- fColorBufferID = 0;
- fDepthStencilBufferID = 0;
- fGL->unref();
- fGL = NULL;
- this->destroyGLContext();
- return false;
- } else {
- return true;
- }
- }
- return false;
-}
--- /dev/null
+
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+#include "gl/SkGLContextHelper.h"
+#include "GrGLUtil.h"
+
+SK_DEFINE_INST_COUNT(SkGLContextHelper)
+
+SkGLContextHelper::SkGLContextHelper()
+ : fFBO(0)
+ , fColorBufferID(0)
+ , fDepthStencilBufferID(0)
+ , fGL(NULL) {
+}
+
+SkGLContextHelper::~SkGLContextHelper() {
+
+ if (fGL) {
+ // TODO: determine why DeleteFramebuffers is generating a GL error in tests
+ SK_GL_NOERRCHECK(*this, DeleteFramebuffers(1, &fFBO));
+ SK_GL_NOERRCHECK(*this, DeleteRenderbuffers(1, &fColorBufferID));
+ SK_GL_NOERRCHECK(*this, DeleteRenderbuffers(1, &fDepthStencilBufferID));
+ }
+
+ SkSafeUnref(fGL);
+}
+
+bool SkGLContextHelper::init(int width, int height) {
+ if (fGL) {
+ fGL->unref();
+ this->destroyGLContext();
+ }
+
+ fGL = this->createGLContext();
+ if (fGL) {
+ const GrGLubyte* temp;
+
+ GrGLBinding bindingInUse = GrGLGetBindingInUse(this->gl());
+
+ if (!fGL->validate(bindingInUse) || !fExtensions.init(bindingInUse, fGL)) {
+ fGL = NULL;
+ this->destroyGLContext();
+ return false;
+ }
+
+ SK_GL_RET(*this, temp, GetString(GR_GL_VERSION));
+ const char* versionStr = reinterpret_cast<const char*>(temp);
+ GrGLVersion version = GrGLGetVersionFromString(versionStr);
+
+ // clear any existing GL erorrs
+ GrGLenum error;
+ do {
+ SK_GL_RET(*this, error, GetError());
+ } while (GR_GL_NO_ERROR != error);
+
+ SK_GL(*this, GenFramebuffers(1, &fFBO));
+ SK_GL(*this, BindFramebuffer(GR_GL_FRAMEBUFFER, fFBO));
+ SK_GL(*this, GenRenderbuffers(1, &fColorBufferID));
+ SK_GL(*this, BindRenderbuffer(GR_GL_RENDERBUFFER, fColorBufferID));
+ if (kES2_GrGLBinding == bindingInUse) {
+ SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER,
+ GR_GL_RGBA8,
+ width, height));
+ } else {
+ SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER,
+ GR_GL_RGBA,
+ width, height));
+ }
+ SK_GL(*this, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
+ GR_GL_COLOR_ATTACHMENT0,
+ GR_GL_RENDERBUFFER,
+ fColorBufferID));
+ SK_GL(*this, GenRenderbuffers(1, &fDepthStencilBufferID));
+ SK_GL(*this, BindRenderbuffer(GR_GL_RENDERBUFFER, fDepthStencilBufferID));
+
+ // Some drivers that support packed depth stencil will only succeed
+ // in binding a packed format an FBO. However, we can't rely on packed
+ // depth stencil being available.
+ bool supportsPackedDepthStencil;
+ if (kES2_GrGLBinding == bindingInUse) {
+ supportsPackedDepthStencil = this->hasExtension("GL_OES_packed_depth_stencil");
+ } else {
+ supportsPackedDepthStencil = version >= GR_GL_VER(3,0) ||
+ this->hasExtension("GL_EXT_packed_depth_stencil") ||
+ this->hasExtension("GL_ARB_framebuffer_object");
+ }
+
+ if (supportsPackedDepthStencil) {
+ // ES2 requires sized internal formats for RenderbufferStorage
+ // On Desktop we let the driver decide.
+ GrGLenum format = kES2_GrGLBinding == bindingInUse ?
+ GR_GL_DEPTH24_STENCIL8 :
+ GR_GL_DEPTH_STENCIL;
+ SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER,
+ format,
+ width, height));
+ SK_GL(*this, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
+ GR_GL_DEPTH_ATTACHMENT,
+ GR_GL_RENDERBUFFER,
+ fDepthStencilBufferID));
+ } else {
+ GrGLenum format = kES2_GrGLBinding == bindingInUse ?
+ GR_GL_STENCIL_INDEX8 :
+ GR_GL_STENCIL_INDEX;
+ SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER,
+ format,
+ width, height));
+ }
+ SK_GL(*this, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
+ GR_GL_STENCIL_ATTACHMENT,
+ GR_GL_RENDERBUFFER,
+ fDepthStencilBufferID));
+ SK_GL(*this, Viewport(0, 0, width, height));
+ SK_GL(*this, ClearStencil(0));
+ SK_GL(*this, Clear(GR_GL_STENCIL_BUFFER_BIT));
+
+ SK_GL_RET(*this, error, GetError());
+ GrGLenum status;
+ SK_GL_RET(*this, status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
+
+ if (GR_GL_FRAMEBUFFER_COMPLETE != status ||
+ GR_GL_NO_ERROR != error) {
+ fFBO = 0;
+ fColorBufferID = 0;
+ fDepthStencilBufferID = 0;
+ fGL->unref();
+ fGL = NULL;
+ this->destroyGLContext();
+ return false;
+ } else {
+ return true;
+ }
+ }
+ return false;
+}
// The solution to this is probably to alter SkDebugGlContext's
// "makeCurrent" method to make a call like "makeCurrent(this)" to
// the debug GL interface (assuming that the application will create
- // multiple SkGLContext's) to let it switch between the active
+ // multiple SkGLContextHelper's) to let it switch between the active
// context. Everything in the GrDebugGL object would then need to be
// moved to a GrContextObj and the GrDebugGL object would just switch
// between them. Note that this approach would also require that
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
stagePtrs[s] = &stages[s];
}
- SkAutoTUnref<GrGLProgram> program(GrGLProgram::Create(this->glContextInfo(),
+ SkAutoTUnref<GrGLProgram> program(GrGLProgram::Create(this->glContext(),
pdesc,
stagePtrs));
if (NULL == program.get()) {
class SkBitmap;
class SkCanvas;
-class SkGLContext;
class SkPDFDevice;
namespace sk_tools {
void PictureRenderer::resetState(bool callFinish) {
#if SK_SUPPORT_GPU
- SkGLContext* glContext = this->getGLContext();
+ SkGLContextHelper* glContext = this->getGLContext();
if (NULL == glContext) {
SkASSERT(kBitmap_DeviceType == fDeviceType);
return;
class SkBitmap;
class SkCanvas;
-class SkGLContext;
+class SkGLContextHelper;
class SkThread;
namespace sk_tools {
}
}
- SkGLContext* getGLContext() {
+ SkGLContextHelper* getGLContext() {
GrContextFactory::GLContextType glContextType
= GrContextFactory::kNull_GLContextType;
switch(fDeviceType) {