Track whether TextureGL owns the handle and should delete it

Change-Id: I2cf21fb0924c47aeb1aeae298661dc4a128a0c6c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/147100
Reviewed-by: Loko Kung <lokokung@google.com>
Reviewed-by: Stephen White <senorblanco@chromium.org>
Commit-Queue: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/dawn/native/opengl/TextureGL.cpp b/src/dawn/native/opengl/TextureGL.cpp
index 2e5c391..d03f3a7 100644
--- a/src/dawn/native/opengl/TextureGL.cpp
+++ b/src/dawn/native/opengl/TextureGL.cpp
@@ -186,6 +186,7 @@
     const OpenGLFunctions& gl = device->GetGL();
 
     gl.GenTextures(1, &mHandle);
+    mOwnsHandle = true;
     uint32_t levels = GetNumMipLevels();
 
     const GLFormat& glFormat = GetGLFormat();
@@ -216,7 +217,7 @@
 
 void Texture::DestroyImpl() {
     TextureBase::DestroyImpl();
-    if (mHandle != 0) {
+    if (mOwnsHandle) {
         const OpenGLFunctions& gl = ToBackend(GetDevice())->GetGL();
         gl.DeleteTextures(1, &mHandle);
         mHandle = 0;
diff --git a/src/dawn/native/opengl/TextureGL.h b/src/dawn/native/opengl/TextureGL.h
index bdc4fea..61f1939 100644
--- a/src/dawn/native/opengl/TextureGL.h
+++ b/src/dawn/native/opengl/TextureGL.h
@@ -45,6 +45,7 @@
     MaybeError ClearTexture(const SubresourceRange& range, TextureBase::ClearValue clearValue);
 
     GLuint mHandle;
+    bool mOwnsHandle = false;
     GLenum mTarget;
     uint32_t mGenID = 0;
 };