From 6177e6999d23a4268ffd98dedfb1da00e272a89b Mon Sep 17 00:00:00 2001 From: "robertphillips@google.com" Date: Thu, 28 Feb 2013 20:16:25 +0000 Subject: [PATCH] Split GrGLContextInfo into GrGLContext & GrGLContextInfo https://codereview.appspot.com/7436045/ git-svn-id: http://skia.googlecode.com/svn/trunk@7905 2bbb7eff-a529-9590-31e7-b0007b416f81 --- bench/BenchGpuTimer_gl.cpp | 4 +- bench/BenchGpuTimer_gl.h | 6 +- bench/BenchTimer.cpp | 2 +- bench/BenchTimer.h | 4 +- bench/benchmain.cpp | 4 +- gyp/gpu.gypi | 8 +- include/gpu/GrContextFactory.h | 6 +- include/gpu/gl/SkANGLEGLContext.h | 4 +- include/gpu/gl/SkDebugGLContext.h | 4 +- .../gl/{SkGLContext.h => SkGLContextHelper.h} | 14 +-- include/gpu/gl/SkMesaGLContext.h | 4 +- include/gpu/gl/SkNativeGLContext.h | 4 +- include/gpu/gl/SkNullGLContext.h | 4 +- src/gpu/GrGpuFactory.cpp | 6 +- src/gpu/gl/GrGLCaps.cpp | 17 ++- src/gpu/gl/GrGLCaps.h | 4 +- .../{GrGLContextInfo.cpp => GrGLContext.cpp} | 101 ++++++++++-------- .../gl/{GrGLContextInfo.h => GrGLContext.h} | 88 ++++++++++----- src/gpu/gl/GrGLProgram.cpp | 34 +++--- src/gpu/gl/GrGLProgram.h | 8 +- src/gpu/gl/GrGLShaderBuilder.cpp | 19 ++-- src/gpu/gl/GrGLShaderBuilder.h | 2 +- src/gpu/gl/GrGLShaderVar.h | 8 +- src/gpu/gl/GrGLUniformManager.h | 6 +- src/gpu/gl/GrGpuGL.cpp | 40 +++---- src/gpu/gl/GrGpuGL.h | 30 +++--- src/gpu/gl/GrGpuGL_program.cpp | 2 +- ...{SkGLContext.cpp => SkGLContextHelper.cpp} | 12 +-- src/gpu/gl/debug/GrGLCreateDebugInterface.cpp | 2 +- tests/GLProgramsTest.cpp | 2 +- tools/PdfRenderer.h | 1 - tools/PictureRenderer.cpp | 2 +- tools/PictureRenderer.h | 4 +- 33 files changed, 244 insertions(+), 212 deletions(-) rename include/gpu/gl/{SkGLContext.h => SkGLContextHelper.h} (88%) rename src/gpu/gl/{GrGLContextInfo.cpp => GrGLContext.cpp} (56%) rename src/gpu/gl/{GrGLContextInfo.h => GrGLContext.h} (56%) rename src/gpu/gl/{SkGLContext.cpp => SkGLContextHelper.cpp} (95%) diff --git a/bench/BenchGpuTimer_gl.cpp b/bench/BenchGpuTimer_gl.cpp index 1b317c6aaa..349fc1529d 100644 --- a/bench/BenchGpuTimer_gl.cpp +++ b/bench/BenchGpuTimer_gl.cpp @@ -6,10 +6,10 @@ * 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(); diff --git a/bench/BenchGpuTimer_gl.h b/bench/BenchGpuTimer_gl.h index 7c7b5c2949..e472a4c514 100644 --- a/bench/BenchGpuTimer_gl.h +++ b/bench/BenchGpuTimer_gl.h @@ -8,18 +8,18 @@ #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; }; diff --git a/bench/BenchTimer.cpp b/bench/BenchTimer.cpp index 4e0484459d..ab9dfdaf18 100644 --- a/bench/BenchTimer.cpp +++ b/bench/BenchTimer.cpp @@ -20,7 +20,7 @@ #include "BenchGpuTimer_gl.h" #endif -BenchTimer::BenchTimer(SkGLContext* gl) +BenchTimer::BenchTimer(SkGLContextHelper* gl) : fCpu(-1.0) , fWall(-1.0) , fTruncatedCpu(-1.0) diff --git a/bench/BenchTimer.h b/bench/BenchTimer.h index 58773d403c..79e1036c52 100644 --- a/bench/BenchTimer.h +++ b/bench/BenchTimer.h @@ -14,7 +14,7 @@ class BenchSysTimer; class BenchGpuTimer; -class SkGLContext; +class SkGLContextHelper; /** * SysTimers and GpuTimers are implemented orthogonally. @@ -27,7 +27,7 @@ class SkGLContext; */ class BenchTimer { public: - BenchTimer(SkGLContext* gl = NULL); + BenchTimer(SkGLContextHelper* gl = NULL); ~BenchTimer(); void start(); void end(); diff --git a/bench/benchmain.cpp b/bench/benchmain.cpp index 5fc74bcec6..96db07d465 100644 --- a/bench/benchmain.cpp +++ b/bench/benchmain.cpp @@ -625,7 +625,7 @@ int tool_main(int argc, char** argv) { SkTArray 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); } @@ -680,7 +680,7 @@ int tool_main(int argc, char** argv) { 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 diff --git a/gyp/gpu.gypi b/gyp/gpu.gypi index dffc07dc70..a1c17273b5 100644 --- a/gyp/gpu.gypi +++ b/gyp/gpu.gypi @@ -139,8 +139,8 @@ '<(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', @@ -225,7 +225,7 @@ '<(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', @@ -236,7 +236,7 @@ '<(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', diff --git a/include/gpu/GrContextFactory.h b/include/gpu/GrContextFactory.h index d425b74416..3d9f1a386d 100644 --- a/include/gpu/GrContextFactory.h +++ b/include/gpu/GrContextFactory.h @@ -104,7 +104,7 @@ public: return fContexts[i].fGrContext; } } - SkAutoTUnref glCtx; + SkAutoTUnref glCtx; SkAutoTUnref grCtx; switch (type) { case kNative_GLContextType: @@ -150,7 +150,7 @@ public: // 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; @@ -163,7 +163,7 @@ public: private: struct GPUContext { GLContextType fType; - SkGLContext* fGLContext; + SkGLContextHelper* fGLContext; GrContext* fGrContext; }; SkTArray fContexts; diff --git a/include/gpu/gl/SkANGLEGLContext.h b/include/gpu/gl/SkANGLEGLContext.h index 7bcf07a87d..63765a0131 100644 --- a/include/gpu/gl/SkANGLEGLContext.h +++ b/include/gpu/gl/SkANGLEGLContext.h @@ -10,12 +10,12 @@ #if SK_ANGLE -#include "SkGLContext.h" +#include "SkGLContextHelper.h" #include #include -class SkANGLEGLContext : public SkGLContext { +class SkANGLEGLContext : public SkGLContextHelper { public: SkANGLEGLContext(); diff --git a/include/gpu/gl/SkDebugGLContext.h b/include/gpu/gl/SkDebugGLContext.h index 6e29b6738b..2437aaeb5f 100644 --- a/include/gpu/gl/SkDebugGLContext.h +++ b/include/gpu/gl/SkDebugGLContext.h @@ -8,9 +8,9 @@ #ifndef SkDebugGLContext_DEFINED #define SkDebugGLContext_DEFINED -#include "SkGLContext.h" +#include "SkGLContextHelper.h" -class SkDebugGLContext : public SkGLContext { +class SkDebugGLContext : public SkGLContextHelper { public: SkDebugGLContext() {}; diff --git a/include/gpu/gl/SkGLContext.h b/include/gpu/gl/SkGLContextHelper.h similarity index 88% rename from include/gpu/gl/SkGLContext.h rename to include/gpu/gl/SkGLContextHelper.h index 43ae9cdc00..386a6958fb 100644 --- a/include/gpu/gl/SkGLContext.h +++ b/include/gpu/gl/SkGLContextHelper.h @@ -1,12 +1,12 @@ /* - * Copyright 2011 Google Inc. + * 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 SkGLContext_DEFINED -#define SkGLContext_DEFINED +#ifndef SkGLContextHelper_DEFINED +#define SkGLContextHelper_DEFINED #include "GrGLExtensions.h" #include "GrGLInterface.h" @@ -16,12 +16,12 @@ * Provides a GrGLInterface struct of function pointers for the context. */ -class SkGLContext : public SkRefCnt { +class SkGLContextHelper : public SkRefCnt { public: - SK_DECLARE_INST_COUNT(SkGLContext) + SK_DECLARE_INST_COUNT(SkGLContextHelper) - SkGLContext(); - virtual ~SkGLContext(); + SkGLContextHelper(); + virtual ~SkGLContextHelper(); /** * Initializes the context and makes it current. diff --git a/include/gpu/gl/SkMesaGLContext.h b/include/gpu/gl/SkMesaGLContext.h index 14a3ca7b27..6470d2eef0 100644 --- a/include/gpu/gl/SkMesaGLContext.h +++ b/include/gpu/gl/SkMesaGLContext.h @@ -8,11 +8,11 @@ #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; diff --git a/include/gpu/gl/SkNativeGLContext.h b/include/gpu/gl/SkNativeGLContext.h index 410c14907f..27a8f09bac 100644 --- a/include/gpu/gl/SkNativeGLContext.h +++ b/include/gpu/gl/SkNativeGLContext.h @@ -8,7 +8,7 @@ #ifndef SkNativeGLContext_DEFINED #define SkNativeGLContext_DEFINED -#include "SkGLContext.h" +#include "SkGLContextHelper.h" #if defined(SK_BUILD_FOR_MAC) #include @@ -23,7 +23,7 @@ #include #endif -class SkNativeGLContext : public SkGLContext { +class SkNativeGLContext : public SkGLContextHelper { public: SkNativeGLContext(); diff --git a/include/gpu/gl/SkNullGLContext.h b/include/gpu/gl/SkNullGLContext.h index 83213a3ac3..4f2639c8d7 100644 --- a/include/gpu/gl/SkNullGLContext.h +++ b/include/gpu/gl/SkNullGLContext.h @@ -8,9 +8,9 @@ #ifndef SkNullGLContext_DEFINED #define SkNullGLContext_DEFINED -#include "SkGLContext.h" +#include "SkGLContextHelper.h" -class SkNullGLContext : public SkGLContext { +class SkNullGLContext : public SkGLContextHelper { public: SkNullGLContext() {}; diff --git a/src/gpu/GrGpuFactory.cpp b/src/gpu/GrGpuFactory.cpp index a5114469ae..a3c8eba452 100644 --- a/src/gpu/GrGpuFactory.cpp +++ b/src/gpu/GrGpuFactory.cpp @@ -34,9 +34,9 @@ GrGpu* GrGpu::Create(GrBackend backend, GrBackendContext backendContext, GrConte #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; diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp index 1276a65a19..d62a310fc6 100644 --- a/src/gpu/gl/GrGLCaps.cpp +++ b/src/gpu/gl/GrGLCaps.cpp @@ -7,7 +7,7 @@ #include "GrGLCaps.h" -#include "GrGLContextInfo.h" +#include "GrGLContext.h" #include "SkTSearch.h" GrGLCaps::GrGLCaps() { @@ -73,14 +73,13 @@ GrGLCaps& GrGLCaps::operator = (const GrGLCaps& caps) { 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(); @@ -178,7 +177,7 @@ void GrGLCaps::init(const GrGLContextInfo& ctxInfo) { fUseNonVBOVertexAndIndexDynamicData = true; } - this->initFSAASupport(ctxInfo); + this->initFSAASupport(ctxInfo, gli); this->initStencilFormats(ctxInfo); } @@ -227,7 +226,7 @@ int coverage_mode_compare(const GrGLCaps::MSAACoverageMode* left, } } -void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo) { +void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { fMSFBOType = kNone_MSFBOType; if (kDesktop_GrGLBinding != ctxInfo.binding()) { @@ -253,11 +252,11 @@ void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo) { 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 @@ -269,9 +268,7 @@ void GrGLCaps::initFSAASupport(const GrGLContextInfo& ctxInfo) { } } if (kNone_MSFBOType != fMSFBOType) { - GR_GL_GetIntegerv(ctxInfo.interface(), - GR_GL_MAX_SAMPLES, - &fMaxSampleCount); + GR_GL_GetIntegerv(gli, GR_GL_MAX_SAMPLES, &fMaxSampleCount); } } diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h index 4143868ed8..48ceb33637 100644 --- a/src/gpu/gl/GrGLCaps.h +++ b/src/gpu/gl/GrGLCaps.h @@ -95,7 +95,7 @@ public: * 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 @@ -267,7 +267,7 @@ private: } }; - 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 diff --git a/src/gpu/gl/GrGLContextInfo.cpp b/src/gpu/gl/GrGLContext.cpp similarity index 56% rename from src/gpu/gl/GrGLContextInfo.cpp rename to src/gpu/gl/GrGLContext.cpp index 1522618d03..ba4196de8e 100644 --- a/src/gpu/gl/GrGLContextInfo.cpp +++ b/src/gpu/gl/GrGLContext.cpp @@ -1,51 +1,23 @@ /* - * Copyright 2012 Google Inc. + * 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 "GrGLContextInfo.h" +#include "GrGLContext.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; +//////////////////////////////////////////////////////////////////////////////// +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; } - -void GrGLContextInfo::reset() { - GrSafeSetNull(fInterface); - fBindingInUse = kNone_GrGLBinding; - fGLVersion = GR_GL_VER(0, 0); - fGLSLGeneration = static_cast(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 @@ -57,19 +29,14 @@ bool GrGLContextInfo::initialize(const GrGLInterface* interface) { 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()); + fGLSLGeneration = GrGetGLSLGeneration(fBindingInUse, interface); fVendor = GrGLGetVendor(interface); - fGLCaps.init(*this); + fGLCaps.init(*this, interface); return true; } } @@ -77,5 +44,45 @@ bool GrGLContextInfo::initialize(const GrGLInterface* interface) { } bool GrGLContextInfo::isInitialized() const { - return kNone_GrGLBinding != fBindingInUse; + return kNone_GrGLBinding != fBindingInUse; +} + +void GrGLContextInfo::reset() { + fBindingInUse = kNone_GrGLBinding; + fGLVersion = GR_GL_VER(0, 0); + fGLSLGeneration = static_cast(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; } diff --git a/src/gpu/gl/GrGLContextInfo.h b/src/gpu/gl/GrGLContext.h similarity index 56% rename from src/gpu/gl/GrGLContextInfo.h rename to src/gpu/gl/GrGLContext.h index bfadabe87f..05647cc9fa 100644 --- a/src/gpu/gl/GrGLContextInfo.h +++ b/src/gpu/gl/GrGLContext.h @@ -1,13 +1,13 @@ /* - * Copyright 2012 Google Inc. + * 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 GrGLContextInfo_DEFINED -#define GrGLContextInfo_DEFINED +#ifndef GrGLContext_DEFINED +#define GrGLContext_DEFINED #include "gl/GrGLExtensions.h" #include "gl/GrGLInterface.h" @@ -18,36 +18,21 @@ #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. + * Encapsulates information about an OpenGL context including 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 + * Default constructor */ - GrGLContextInfo(const GrGLContextInfo& ctx); - - ~GrGLContextInfo(); + GrGLContextInfo() { this->reset(); } /** * Copies a GrGLContextInfo */ - GrGLContextInfo& operator = (const GrGLContextInfo& ctx); - + GrGLContextInfo& operator= (const GrGLContextInfo& ctxInfo); + /** * Initializes a GrGLContextInfo from a GrGLInterface and the currently * bound OpenGL context accessible by the GrGLInterface. @@ -55,7 +40,6 @@ public: 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; } @@ -74,10 +58,13 @@ public: return fExtensions.has(ext); } -private: + /** + * Reset the information + */ void reset(); - const GrGLInterface* fInterface; +private: + GrGLBinding fBindingInUse; GrGLVersion fGLVersion; GrGLSLGeneration fGLSLGeneration; @@ -86,4 +73,51 @@ private: 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 diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp index eb493257f3..781e15fdde 100644 --- a/src/gpu/gl/GrGLProgram.cpp +++ b/src/gpu/gl/GrGLProgram.cpp @@ -20,8 +20,8 @@ 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."); @@ -229,7 +229,7 @@ void GrGLProgram::BuildDesc(const GrDrawState& drawState, #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)); @@ -240,10 +240,10 @@ GrGLProgram* GrGLProgram::Create(const GrGLContextInfo& gl, 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; @@ -438,7 +438,7 @@ bool GrGLProgram::genEdgeCoverage(SkString* coverageVar, 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; @@ -451,7 +451,7 @@ bool GrGLProgram::genEdgeCoverage(SkString* coverageVar, 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; @@ -548,7 +548,7 @@ void gen_attribute_coverage(GrGLShaderBuilder* segments, 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" @@ -597,7 +597,7 @@ void print_shader(GrGLint stringCnt, } // 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, @@ -638,7 +638,7 @@ GrGLuint compile_shader(const GrGLContextInfo& gl, } // 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); @@ -657,7 +657,7 @@ bool GrGLProgram::compileShaders(const GrGLShaderBuilder& builder) { GrPrintf("\n"); } - if (!(fVShaderID = compile_shader(fContextInfo, GR_GL_VERTEX_SHADER, shader))) { + if (!(fVShaderID = compile_shader(fContext, GR_GL_VERTEX_SHADER, shader))) { return false; } @@ -667,7 +667,7 @@ bool GrGLProgram::compileShaders(const GrGLShaderBuilder& builder) { 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 { @@ -679,7 +679,7 @@ bool GrGLProgram::compileShaders(const GrGLShaderBuilder& builder) { 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; } @@ -689,7 +689,7 @@ bool GrGLProgram::compileShaders(const GrGLShaderBuilder& builder) { 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 @@ -738,11 +738,11 @@ bool GrGLProgram::genProgram(const GrEffectStage* stages[]) { // 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) { diff --git a/src/gpu/gl/GrGLProgram.h b/src/gpu/gl/GrGLProgram.h index ea39fa8e53..cde918b54b 100644 --- a/src/gpu/gl/GrGLProgram.h +++ b/src/gpu/gl/GrGLProgram.h @@ -11,7 +11,7 @@ #include "GrDrawState.h" #include "GrGLEffect.h" -#include "GrGLContextInfo.h" +#include "GrGLContext.h" #include "GrGLSL.h" #include "GrGLTexture.h" #include "GrGLUniformManager.h" @@ -55,7 +55,7 @@ public: const GrGpuGL* gpu, Desc* outDesc); - static GrGLProgram* Create(const GrGLContextInfo& gl, + static GrGLProgram* Create(const GrGLContext& gl, const Desc& desc, const GrEffectStage* stages[]); @@ -206,7 +206,7 @@ public: static const AttribLayout kAttribLayouts[kGrVertexAttribTypeCount]; private: - GrGLProgram(const GrGLContextInfo& gl, + GrGLProgram(const GrGLContext& gl, const Desc& desc, const GrEffectStage* stages[]); @@ -290,7 +290,7 @@ private: GrGLEffect* fEffects[GrDrawState::kNumStages]; Desc fDesc; - const GrGLContextInfo& fContextInfo; + const GrGLContext& fContext; GrGLUniformManager fUniformManager; UniformHandles fUniformHandles; diff --git a/src/gpu/gl/GrGLShaderBuilder.cpp b/src/gpu/gl/GrGLShaderBuilder.cpp index 1618fe5416..aa3505cba5 100644 --- a/src/gpu/gl/GrGLShaderBuilder.cpp +++ b/src/gpu/gl/GrGLShaderBuilder.cpp @@ -81,7 +81,8 @@ void append_swizzle(SkString* outAppend, // 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) @@ -90,7 +91,7 @@ GrGLShaderBuilder::GrGLShaderBuilder(const GrGLContextInfo& ctx, GrGLUniformMana , fFSInputs(kVarsPerBlock) , fFSOutputs(kMaxFSOutputs) , fUsesGS(false) - , fContext(ctx) + , fCtxInfo(ctxInfo) , fUniformManager(uniformManager) , fCurrentStageIdx(kNonStageIdx) , fSetupFragPosition(false) @@ -111,7 +112,7 @@ void GrGLShaderBuilder::appendTextureLookup(SkString* out, 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( @@ -261,7 +262,7 @@ void GrGLShaderBuilder::addVarying(GrSLType type, 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, @@ -327,7 +328,7 @@ void GrGLShaderBuilder::emitFunction(ShaderType shader, 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(", "); } @@ -365,7 +366,7 @@ inline void append_default_precision_qualifier(GrGLShaderVar::Precision p, 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"); } } @@ -373,7 +374,7 @@ void GrGLShaderBuilder::appendDecls(const VarArray& vars, SkString* out) const { 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"); } } @@ -406,13 +407,13 @@ void GrGLShaderBuilder::getShader(ShaderType type, SkString* shaderStr) const { 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"); diff --git a/src/gpu/gl/GrGLShaderBuilder.h b/src/gpu/gl/GrGLShaderBuilder.h index 87136cdf53..d50fbce9c8 100644 --- a/src/gpu/gl/GrGLShaderBuilder.h +++ b/src/gpu/gl/GrGLShaderBuilder.h @@ -217,7 +217,7 @@ private: kNonStageIdx = -1, }; - const GrGLContextInfo& fContext; + const GrGLContextInfo& fCtxInfo; GrGLUniformManager& fUniformManager; int fCurrentStageIdx; SkString fFSFunctions; diff --git a/src/gpu/gl/GrGLShaderVar.h b/src/gpu/gl/GrGLShaderVar.h index 89fa087460..ecf0b479ae 100644 --- a/src/gpu/gl/GrGLShaderVar.h +++ b/src/gpu/gl/GrGLShaderVar.h @@ -8,7 +8,7 @@ #ifndef GrGLShaderVar_DEFINED #define GrGLShaderVar_DEFINED -#include "GrGLContextInfo.h" +#include "GrGLContext.h" #include "GrGLSL.h" #include "SkString.h" @@ -252,7 +252,7 @@ public: /** * 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. @@ -260,10 +260,10 @@ public: } 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()) { diff --git a/src/gpu/gl/GrGLUniformManager.h b/src/gpu/gl/GrGLUniformManager.h index 8f435d3037..ee693a6a5b 100644 --- a/src/gpu/gl/GrGLUniformManager.h +++ b/src/gpu/gl/GrGLUniformManager.h @@ -14,7 +14,7 @@ #include "SkTArray.h" -class GrGLContextInfo; +class GrGLContext; class SkMatrix; /** Manages a program's uniforms. @@ -25,7 +25,7 @@ public: 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); @@ -78,7 +78,7 @@ private: }; SkTArray fUniforms; - const GrGLContextInfo& fContext; + const GrGLContext& fContext; }; #endif diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp index 92bac03b8a..8ea7e5cde4 100644 --- a/src/gpu/gl/GrGpuGL.cpp +++ b/src/gpu/gl/GrGpuGL.cpp @@ -147,17 +147,17 @@ static bool fbo_test(const GrGLInterface* gl, int w, int h) { 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; @@ -178,7 +178,7 @@ GrGpuGL::GrGpuGL(const GrGLContextInfo& ctxInfo, GrContext* context) this->initCaps(); - fProgramCache = SkNEW_ARGS(ProgramCache, (this->glContextInfo())); + fProgramCache = SkNEW_ARGS(ProgramCache, (this->glContext())); fHWGeometryState.setMaxAttribArrays(this->glCaps().maxVertexAttributes()); @@ -827,34 +827,34 @@ bool GrGpuGL::uploadTexData(const GrGLTexture::Desc& desc, } 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; } @@ -904,7 +904,7 @@ bool GrGpuGL::createRenderTargetObjects(int width, int height, 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)) { @@ -920,7 +920,7 @@ bool GrGpuGL::createRenderTargetObjects(int width, int height, if (status != GR_GL_FRAMEBUFFER_COMPLETE) { goto FAILED; } - fGLContextInfo.caps().markConfigAsValidColorAttachment( + fGLContext.info().caps().markConfigAsValidColorAttachment( desc->fConfig); } } @@ -935,7 +935,7 @@ bool GrGpuGL::createRenderTargetObjects(int width, int height, if (status != GR_GL_FRAMEBUFFER_COMPLETE) { goto FAILED; } - fGLContextInfo.caps().markConfigAsValidColorAttachment(desc->fConfig); + fGLContext.info().caps().markConfigAsValidColorAttachment(desc->fConfig); } return true; @@ -1131,7 +1131,7 @@ bool GrGpuGL::createStencilBufferForRenderTarget(GrRenderTarget* rt, // 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); @@ -1220,7 +1220,7 @@ bool GrGpuGL::attachStencilBufferToRenderTarget(GrStencilBuffer* sb, } return false; } else { - fGLContextInfo.caps().markColorConfigAndStencilFormatAsVerified( + fGLContext.info().caps().markColorConfigAndStencilFormatAsVerified( rt->config(), glsb->format()); } diff --git a/src/gpu/gl/GrGpuGL.h b/src/gpu/gl/GrGpuGL.h index b47865cba7..a859d18595 100644 --- a/src/gpu/gl/GrGpuGL.h +++ b/src/gpu/gl/GrGpuGL.h @@ -13,7 +13,7 @@ #include "GrBinHashKey.h" #include "GrDrawState.h" #include "GrGpu.h" -#include "GrGLContextInfo.h" +#include "GrGLContext.h" #include "GrGLIndexBuffer.h" #include "GrGLIRect.h" #include "GrGLProgram.h" @@ -24,17 +24,13 @@ 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); @@ -55,7 +51,7 @@ public: 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); @@ -137,17 +133,15 @@ private: // 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[]); @@ -188,7 +182,7 @@ private: 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) @@ -236,7 +230,7 @@ private: void fillInConfigRenderableTable(); - GrGLContextInfo fGLContextInfo; + GrGLContext fGLContext; // GL program-related state ProgramCache* fProgramCache; diff --git a/src/gpu/gl/GrGpuGL_program.cpp b/src/gpu/gl/GrGpuGL_program.cpp index 8526100f9d..e5a71831ec 100644 --- a/src/gpu/gl/GrGpuGL_program.cpp +++ b/src/gpu/gl/GrGpuGL_program.cpp @@ -16,7 +16,7 @@ static const UniformHandle kInvalidUniformHandle = GrGLUniformManager::kInvalidU #define SKIP_CACHE_CHECK true #define GR_UINT32_MAX static_cast(-1) -GrGpuGL::ProgramCache::ProgramCache(const GrGLContextInfo& gl) +GrGpuGL::ProgramCache::ProgramCache(const GrGLContext& gl) : fCount(0) , fCurrLRUStamp(0) , fGL(gl) { diff --git a/src/gpu/gl/SkGLContext.cpp b/src/gpu/gl/SkGLContextHelper.cpp similarity index 95% rename from src/gpu/gl/SkGLContext.cpp rename to src/gpu/gl/SkGLContextHelper.cpp index 6076845082..9dcc8ecbb8 100644 --- a/src/gpu/gl/SkGLContext.cpp +++ b/src/gpu/gl/SkGLContextHelper.cpp @@ -1,23 +1,23 @@ /* - * Copyright 2011 Google Inc. + * 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/SkGLContext.h" +#include "gl/SkGLContextHelper.h" #include "GrGLUtil.h" -SK_DEFINE_INST_COUNT(SkGLContext) +SK_DEFINE_INST_COUNT(SkGLContextHelper) -SkGLContext::SkGLContext() +SkGLContextHelper::SkGLContextHelper() : fFBO(0) , fColorBufferID(0) , fDepthStencilBufferID(0) , fGL(NULL) { } -SkGLContext::~SkGLContext() { +SkGLContextHelper::~SkGLContextHelper() { if (fGL) { // TODO: determine why DeleteFramebuffers is generating a GL error in tests @@ -29,7 +29,7 @@ SkGLContext::~SkGLContext() { SkSafeUnref(fGL); } -bool SkGLContext::init(int width, int height) { +bool SkGLContextHelper::init(int width, int height) { if (fGL) { fGL->unref(); this->destroyGLContext(); diff --git a/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp b/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp index ab3501c14b..21a3d1bf71 100644 --- a/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp +++ b/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp @@ -738,7 +738,7 @@ public: // 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 diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp index 3c9af5c98f..45c5f2d162 100644 --- a/tests/GLProgramsTest.cpp +++ b/tests/GLProgramsTest.cpp @@ -138,7 +138,7 @@ bool GrGpuGL::programUnitTest(int maxStages) { for (int s = 0; s < GrDrawState::kNumStages; ++s) { stagePtrs[s] = &stages[s]; } - SkAutoTUnref program(GrGLProgram::Create(this->glContextInfo(), + SkAutoTUnref program(GrGLProgram::Create(this->glContext(), pdesc, stagePtrs)); if (NULL == program.get()) { diff --git a/tools/PdfRenderer.h b/tools/PdfRenderer.h index 3524a9d8f9..d2d66378b6 100644 --- a/tools/PdfRenderer.h +++ b/tools/PdfRenderer.h @@ -22,7 +22,6 @@ class SkBitmap; class SkCanvas; -class SkGLContext; class SkPDFDevice; namespace sk_tools { diff --git a/tools/PictureRenderer.cpp b/tools/PictureRenderer.cpp index caab64a98d..ab5df5414e 100644 --- a/tools/PictureRenderer.cpp +++ b/tools/PictureRenderer.cpp @@ -203,7 +203,7 @@ void PictureRenderer::buildBBoxHierarchy() { 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; diff --git a/tools/PictureRenderer.h b/tools/PictureRenderer.h index 47fc7d7a31..438488a66b 100644 --- a/tools/PictureRenderer.h +++ b/tools/PictureRenderer.h @@ -29,7 +29,7 @@ class SkBitmap; class SkCanvas; -class SkGLContext; +class SkGLContextHelper; class SkThread; namespace sk_tools { @@ -228,7 +228,7 @@ public: } } - SkGLContext* getGLContext() { + SkGLContextHelper* getGLContext() { GrContextFactory::GLContextType glContextType = GrContextFactory::kNull_GLContextType; switch(fDeviceType) { -- 2.34.1