Dawn: fix memory corruption in DawnTestContext.

Move the dawn_native::Instance ownership from DawnTestContextImpl to
DawnTestContext (its parent class), which owns the wgpu::Device.

dawn_native::Instance must outlive any wgpu::Devices created from it.

Bug: skia: 10311
Change-Id: Iedc4ed94f03b61d5e43cd5c93eb68e24bc4474e1
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/293852
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
diff --git a/tools/gpu/dawn/DawnTestContext.cpp b/tools/gpu/dawn/DawnTestContext.cpp
index 34bc5b3..f30c5ec 100644
--- a/tools/gpu/dawn/DawnTestContext.cpp
+++ b/tools/gpu/dawn/DawnTestContext.cpp
@@ -6,7 +6,6 @@
  */
 
 #include "dawn/webgpu_cpp.h"
-#include "dawn_native/DawnNative.h"
 #include "tools/gpu/dawn/DawnTestContext.h"
 
 #ifdef SK_BUILD_FOR_UNIX
@@ -150,15 +149,13 @@
 private:
     DawnTestContextImpl(std::unique_ptr<dawn_native::Instance> instance,
                         const wgpu::Device& device)
-            : DawnTestContext(device)
-            , fInstance(std::move(instance)) {
+            : DawnTestContext(std::move(instance), device) {
         fFenceSupport = true;
     }
 
     void onPlatformMakeNotCurrent() const override {}
     void onPlatformMakeCurrent() const override {}
     std::function<void()> onPlatformGetAutoContextRestore() const override  { return nullptr; }
-    std::unique_ptr<dawn_native::Instance> fInstance;
 
     typedef sk_gpu_test::DawnTestContext INHERITED;
 };
diff --git a/tools/gpu/dawn/DawnTestContext.h b/tools/gpu/dawn/DawnTestContext.h
index 63f35f6..73b4e5d 100644
--- a/tools/gpu/dawn/DawnTestContext.h
+++ b/tools/gpu/dawn/DawnTestContext.h
@@ -9,6 +9,7 @@
 #define DawnTestContext_DEFINED
 
 #include "tools/gpu/TestContext.h"
+#include <dawn_native/DawnNative.h>
 
 #ifdef SK_DAWN
 
@@ -22,8 +23,10 @@
     }
 
 protected:
-    DawnTestContext(const wgpu::Device& device) : fDevice(device) {}
+    DawnTestContext(std::unique_ptr<dawn_native::Instance> instance, const wgpu::Device& device)
+        : fInstance(std::move(instance)), fDevice(device) {}
 
+    std::unique_ptr<dawn_native::Instance> fInstance;
     wgpu::Device fDevice;
 
 private: