Split apart creating and updating GrBackendTextures internally.

This change does not any public APIs but just pulls apart the create and
update steps inside of createBackendTexture. A future CL will allow just
calling update from the public API with an already create texture.

This change only splits apart the work for non compressed textures.
Compressed support can be added at a future time, but for many backends
it should be fairly trivial since the update call handles compressed and
uncompressed already.

Change-Id: Iae99e9f140c347effe66b5d669c6f39bce023115
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/287856
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 672d380..379e149 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -405,7 +405,7 @@
     }
 
     return fGpu->createBackendTexture({width, height}, backendFormat, renderable,
-                                      mipMapped, isProtected, nullptr, nullptr, nullptr);
+                                      mipMapped, isProtected);
 }
 
 GrBackendTexture GrContext::createBackendTexture(int width, int height,
@@ -497,6 +497,31 @@
     return result;
 }
 
+static GrBackendTexture create_and_update_backend_texture(GrContext* context,
+                                                          SkISize dimensions,
+                                                          const GrBackendFormat& backendFormat,
+                                                          GrMipMapped mipMapped,
+                                                          GrRenderable renderable,
+                                                          GrProtected isProtected,
+                                                          GrGpuFinishedProc finishedProc,
+                                                          GrGpuFinishedContext finishedContext,
+                                                          const GrGpu::BackendTextureData* data) {
+    GrGpu* gpu = context->priv().getGpu();
+
+    GrBackendTexture beTex = gpu->createBackendTexture(dimensions, backendFormat, renderable,
+                                                       mipMapped, isProtected);
+    if (!beTex.isValid()) {
+        return {};
+    }
+
+    if (!context->priv().getGpu()->updateBackendTexture(beTex, finishedProc, finishedContext,
+                                                        data)) {
+        context->deleteBackendTexture(beTex);
+        return {};
+    }
+    return beTex;
+}
+
 GrBackendTexture GrContext::createBackendTexture(int width, int height,
                                                  const GrBackendFormat& backendFormat,
                                                  const SkColor4f& color,
@@ -517,8 +542,9 @@
     }
 
     GrGpu::BackendTextureData data(color);
-    return fGpu->createBackendTexture({width, height}, backendFormat, renderable,
-                                      mipMapped, isProtected, finishedProc, finishedContext, &data);
+    return create_and_update_backend_texture(this, {width, height}, backendFormat, mipMapped,
+                                             renderable, isProtected, finishedProc, finishedContext,
+                                             &data);
 }
 
 GrBackendTexture GrContext::createBackendTexture(int width, int height,
@@ -592,8 +618,9 @@
     GrBackendFormat backendFormat = this->defaultBackendFormat(colorType, renderable);
 
     GrGpu::BackendTextureData data(srcData);
-    return fGpu->createBackendTexture({baseWidth, baseHeight}, backendFormat, renderable,
-                                      mipMapped, isProtected, finishedProc, finishedContext, &data);
+    return create_and_update_backend_texture(this, {baseWidth, baseHeight}, backendFormat,
+                                             mipMapped, renderable, isProtected, finishedProc,
+                                             finishedContext, &data);
 }
 
 //////////////////////////////////////////////////////////////////////////////