diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-01-16 18:39:04 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-01-16 18:39:04 +0000 |
commit | b1854a85095f9924947bc00e665da47b0c0bdfb9 (patch) | |
tree | 43f177933917ec14fdb565700189215c4f50a41d /src | |
parent | 5b8bde5db24f581d69b7efce72cf42110b80eaf5 (diff) |
Make GrGLContextInfo have private ptr to GrGLInterface
BUG=skia:2042
R=robertphillips@google.com
Author: bsalomon@google.com
Review URL: https://codereview.chromium.org/140843003
git-svn-id: http://skia.googlecode.com/svn/trunk@13111 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/gl/GrGLContext.cpp | 60 | ||||
-rw-r--r-- | src/gpu/gl/GrGLContext.h | 80 | ||||
-rw-r--r-- | src/gpu/gl/GrGLShaderBuilder.cpp | 2 | ||||
-rw-r--r-- | src/gpu/gl/GrGpuGL.cpp | 24 | ||||
-rw-r--r-- | src/gpu/gl/GrGpuGL.h | 13 |
5 files changed, 64 insertions, 115 deletions
diff --git a/src/gpu/gl/GrGLContext.cpp b/src/gpu/gl/GrGLContext.cpp index 2eb4893019..d95fe1cb3c 100644 --- a/src/gpu/gl/GrGLContext.cpp +++ b/src/gpu/gl/GrGLContext.cpp @@ -8,16 +8,17 @@ #include "GrGLContext.h" //////////////////////////////////////////////////////////////////////////////// -GrGLContextInfo& GrGLContextInfo::operator= (const GrGLContextInfo& ctxInfo) { - fStandard = ctxInfo.fStandard; - fGLVersion = ctxInfo.fGLVersion; - fGLSLGeneration = ctxInfo.fGLSLGeneration; - fVendor = ctxInfo.fVendor; - fRenderer = ctxInfo.fRenderer; - fExtensions = ctxInfo.fExtensions; - fIsMesa = ctxInfo.fIsMesa; - fIsChromium = ctxInfo.fIsChromium; - *fGLCaps = *ctxInfo.fGLCaps.get(); + +GrGLContextInfo& GrGLContextInfo::operator= (const GrGLContextInfo& that) { + fInterface.reset(SkSafeRef(that.fInterface.get())); + fGLVersion = that.fGLVersion; + fGLSLGeneration = that.fGLSLGeneration; + fVendor = that.fVendor; + fRenderer = that.fRenderer; + fExtensions = that.fExtensions; + fIsMesa = that.fIsMesa; + fIsChromium = that.fIsChromium; + *fGLCaps = *that.fGLCaps.get(); return *this; } @@ -48,8 +49,8 @@ bool GrGLContextInfo::initialize(const GrGLInterface* interface) { fIsChromium = GrGLIsChromiumFromRendererString(renderer); - // This must be done before calling GrGLCaps::init() - fStandard = interface->fStandard; + // This must occur before caps init. + fInterface.reset(SkRef(interface)); fGLCaps->init(*this, interface); @@ -60,11 +61,11 @@ bool GrGLContextInfo::initialize(const GrGLInterface* interface) { } bool GrGLContextInfo::isInitialized() const { - return kNone_GrGLStandard != fStandard; + return NULL != fInterface.get(); } void GrGLContextInfo::reset() { - fStandard = kNone_GrGLStandard; + fInterface.reset(NULL); fGLVersion = GR_GL_VER(0, 0); fGLSLGeneration = static_cast<GrGLSLGeneration>(0); fVendor = kOther_GrGLVendor; @@ -74,34 +75,3 @@ void GrGLContextInfo::reset() { 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) { - SkRefCnt_SafeAssign(fInterface, ctx.fInterface); - fInfo = ctx.fInfo; - return *this; -} - -void GrGLContext::reset() { - SkSafeSetNull(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/GrGLContext.h b/src/gpu/gl/GrGLContext.h index a418121f49..13c94a902d 100644 --- a/src/gpu/gl/GrGLContext.h +++ b/src/gpu/gl/GrGLContext.h @@ -31,10 +31,12 @@ public: this->reset(); } - /** - * Copies a GrGLContextInfo - */ - GrGLContextInfo& operator= (const GrGLContextInfo& ctxInfo); + GrGLContextInfo(const GrGLContextInfo& that) { + fGLCaps.reset(SkNEW(GrGLCaps)); + *this = that; + } + + GrGLContextInfo& operator= (const GrGLContextInfo&); /** * Initializes a GrGLContextInfo from a GrGLInterface and the currently @@ -43,7 +45,7 @@ public: bool initialize(const GrGLInterface* interface); bool isInitialized() const; - GrGLStandard standard() const { return fStandard; } + GrGLStandard standard() const { return fInterface->fStandard; } GrGLVersion version() const { return fGLVersion; } GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; } GrGLVendor vendor() const { return fVendor; } @@ -59,7 +61,7 @@ public: const GrGLExtensions& extensions() const { return fExtensions; } /** - * Shortcut for extensions().has(ext); + * Shortcut for extensions().has(ext) */ bool hasExtension(const char* ext) const { if (!this->isInitialized()) { @@ -73,64 +75,42 @@ public: */ void reset(); -private: - - GrGLStandard fStandard; - GrGLVersion fGLVersion; - GrGLSLGeneration fGLSLGeneration; - GrGLVendor fVendor; - GrGLRenderer fRenderer; - GrGLExtensions fExtensions; - bool fIsMesa; - bool fIsChromium; - SkAutoTUnref<GrGLCaps> fGLCaps; +protected: + SkAutoTUnref<const GrGLInterface> fInterface; + GrGLVersion fGLVersion; + GrGLSLGeneration fGLSLGeneration; + GrGLVendor fVendor; + GrGLRenderer fRenderer; + GrGLExtensions fExtensions; + bool fIsMesa; + bool fIsChromium; + SkAutoTUnref<GrGLCaps> fGLCaps; }; /** - * Encapsulates the GrGLInterface used to make GL calls plus information - * about the context (via GrGLContextInfo). + * Extension of GrGLContextInfo that also provides access to GrGLInterface. */ -class GrGLContext { +class GrGLContext : public GrGLContextInfo { 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() { SkSafeUnref(fInterface); } + explicit GrGLContext(const GrGLInterface* interface) { + this->initialize(interface); + } - /** - * Copies a GrGLContext - */ - GrGLContext& operator= (const GrGLContext& ctx); + GrGLContext(const GrGLContext& that) : INHERITED(that) {} - /** - * 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(); } + GrGLContext& operator= (const GrGLContext& that) { + this->INHERITED::operator=(that); + return *this; + } - const GrGLInterface* interface() const { return fInterface; } - const GrGLContextInfo& info() const { return fInfo; } - GrGLContextInfo& info() { return fInfo; } + const GrGLInterface* interface() const { return fInterface.get(); } private: - void reset(); - - const GrGLInterface* fInterface; - GrGLContextInfo fInfo; + typedef GrGLContextInfo INHERITED; }; #endif diff --git a/src/gpu/gl/GrGLShaderBuilder.cpp b/src/gpu/gl/GrGLShaderBuilder.cpp index 3d01ba5553..89f4cbf4a6 100644 --- a/src/gpu/gl/GrGLShaderBuilder.cpp +++ b/src/gpu/gl/GrGLShaderBuilder.cpp @@ -649,7 +649,7 @@ static bool attach_shader(const GrGLContext& glCtx, GR_GL_CALL(gli, CompileShader(shaderId)); // Calling GetShaderiv in Chromium is quite expensive. Assume success in release builds. - bool checkCompiled = !glCtx.info().isChromium(); + bool checkCompiled = !glCtx.isChromium(); #ifdef SK_DEBUG checkCompiled = true; #endif diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp index 4e83b050a9..6f8d65332e 100644 --- a/src/gpu/gl/GrGpuGL.cpp +++ b/src/gpu/gl/GrGpuGL.cpp @@ -118,10 +118,10 @@ GrGpuGL::GrGpuGL(const GrGLContext& ctx, GrContext* context) SkASSERT(ctx.isInitialized()); - fCaps.reset(SkRef(ctx.info().caps())); + fCaps.reset(SkRef(ctx.caps())); - fHWBoundTextures.reset(ctx.info().caps()->maxFragmentTextureUnits()); - fHWTexGenSettings.reset(ctx.info().caps()->maxFixedFunctionTextureCoords()); + fHWBoundTextures.reset(this->glCaps().maxFragmentTextureUnits()); + fHWTexGenSettings.reset(this->glCaps().maxFixedFunctionTextureCoords()); GrGLClearErr(fGLContext.interface()); @@ -138,9 +138,9 @@ GrGpuGL::GrGpuGL(const GrGLContext& ctx, GrContext* context) GrPrintf("------ RENDERER %s\n", renderer); GrPrintf("------ VERSION %s\n", version); GrPrintf("------ EXTENSIONS\n"); - ctx.info().extensions().print(); + ctx.extensions().print(); GrPrintf("\n"); - GrPrintf(ctx.info().caps()->dump().c_str()); + GrPrintf(this->glCaps().dump().c_str()); } fProgramCache = SkNEW_ARGS(ProgramCache, (this)); @@ -175,7 +175,7 @@ GrPixelConfig GrGpuGL::preferredReadPixelsConfig(GrPixelConfig readConfig, GrPixelConfig surfaceConfig) const { if (GR_GL_RGBA_8888_PIXEL_OPS_SLOW && kRGBA_8888_GrPixelConfig == readConfig) { return kBGRA_8888_GrPixelConfig; - } else if (fGLContext.info().isMesa() && + } else if (this->glContext().isMesa() && GrBytesPerPixel(readConfig) == 4 && GrPixelConfigSwapRAndB(readConfig) == surfaceConfig) { // Mesa 3D takes a slow path on when reading back BGRA from an RGBA surface and vice-versa. @@ -713,7 +713,7 @@ static bool renderbuffer_storage_msaa(GrGLContext& ctx, GrGLenum format, int width, int height) { CLEAR_ERROR_BEFORE_ALLOC(ctx.interface()); - SkASSERT(GrGLCaps::kNone_MSFBOType != ctx.info().caps()->msFBOType()); + SkASSERT(GrGLCaps::kNone_MSFBOType != ctx.caps()->msFBOType()); #if GR_GL_IGNORE_ES3_MSAA GL_ALLOC_CALL(ctx.interface(), RenderbufferStorageMultisample(GR_GL_RENDERBUFFER, @@ -721,7 +721,7 @@ static bool renderbuffer_storage_msaa(GrGLContext& ctx, format, width, height)); #else - switch (ctx.info().caps()->msFBOType()) { + switch (ctx.caps()->msFBOType()) { case GrGLCaps::kDesktop_ARB_MSFBOType: case GrGLCaps::kDesktop_EXT_MSFBOType: case GrGLCaps::kES_3_0_MSFBOType: @@ -820,7 +820,7 @@ bool GrGpuGL::createRenderTargetObjects(int width, int height, if (status != GR_GL_FRAMEBUFFER_COMPLETE) { goto FAILED; } - fGLContext.info().caps()->markConfigAsValidColorAttachment(desc->fConfig); + fGLContext.caps()->markConfigAsValidColorAttachment(desc->fConfig); } } GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fTexFBOID)); @@ -842,7 +842,7 @@ bool GrGpuGL::createRenderTargetObjects(int width, int height, if (status != GR_GL_FRAMEBUFFER_COMPLETE) { goto FAILED; } - fGLContext.info().caps()->markConfigAsValidColorAttachment(desc->fConfig); + fGLContext.caps()->markConfigAsValidColorAttachment(desc->fConfig); } return true; @@ -1138,7 +1138,7 @@ bool GrGpuGL::attachStencilBufferToRenderTarget(GrStencilBuffer* sb, GrRenderTar } return false; } else { - fGLContext.info().caps()->markColorConfigAndStencilFormatAsVerified( + fGLContext.caps()->markColorConfigAndStencilFormatAsVerified( rt->config(), glsb->format()); } @@ -1531,7 +1531,7 @@ void GrGpuGL::flushRenderTarget(const SkIRect* bound) { // lots of repeated command buffer flushes when the compositor is // rendering with Ganesh, which is really slow; even too slow for // Debug mode. - if (!this->glContext().info().isChromium()) { + if (!this->glContext().isChromium()) { GrGLenum status; GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); if (status != GR_GL_FRAMEBUFFER_COMPLETE) { diff --git a/src/gpu/gl/GrGpuGL.h b/src/gpu/gl/GrGpuGL.h index 13243f3bd7..edd58c44bc 100644 --- a/src/gpu/gl/GrGpuGL.h +++ b/src/gpu/gl/GrGpuGL.h @@ -34,10 +34,11 @@ public: const GrGLContext& glContext() const { return fGLContext; } const GrGLInterface* glInterface() const { return fGLContext.interface(); } - const GrGLContextInfo& ctxInfo() const { return fGLContext.info(); } - GrGLStandard glStandard() const { return fGLContext.info().standard(); } - GrGLVersion glVersion() const { return fGLContext.info().version(); } - GrGLSLGeneration glslGeneration() const { return fGLContext.info().glslGeneration(); } + const GrGLContextInfo& ctxInfo() const { return fGLContext; } + GrGLStandard glStandard() const { return fGLContext.standard(); } + GrGLVersion glVersion() const { return fGLContext.version(); } + GrGLSLGeneration glslGeneration() const { return fGLContext.glslGeneration(); } + const GrGLCaps& glCaps() const { return *fGLContext.caps(); } // Used by GrGLProgram and GrGLTexGenProgramEffects to configure OpenGL state. void bindTexture(int unitIdx, const GrTextureParams& params, GrGLTexture* texture); @@ -77,8 +78,6 @@ public: virtual void abandonResources() SK_OVERRIDE; - const GrGLCaps& glCaps() const { return *fGLContext.info().caps(); } - // These functions should be used to bind GL objects. They track the GL state and skip redundant // bindings. Making the equivalent glBind calls directly will confuse the state tracking. void bindVertexArray(GrGLuint id) { @@ -177,7 +176,7 @@ private: // have been accounted for). void flushBlend(bool isLines, GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff); - bool hasExtension(const char* ext) const { return fGLContext.info().hasExtension(ext); } + bool hasExtension(const char* ext) const { return fGLContext.hasExtension(ext); } static bool BlendCoeffReferencesConstant(GrBlendCoeff coeff); |