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>
diff --git a/src/gpu/gl/GrGLContext.cpp b/src/gpu/gl/GrGLContext.cpp
index 9d18b5f..dd774cd 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) {
- 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 @@
&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 @@
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;