Change texture state validation in CopyTextureForBrowser() to report meaningful errors

CopyTextureForBrowser() will support all uploading paths for WebGPU
CopyExternalImageToTexture(). The validation checks for texture states
should report accurate errors to meet CopyExternalImageToTexture() validate
rules.

Bug: dawn:1306
Change-Id: Ie3b25ec82246d53e6c82968b5dc2f8a253c560c1
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/81240
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Shaobo Yan <shaobo.yan@intel.com>
diff --git a/src/dawn/native/CopyTextureForBrowserHelper.cpp b/src/dawn/native/CopyTextureForBrowserHelper.cpp
index d51cb83..84b78c3 100644
--- a/src/dawn/native/CopyTextureForBrowserHelper.cpp
+++ b/src/dawn/native/CopyTextureForBrowserHelper.cpp
@@ -257,12 +257,6 @@
             return {};
         }
 
-        MaybeError ValidateTextureState(const TextureBase* texture) {
-            DAWN_INVALID_IF(texture->GetTextureState() == TextureBase::TextureState::Destroyed,
-                            "Destroyed texture %s used in CopyTextureForBrowser().", texture);
-            return {};
-        }
-
         RenderPipelineBase* GetCachedPipeline(InternalPipelineStore* store,
                                               wgpu::TextureFormat dstFormat) {
             auto pipeline = store->copyTextureForBrowserPipelines.find(dstFormat);
@@ -332,8 +326,11 @@
         DAWN_TRY(device->ValidateObject(source->texture));
         DAWN_TRY(device->ValidateObject(destination->texture));
 
-        DAWN_TRY(ValidateTextureState(source->texture));
-        DAWN_TRY(ValidateTextureState(destination->texture));
+        DAWN_INVALID_IF(source->texture->GetTextureState() == TextureBase::TextureState::Destroyed,
+                        "Source texture %s is destroyed.", source->texture);
+
+        DAWN_INVALID_IF(source->texture->GetTextureState() == TextureBase::TextureState::Destroyed,
+                        "Destination texture %s is destroyed.", destination->texture);
 
         DAWN_TRY_CONTEXT(ValidateImageCopyTexture(device, *source, *copySize),
                          "validating the ImageCopyTexture for the source");