Commit f48b41ec authored by Miguel Casas's avatar Miguel Casas Committed by Commit Bot

SharedImageBackingFactoryGLTexture: Support 1010102 formats

crrev.com/c/2070820 moved the buffer allocation in the BufferQueue from
using CreateGpuMemoryBuffer() to letting the SharedImageBackingFactory
decide if it's OK; this broke HDR playback on ChromeOS, where we import
GMBs as 1010102 formats when high bitdepth is needed. This CL fixes that
by adding support for {RGBA,BGRA}_1010102 where appropriate.

Bug: 1064385
Change-Id: Ia0ca81db2619bc0c000c698e15ba49fbca3266fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2131029
Commit-Queue: Miguel Casas <mcasas@chromium.org>
Reviewed-by: default avatarSunny Sachanandani <sunnyps@chromium.org>
Reviewed-by: default avatarAndres Calderon Jaramillo <andrescj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#757492}
parent 2a66429a
...@@ -200,6 +200,8 @@ unsigned int GLInternalFormat(ResourceFormat format) { ...@@ -200,6 +200,8 @@ unsigned int GLInternalFormat(ResourceFormat format) {
return GL_RG8_EXT; return GL_RG8_EXT;
else if (format == ETC1) else if (format == ETC1)
return GL_ETC1_RGB8_OES; return GL_ETC1_RGB8_OES;
else if (format == RGBA_1010102 || format == BGRA_1010102)
return GL_RGB10_A2_EXT;
return GLDataFormat(format); return GLDataFormat(format);
} }
...@@ -337,6 +339,8 @@ bool IsGpuMemoryBufferFormatSupported(ResourceFormat format) { ...@@ -337,6 +339,8 @@ bool IsGpuMemoryBufferFormatSupported(ResourceFormat format) {
case R16_EXT: case R16_EXT:
case RGBA_4444: case RGBA_4444:
case RGBA_8888: case RGBA_8888:
case RGBA_1010102:
case BGRA_1010102:
case RGBA_F16: case RGBA_F16:
return true; return true;
// These formats have no BufferFormat equivalent or are only used // These formats have no BufferFormat equivalent or are only used
...@@ -350,8 +354,6 @@ bool IsGpuMemoryBufferFormatSupported(ResourceFormat format) { ...@@ -350,8 +354,6 @@ bool IsGpuMemoryBufferFormatSupported(ResourceFormat format) {
case RG_88: case RG_88:
case RGBX_8888: case RGBX_8888:
case BGRX_8888: case BGRX_8888:
case RGBA_1010102:
case BGRA_1010102:
case YVU_420: case YVU_420:
case YUV_420_BIPLANAR: case YUV_420_BIPLANAR:
case P010: case P010:
...@@ -431,7 +433,6 @@ bool GLSupportsFormat(ResourceFormat format) { ...@@ -431,7 +433,6 @@ bool GLSupportsFormat(ResourceFormat format) {
switch (format) { switch (format) {
case BGR_565: case BGR_565:
case BGRX_8888: case BGRX_8888:
case BGRA_1010102:
case YVU_420: case YVU_420:
case YUV_420_BIPLANAR: case YUV_420_BIPLANAR:
case P010: case P010:
......
...@@ -746,13 +746,13 @@ SharedImageBackingFactoryGLTexture::SharedImageBackingFactoryGLTexture( ...@@ -746,13 +746,13 @@ SharedImageBackingFactoryGLTexture::SharedImageBackingFactoryGLTexture(
FormatInfo& info = format_info_[i]; FormatInfo& info = format_info_[i];
if (!viz::GLSupportsFormat(format)) if (!viz::GLSupportsFormat(format))
continue; continue;
GLuint image_internal_format = viz::GLInternalFormat(format); const GLuint image_internal_format = viz::GLInternalFormat(format);
GLenum gl_format = viz::GLDataFormat(format); const GLenum gl_format = viz::GLDataFormat(format);
GLenum gl_type = viz::GLDataType(format); const GLenum gl_type = viz::GLDataType(format);
bool uncompressed_format_valid = const bool uncompressed_format_valid =
validators->texture_internal_format.IsValid(image_internal_format) && validators->texture_internal_format.IsValid(image_internal_format) &&
validators->texture_format.IsValid(gl_format); validators->texture_format.IsValid(gl_format);
bool compressed_format_valid = const bool compressed_format_valid =
validators->compressed_texture_format.IsValid(image_internal_format); validators->compressed_texture_format.IsValid(image_internal_format);
if ((uncompressed_format_valid || compressed_format_valid) && if ((uncompressed_format_valid || compressed_format_valid) &&
validators->pixel_type.IsValid(gl_type)) { validators->pixel_type.IsValid(gl_type)) {
...@@ -781,21 +781,24 @@ SharedImageBackingFactoryGLTexture::SharedImageBackingFactoryGLTexture( ...@@ -781,21 +781,24 @@ SharedImageBackingFactoryGLTexture::SharedImageBackingFactoryGLTexture(
} }
} }
if (!info.enabled || !enable_scanout_images || if (!info.enabled || !enable_scanout_images ||
!IsGpuMemoryBufferFormatSupported(format)) !IsGpuMemoryBufferFormatSupported(format)) {
continue; continue;
gfx::BufferFormat buffer_format = viz::BufferFormat(format); }
const gfx::BufferFormat buffer_format = viz::BufferFormat(format);
switch (buffer_format) { switch (buffer_format) {
case gfx::BufferFormat::RGBA_8888: case gfx::BufferFormat::RGBA_8888:
case gfx::BufferFormat::BGRA_8888: case gfx::BufferFormat::BGRA_8888:
case gfx::BufferFormat::RGBA_F16: case gfx::BufferFormat::RGBA_F16:
case gfx::BufferFormat::R_8: case gfx::BufferFormat::R_8:
case gfx::BufferFormat::BGRA_1010102:
case gfx::BufferFormat::RGBA_1010102:
break; break;
default: default:
continue; continue;
} }
info.allow_scanout = true; info.allow_scanout = true;
info.buffer_format = buffer_format; info.buffer_format = buffer_format;
DCHECK_EQ(info.gl_format, DCHECK_EQ(info.image_internal_format,
gl::BufferFormatToGLInternalFormat(buffer_format)); gl::BufferFormatToGLInternalFormat(buffer_format));
if (base::Contains(gpu_preferences.texture_target_exception_list, if (base::Contains(gpu_preferences.texture_target_exception_list,
gfx::BufferUsageAndFormat(gfx::BufferUsage::SCANOUT, gfx::BufferUsageAndFormat(gfx::BufferUsage::SCANOUT,
......
...@@ -77,7 +77,7 @@ bool IsAndroid() { ...@@ -77,7 +77,7 @@ bool IsAndroid() {
} }
class SharedImageBackingFactoryGLTextureTestBase class SharedImageBackingFactoryGLTextureTestBase
: public testing::TestWithParam<bool> { : public testing::TestWithParam<std::tuple<bool, viz::ResourceFormat>> {
public: public:
SharedImageBackingFactoryGLTextureTestBase(bool is_thread_safe) SharedImageBackingFactoryGLTextureTestBase(bool is_thread_safe)
: shared_image_manager_( : shared_image_manager_(
...@@ -96,6 +96,13 @@ class SharedImageBackingFactoryGLTextureTestBase ...@@ -96,6 +96,13 @@ class SharedImageBackingFactoryGLTextureTestBase
feature_info->validators()->compressed_texture_format.IsValid( feature_info->validators()->compressed_texture_format.IsValid(
GL_ETC1_RGB8_OES); GL_ETC1_RGB8_OES);
if ((get_format() == viz::ResourceFormat::BGRA_1010102 &&
!feature_info->feature_flags().chromium_image_ar30) ||
(get_format() == viz::ResourceFormat::RGBA_1010102 &&
!feature_info->feature_flags().chromium_image_ab30)) {
GTEST_SKIP();
}
GpuPreferences preferences; GpuPreferences preferences;
preferences.use_passthrough_cmd_decoder = use_passthrough(); preferences.use_passthrough_cmd_decoder = use_passthrough();
backing_factory_ = std::make_unique<SharedImageBackingFactoryGLTexture>( backing_factory_ = std::make_unique<SharedImageBackingFactoryGLTexture>(
...@@ -109,9 +116,12 @@ class SharedImageBackingFactoryGLTextureTestBase ...@@ -109,9 +116,12 @@ class SharedImageBackingFactoryGLTextureTestBase
} }
bool use_passthrough() { bool use_passthrough() {
return GetParam() && gles2::PassthroughCommandDecoderSupported(); return std::get<0>(GetParam()) &&
gles2::PassthroughCommandDecoderSupported();
} }
viz::ResourceFormat get_format() { return std::get<1>(GetParam()); }
bool supports_etc1() { return supports_etc1_; } bool supports_etc1() { return supports_etc1_; }
GrContext* gr_context() { return context_state_->gr_context(); } GrContext* gr_context() { return context_state_->gr_context(); }
...@@ -197,7 +207,7 @@ class CreateAndValidateSharedImageRepresentations { ...@@ -197,7 +207,7 @@ class CreateAndValidateSharedImageRepresentations {
TEST_P(SharedImageBackingFactoryGLTextureTest, Basic) { TEST_P(SharedImageBackingFactoryGLTextureTest, Basic) {
auto mailbox = Mailbox::GenerateForSharedImage(); auto mailbox = Mailbox::GenerateForSharedImage();
auto format = viz::ResourceFormat::RGBA_8888; auto format = get_format();
gfx::Size size(256, 256); gfx::Size size(256, 256);
auto color_space = gfx::ColorSpace::CreateSRGB(); auto color_space = gfx::ColorSpace::CreateSRGB();
uint32_t usage = SHARED_IMAGE_USAGE_GLES2; uint32_t usage = SHARED_IMAGE_USAGE_GLES2;
...@@ -264,6 +274,10 @@ TEST_P(SharedImageBackingFactoryGLTextureTest, Basic) { ...@@ -264,6 +274,10 @@ TEST_P(SharedImageBackingFactoryGLTextureTest, Basic) {
gl_representation.reset(); gl_representation.reset();
} }
// Skia does not support RGBA_1010102 as render target, only BGRA_1010102.
if (format == viz::ResourceFormat::RGBA_1010102)
return;
// Finally, validate a SharedImageRepresentationSkia. // Finally, validate a SharedImageRepresentationSkia.
auto skia_representation = shared_image_representation_factory_->ProduceSkia( auto skia_representation = shared_image_representation_factory_->ProduceSkia(
mailbox, context_state_.get()); mailbox, context_state_.get());
...@@ -291,20 +305,20 @@ TEST_P(SharedImageBackingFactoryGLTextureTest, Basic) { ...@@ -291,20 +305,20 @@ TEST_P(SharedImageBackingFactoryGLTextureTest, Basic) {
EXPECT_TRUE(promise_texture); EXPECT_TRUE(promise_texture);
EXPECT_TRUE(begin_semaphores.empty()); EXPECT_TRUE(begin_semaphores.empty());
EXPECT_TRUE(end_semaphores.empty()); EXPECT_TRUE(end_semaphores.empty());
GrBackendTexture backend_texture = promise_texture->backendTexture(); GrBackendTexture backend_texture = promise_texture->backendTexture();
EXPECT_TRUE(backend_texture.isValid()); EXPECT_TRUE(backend_texture.isValid());
EXPECT_EQ(size.width(), backend_texture.width()); EXPECT_EQ(size.width(), backend_texture.width());
EXPECT_EQ(size.height(), backend_texture.height()); EXPECT_EQ(size.height(), backend_texture.height());
scoped_read_access.reset(); scoped_read_access.reset();
skia_representation.reset(); skia_representation.reset();
shared_image.reset(); shared_image.reset();
EXPECT_FALSE(mailbox_manager_.ConsumeTexture(mailbox)); EXPECT_FALSE(mailbox_manager_.ConsumeTexture(mailbox));
} }
TEST_P(SharedImageBackingFactoryGLTextureTest, Image) { TEST_P(SharedImageBackingFactoryGLTextureTest, Image) {
auto mailbox = Mailbox::GenerateForSharedImage(); auto mailbox = Mailbox::GenerateForSharedImage();
auto format = viz::ResourceFormat::RGBA_8888; auto format = get_format();
gfx::Size size(256, 256); gfx::Size size(256, 256);
auto color_space = gfx::ColorSpace::CreateSRGB(); auto color_space = gfx::ColorSpace::CreateSRGB();
uint32_t usage = SHARED_IMAGE_USAGE_SCANOUT; uint32_t usage = SHARED_IMAGE_USAGE_SCANOUT;
...@@ -378,6 +392,10 @@ TEST_P(SharedImageBackingFactoryGLTextureTest, Image) { ...@@ -378,6 +392,10 @@ TEST_P(SharedImageBackingFactoryGLTextureTest, Image) {
gl_representation.reset(); gl_representation.reset();
} }
// Skia does not support RGBA_1010102 as render target, only BGRA_1010102.
if (format == viz::ResourceFormat::RGBA_1010102)
return;
// Finally, validate a SharedImageRepresentationSkia. // Finally, validate a SharedImageRepresentationSkia.
auto skia_representation = shared_image_representation_factory_->ProduceSkia( auto skia_representation = shared_image_representation_factory_->ProduceSkia(
mailbox, context_state_.get()); mailbox, context_state_.get());
...@@ -417,9 +435,9 @@ TEST_P(SharedImageBackingFactoryGLTextureTest, Image) { ...@@ -417,9 +435,9 @@ TEST_P(SharedImageBackingFactoryGLTextureTest, Image) {
if (!use_passthrough() && if (!use_passthrough() &&
context_state_->feature_info()->feature_flags().ext_texture_rg) { context_state_->feature_info()->feature_flags().ext_texture_rg) {
// Create a R-8 image texture, and check that the internal_format is that of // Create a R-8 image texture, and check that the internal_format is that
// the image (GL_RGBA for TextureImageFactory). This only matters for the // of the image (GL_RGBA for TextureImageFactory). This only matters for
// validating decoder. // the validating decoder.
auto format = viz::ResourceFormat::RED_8; auto format = viz::ResourceFormat::RED_8;
gpu::SurfaceHandle surface_handle = gpu::kNullSurfaceHandle; gpu::SurfaceHandle surface_handle = gpu::kNullSurfaceHandle;
backing = backing_factory_->CreateSharedImage( backing = backing_factory_->CreateSharedImage(
...@@ -498,7 +516,7 @@ TEST_P(SharedImageBackingFactoryGLTextureTest, InitialData) { ...@@ -498,7 +516,7 @@ TEST_P(SharedImageBackingFactoryGLTextureTest, InitialData) {
TEST_P(SharedImageBackingFactoryGLTextureTest, InitialDataImage) { TEST_P(SharedImageBackingFactoryGLTextureTest, InitialDataImage) {
auto mailbox = Mailbox::GenerateForSharedImage(); auto mailbox = Mailbox::GenerateForSharedImage();
auto format = viz::ResourceFormat::RGBA_8888; auto format = get_format();
gfx::Size size(256, 256); gfx::Size size(256, 256);
auto color_space = gfx::ColorSpace::CreateSRGB(); auto color_space = gfx::ColorSpace::CreateSRGB();
uint32_t usage = SHARED_IMAGE_USAGE_GLES2 | SHARED_IMAGE_USAGE_SCANOUT; uint32_t usage = SHARED_IMAGE_USAGE_GLES2 | SHARED_IMAGE_USAGE_SCANOUT;
...@@ -537,7 +555,7 @@ TEST_P(SharedImageBackingFactoryGLTextureTest, InitialDataImage) { ...@@ -537,7 +555,7 @@ TEST_P(SharedImageBackingFactoryGLTextureTest, InitialDataImage) {
TEST_P(SharedImageBackingFactoryGLTextureTest, InitialDataWrongSize) { TEST_P(SharedImageBackingFactoryGLTextureTest, InitialDataWrongSize) {
auto mailbox = Mailbox::GenerateForSharedImage(); auto mailbox = Mailbox::GenerateForSharedImage();
auto format = viz::ResourceFormat::RGBA_8888; auto format = get_format();
gfx::Size size(256, 256); gfx::Size size(256, 256);
auto color_space = gfx::ColorSpace::CreateSRGB(); auto color_space = gfx::ColorSpace::CreateSRGB();
uint32_t usage = SHARED_IMAGE_USAGE_GLES2; uint32_t usage = SHARED_IMAGE_USAGE_GLES2;
...@@ -566,7 +584,7 @@ TEST_P(SharedImageBackingFactoryGLTextureTest, InvalidFormat) { ...@@ -566,7 +584,7 @@ TEST_P(SharedImageBackingFactoryGLTextureTest, InvalidFormat) {
TEST_P(SharedImageBackingFactoryGLTextureTest, InvalidSize) { TEST_P(SharedImageBackingFactoryGLTextureTest, InvalidSize) {
auto mailbox = Mailbox::GenerateForSharedImage(); auto mailbox = Mailbox::GenerateForSharedImage();
auto format = viz::ResourceFormat::RGBA_8888; auto format = get_format();
gfx::Size size(0, 0); gfx::Size size(0, 0);
auto color_space = gfx::ColorSpace::CreateSRGB(); auto color_space = gfx::ColorSpace::CreateSRGB();
gpu::SurfaceHandle surface_handle = gpu::kNullSurfaceHandle; gpu::SurfaceHandle surface_handle = gpu::kNullSurfaceHandle;
...@@ -585,7 +603,7 @@ TEST_P(SharedImageBackingFactoryGLTextureTest, InvalidSize) { ...@@ -585,7 +603,7 @@ TEST_P(SharedImageBackingFactoryGLTextureTest, InvalidSize) {
TEST_P(SharedImageBackingFactoryGLTextureTest, EstimatedSize) { TEST_P(SharedImageBackingFactoryGLTextureTest, EstimatedSize) {
auto mailbox = Mailbox::GenerateForSharedImage(); auto mailbox = Mailbox::GenerateForSharedImage();
auto format = viz::ResourceFormat::RGBA_8888; auto format = get_format();
gfx::Size size(256, 256); gfx::Size size(256, 256);
auto color_space = gfx::ColorSpace::CreateSRGB(); auto color_space = gfx::ColorSpace::CreateSRGB();
gpu::SurfaceHandle surface_handle = gpu::kNullSurfaceHandle; gpu::SurfaceHandle surface_handle = gpu::kNullSurfaceHandle;
...@@ -749,7 +767,7 @@ TEST_P(SharedImageBackingFactoryGLTextureWithGMBTest, ...@@ -749,7 +767,7 @@ TEST_P(SharedImageBackingFactoryGLTextureWithGMBTest,
GpuMemoryBufferImportEmpty) { GpuMemoryBufferImportEmpty) {
auto mailbox = Mailbox::GenerateForSharedImage(); auto mailbox = Mailbox::GenerateForSharedImage();
gfx::Size size(256, 256); gfx::Size size(256, 256);
gfx::BufferFormat format = gfx::BufferFormat::RGBA_8888; gfx::BufferFormat format = viz::BufferFormat(get_format());
auto color_space = gfx::ColorSpace::CreateSRGB(); auto color_space = gfx::ColorSpace::CreateSRGB();
uint32_t usage = SHARED_IMAGE_USAGE_GLES2; uint32_t usage = SHARED_IMAGE_USAGE_GLES2;
...@@ -764,7 +782,7 @@ TEST_P(SharedImageBackingFactoryGLTextureWithGMBTest, ...@@ -764,7 +782,7 @@ TEST_P(SharedImageBackingFactoryGLTextureWithGMBTest,
GpuMemoryBufferImportNative) { GpuMemoryBufferImportNative) {
auto mailbox = Mailbox::GenerateForSharedImage(); auto mailbox = Mailbox::GenerateForSharedImage();
gfx::Size size(256, 256); gfx::Size size(256, 256);
gfx::BufferFormat format = gfx::BufferFormat::RGBA_8888; gfx::BufferFormat format = viz::BufferFormat(get_format());
auto color_space = gfx::ColorSpace::CreateSRGB(); auto color_space = gfx::ColorSpace::CreateSRGB();
uint32_t usage = SHARED_IMAGE_USAGE_GLES2; uint32_t usage = SHARED_IMAGE_USAGE_GLES2;
...@@ -792,7 +810,7 @@ TEST_P(SharedImageBackingFactoryGLTextureWithGMBTest, ...@@ -792,7 +810,7 @@ TEST_P(SharedImageBackingFactoryGLTextureWithGMBTest,
GpuMemoryBufferImportSharedMemory) { GpuMemoryBufferImportSharedMemory) {
auto mailbox = Mailbox::GenerateForSharedImage(); auto mailbox = Mailbox::GenerateForSharedImage();
gfx::Size size(256, 256); gfx::Size size(256, 256);
gfx::BufferFormat format = gfx::BufferFormat::RGBA_8888; gfx::BufferFormat format = viz::BufferFormat(get_format());
auto color_space = gfx::ColorSpace::CreateSRGB(); auto color_space = gfx::ColorSpace::CreateSRGB();
uint32_t usage = SHARED_IMAGE_USAGE_GLES2; uint32_t usage = SHARED_IMAGE_USAGE_GLES2;
...@@ -826,7 +844,7 @@ TEST_P(SharedImageBackingFactoryGLTextureWithGMBTest, ...@@ -826,7 +844,7 @@ TEST_P(SharedImageBackingFactoryGLTextureWithGMBTest,
return; return;
auto mailbox = Mailbox::GenerateForSharedImage(); auto mailbox = Mailbox::GenerateForSharedImage();
gfx::Size size(256, 256); gfx::Size size(256, 256);
gfx::BufferFormat format = gfx::BufferFormat::RGBA_8888; gfx::BufferFormat format = viz::BufferFormat(get_format());
auto color_space = gfx::ColorSpace::CreateSRGB(); auto color_space = gfx::ColorSpace::CreateSRGB();
uint32_t usage = SHARED_IMAGE_USAGE_GLES2; uint32_t usage = SHARED_IMAGE_USAGE_GLES2;
...@@ -847,7 +865,7 @@ TEST_P(SharedImageBackingFactoryGLTextureWithGMBTest, ...@@ -847,7 +865,7 @@ TEST_P(SharedImageBackingFactoryGLTextureWithGMBTest,
EXPECT_TRUE(representation); EXPECT_TRUE(representation);
EXPECT_TRUE(representation->GetTexture()->service_id()); EXPECT_TRUE(representation->GetTexture()->service_id());
EXPECT_EQ(size, representation->size()); EXPECT_EQ(size, representation->size());
EXPECT_EQ(viz::ResourceFormat::RGBA_8888, representation->format()); EXPECT_EQ(get_format(), representation->format());
EXPECT_EQ(color_space, representation->color_space()); EXPECT_EQ(color_space, representation->color_space());
EXPECT_EQ(usage, representation->usage()); EXPECT_EQ(usage, representation->usage());
...@@ -1044,15 +1062,28 @@ CreateAndValidateSharedImageRepresentations:: ...@@ -1044,15 +1062,28 @@ CreateAndValidateSharedImageRepresentations::
EXPECT_FALSE(mailbox_manager_->ConsumeTexture(mailbox_)); EXPECT_FALSE(mailbox_manager_->ConsumeTexture(mailbox_));
} }
#if !defined(OS_ANDROID)
const auto kResourceFormats =
::testing::Values(viz::ResourceFormat::RGBA_8888,
viz::ResourceFormat::BGRA_1010102,
viz::ResourceFormat::RGBA_1010102);
#else
// High bit depth rendering is not supported on Android.
const auto kResourceFormats = ::testing::Values(viz::ResourceFormat::RGBA_8888);
#endif
INSTANTIATE_TEST_SUITE_P(Service, INSTANTIATE_TEST_SUITE_P(Service,
SharedImageBackingFactoryGLTextureTest, SharedImageBackingFactoryGLTextureTest,
::testing::Bool()); ::testing::Combine(::testing::Bool(),
kResourceFormats));
INSTANTIATE_TEST_SUITE_P(Service, INSTANTIATE_TEST_SUITE_P(Service,
SharedImageBackingFactoryGLTextureThreadSafeTest, SharedImageBackingFactoryGLTextureThreadSafeTest,
::testing::Bool()); ::testing::Combine(::testing::Bool(),
kResourceFormats));
INSTANTIATE_TEST_SUITE_P(Service, INSTANTIATE_TEST_SUITE_P(Service,
SharedImageBackingFactoryGLTextureWithGMBTest, SharedImageBackingFactoryGLTextureWithGMBTest,
::testing::Bool()); ::testing::Combine(::testing::Bool(),
kResourceFormats));
} // anonymous namespace } // anonymous namespace
} // namespace gpu } // namespace gpu
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment