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>
This commit is contained in:
parent
a4ceaa1e5a
commit
8ab1cc477b
@ -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) {
|
||||
return nullptr;
|
||||
}
|
||||
ConstructorArgs args;
|
||||
args.fInterface = interface;
|
||||
|
||||
const GrGLubyte* verUByte;
|
||||
GR_GL_CALL_RET(interface, 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));
|
||||
const char* renderer = reinterpret_cast<const char*>(rendererUByte);
|
||||
|
||||
std::unique_ptr<GrGLContext> GrGLContext::Make(sk_sp<const GrGLInterface> interface,
|
||||
const GrContextOptions& options) {
|
||||
if (!interface->validate()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const GrGLubyte* verUByte;
|
||||
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.get(), rendererUByte, GetString(GR_GL_RENDERER));
|
||||
const char* renderer = reinterpret_cast<const char*>(rendererUByte);
|
||||
|
||||
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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -199,16 +199,16 @@ 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 sk_sp<GrGpu>(new GrGLGpu(std::move(glContext), context));
|
||||
}
|
||||
|
||||
GrGLGpu::GrGLGpu(GrGLContext* ctx, GrContext* context)
|
||||
GrGLGpu::GrGLGpu(std::unique_ptr<GrGLContext> ctx, GrContext* context)
|
||||
: GrGpu(context)
|
||||
, fGLContext(ctx)
|
||||
, fGLContext(std::move(ctx))
|
||||
, fProgramCache(new ProgramCache(this))
|
||||
, fHWProgramID(0)
|
||||
, fTempSrcFBOID(0)
|
||||
@ -216,8 +216,8 @@ GrGLGpu::GrGLGpu(GrGLContext* ctx, GrContext* context)
|
||||
, fStencilClearFBOID(0)
|
||||
, fHWMaxUsedBufferTextureUnit(-1)
|
||||
, fHWMinSampleShading(0.0) {
|
||||
SkASSERT(ctx);
|
||||
fCaps.reset(SkRef(ctx->caps()));
|
||||
SkASSERT(fGLContext);
|
||||
fCaps = sk_ref_sp(fGLContext->caps());
|
||||
|
||||
fHWBoundTextureUniqueIDs.reset(this->caps()->shaderCaps()->maxCombinedSamplers());
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user