diff options
author | Brian Salomon <bsalomon@google.com> | 2017-12-07 12:40:00 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-12-07 20:24:10 +0000 |
commit | 8ab1cc477b039684f61c0a7a0a996979cf5d33cc (patch) | |
tree | 24b36105cd1733e1d5ff6654afb9d0f83ed9f934 | |
parent | a4ceaa1e5a555d27bfea40811c209640fa248392 (diff) |
Make GrGLContext be uniquely owned.
Make GrGLContext take GrGLInterface by sk_sp
Change-Id: Iab11b27a7093ec897aaeeab9253958aeaa590b63
Reviewed-on: https://skia-review.googlesource.com/81701
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
-rw-r--r-- | src/gpu/gl/GrGLContext.cpp | 28 | ||||
-rw-r--r-- | src/gpu/gl/GrGLContext.h | 19 | ||||
-rw-r--r-- | src/gpu/gl/GrGLGpu.cpp | 32 | ||||
-rw-r--r-- | src/gpu/gl/GrGLGpu.h | 6 |
4 files changed, 41 insertions, 44 deletions
diff --git a/src/gpu/gl/GrGLContext.cpp b/src/gpu/gl/GrGLContext.cpp index 9d18b5fee2..dd774cd76d 100644 --- a/src/gpu/gl/GrGLContext.cpp +++ b/src/gpu/gl/GrGLContext.cpp @@ -11,36 +11,31 @@ //////////////////////////////////////////////////////////////////////////////// -GrGLContext* GrGLContext::Create(const GrGLInterface* interface, const GrContextOptions& options) { - // We haven't validated the GrGLInterface yet, so check for GetString function pointer - if (!interface->fFunctions.fGetString) { +std::unique_ptr<GrGLContext> GrGLContext::Make(sk_sp<const GrGLInterface> interface, + const GrContextOptions& options) { + if (!interface->validate()) { return nullptr; } - ConstructorArgs args; - args.fInterface = interface; const GrGLubyte* verUByte; - GR_GL_CALL_RET(interface, verUByte, GetString(GR_GL_VERSION)); + GR_GL_CALL_RET(interface.get(), verUByte, GetString(GR_GL_VERSION)); const char* ver = reinterpret_cast<const char*>(verUByte); const GrGLubyte* rendererUByte; - GR_GL_CALL_RET(interface, rendererUByte, GetString(GR_GL_RENDERER)); + GR_GL_CALL_RET(interface.get(), rendererUByte, GetString(GR_GL_RENDERER)); const char* renderer = reinterpret_cast<const char*>(rendererUByte); - if (!interface->validate()) { - return nullptr; - } - + ConstructorArgs args; args.fGLVersion = GrGLGetVersionFromString(ver); if (GR_GL_INVALID_VER == args.fGLVersion) { return nullptr; } - if (!GrGLGetGLSLGeneration(interface, &args.fGLSLGeneration)) { + if (!GrGLGetGLSLGeneration(interface.get(), &args.fGLSLGeneration)) { return nullptr; } - args.fVendor = GrGLGetVendor(interface); + args.fVendor = GrGLGetVendor(interface.get()); args.fRenderer = GrGLGetRendererFromString(renderer); @@ -62,8 +57,9 @@ GrGLContext* GrGLContext::Create(const GrGLInterface* interface, const GrContext &args.fDriver, &args.fDriverVersion); args.fContextOptions = &options; + args.fInterface = std::move(interface); - return new GrGLContext(args); + return std::unique_ptr<GrGLContext>(new GrGLContext(std::move(args))); } GrGLContext::~GrGLContext() { @@ -77,8 +73,8 @@ SkSL::Compiler* GrGLContext::compiler() const { return fCompiler; } -GrGLContextInfo::GrGLContextInfo(const ConstructorArgs& args) { - fInterface.reset(SkRef(args.fInterface)); +GrGLContextInfo::GrGLContextInfo(ConstructorArgs&& args) { + fInterface = std::move(args.fInterface); fGLVersion = args.fGLVersion; fGLSLGeneration = args.fGLSLGeneration; fVendor = args.fVendor; diff --git a/src/gpu/gl/GrGLContext.h b/src/gpu/gl/GrGLContext.h index 4e3712559c..998a5f5194 100644 --- a/src/gpu/gl/GrGLContext.h +++ b/src/gpu/gl/GrGLContext.h @@ -23,8 +23,13 @@ namespace SkSL { * Encapsulates information about an OpenGL context including the OpenGL * version, the GrGLStandard type of the context, and GLSL version. */ -class GrGLContextInfo : public SkRefCnt { +class GrGLContextInfo { public: + GrGLContextInfo(const GrGLContextInfo&) = delete; + GrGLContextInfo& operator=(const GrGLContextInfo&) = delete; + + virtual ~GrGLContextInfo() {} + GrGLStandard standard() const { return fInterface->fStandard; } GrGLVersion version() const { return fGLVersion; } GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; } @@ -45,11 +50,9 @@ public: const GrGLExtensions& extensions() const { return fInterface->fExtensions; } - virtual ~GrGLContextInfo() {} - protected: struct ConstructorArgs { - const GrGLInterface* fInterface; + sk_sp<const GrGLInterface> fInterface; GrGLVersion fGLVersion; GrGLSLGeneration fGLSLGeneration; GrGLVendor fVendor; @@ -62,7 +65,7 @@ protected: const GrContextOptions* fContextOptions; }; - GrGLContextInfo(const ConstructorArgs& args); + GrGLContextInfo(ConstructorArgs&&); sk_sp<const GrGLInterface> fInterface; GrGLVersion fGLVersion; @@ -86,7 +89,7 @@ public: * Creates a GrGLContext from a GrGLInterface and the currently * bound OpenGL context accessible by the GrGLInterface. */ - static GrGLContext* Create(const GrGLInterface* interface, const GrContextOptions& options); + static std::unique_ptr<GrGLContext> Make(sk_sp<const GrGLInterface>, const GrContextOptions&); const GrGLInterface* interface() const { return fInterface.get(); } @@ -95,9 +98,7 @@ public: ~GrGLContext() override; private: - GrGLContext(const ConstructorArgs& args) - : INHERITED(args) - , fCompiler(nullptr) {} + GrGLContext(ConstructorArgs&& args) : INHERITED(std::move(args)), fCompiler(nullptr) {} mutable SkSL::Compiler* fCompiler; diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index 33096160a4..ba3f1c2e11 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -199,25 +199,25 @@ sk_sp<GrGpu> GrGLGpu::Make(sk_sp<const GrGLInterface> interface, const GrContext #ifdef USE_NSIGHT const_cast<GrContextOptions&>(options).fSuppressPathRendering = true; #endif - GrGLContext* glContext = GrGLContext::Create(interface.get(), options); - if (glContext) { - return sk_sp<GrGpu>(new GrGLGpu(glContext, context)); + auto glContext = GrGLContext::Make(std::move(interface), options); + if (!glContext) { + return nullptr; } - return nullptr; + return sk_sp<GrGpu>(new GrGLGpu(std::move(glContext), context)); } -GrGLGpu::GrGLGpu(GrGLContext* ctx, GrContext* context) - : GrGpu(context) - , fGLContext(ctx) - , fProgramCache(new ProgramCache(this)) - , fHWProgramID(0) - , fTempSrcFBOID(0) - , fTempDstFBOID(0) - , fStencilClearFBOID(0) - , fHWMaxUsedBufferTextureUnit(-1) - , fHWMinSampleShading(0.0) { - SkASSERT(ctx); - fCaps.reset(SkRef(ctx->caps())); +GrGLGpu::GrGLGpu(std::unique_ptr<GrGLContext> ctx, GrContext* context) + : GrGpu(context) + , fGLContext(std::move(ctx)) + , fProgramCache(new ProgramCache(this)) + , fHWProgramID(0) + , fTempSrcFBOID(0) + , fTempDstFBOID(0) + , fStencilClearFBOID(0) + , fHWMaxUsedBufferTextureUnit(-1) + , fHWMinSampleShading(0.0) { + SkASSERT(fGLContext); + fCaps = sk_ref_sp(fGLContext->caps()); fHWBoundTextureUniqueIDs.reset(this->caps()->shaderCaps()->maxCombinedSamplers()); diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h index 5c26924dec..cd78a6455c 100644 --- a/src/gpu/gl/GrGLGpu.h +++ b/src/gpu/gl/GrGLGpu.h @@ -189,7 +189,7 @@ public: void insertEventMarker(const char*); private: - GrGLGpu(GrGLContext* ctx, GrContext* context); + GrGLGpu(std::unique_ptr<GrGLContext>, GrContext*); // GrGpu overrides void onResetContext(uint32_t resetBits) override; @@ -415,13 +415,13 @@ private: void onDumpJSON(SkJSONWriter*) const override; - sk_sp<GrGLContext> fGLContext; - bool createCopyProgram(GrTexture* srcTexture); bool createMipmapProgram(int progIdx); bool createStencilClipClearProgram(); bool createClearColorProgram(); + std::unique_ptr<GrGLContext> fGLContext; + // GL program-related state ProgramCache* fProgramCache; |