[Mac] Pass SharedTextureMemory in TextureMTL initialization

Small prepatory CL for moving TextureMTL creation from TextureMTL
to SharedTextureMemoryMTL - TextureMTL will grab the TextureMTL objects
from SharedTextureMemoryMTL in init, which will then allow
SharedTextureMemoryMTL freedom in caching these objects as suitable.

Change-Id: I2b72b256e323e0c94eea941d791d555ea6bdbd58
Bug: dawn:2152, 1493854
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/169880
Commit-Queue: Colin Blundell <blundell@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/dawn/native/metal/TextureMTL.h b/src/dawn/native/metal/TextureMTL.h
index cca6285..0bc8eea 100644
--- a/src/dawn/native/metal/TextureMTL.h
+++ b/src/dawn/native/metal/TextureMTL.h
@@ -82,9 +82,9 @@
     NSRef<MTLTextureDescriptor> CreateMetalTextureDescriptor() const;
 
     MaybeError InitializeAsInternalTexture(const UnpackedPtr<TextureDescriptor>& descriptor);
-    MaybeError InitializeFromSharedTextureMemoryIOSurface(
-        const UnpackedPtr<TextureDescriptor>& textureDescriptor,
-        IOSurfaceRef ioSurface);
+    MaybeError InitializeFromSharedTextureMemory(
+        SharedTextureMemory* memory,
+        const UnpackedPtr<TextureDescriptor>& textureDescriptor);
     void InitializeAsWrapping(const UnpackedPtr<TextureDescriptor>& descriptor,
                               NSPRef<id<MTLTexture>> wrapped);
 
diff --git a/src/dawn/native/metal/TextureMTL.mm b/src/dawn/native/metal/TextureMTL.mm
index 91c6221..357df7b 100644
--- a/src/dawn/native/metal/TextureMTL.mm
+++ b/src/dawn/native/metal/TextureMTL.mm
@@ -329,8 +329,7 @@
 
     Device* device = ToBackend(memory->GetDevice());
     Ref<Texture> texture = AcquireRef(new Texture(device, descriptor));
-    DAWN_TRY(
-        texture->InitializeFromSharedTextureMemoryIOSurface(descriptor, memory->GetIOSurface()));
+    DAWN_TRY(texture->InitializeFromSharedTextureMemory(memory, descriptor));
     texture->mSharedTextureMemoryContents = memory->GetContents();
     return texture;
 }
@@ -403,15 +402,15 @@
     SetLabelImpl();
 }
 
-MaybeError Texture::InitializeFromSharedTextureMemoryIOSurface(
-    const UnpackedPtr<TextureDescriptor>& textureDescriptor,
-    IOSurfaceRef ioSurface) {
+MaybeError Texture::InitializeFromSharedTextureMemory(
+    SharedTextureMemory* memory,
+    const UnpackedPtr<TextureDescriptor>& textureDescriptor) {
     DAWN_INVALID_IF(
         GetInternalUsage() & wgpu::TextureUsage::TransientAttachment,
         "Usage flags (%s) include %s, which is not compatible with creation from IOSurface.",
         GetInternalUsage(), wgpu::TextureUsage::TransientAttachment);
 
-    mIOSurface = ioSurface;
+    mIOSurface = memory->GetIOSurface();
 
     Device* device = ToBackend(GetDevice());
 
@@ -439,7 +438,7 @@
         mMtlPlaneTextures->resize(1);
         mMtlPlaneTextures[0] =
             AcquireNSPRef([device->GetMTLDevice() newTextureWithDescriptor:mtlDesc
-                                                                 iosurface:ioSurface
+                                                                 iosurface:mIOSurface.Get()
                                                                      plane:0]);
     } else {
         mMtlUsage = kMetalTextureUsageForSharedTextureMemoryIOSurface;