Skip to content

Commit 82f5dc1

Browse files
hitawala-chromiumChromium LUCI CQ
authored andcommitted
[gpu] Add GetMappableSharedImageFormatForTesting to SIF utils
Add GetMappableSharedImageFormatForTesting util method that returns all mappable SIFormats similar to its BufferFormat equivalent GetBufferFormatsForTesting that is now removed in this CL. This is done as part of moving away from BufferFormat to SharedImageFormat. Bug: 356649879 Change-Id: Ib35274eddfa58e1d9d76dbc65cd5e404332a0643 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7055704 Reviewed-by: Vasiliy Telezhnikov <[email protected]> Commit-Queue: Saifuddin Hitawala <[email protected]> Reviewed-by: Giovanni Ortuno Urquidi <[email protected]> Cr-Commit-Position: refs/heads/main@{#1532381}
1 parent d46c259 commit 82f5dc1

File tree

9 files changed

+49
-51
lines changed

9 files changed

+49
-51
lines changed

components/viz/common/resources/shared_image_format_utils.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,29 @@
77
#include <GLES2/gl2.h>
88
#include <GLES2/gl2ext.h>
99

10+
#include <array>
11+
1012
#include "base/check_op.h"
1113
#include "base/logging.h"
1214
#include "base/notreached.h"
1315
#include "third_party/skia/include/core/SkColorType.h"
1416
#include "ui/gfx/buffer_types.h"
1517

1618
namespace viz {
19+
namespace {
20+
21+
constexpr auto kMappableSharedImageFormats = std::to_array<SharedImageFormat>(
22+
{SinglePlaneFormat::kR_8, SinglePlaneFormat::kR_16,
23+
SinglePlaneFormat::kRG_88, SinglePlaneFormat::kRG_1616,
24+
SinglePlaneFormat::kBGR_565, SinglePlaneFormat::kRGBA_4444,
25+
SinglePlaneFormat::kRGBX_8888, SinglePlaneFormat::kRGBA_8888,
26+
SinglePlaneFormat::kBGRX_8888, SinglePlaneFormat::kBGRA_1010102,
27+
SinglePlaneFormat::kRGBA_1010102, SinglePlaneFormat::kBGRA_8888,
28+
SinglePlaneFormat::kRGBA_F16, MultiPlaneFormat::kNV12,
29+
MultiPlaneFormat::kYV12, MultiPlaneFormat::kNV12A,
30+
MultiPlaneFormat::kP010});
31+
32+
} // namespace
1733

1834
SkColorType ToClosestSkColorType(SharedImageFormat format) {
1935
CHECK(format.is_single_plane());
@@ -350,6 +366,10 @@ bool IsOddSizeMultiPlanarBuffersAllowed() {
350366
#endif
351367
}
352368

369+
base::span<const SharedImageFormat> GetMappableSharedImageFormatForTesting() {
370+
return kMappableSharedImageFormats;
371+
}
372+
353373
// static
354374
unsigned int
355375
SharedImageFormatRestrictedSinglePlaneUtils::ToGLTextureStorageFormat(

components/viz/common/resources/shared_image_format_utils.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "components/viz/common/resources/shared_image_format.h"
1010

1111
namespace gpu {
12+
class GpuMemoryBufferSupport;
1213
class MappableBufferNativePixmap;
1314
class SharedImageFormatToBufferFormatRestrictedUtilsAccessor;
1415
class SharedImageFormatRestrictedUtilsAccessor;
@@ -113,6 +114,10 @@ std::optional<size_t> SharedMemorySizeForSharedImageFormat(
113114
COMPONENT_EXPORT(VIZ_SHARED_IMAGE_FORMAT)
114115
bool IsOddSizeMultiPlanarBuffersAllowed();
115116

117+
// Returns a span containing all mappable SharedImageFormats.
118+
COMPONENT_EXPORT(VIZ_SHARED_IMAGE_FORMAT)
119+
base::span<const SharedImageFormat> GetMappableSharedImageFormatForTesting();
120+
116121
// Utilities that conceptually belong only on the service side, but are
117122
// currently used by some clients. Usage is restricted to friended clients.
118123
class COMPONENT_EXPORT(VIZ_SHARED_IMAGE_FORMAT)
@@ -135,6 +140,7 @@ class COMPONENT_EXPORT(VIZ_SHARED_IMAGE_FORMAT)
135140
class COMPONENT_EXPORT(VIZ_SHARED_IMAGE_FORMAT)
136141
SharedImageFormatToBufferFormatRestrictedUtils {
137142
private:
143+
friend class gpu::GpuMemoryBufferSupport;
138144
friend class gpu::SharedImageFormatToBufferFormatRestrictedUtilsAccessor;
139145
friend class gpu::MappableBufferNativePixmap;
140146
friend class ui::WaylandOverlayManager;

gpu/command_buffer/client/internal/mappable_buffer_test_template.h

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ TYPED_TEST_SUITE_P(MappableBufferTest);
187187
TYPED_TEST_P(MappableBufferTest, CreateFromHandle) {
188188
const gfx::Size kBufferSize(8, 8);
189189

190-
for (auto buffer_format : gfx::GetBufferFormatsForTesting()) {
190+
for (auto format : viz::GetMappableSharedImageFormatForTesting()) {
191191
gfx::BufferUsage usages[] = {
192192
gfx::BufferUsage::GPU_READ,
193193
gfx::BufferUsage::SCANOUT,
@@ -201,12 +201,11 @@ TYPED_TEST_P(MappableBufferTest, CreateFromHandle) {
201201
gfx::BufferUsage::SCANOUT_VEA_CPU_READ,
202202
gfx::BufferUsage::VEA_READ_CAMERA_AND_CPU_READ_WRITE,
203203
};
204-
viz::SharedImageFormat format = viz::GetSharedImageFormat(buffer_format);
205204
for (auto usage : usages) {
206205
if (TypeParam::kBufferType != gfx::SHARED_MEMORY_BUFFER &&
207206
!TestFixture::gpu_memory_buffer_support()
208207
->IsNativeGpuMemoryBufferConfigurationSupportedForTesting(
209-
buffer_format, usage)) {
208+
format, usage)) {
210209
continue;
211210
}
212211

@@ -228,7 +227,7 @@ TYPED_TEST_P(MappableBufferTest, CreateFromHandle) {
228227
TYPED_TEST_P(MappableBufferTest, CreateFromHandleSmallBuffer) {
229228
const gfx::Size kBufferSize(8, 8);
230229

231-
for (auto buffer_format : gfx::GetBufferFormatsForTesting()) {
230+
for (auto format : viz::GetMappableSharedImageFormatForTesting()) {
232231
gfx::BufferUsage usages[] = {
233232
gfx::BufferUsage::GPU_READ,
234233
gfx::BufferUsage::SCANOUT,
@@ -242,12 +241,11 @@ TYPED_TEST_P(MappableBufferTest, CreateFromHandleSmallBuffer) {
242241
gfx::BufferUsage::SCANOUT_VEA_CPU_READ,
243242
gfx::BufferUsage::VEA_READ_CAMERA_AND_CPU_READ_WRITE,
244243
};
245-
viz::SharedImageFormat format = viz::GetSharedImageFormat(buffer_format);
246244
for (auto usage : usages) {
247245
if (TypeParam::kBufferType != gfx::SHARED_MEMORY_BUFFER &&
248246
!TestFixture::gpu_memory_buffer_support()
249247
->IsNativeGpuMemoryBufferConfigurationSupportedForTesting(
250-
buffer_format, usage)) {
248+
format, usage)) {
251249
continue;
252250
}
253251

@@ -279,12 +277,11 @@ TYPED_TEST_P(MappableBufferTest, Map) {
279277
// Use a multiple of 4 for both dimensions to support compressed formats.
280278
const gfx::Size kBufferSize(4, 4);
281279

282-
for (auto buffer_format : gfx::GetBufferFormatsForTesting()) {
283-
viz::SharedImageFormat format = viz::GetSharedImageFormat(buffer_format);
280+
for (auto format : viz::GetMappableSharedImageFormatForTesting()) {
284281
if (TypeParam::kBufferType != gfx::SHARED_MEMORY_BUFFER &&
285282
!TestFixture::gpu_memory_buffer_support()
286283
->IsNativeGpuMemoryBufferConfigurationSupportedForTesting(
287-
buffer_format, gfx::BufferUsage::GPU_READ_CPU_READ_WRITE)) {
284+
format, gfx::BufferUsage::GPU_READ_CPU_READ_WRITE)) {
288285
continue;
289286
}
290287

@@ -341,12 +338,11 @@ TYPED_TEST_P(MappableBufferTest, PersistentMap) {
341338
// Use a multiple of 4 for both dimensions to support compressed formats.
342339
const gfx::Size kBufferSize(4, 4);
343340

344-
for (auto buffer_format : gfx::GetBufferFormatsForTesting()) {
345-
viz::SharedImageFormat format = viz::GetSharedImageFormat(buffer_format);
341+
for (auto format : viz::GetMappableSharedImageFormatForTesting()) {
346342
if (TypeParam::kBufferType != gfx::SHARED_MEMORY_BUFFER &&
347343
!TestFixture::gpu_memory_buffer_support()
348344
->IsNativeGpuMemoryBufferConfigurationSupportedForTesting(
349-
buffer_format, gfx::BufferUsage::GPU_READ_CPU_READ_WRITE)) {
345+
format, gfx::BufferUsage::GPU_READ_CPU_READ_WRITE)) {
350346
continue;
351347
}
352348

@@ -421,7 +417,7 @@ TYPED_TEST_P(MappableBufferTest, SerializeAndDeserialize) {
421417
const gfx::Size kBufferSize(8, 8);
422418
const gfx::GpuMemoryBufferType kBufferType = TypeParam::kBufferType;
423419

424-
for (auto buffer_format : gfx::GetBufferFormatsForTesting()) {
420+
for (auto format : viz::GetMappableSharedImageFormatForTesting()) {
425421
gfx::BufferUsage usages[] = {
426422
gfx::BufferUsage::GPU_READ,
427423
gfx::BufferUsage::SCANOUT,
@@ -435,12 +431,11 @@ TYPED_TEST_P(MappableBufferTest, SerializeAndDeserialize) {
435431
gfx::BufferUsage::SCANOUT_VEA_CPU_READ,
436432
gfx::BufferUsage::VEA_READ_CAMERA_AND_CPU_READ_WRITE,
437433
};
438-
viz::SharedImageFormat format = viz::GetSharedImageFormat(buffer_format);
439434
for (auto usage : usages) {
440435
if (TypeParam::kBufferType != gfx::SHARED_MEMORY_BUFFER &&
441436
!TestFixture::gpu_memory_buffer_support()
442437
->IsNativeGpuMemoryBufferConfigurationSupportedForTesting(
443-
buffer_format, usage)) {
438+
format, usage)) {
444439
continue;
445440
}
446441

gpu/command_buffer/service/shared_image/d3d_image_backing_factory_unittest.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2556,7 +2556,7 @@ TEST_F(D3DImageBackingFactoryBufferTest, CreateSharedImageImportToDawn) {
25562556

25572557
// Disabled by default as it requires DX11.
25582558
TEST_F(D3DImageBackingFactoryTest, DISABLED_CreateGpuMemoryBuffer) {
2559-
for (auto format : gfx::GetBufferFormatsForTesting()) {
2559+
for (auto format : viz::GetMappableSharedImageFormatForTesting()) {
25602560
gfx::BufferUsage usages[] = {
25612561
gfx::BufferUsage::GPU_READ,
25622562
gfx::BufferUsage::SCANOUT,
@@ -2580,8 +2580,7 @@ TEST_F(D3DImageBackingFactoryTest, DISABLED_CreateGpuMemoryBuffer) {
25802580

25812581
gfx::GpuMemoryBufferHandle handle =
25822582
D3DImageBackingFactory::CreateGpuMemoryBufferHandle(
2583-
/*io_runner=*/nullptr, gfx::Size(2, 2),
2584-
viz::GetSharedImageFormat(format), usage);
2583+
/*io_runner=*/nullptr, gfx::Size(2, 2), format, usage);
25852584
EXPECT_EQ(handle.type, gfx::DXGI_SHARED_HANDLE);
25862585
}
25872586
}

gpu/command_buffer/service/shared_image/iosurface_image_backing_factory_unittest.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ TEST_F(IOSurfaceImageBackingFactoryTest, GL_SkiaGL) {
185185
}
186186

187187
TEST_F(IOSurfaceImageBackingFactoryTest, CreateGpuMemoryBuffer) {
188-
for (auto format : gfx::GetBufferFormatsForTesting()) {
188+
for (auto format : viz::GetMappableSharedImageFormatForTesting()) {
189189
if (!gpu::GpuMemoryBufferSupport::
190190
IsNativeGpuMemoryBufferConfigurationSupportedForTesting(
191191
format, gfx::BufferUsage::GPU_READ)) {
@@ -194,7 +194,7 @@ TEST_F(IOSurfaceImageBackingFactoryTest, CreateGpuMemoryBuffer) {
194194

195195
gfx::GpuMemoryBufferHandle handle =
196196
IOSurfaceImageBackingFactory::CreateGpuMemoryBufferHandle(
197-
gfx::Size(2, 2), viz::GetSharedImageFormat(format));
197+
gfx::Size(2, 2), format);
198198
EXPECT_EQ(handle.type, gfx::IO_SURFACE_BUFFER);
199199
}
200200
}

gpu/command_buffer/service/shared_image/ozone_image_backing_factory_unittest.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ TEST_F(OzoneImageBackingFactoryTest, CorrectlyDestroysAndMarksContextLost) {
605605
}
606606

607607
TEST_F(OzoneImageBackingFactoryTest, CreateGpuMemoryBufferHandle) {
608-
for (auto format : gfx::GetBufferFormatsForTesting()) {
608+
for (auto format : viz::GetMappableSharedImageFormatForTesting()) {
609609
gfx::BufferUsage usages[] = {
610610
gfx::BufferUsage::GPU_READ,
611611
gfx::BufferUsage::SCANOUT,
@@ -629,8 +629,8 @@ TEST_F(OzoneImageBackingFactoryTest, CreateGpuMemoryBufferHandle) {
629629

630630
gfx::GpuMemoryBufferHandle handle =
631631
OzoneImageBackingFactory::CreateGpuMemoryBufferHandle(
632-
/*vulkan_context_provider=*/nullptr, gfx::Size(2, 2),
633-
viz::GetSharedImageFormat(format), usage);
632+
/*vulkan_context_provider=*/nullptr, gfx::Size(2, 2), format,
633+
usage);
634634
EXPECT_EQ(handle.type, gfx::NATIVE_PIXMAP);
635635
}
636636
}

gpu/ipc/common/gpu_memory_buffer_support.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "base/memory/unsafe_shared_memory_pool.h"
1717
#include "base/unguessable_token.h"
1818
#include "build/build_config.h"
19+
#include "components/viz/common/resources/shared_image_format_utils.h"
1920
#include "gpu/ipc/common/gpu_ipc_common_export.h"
2021
#include "ui/gfx/buffer_types.h"
2122
#include "ui/gfx/geometry/size.h"
@@ -55,9 +56,12 @@ class GPU_IPC_COMMON_EXPORT GpuMemoryBufferSupport {
5556

5657
// Returns whether the provided buffer format is supported.
5758
static bool IsNativeGpuMemoryBufferConfigurationSupportedForTesting(
58-
gfx::BufferFormat format,
59+
viz::SharedImageFormat format,
5960
gfx::BufferUsage usage) {
60-
return IsNativeGpuMemoryBufferConfigurationSupported(format, usage);
61+
return IsNativeGpuMemoryBufferConfigurationSupported(
62+
viz::SharedImageFormatToBufferFormatRestrictedUtils::ToBufferFormat(
63+
format),
64+
usage);
6165
}
6266

6367
private:

ui/gfx/buffer_format_util.cc

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,8 @@
77
#include "base/check_op.h"
88
#include "base/notreached.h"
99
#include "base/types/cxx23_to_underlying.h"
10-
#include "ui/gfx/switches.h"
1110

1211
namespace gfx {
13-
namespace {
14-
15-
constexpr auto kBufferFormats = std::to_array<BufferFormat>(
16-
{BufferFormat::R_8, BufferFormat::R_16, BufferFormat::RG_88,
17-
BufferFormat::RG_1616, BufferFormat::BGR_565, BufferFormat::RGBA_4444,
18-
BufferFormat::RGBX_8888, BufferFormat::RGBA_8888, BufferFormat::BGRX_8888,
19-
BufferFormat::BGRA_1010102, BufferFormat::RGBA_1010102,
20-
BufferFormat::BGRA_8888, BufferFormat::RGBA_F16,
21-
BufferFormat::YUV_420_BIPLANAR, BufferFormat::YVU_420,
22-
BufferFormat::YUVA_420_TRIPLANAR, BufferFormat::P010});
23-
24-
static_assert(std::size(kBufferFormats) ==
25-
(static_cast<int>(BufferFormat::LAST) + 1),
26-
"BufferFormat::LAST must be last value of kBufferFormats");
27-
28-
} // namespace
29-
30-
base::span<const BufferFormat> GetBufferFormatsForTesting() {
31-
return kBufferFormats;
32-
}
3312

3413
const char* BufferFormatToString(BufferFormat format) {
3514
switch (format) {

ui/gfx/buffer_format_util.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,10 @@
88
#include <stddef.h>
99

1010
#include "base/component_export.h"
11-
#include "base/containers/span.h"
1211
#include "ui/gfx/buffer_types.h"
1312

1413
namespace gfx {
1514

16-
// Returns a span containing all buffer formats.
17-
COMPONENT_EXPORT(GFX)
18-
base::span<const BufferFormat> GetBufferFormatsForTesting();
19-
2015
// Returns the name of |format| as a string.
2116
COMPONENT_EXPORT(GFX) const char* BufferFormatToString(BufferFormat format);
2217

0 commit comments

Comments
 (0)