gpu: win: Move SCANOUT flag on CompoundImageBacking from gpu to shmem

This change moves the SCANOUT flag on Windows for NV12 SharedImages from
being on the gpu backing of a CompoundImageBacking to being on the
shared memory backing. This allows us to better distinguish on the
D3DImageBacking side which SCANOUT allocations are which, letting us
correctly identify the upcoming DComp texture backings.

Bug: 40150597
Change-Id: I18c973afbe498acbf0025746e194b245d768fa23
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5662236
Reviewed-by: Vasiliy Telezhnikov <vasilyt@chromium.org>
Commit-Queue: Michael Tang <tangm@microsoft.com>
Cr-Commit-Position: refs/heads/main@{#1321203}
diff --git a/gpu/command_buffer/common/shared_image_usage.h b/gpu/command_buffer/common/shared_image_usage.h
index b7bf8f1..dfd3b12 100644
--- a/gpu/command_buffer/common/shared_image_usage.h
+++ b/gpu/command_buffer/common/shared_image_usage.h
@@ -130,11 +130,16 @@
     }
   }
 
-  // Unions with 'set_b' and returns result.
+  // Unions with 'set_b' and stores result in self.
   inline constexpr void PutAll(gpu::SharedImageUsageSet set_b) {
     set_storage_ = set_storage_ | static_cast<uint32_t>(set_b);
   }
 
+  // Removes all values in 'set_b' from our set.
+  inline constexpr void RemoveAll(gpu::SharedImageUsageSet set_b) {
+    set_storage_ = set_storage_ & ~static_cast<uint32_t>(set_b);
+  }
+
   // Test set membership via intersection. Returns true if 'set_b' is a subset.
   inline constexpr bool HasAll(gpu::SharedImageUsageSet set_b) const {
     return (set_storage_ & set_b.set_storage_) == set_b.set_storage_;
diff --git a/gpu/command_buffer/service/shared_image/compound_image_backing.cc b/gpu/command_buffer/service/shared_image/compound_image_backing.cc
index 8ac2a7f1..7ac53807 100644
--- a/gpu/command_buffer/service/shared_image/compound_image_backing.cc
+++ b/gpu/command_buffer/service/shared_image/compound_image_backing.cc
@@ -70,6 +70,25 @@
   }
 }
 
+#if BUILDFLAG(IS_WIN)
+// Only allow shmem overlays for NV12 on Windows.
+// This moves the SCANOUT flag from the GPU backing to the shmem backing in the
+// CompoundImageBacking.
+constexpr bool kAllowShmOverlays = true;
+#else
+constexpr bool kAllowShmOverlays = false;
+#endif
+
+gpu::SharedImageUsageSet GetShmSharedImageUsage(SharedImageUsageSet usage) {
+  if (kAllowShmOverlays) {
+    return usage.HasAny(gpu::SHARED_IMAGE_USAGE_SCANOUT)
+               ? SHARED_IMAGE_USAGE_CPU_WRITE | SHARED_IMAGE_USAGE_SCANOUT
+               : SHARED_IMAGE_USAGE_CPU_WRITE;
+  }
+
+  return SHARED_IMAGE_USAGE_CPU_WRITE;
+}
+
 }  // namespace
 
 // Wrapped representation types are not in the anonymous namespace because they
@@ -384,9 +403,24 @@
 }
 
 // static
+SharedImageUsageSet CompoundImageBacking::GetGpuSharedImageUsage(
+    SharedImageUsageSet usage) {
+  // Add allow copying from the shmem backing to the gpu backing.
+  usage |= SHARED_IMAGE_USAGE_CPU_UPLOAD;
+
+  if (kAllowShmOverlays) {
+    // Remove SCANOUT usage since it was previously moved to the shmem backing.
+    // See: |GetShmSharedImageUsage|
+    usage.RemoveAll(SharedImageUsageSet(gpu::SHARED_IMAGE_USAGE_SCANOUT));
+    return usage;
+  }
+
+  return usage;
+}
+
+// static
 std::unique_ptr<SharedImageBacking> CompoundImageBacking::CreateSharedMemory(
     SharedImageBackingFactory* gpu_backing_factory,
-    bool allow_shm_overlays,
     const Mailbox& mailbox,
     gfx::GpuMemoryBufferHandle handle,
     viz::SharedImageFormat format,
@@ -394,7 +428,7 @@
     const gfx::ColorSpace& color_space,
     GrSurfaceOrigin surface_origin,
     SkAlphaType alpha_type,
-    uint32_t usage,
+    SharedImageUsageSet usage,
     std::string debug_label) {
   DCHECK(IsValidSharedMemoryBufferFormat(size, format));
 
@@ -407,19 +441,18 @@
 
   auto shm_backing = std::make_unique<SharedMemoryImageBacking>(
       mailbox, format, size, color_space, surface_origin, alpha_type,
-      SHARED_IMAGE_USAGE_CPU_WRITE, debug_label, std::move(shm_wrapper));
+      GetShmSharedImageUsage(usage), debug_label, std::move(shm_wrapper));
   shm_backing->SetNotRefCounted();
 
   return base::WrapUnique(new CompoundImageBacking(
       mailbox, format, size, color_space, surface_origin, alpha_type, usage,
-      std::move(debug_label), allow_shm_overlays, std::move(shm_backing),
+      std::move(debug_label), std::move(shm_backing),
       gpu_backing_factory->GetWeakPtr()));
 }
 
 // static
 std::unique_ptr<SharedImageBacking> CompoundImageBacking::CreateSharedMemory(
     SharedImageBackingFactory* gpu_backing_factory,
-    bool allow_shm_overlays,
     const Mailbox& mailbox,
     gfx::GpuMemoryBufferHandle handle,
     gfx::BufferFormat format,
@@ -428,7 +461,7 @@
     const gfx::ColorSpace& color_space,
     GrSurfaceOrigin surface_origin,
     SkAlphaType alpha_type,
-    uint32_t usage,
+    SharedImageUsageSet usage,
     std::string debug_label) {
   DCHECK(IsValidSharedMemoryBufferFormat(size, format, plane));
 
@@ -444,27 +477,26 @@
 
   auto shm_backing = std::make_unique<SharedMemoryImageBacking>(
       mailbox, plane_format, plane_size, color_space, surface_origin,
-      alpha_type, SHARED_IMAGE_USAGE_CPU_WRITE, debug_label,
+      alpha_type, GetShmSharedImageUsage(usage), debug_label,
       std::move(shm_wrapper));
   shm_backing->SetNotRefCounted();
 
   return base::WrapUnique(new CompoundImageBacking(
       mailbox, plane_format, plane_size, color_space, surface_origin,
-      alpha_type, usage, std::move(debug_label), allow_shm_overlays,
-      std::move(shm_backing), gpu_backing_factory->GetWeakPtr()));
+      alpha_type, usage, std::move(debug_label), std::move(shm_backing),
+      gpu_backing_factory->GetWeakPtr()));
 }
 
 // static
 std::unique_ptr<SharedImageBacking> CompoundImageBacking::CreateSharedMemory(
     SharedImageBackingFactory* gpu_backing_factory,
-    bool allow_shm_overlays,
     const Mailbox& mailbox,
     viz::SharedImageFormat format,
     const gfx::Size& size,
     const gfx::ColorSpace& color_space,
     GrSurfaceOrigin surface_origin,
     SkAlphaType alpha_type,
-    uint32_t usage,
+    SharedImageUsageSet usage,
     std::string debug_label,
     gfx::BufferUsage buffer_usage) {
   DCHECK(IsValidSharedMemoryBufferFormat(size, format));
@@ -482,13 +514,13 @@
 
   auto shm_backing = std::make_unique<SharedMemoryImageBacking>(
       mailbox, format, size, color_space, surface_origin, alpha_type,
-      SHARED_IMAGE_USAGE_CPU_WRITE, debug_label, std::move(shm_wrapper),
+      GetShmSharedImageUsage(usage), debug_label, std::move(shm_wrapper),
       std::move(handle));
   shm_backing->SetNotRefCounted();
 
   return base::WrapUnique(new CompoundImageBacking(
       mailbox, format, size, color_space, surface_origin, alpha_type, usage,
-      std::move(debug_label), allow_shm_overlays, std::move(shm_backing),
+      std::move(debug_label), std::move(shm_backing),
       gpu_backing_factory->GetWeakPtr(), std::move(buffer_usage)));
 }
 
@@ -499,9 +531,8 @@
     const gfx::ColorSpace& color_space,
     GrSurfaceOrigin surface_origin,
     SkAlphaType alpha_type,
-    uint32_t usage,
+    SharedImageUsageSet usage,
     std::string debug_label,
-    bool allow_shm_overlays,
     std::unique_ptr<SharedMemoryImageBacking> shm_backing,
     base::WeakPtr<SharedImageBackingFactory> gpu_backing_factory,
     std::optional<gfx::BufferUsage> buffer_usage)
@@ -520,8 +551,9 @@
   DCHECK_EQ(size, shm_backing->size());
   elements_[0].backing = std::move(shm_backing);
   elements_[0].access_streams = kMemoryStreamSet;
-  if (allow_shm_overlays)
+  if (kAllowShmOverlays && usage.HasAny(gpu::SHARED_IMAGE_USAGE_SCANOUT)) {
     elements_[0].access_streams.Put(SharedImageAccessStream::kOverlay);
+  }
   elements_[0].content_id_ = latest_content_id_;
 
   elements_[1].create_callback = base::BindOnce(
@@ -833,7 +865,7 @@
   backing = factory->CreateSharedImage(
       mailbox(), format(), kNullSurfaceHandle, size(), color_space(),
       surface_origin(), alpha_type(),
-      SharedImageUsageSet(usage()) | SHARED_IMAGE_USAGE_CPU_UPLOAD,
+      GetGpuSharedImageUsage(SharedImageUsageSet(usage())),
       std::move(debug_label), /*is_thread_safe=*/false);
   if (!backing) {
     DLOG(ERROR) << "Failed to allocate GPU backing";
diff --git a/gpu/command_buffer/service/shared_image/compound_image_backing.h b/gpu/command_buffer/service/shared_image/compound_image_backing.h
index fc68005..651d337 100644
--- a/gpu/command_buffer/service/shared_image/compound_image_backing.h
+++ b/gpu/command_buffer/service/shared_image/compound_image_backing.h
@@ -8,6 +8,7 @@
 #include "base/containers/enum_set.h"
 #include "base/memory/scoped_refptr.h"
 #include "gpu/command_buffer/common/mailbox.h"
+#include "gpu/command_buffer/common/shared_image_usage.h"
 #include "gpu/command_buffer/service/memory_tracking.h"
 #include "gpu/command_buffer/service/shared_image/shared_image_backing.h"
 #include "gpu/command_buffer/service/shared_image/shared_image_manager.h"
@@ -53,11 +54,13 @@
                                               gfx::BufferFormat buffer_format,
                                               gfx::BufferPlane plane);
 
+  // Remove the SCANOUT flag if |kAllowShmOverlays|.
+  static SharedImageUsageSet GetGpuSharedImageUsage(SharedImageUsageSet usage);
+
   // Creates a backing that contains a shared memory backing and GPU backing
   // provided by `gpu_backing_factory`.
   static std::unique_ptr<SharedImageBacking> CreateSharedMemory(
       SharedImageBackingFactory* gpu_backing_factory,
-      bool allow_shm_overlays,
       const Mailbox& mailbox,
       gfx::GpuMemoryBufferHandle handle,
       viz::SharedImageFormat format,
@@ -65,14 +68,13 @@
       const gfx::ColorSpace& color_space,
       GrSurfaceOrigin surface_origin,
       SkAlphaType alpha_type,
-      uint32_t usage,
+      SharedImageUsageSet usage,
       std::string debug_label);
 
   // Creates a backing that contains a shared memory backing and GPU backing
   // provided by `gpu_backing_factory`.
   static std::unique_ptr<SharedImageBacking> CreateSharedMemory(
       SharedImageBackingFactory* gpu_backing_factory,
-      bool allow_shm_overlays,
       const Mailbox& mailbox,
       gfx::GpuMemoryBufferHandle handle,
       gfx::BufferFormat buffer_format,
@@ -81,7 +83,7 @@
       const gfx::ColorSpace& color_space,
       GrSurfaceOrigin surface_origin,
       SkAlphaType alpha_type,
-      uint32_t usage,
+      SharedImageUsageSet usage,
       std::string debug_label);
 
   // Creates a backing that contains a shared memory backing and GPU backing
@@ -93,14 +95,13 @@
   // BufferUsage.
   static std::unique_ptr<SharedImageBacking> CreateSharedMemory(
       SharedImageBackingFactory* gpu_backing_factory,
-      bool allow_shm_overlays,
       const Mailbox& mailbox,
       viz::SharedImageFormat format,
       const gfx::Size& size,
       const gfx::ColorSpace& color_space,
       GrSurfaceOrigin surface_origin,
       SkAlphaType alpha_type,
-      uint32_t usage,
+      SharedImageUsageSet usage,
       std::string debug_label,
       gfx::BufferUsage buffer_usage);
 
@@ -183,9 +184,8 @@
       const gfx::ColorSpace& color_space,
       GrSurfaceOrigin surface_origin,
       SkAlphaType alpha_type,
-      uint32_t usage,
+      SharedImageUsageSet usage,
       std::string debug_label,
-      bool allow_shm_overlays,
       std::unique_ptr<SharedMemoryImageBacking> shm_backing,
       base::WeakPtr<SharedImageBackingFactory> gpu_backing_factory,
       std::optional<gfx::BufferUsage> buffer_usage = std::nullopt);
diff --git a/gpu/command_buffer/service/shared_image/compound_image_backing_unittest.cc b/gpu/command_buffer/service/shared_image/compound_image_backing_unittest.cc
index 322945af..f595662 100644
--- a/gpu/command_buffer/service/shared_image/compound_image_backing_unittest.cc
+++ b/gpu/command_buffer/service/shared_image/compound_image_backing_unittest.cc
@@ -145,7 +145,7 @@
 
   // Create a compound backing containing shared memory + GPU backing.
   std::unique_ptr<SharedImageBacking> CreateCompoundBacking(
-      bool allow_shm_overlays = false) {
+      bool add_scanout_usage = false) {
     constexpr gfx::Size size(100, 100);
     constexpr gfx::BufferFormat buffer_format = gfx::BufferFormat::RGBA_8888;
     constexpr gfx::BufferUsage buffer_usage =
@@ -157,14 +157,16 @@
             buffer_usage);
 
     return CompoundImageBacking::CreateSharedMemory(
-        &test_factory_, allow_shm_overlays, Mailbox::Generate(),
-        std::move(handle), viz::GetSinglePlaneSharedImageFormat(buffer_format),
-        size, gfx::ColorSpace(), kTopLeft_GrSurfaceOrigin, kOpaque_SkAlphaType,
-        SHARED_IMAGE_USAGE_DISPLAY_READ, "TestLabel");
+        &test_factory_, Mailbox::Generate(), std::move(handle),
+        viz::GetSinglePlaneSharedImageFormat(buffer_format), size,
+        gfx::ColorSpace(), kTopLeft_GrSurfaceOrigin, kOpaque_SkAlphaType,
+        add_scanout_usage
+            ? SHARED_IMAGE_USAGE_DISPLAY_READ | SHARED_IMAGE_USAGE_SCANOUT
+            : SHARED_IMAGE_USAGE_DISPLAY_READ,
+        "TestLabel");
   }
 
-  std::unique_ptr<SharedImageBacking> CreateMultiplanarCompoundBacking(
-      bool allow_shm_overlays = false) {
+  std::unique_ptr<SharedImageBacking> CreateMultiplanarCompoundBacking() {
     constexpr gfx::Size size(100, 100);
     constexpr gfx::BufferFormat buffer_format =
         gfx::BufferFormat::YUV_420_BIPLANAR;
@@ -177,9 +179,9 @@
             buffer_usage);
 
     return CompoundImageBacking::CreateSharedMemory(
-        &test_factory_, allow_shm_overlays, Mailbox::Generate(),
-        std::move(handle), viz::MultiPlaneFormat::kNV12, size,
-        gfx::ColorSpace(), kTopLeft_GrSurfaceOrigin, kOpaque_SkAlphaType,
+        &test_factory_, Mailbox::Generate(), std::move(handle),
+        viz::MultiPlaneFormat::kNV12, size, gfx::ColorSpace(),
+        kTopLeft_GrSurfaceOrigin, kOpaque_SkAlphaType,
         SHARED_IMAGE_USAGE_DISPLAY_READ, "TestLabel");
   }
 
@@ -346,8 +348,11 @@
   EXPECT_TRUE(GetGpuHasLatestContent(compound_backing));
 }
 
+#if BUILDFLAG(IS_WIN)
+// Tests the behavior of |kAllowShmemOverlays|, which is only true on Windows.
+// In this case we expect there to be scanout access, but no GPU access.
 TEST_F(CompoundImageBackingTest, NoUploadOnOverlayMemoryAccess) {
-  auto backing = CreateCompoundBacking(/*allow_shm_overlays=*/true);
+  auto backing = CreateCompoundBacking(/*add_scanout_usage=*/true);
   auto* compound_backing = static_cast<CompoundImageBacking*>(backing.get());
 
   auto factory_rep = manager_.Register(std::move(backing), &tracker_);
@@ -356,15 +361,14 @@
       manager_.ProduceOverlay(compound_backing->mailbox(), &tracker_);
   auto access = overlay_rep->BeginScopedReadAccess();
 
-#if BUILDFLAG(IS_WIN)
   std::optional<gl::DCLayerOverlayImage> overlay_image =
       access->GetDCLayerOverlayImage();
   ASSERT_TRUE(overlay_image);
   EXPECT_EQ(overlay_image->type(), gl::DCLayerOverlayType::kNV12Pixmap);
-#endif
 
   EXPECT_FALSE(HasGpuBacking(compound_backing));
 }
+#endif
 
 TEST_F(CompoundImageBackingTest, LazyAllocationFailsCreate) {
   auto backing = CreateCompoundBacking();
diff --git a/gpu/command_buffer/service/shared_image/d3d_image_backing_factory.cc b/gpu/command_buffer/service/shared_image/d3d_image_backing_factory.cc
index 5ed630b..9194e995 100644
--- a/gpu/command_buffer/service/shared_image/d3d_image_backing_factory.cc
+++ b/gpu/command_buffer/service/shared_image/d3d_image_backing_factory.cc
@@ -547,6 +547,19 @@
     return false;
   }
 
+  const bool is_scanout = usage.HasAny(gpu::SHARED_IMAGE_USAGE_SCANOUT);
+  const bool is_video_decode =
+      usage.HasAny(gpu::SHARED_IMAGE_USAGE_VIDEO_DECODE);
+  if (is_scanout) {
+    if (!is_video_decode && gmb_type != gfx::DXGI_SHARED_HANDLE) {
+      return false;
+    } else {
+      // Video decode and video frames via GMBs are handled specially in
+      // |SwapChainPresenter|, so we must assume it's safe to create a scanout
+      // image backing for it.
+    }
+  }
+
   if (gmb_type == gfx::EMPTY_BUFFER) {
     if (GetDXGIFormatForCreateTexture(format) == DXGI_FORMAT_UNKNOWN) {
       return false;
diff --git a/gpu/command_buffer/service/shared_image/d3d_image_backing_factory_unittest.cc b/gpu/command_buffer/service/shared_image/d3d_image_backing_factory_unittest.cc
index e029ce0..723aba3 100644
--- a/gpu/command_buffer/service/shared_image/d3d_image_backing_factory_unittest.cc
+++ b/gpu/command_buffer/service/shared_image/d3d_image_backing_factory_unittest.cc
@@ -1863,10 +1863,9 @@
     // CompoundImageBacking wrapping D3DImageBacking is required for shared
     // memory support.
     auto backing = CompoundImageBacking::CreateSharedMemory(
-        shared_image_factory_.get(), /*allow_shm_overlays=*/true, mailboxes[i],
-        std::move(shm_gmb_handle), gfx::BufferFormat::YUV_420_BIPLANAR,
-        planes[i], size, gfx::ColorSpace(), kTopLeft_GrSurfaceOrigin,
-        kPremul_SkAlphaType, usage, "TestLabel");
+        shared_image_factory_.get(), mailboxes[i], std::move(shm_gmb_handle),
+        gfx::BufferFormat::YUV_420_BIPLANAR, planes[i], size, gfx::ColorSpace(),
+        kTopLeft_GrSurfaceOrigin, kPremul_SkAlphaType, usage, "TestLabel");
     EXPECT_NE(backing, nullptr);
 
     shared_image_backings.push_back(std::move(backing));
@@ -2034,10 +2033,9 @@
   // CompoundImageBacking wrapping D3DImageBacking is required for shared
   // memory support.
   auto backing = CompoundImageBacking::CreateSharedMemory(
-      shared_image_factory_.get(), /*allow_shm_overlays=*/true, mailbox,
-      std::move(shm_gmb_handle), viz::MultiPlaneFormat::kNV12, size,
-      gfx::ColorSpace(), kTopLeft_GrSurfaceOrigin, kPremul_SkAlphaType, usage,
-      "TestLabel");
+      shared_image_factory_.get(), mailbox, std::move(shm_gmb_handle),
+      viz::MultiPlaneFormat::kNV12, size, gfx::ColorSpace(),
+      kTopLeft_GrSurfaceOrigin, kPremul_SkAlphaType, usage, "TestLabel");
   EXPECT_NE(backing, nullptr);
 
   EXPECT_EQ(backing->mailbox(), mailbox);
diff --git a/gpu/command_buffer/service/shared_image/shared_image_factory.cc b/gpu/command_buffer/service/shared_image/shared_image_factory.cc
index b7b1f56..5a68e36 100644
--- a/gpu/command_buffer/service/shared_image/shared_image_factory.cc
+++ b/gpu/command_buffer/service/shared_image/shared_image_factory.cc
@@ -103,13 +103,6 @@
              base::FEATURE_DISABLED_BY_DEFAULT);
 #endif
 
-#if BUILDFLAG(IS_WIN)
-// Only allow shmem overlays for NV12 on Windows.
-constexpr bool kAllowShmOverlays = true;
-#else
-constexpr bool kAllowShmOverlays = false;
-#endif
-
 const char* GmbTypeToString(gfx::GpuMemoryBufferType type) {
   switch (type) {
     case gfx::EMPTY_BUFFER:
@@ -541,8 +534,10 @@
         if (CompoundImageBacking::IsValidSharedMemoryBufferFormat(size,
                                                                   format)) {
           factory =
-              GetFactoryByUsage(usage | SHARED_IMAGE_USAGE_CPU_UPLOAD, format,
-                                size, /*pixel_data=*/{}, gfx::EMPTY_BUFFER);
+              GetFactoryByUsage(CompoundImageBacking::GetGpuSharedImageUsage(
+                                    SharedImageUsageSet(usage)),
+                                format, size,
+                                /*pixel_data=*/{}, gfx::EMPTY_BUFFER);
           use_compound = factory != nullptr;
         }
       }
@@ -555,8 +550,8 @@
 
       if (use_compound) {
         backing = CompoundImageBacking::CreateSharedMemory(
-            factory, kAllowShmOverlays, mailbox, format, size, color_space,
-            surface_origin, alpha_type, usage, debug_label, buffer_usage);
+            factory, mailbox, format, size, color_space, surface_origin,
+            alpha_type, SharedImageUsage(usage), debug_label, buffer_usage);
       } else {
         backing = factory->CreateSharedImage(
             mailbox, format, surface_handle, size, color_space, surface_origin,
@@ -652,8 +647,10 @@
     // Check if CompoundImageBacking can hold shared memory buffer plus
     // another GPU backing type to satisfy requirements.
     if (CompoundImageBacking::IsValidSharedMemoryBufferFormat(size, format)) {
-      factory = GetFactoryByUsage(usage | SHARED_IMAGE_USAGE_CPU_UPLOAD, format,
-                                  size, /*pixel_data=*/{}, gfx::EMPTY_BUFFER);
+      factory =
+          GetFactoryByUsage(CompoundImageBacking::GetGpuSharedImageUsage(
+                                SharedImageUsageSet(usage)),
+                            format, size, /*pixel_data=*/{}, gfx::EMPTY_BUFFER);
       use_compound = factory != nullptr;
     }
   }
@@ -666,8 +663,8 @@
   std::unique_ptr<SharedImageBacking> backing;
   if (use_compound) {
     backing = CompoundImageBacking::CreateSharedMemory(
-        factory, kAllowShmOverlays, mailbox, std::move(buffer_handle), format,
-        size, color_space, surface_origin, alpha_type, usage,
+        factory, mailbox, std::move(buffer_handle), format, size, color_space,
+        surface_origin, alpha_type, SharedImageUsage(usage),
         std::move(debug_label));
   } else {
     backing = factory->CreateSharedImage(
@@ -722,9 +719,10 @@
       const auto plane_format = viz::GetSinglePlaneSharedImageFormat(
           GetPlaneBufferFormat(plane, format));
       const gfx::Size plane_size = GetPlaneSize(plane, size);
-      factory =
-          GetFactoryByUsage(usage | SHARED_IMAGE_USAGE_CPU_UPLOAD, plane_format,
-                            plane_size, /*pixel_data=*/{}, gfx::EMPTY_BUFFER);
+      factory = GetFactoryByUsage(CompoundImageBacking::GetGpuSharedImageUsage(
+                                      SharedImageUsageSet(usage)),
+                                  plane_format, plane_size, /*pixel_data=*/{},
+                                  gfx::EMPTY_BUFFER);
       use_compound = factory != nullptr;
     }
   }
@@ -737,8 +735,8 @@
   std::unique_ptr<SharedImageBacking> backing;
   if (use_compound) {
     backing = CompoundImageBacking::CreateSharedMemory(
-        factory, kAllowShmOverlays, mailbox, std::move(handle), format, plane,
-        size, color_space, surface_origin, alpha_type, usage,
+        factory, mailbox, std::move(handle), format, plane, size, color_space,
+        surface_origin, alpha_type, SharedImageUsage(usage),
         std::move(debug_label));
   } else {
     backing = factory->CreateSharedImage(