From 424cc26add7ed491c6941d0c0c3a0e6d83190307 Mon Sep 17 00:00:00 2001 From: bsalomon Date: Fri, 22 May 2015 10:37:30 -0700 Subject: [PATCH] Remove init from GrGLContextInfo and caps classes Make Gr*Caps, GrGLContext* noncopyable Review URL: https://codereview.chromium.org/1153813002 --- include/gpu/GrCaps.h | 21 +--- src/effects/gradients/SkSweepGradient.cpp | 2 +- src/gpu/GrDrawTarget.cpp | 49 +-------- src/gpu/GrGpuFactory.cpp | 30 +----- src/gpu/gl/GrGLCaps.cpp | 102 ++---------------- src/gpu/gl/GrGLCaps.h | 39 ++----- src/gpu/gl/GrGLContext.cpp | 125 ++++++++++------------ src/gpu/gl/GrGLContext.h | 59 +++------- src/gpu/gl/GrGLGpu.cpp | 43 +++++--- src/gpu/gl/GrGLGpu.h | 24 +++-- 10 files changed, 137 insertions(+), 357 deletions(-) diff --git a/include/gpu/GrCaps.h b/include/gpu/GrCaps.h index 3381bd36b4..580017a9fe 100644 --- a/include/gpu/GrCaps.h +++ b/include/gpu/GrCaps.h @@ -52,16 +52,8 @@ public: int fBits; }; - GrShaderCaps() { - this->reset(); - } - virtual ~GrShaderCaps() {} - GrShaderCaps(const GrShaderCaps& other) : INHERITED() { - *this = other; - } - GrShaderCaps& operator= (const GrShaderCaps&); + GrShaderCaps(); - virtual void reset(); virtual SkString dump() const; bool shaderDerivativeSupport() const { return fShaderDerivativeSupport; } @@ -111,17 +103,8 @@ class GrCaps : public SkRefCnt { public: SK_DECLARE_INST_COUNT(GrCaps) - GrCaps() { - fShaderCaps.reset(NULL); - this->reset(); - } - GrCaps(const GrCaps& other) : INHERITED() { - *this = other; - } - virtual ~GrCaps() {} - GrCaps& operator= (const GrCaps&); + GrCaps(); - virtual void reset(); virtual SkString dump() const; GrShaderCaps* shaderCaps() const { return fShaderCaps; } diff --git a/src/effects/gradients/SkSweepGradient.cpp b/src/effects/gradients/SkSweepGradient.cpp index 686d87742e..ce4edae9b8 100644 --- a/src/effects/gradients/SkSweepGradient.cpp +++ b/src/effects/gradients/SkSweepGradient.cpp @@ -277,7 +277,7 @@ void GrGLSweepGradient::emitCode(GrGLFPBuilder* builder, const GrSweepGradient& ge = fp.cast(); this->emitUniforms(builder, ge); SkString coords2D = builder->getFragmentShaderBuilder()->ensureFSCoords2D(coords, 0); - const GrGLContextInfo ctxInfo = builder->ctxInfo(); + const GrGLContextInfo& ctxInfo = builder->ctxInfo(); SkString t; // 0.1591549430918 is 1/(2*pi), used since atan returns values [-pi, pi] // On Intel GPU there is an issue where it reads the second arguement to atan "- %s.x" as an int diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp index 20288a9916..2d5d0b8ee6 100644 --- a/src/gpu/GrDrawTarget.cpp +++ b/src/gpu/GrDrawTarget.cpp @@ -532,34 +532,16 @@ GrDrawTarget::PipelineInfo::PipelineInfo(GrPipelineBuilder* pipelineBuilder, /////////////////////////////////////////////////////////////////////////////// -void GrShaderCaps::reset() { +GrShaderCaps::GrShaderCaps() { fShaderDerivativeSupport = false; fGeometryShaderSupport = false; fPathRenderingSupport = false; fDstReadInShaderSupport = false; fDualSourceBlendingSupport = false; fMixedSamplesSupport = false; - fShaderPrecisionVaries = false; } -GrShaderCaps& GrShaderCaps::operator=(const GrShaderCaps& other) { - fShaderDerivativeSupport = other.fShaderDerivativeSupport; - fGeometryShaderSupport = other.fGeometryShaderSupport; - fPathRenderingSupport = other.fPathRenderingSupport; - fDstReadInShaderSupport = other.fDstReadInShaderSupport; - fDualSourceBlendingSupport = other.fDualSourceBlendingSupport; - fMixedSamplesSupport = other.fMixedSamplesSupport; - - fShaderPrecisionVaries = other.fShaderPrecisionVaries; - for (int s = 0; s < kGrShaderTypeCount; ++s) { - for (int p = 0; p < kGrSLPrecisionCount; ++p) { - fFloatPrecisions[s][p] = other.fFloatPrecisions[s][p]; - } - } - return *this; -} - static const char* shader_type_to_string(GrShaderType type) { switch (type) { case kVertex_GrShaderType: @@ -616,7 +598,7 @@ SkString GrShaderCaps::dump() const { /////////////////////////////////////////////////////////////////////////////// -void GrCaps::reset() { +GrCaps::GrCaps() { fMipMapSupport = false; fNPOTTextureTileSupport = false; fTwoSidedStencilSupport = false; @@ -641,33 +623,6 @@ void GrCaps::reset() { memset(fConfigTextureSupport, 0, sizeof(fConfigTextureSupport)); } -GrCaps& GrCaps::operator=(const GrCaps& other) { - fMipMapSupport = other.fMipMapSupport; - fNPOTTextureTileSupport = other.fNPOTTextureTileSupport; - fTwoSidedStencilSupport = other.fTwoSidedStencilSupport; - fStencilWrapOpsSupport = other.fStencilWrapOpsSupport; - fDiscardRenderTargetSupport = other.fDiscardRenderTargetSupport; - fReuseScratchTextures = other.fReuseScratchTextures; - fGpuTracingSupport = other.fGpuTracingSupport; - fCompressedTexSubImageSupport = other.fCompressedTexSubImageSupport; - fOversizedStencilSupport = other.fOversizedStencilSupport; - fTextureBarrierSupport = other.fTextureBarrierSupport; - - fUseDrawInsteadOfClear = other.fUseDrawInsteadOfClear; - - fBlendEquationSupport = other.fBlendEquationSupport; - fMapBufferFlags = other.fMapBufferFlags; - - fMaxRenderTargetSize = other.fMaxRenderTargetSize; - fMaxTextureSize = other.fMaxTextureSize; - fMaxSampleCount = other.fMaxSampleCount; - - memcpy(fConfigRenderSupport, other.fConfigRenderSupport, sizeof(fConfigRenderSupport)); - memcpy(fConfigTextureSupport, other.fConfigTextureSupport, sizeof(fConfigTextureSupport)); - - return *this; -} - static SkString map_flags_to_string(uint32_t flags) { SkString str; if (GrCaps::kNone_MapFlags == flags) { diff --git a/src/gpu/GrGpuFactory.cpp b/src/gpu/GrGpuFactory.cpp index 74adf98236..bd572e6860 100644 --- a/src/gpu/GrGpuFactory.cpp +++ b/src/gpu/GrGpuFactory.cpp @@ -9,38 +9,12 @@ #include "GrGpuFactory.h" -#include "gl/GrGLConfig.h" - #include "GrGpu.h" +#include "gl/GrGLConfig.h" #include "gl/GrGLGpu.h" -static GrGpu* gl_gpu_create(GrBackendContext backendContext, GrContext* context) { - const GrGLInterface* glInterface = NULL; - SkAutoTUnref glInterfaceUnref; - - glInterface = reinterpret_cast(backendContext); - if (NULL == glInterface) { - glInterface = GrGLDefaultInterface(); - // By calling GrGLDefaultInterface we've taken a ref on the - // returned object. We only want to hold that ref until after - // the GrGpu is constructed and has taken ownership. - glInterfaceUnref.reset(glInterface); - } - if (NULL == glInterface) { -#ifdef SK_DEBUG - SkDebugf("No GL interface provided!\n"); -#endif - return NULL; - } - GrGLContext ctx(glInterface); - if (ctx.isInitialized()) { - return SkNEW_ARGS(GrGLGpu, (ctx, context)); - } - return NULL; -} - static const int kMaxNumBackends = 4; -static CreateGpuProc gGpuFactories[kMaxNumBackends] = {gl_gpu_create, NULL, NULL, NULL}; +static CreateGpuProc gGpuFactories[kMaxNumBackends] = {GrGLGpu::Create, NULL, NULL, NULL}; GrGpuFactoryRegistrar::GrGpuFactoryRegistrar(int i, CreateGpuProc proc) { gGpuFactories[i] = proc; diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp index 85a72600d0..2a97137f12 100644 --- a/src/gpu/gl/GrGLCaps.cpp +++ b/src/gpu/gl/GrGLCaps.cpp @@ -12,13 +12,7 @@ #include "SkTSearch.h" #include "SkTSort.h" -GrGLCaps::GrGLCaps() { - this->reset(); -} - -void GrGLCaps::reset() { - INHERITED::reset(); - +GrGLCaps::GrGLCaps(const GrGLContextInfo& ctxInfo, const GrGLInterface* glInterface) { fVerifiedColorConfigs.reset(); fStencilFormats.reset(); fStencilVerifiedColorConfigs.reset(); @@ -51,59 +45,12 @@ void GrGLCaps::reset() { fReadPixelsSupportedCache.reset(); - fShaderCaps.reset(SkNEW(GrGLSLCaps)); + this->init(ctxInfo, glInterface); + fShaderCaps.reset(SkNEW_ARGS(GrGLSLCaps, (ctxInfo, glInterface, *this))); } -GrGLCaps::GrGLCaps(const GrGLCaps& caps) : GrCaps() { - *this = caps; -} - -GrGLCaps& GrGLCaps::operator= (const GrGLCaps& caps) { - INHERITED::operator=(caps); - fVerifiedColorConfigs = caps.fVerifiedColorConfigs; - fStencilFormats = caps.fStencilFormats; - fStencilVerifiedColorConfigs = caps.fStencilVerifiedColorConfigs; - fLATCAlias = caps.fLATCAlias; - fMaxFragmentUniformVectors = caps.fMaxFragmentUniformVectors; - fMaxVertexAttributes = caps.fMaxVertexAttributes; - fMaxFragmentTextureUnits = caps.fMaxFragmentTextureUnits; - fMSFBOType = caps.fMSFBOType; - fInvalidateFBType = caps.fInvalidateFBType; - fMapBufferType = caps.fMapBufferType; - fRGBA8RenderbufferSupport = caps.fRGBA8RenderbufferSupport; - fBGRAIsInternalFormat = caps.fBGRAIsInternalFormat; - fTextureSwizzleSupport = caps.fTextureSwizzleSupport; - fUnpackRowLengthSupport = caps.fUnpackRowLengthSupport; - fUnpackFlipYSupport = caps.fUnpackFlipYSupport; - fPackRowLengthSupport = caps.fPackRowLengthSupport; - fPackFlipYSupport = caps.fPackFlipYSupport; - fTextureUsageSupport = caps.fTextureUsageSupport; - fTexStorageSupport = caps.fTexStorageSupport; - fTextureRedSupport = caps.fTextureRedSupport; - fImagingSupport = caps.fImagingSupport; - fTwoFormatLimit = caps.fTwoFormatLimit; - fFragCoordsConventionSupport = caps.fFragCoordsConventionSupport; - fVertexArrayObjectSupport = caps.fVertexArrayObjectSupport; - fES2CompatibilitySupport = caps.fES2CompatibilitySupport; - fMultisampleDisableSupport = caps.fMultisampleDisableSupport; - fUseNonVBOVertexAndIndexDynamicData = caps.fUseNonVBOVertexAndIndexDynamicData; - fIsCoreProfile = caps.fIsCoreProfile; - fFullClearIsFree = caps.fFullClearIsFree; - - *(reinterpret_cast(fShaderCaps.get())) = - *(reinterpret_cast(caps.fShaderCaps.get())); - - return *this; -} - -bool GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { - - this->reset(); - if (!ctxInfo.isInitialized()) { - return false; - } - +void GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { GrGLStandard standard = ctxInfo.standard(); GrGLVersion version = ctxInfo.version(); @@ -375,10 +322,6 @@ bool GrGLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { this->initConfigTexturableTable(ctxInfo, gli); this->initConfigRenderableTable(ctxInfo); - - reinterpret_cast(fShaderCaps.get())->init(ctxInfo, gli, *this); - - return true; } void GrGLCaps::initConfigRenderableTable(const GrGLContextInfo& ctxInfo) { @@ -948,46 +891,21 @@ SkString GrGLCaps::dump() const { //////////////////////////////////////////////////////////////////////////////////////////// -GrGLSLCaps::GrGLSLCaps() { - this->reset(); -} - - -void GrGLSLCaps::reset() { - INHERITED::reset(); - +GrGLSLCaps::GrGLSLCaps(const GrGLContextInfo& ctxInfo, + const GrGLInterface* gli, + const GrGLCaps& glCaps) { fDropsTileOnZeroDivide = false; fFBFetchSupport = false; fFBFetchNeedsCustomOutput = false; fAdvBlendEqInteraction = kNotSupported_AdvBlendEqInteraction; fFBFetchColorName = NULL; fFBFetchExtensionString = NULL; + this->init(ctxInfo, gli, glCaps); } -GrGLSLCaps::GrGLSLCaps(const GrGLSLCaps& caps) : GrShaderCaps() { - *this = caps; -} - -GrGLSLCaps& GrGLSLCaps::operator= (const GrGLSLCaps& caps) { - INHERITED::operator=(caps); - fDropsTileOnZeroDivide = caps.fDropsTileOnZeroDivide; - fFBFetchSupport = caps.fFBFetchSupport; - fFBFetchNeedsCustomOutput = caps.fFBFetchNeedsCustomOutput; - fAdvBlendEqInteraction = caps.fAdvBlendEqInteraction; - fFBFetchColorName = caps.fFBFetchColorName; - fFBFetchExtensionString = caps.fFBFetchExtensionString; - - return *this; -} - -bool GrGLSLCaps::init(const GrGLContextInfo& ctxInfo, +void GrGLSLCaps::init(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli, const GrGLCaps& glCaps) { - this->reset(); - if (!ctxInfo.isInitialized()) { - return false; - } - GrGLStandard standard = ctxInfo.standard(); GrGLVersion version = ctxInfo.version(); @@ -1081,8 +999,6 @@ bool GrGLSLCaps::init(const GrGLContextInfo& ctxInfo, } this->initShaderPrecisionTable(ctxInfo, gli); - - return true; } SkString GrGLSLCaps::dump() const { diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h index a4d60e2bdc..cd84242292 100644 --- a/src/gpu/gl/GrGLCaps.h +++ b/src/gpu/gl/GrGLCaps.h @@ -87,26 +87,11 @@ public: kLast_MapBufferType = kChromium_MapBufferType, }; - /** - * Creates a GrGLCaps that advertises no support for any extensions, - * formats, etc. Call init to initialize from a GrGLContextInfo. - */ - GrGLCaps(); - - GrGLCaps(const GrGLCaps& caps); - - GrGLCaps& operator = (const GrGLCaps& caps); - - /** - * Resets the caps such that nothing is supported. - */ - void reset() override; - /** * Initializes the GrGLCaps to the set of features supported in the current * OpenGL context accessible via ctxInfo. */ - bool init(const GrGLContextInfo& ctxInfo, const GrGLInterface* glInterface); + GrGLCaps(const GrGLContextInfo& ctxInfo, const GrGLInterface* glInterface); /** * Call to note that a color config has been verified as a valid color @@ -277,6 +262,8 @@ public: GrGLSLCaps* glslCaps() const { return reinterpret_cast(fShaderCaps.get()); } private: + void init(const GrGLContextInfo& ctxInfo, const GrGLInterface* glInterface); + /** * Maintains a bit per GrPixelConfig. It is used to avoid redundantly * performing glCheckFrameBufferStatus for the same config. @@ -396,27 +383,11 @@ public: kLast_AdvBlendEqInteraction = kSpecificEnables_AdvBlendEqInteraction }; - /** - * Creates a GrGLSLCaps that advertises no support for any extensions, - * formats, etc. Call init to initialize from a GrGLContextInfo. - */ - GrGLSLCaps(); - ~GrGLSLCaps() override {} - - GrGLSLCaps(const GrGLSLCaps& caps); - - GrGLSLCaps& operator = (const GrGLSLCaps& caps); - - /** - * Resets the caps such that nothing is supported. - */ - void reset() override; - /** * Initializes the GrGLSLCaps to the set of features supported in the current * OpenGL context accessible via ctxInfo. */ - bool init(const GrGLContextInfo&, const GrGLInterface*, const GrGLCaps&); + GrGLSLCaps(const GrGLContextInfo&, const GrGLInterface*, const GrGLCaps&); /** * Some helper functions for encapsulating various extensions to read FB Buffer on openglES @@ -449,6 +420,8 @@ public: SkString dump() const override; private: + void init(const GrGLContextInfo&, const GrGLInterface*, const GrGLCaps&); + // Must be called after fGeometryShaderSupport is initialized. void initShaderPrecisionTable(const GrGLContextInfo&, const GrGLInterface*); diff --git a/src/gpu/gl/GrGLContext.cpp b/src/gpu/gl/GrGLContext.cpp index fc8b195fd3..8115687093 100644 --- a/src/gpu/gl/GrGLContext.cpp +++ b/src/gpu/gl/GrGLContext.cpp @@ -9,78 +9,63 @@ //////////////////////////////////////////////////////////////////////////////// -GrGLContextInfo& GrGLContextInfo::operator= (const GrGLContextInfo& that) { - fInterface.reset(SkSafeRef(that.fInterface.get())); - fGLVersion = that.fGLVersion; - fGLSLGeneration = that.fGLSLGeneration; - fVendor = that.fVendor; - fRenderer = that.fRenderer; - fIsMesa = that.fIsMesa; - fIsChromium = that.fIsChromium; - *fGLCaps = *that.fGLCaps.get(); - 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->fFunctions.fGetString) { - const GrGLubyte* verUByte; - GR_GL_CALL_RET(interface, verUByte, GetString(GR_GL_VERSION)); - const char* ver = reinterpret_cast(verUByte); - - const GrGLubyte* rendererUByte; - GR_GL_CALL_RET(interface, rendererUByte, GetString(GR_GL_RENDERER)); - const char* renderer = reinterpret_cast(rendererUByte); - - if (interface->validate()) { - - fGLVersion = GrGLGetVersionFromString(ver); - if (GR_GL_INVALID_VER == fGLVersion) { - return false; - } - - if (!GrGetGLSLGeneration(interface, &fGLSLGeneration)) { - return false; - } - - fVendor = GrGLGetVendor(interface); - - /* - * Qualcomm drivers have a horrendous bug with some drivers. Though they claim to - * support GLES 3.00, some perfectly valid GLSL300 shaders will only compile with - * #version 100, and will fail to compile with #version 300 es. In the long term, we - * need to lock this down to a specific driver version. - */ - if (kQualcomm_GrGLVendor == fVendor) { - fGLSLGeneration = k110_GrGLSLGeneration; - } - - fRenderer = GrGLGetRendererFromString(renderer); - - fIsMesa = GrGLIsMesaFromVersionString(ver); - - fIsChromium = GrGLIsChromiumFromRendererString(renderer); - - // This must occur before caps init. - fInterface.reset(SkRef(interface)); - - return fGLCaps->init(*this, interface); - } +GrGLContext* GrGLContext::Create(const GrGLInterface* interface) { + // We haven't validated the GrGLInterface yet, so check for GetString function pointer + if (!interface->fFunctions.fGetString) { + return NULL; } - return false; + ConstructorArgs args; + args.fInterface = interface; + + const GrGLubyte* verUByte; + GR_GL_CALL_RET(interface, verUByte, GetString(GR_GL_VERSION)); + const char* ver = reinterpret_cast(verUByte); + + const GrGLubyte* rendererUByte; + GR_GL_CALL_RET(interface, rendererUByte, GetString(GR_GL_RENDERER)); + const char* renderer = reinterpret_cast(rendererUByte); + + if (!interface->validate()) { + return NULL; + } + + args.fGLVersion = GrGLGetVersionFromString(ver); + if (GR_GL_INVALID_VER == args.fGLVersion) { + return NULL; + } + + if (!GrGetGLSLGeneration(interface, &args.fGLSLGeneration)) { + return NULL; + } + + args.fVendor = GrGLGetVendor(interface); + + /* + * Qualcomm drivers have a horrendous bug with some drivers. Though they claim to + * support GLES 3.00, some perfectly valid GLSL300 shaders will only compile with + * #version 100, and will fail to compile with #version 300 es. In the long term, we + * need to lock this down to a specific driver version. + */ + if (kQualcomm_GrGLVendor == args.fVendor) { + args.fGLSLGeneration = k110_GrGLSLGeneration; + } + + args.fRenderer = GrGLGetRendererFromString(renderer); + + args.fIsMesa = GrGLIsMesaFromVersionString(ver); + + args.fIsChromium = GrGLIsChromiumFromRendererString(renderer); + return SkNEW_ARGS(GrGLContext, (args)); } -bool GrGLContextInfo::isInitialized() const { return SkToBool(fInterface.get()); } +GrGLContextInfo::GrGLContextInfo(const ConstructorArgs& args) { + fInterface.reset(SkRef(args.fInterface)); + fGLVersion = args.fGLVersion; + fGLSLGeneration = args.fGLSLGeneration; + fVendor = args.fVendor; + fRenderer = args.fRenderer; + fIsMesa = args.fIsMesa; + fIsChromium = args.fIsChromium; -void GrGLContextInfo::reset() { - fInterface.reset(NULL); - fGLVersion = GR_GL_VER(0, 0); - fGLSLGeneration = static_cast(0); - fVendor = kOther_GrGLVendor; - fRenderer = kOther_GrGLRenderer; - fIsMesa = false; - fIsChromium = false; - fGLCaps->reset(); + fGLCaps.reset(SkNEW_ARGS(GrGLCaps, (*this, fInterface))); } diff --git a/src/gpu/gl/GrGLContext.h b/src/gpu/gl/GrGLContext.h index 7f46522af2..e84c8ecffc 100644 --- a/src/gpu/gl/GrGLContext.h +++ b/src/gpu/gl/GrGLContext.h @@ -21,30 +21,8 @@ * Encapsulates information about an OpenGL context including the OpenGL * version, the GrGLStandard type of the context, and GLSL version. */ -class GrGLContextInfo { +class GrGLContextInfo : public SkNoncopyable { public: - /** - * Default constructor - */ - GrGLContextInfo() { - fGLCaps.reset(SkNEW(GrGLCaps)); - this->reset(); - } - - GrGLContextInfo(const GrGLContextInfo& that) { - fGLCaps.reset(SkNEW(GrGLCaps)); - *this = that; - } - - GrGLContextInfo& operator= (const GrGLContextInfo&); - - /** - * Initializes a GrGLContextInfo from a GrGLInterface and the currently - * bound OpenGL context accessible by the GrGLInterface. - */ - bool initialize(const GrGLInterface* interface); - bool isInitialized() const; - GrGLStandard standard() const { return fInterface->fStandard; } GrGLVersion version() const { return fGLVersion; } GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; } @@ -59,20 +37,24 @@ public: const GrGLCaps* caps() const { return fGLCaps.get(); } GrGLCaps* caps() { return fGLCaps; } bool hasExtension(const char* ext) const { - if (!this->isInitialized()) { - return false; - } return fInterface->hasExtension(ext); } const GrGLExtensions& extensions() const { return fInterface->fExtensions; } - /** - * Reset the information - */ - void reset(); - protected: + struct ConstructorArgs { + const GrGLInterface* fInterface; + GrGLVersion fGLVersion; + GrGLSLGeneration fGLSLGeneration; + GrGLVendor fVendor; + GrGLRenderer fRenderer; + bool fIsMesa; + bool fIsChromium; + }; + + GrGLContextInfo(const ConstructorArgs& args); + SkAutoTUnref fInterface; GrGLVersion fGLVersion; GrGLSLGeneration fGLSLGeneration; @@ -92,20 +74,13 @@ public: * Creates a GrGLContext from a GrGLInterface and the currently * bound OpenGL context accessible by the GrGLInterface. */ - explicit GrGLContext(const GrGLInterface* interface) { - this->initialize(interface); - } + static GrGLContext* Create(const GrGLInterface* interface); - GrGLContext(const GrGLContext& that) : INHERITED(that) {} - - GrGLContext& operator= (const GrGLContext& that) { - this->INHERITED::operator=(that); - return *this; - } - - const GrGLInterface* interface() const { return fInterface.get(); } + const GrGLInterface* interface() const { return fInterface; } private: + GrGLContext(const ConstructorArgs& args) : INHERITED(args) {} + typedef GrGLContextInfo INHERITED; }; diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index d48f208011..07aaaae26b 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -157,18 +157,35 @@ bool GrGLGpu::BlendCoeffReferencesConstant(GrBlendCoeff coeff) { /////////////////////////////////////////////////////////////////////////////// +GrGpu* GrGLGpu::Create(GrBackendContext backendContext, GrContext* context) { + SkAutoTUnref glInterface( + reinterpret_cast(backendContext)); + if (!glInterface) { + glInterface.reset(GrGLDefaultInterface()); + } else { + glInterface->ref(); + } + if (!glInterface) { + return NULL; + } + GrGLContext* glContext = GrGLContext::Create(glInterface); + if (glContext) { + return SkNEW_ARGS(GrGLGpu, (glContext, context)); + } + return NULL; +} + static bool gPrintStartupSpew; -GrGLGpu::GrGLGpu(const GrGLContext& ctx, GrContext* context) +GrGLGpu::GrGLGpu(GrGLContext* ctx, GrContext* context) : GrGpu(context) , fGLContext(ctx) { - - SkASSERT(ctx.isInitialized()); - fCaps.reset(SkRef(ctx.caps())); + SkASSERT(ctx); + fCaps.reset(SkRef(ctx->caps())); fHWBoundTextureUniqueIDs.reset(this->glCaps().maxFragmentTextureUnits()); - GrGLClearErr(fGLContext.interface()); + GrGLClearErr(this->glInterface()); if (gPrintStartupSpew) { const GrGLubyte* vendor; const GrGLubyte* renderer; @@ -182,7 +199,7 @@ GrGLGpu::GrGLGpu(const GrGLContext& ctx, GrContext* context) SkDebugf("------ RENDERER %s\n", renderer); SkDebugf("------ VERSION %s\n", version); SkDebugf("------ EXTENSIONS\n"); - ctx.extensions().print(); + this->glContext().extensions().print(); SkDebugf("\n"); SkDebugf("%s", this->glCaps().dump().c_str()); } @@ -331,7 +348,7 @@ void GrGLGpu::onResetContext(uint32_t resetBits) { } if (kGLES_GrGLStandard == this->glStandard() && - fGLContext.hasExtension("GL_ARM_shader_framebuffer_fetch")) { + this->hasExtension("GL_ARM_shader_framebuffer_fetch")) { // The arm extension requires specifically enabling MSAA fetching per sample. // On some devices this may have a perf hit. Also multiple render targets are disabled GL_CALL(Enable(GR_GL_FETCH_PER_SAMPLE_ARM)); @@ -812,7 +829,7 @@ bool GrGLGpu::uploadCompressedTexData(const GrSurfaceDesc& desc, return true; } -static bool renderbuffer_storage_msaa(GrGLContext& ctx, +static bool renderbuffer_storage_msaa(const GrGLContext& ctx, int sampleCount, GrGLenum format, int width, int height) { @@ -899,7 +916,7 @@ bool GrGLGpu::createRenderTargetObjects(const GrSurfaceDesc& desc, if (idDesc->fRTFBOID != idDesc->fTexFBOID) { SkASSERT(desc.fSampleCnt > 0); GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, idDesc->fMSColorRenderbufferID)); - if (!renderbuffer_storage_msaa(fGLContext, + if (!renderbuffer_storage_msaa(*fGLContext, desc.fSampleCnt, msColorFormat, desc.fWidth, desc.fHeight)) { @@ -917,7 +934,7 @@ bool GrGLGpu::createRenderTargetObjects(const GrSurfaceDesc& desc, if (status != GR_GL_FRAMEBUFFER_COMPLETE) { goto FAILED; } - fGLContext.caps()->markConfigAsValidColorAttachment(desc.fConfig); + fGLContext->caps()->markConfigAsValidColorAttachment(desc.fConfig); } } fStats.incRenderTargetBinds(); @@ -940,7 +957,7 @@ bool GrGLGpu::createRenderTargetObjects(const GrSurfaceDesc& desc, if (status != GR_GL_FRAMEBUFFER_COMPLETE) { goto FAILED; } - fGLContext.caps()->markConfigAsValidColorAttachment(desc.fConfig); + fGLContext->caps()->markConfigAsValidColorAttachment(desc.fConfig); } return true; @@ -1162,7 +1179,7 @@ bool GrGLGpu::createStencilAttachmentForRenderTarget(GrRenderTarget* rt, int wid // version on a GL that doesn't have an MSAA extension. bool created; if (samples > 0) { - created = renderbuffer_storage_msaa(fGLContext, + created = renderbuffer_storage_msaa(*fGLContext, samples, sFmt.fInternalFormat, width, height); @@ -1303,7 +1320,7 @@ bool GrGLGpu::attachStencilAttachmentToRenderTarget(GrStencilAttachment* sb, GrR } return false; } else { - fGLContext.caps()->markColorConfigAndStencilFormatAsVerified( + fGLContext->caps()->markColorConfigAndStencilFormatAsVerified( rt->config(), glsb->format()); } diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h index 3323ece079..d7b11026f5 100644 --- a/src/gpu/gl/GrGLGpu.h +++ b/src/gpu/gl/GrGLGpu.h @@ -32,19 +32,19 @@ class GrNonInstancedVertices; class GrGLGpu : public GrGpu { public: - GrGLGpu(const GrGLContext& ctx, GrContext* context); + static GrGpu* Create(GrBackendContext backendContext, GrContext* context); ~GrGLGpu() override; void contextAbandoned() override; - const GrGLContext& glContext() const { return fGLContext; } + const GrGLContext& glContext() const { return *fGLContext; } - const GrGLInterface* glInterface() const { return fGLContext.interface(); } - 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(); } + const GrGLInterface* glInterface() const { return fGLContext->interface(); } + 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(); } GrGLPathRendering* glPathRendering() { SkASSERT(glCaps().shaderCaps()->pathRenderingSupport()); @@ -114,6 +114,8 @@ public: const GrBatchTracker&) const override; private: + GrGLGpu(GrGLContext* ctx, GrContext* context); + // GrGpu overrides void onResetContext(uint32_t resetBits) override; @@ -183,7 +185,7 @@ private: // Subclasses should call this to flush the blend state. void flushBlend(const GrXferProcessor::BlendInfo& blendInfo); - bool hasExtension(const char* ext) const { return fGLContext.hasExtension(ext); } + bool hasExtension(const char* ext) const { return fGLContext->hasExtension(ext); } static bool BlendCoeffReferencesConstant(GrBlendCoeff coeff); @@ -294,7 +296,7 @@ private: void unbindTextureFromFBO(GrGLenum fboTarget); - GrGLContext fGLContext; + SkAutoTDelete fGLContext; // GL program-related state ProgramCache* fProgramCache; @@ -327,7 +329,7 @@ private: } } fHWScissorSettings; - GrGLIRect fHWViewport; + GrGLIRect fHWViewport; /** * Tracks bound vertex and index buffers and vertex attrib array state.