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) {
return GL_RG8_EXT;
else if (format == ETC1)
return GL_ETC1_RGB8_OES;
else if (format == RGBA_1010102 || format == BGRA_1010102)
return GL_RGB10_A2_EXT;
return GLDataFormat(format);
}
......@@ -337,6 +339,8 @@ bool IsGpuMemoryBufferFormatSupported(ResourceFormat format) {
case R16_EXT:
case RGBA_4444:
case RGBA_8888:
case RGBA_1010102:
case BGRA_1010102:
case RGBA_F16:
return true;
// These formats have no BufferFormat equivalent or are only used
......@@ -350,8 +354,6 @@ bool IsGpuMemoryBufferFormatSupported(ResourceFormat format) {
case RG_88:
case RGBX_8888:
case BGRX_8888:
case RGBA_1010102:
case BGRA_1010102:
case YVU_420:
case YUV_420_BIPLANAR:
case P010:
......@@ -431,7 +433,6 @@ bool GLSupportsFormat(ResourceFormat format) {
switch (format) {
case BGR_565:
case BGRX_8888:
case BGRA_1010102:
case YVU_420:
case YUV_420_BIPLANAR:
case P010:
......
......@@ -746,13 +746,13 @@ SharedImageBackingFactoryGLTexture::SharedImageBackingFactoryGLTexture(
FormatInfo& info = format_info_[i];
if (!viz::GLSupportsFormat(format))
continue;
GLuint image_internal_format = viz::GLInternalFormat(format);
GLenum gl_format = viz::GLDataFormat(format);
GLenum gl_type = viz::GLDataType(format);
bool uncompressed_format_valid =
const GLuint image_internal_format = viz::GLInternalFormat(format);
const GLenum gl_format = viz::GLDataFormat(format);
const GLenum gl_type = viz::GLDataType(format);
const bool uncompressed_format_valid =
validators->texture_internal_format.IsValid(image_internal_format) &&
validators->texture_format.IsValid(gl_format);
bool compressed_format_valid =
const bool compressed_format_valid =
validators->compressed_texture_format.IsValid(image_internal_format);
if ((uncompressed_format_valid || compressed_format_valid) &&
validators->pixel_type.IsValid(gl_type)) {
......@@ -781,21 +781,24 @@ SharedImageBackingFactoryGLTexture::SharedImageBackingFactoryGLTexture(
}
}
if (!info.enabled || !enable_scanout_images ||
!IsGpuMemoryBufferFormatSupported(format))
!IsGpuMemoryBufferFormatSupported(format)) {
continue;
gfx::BufferFormat buffer_format = viz::BufferFormat(format);
}
const gfx::BufferFormat buffer_format = viz::BufferFormat(format);
switch (buffer_format) {
case gfx::BufferFormat::RGBA_8888:
case gfx::BufferFormat::BGRA_8888:
case gfx::BufferFormat::RGBA_F16:
case gfx::BufferFormat::R_8:
case gfx::BufferFormat::BGRA_1010102:
case gfx::BufferFormat::RGBA_1010102:
break;
default:
continue;
}
info.allow_scanout = true;
info.buffer_format = buffer_format;
DCHECK_EQ(info.gl_format,
DCHECK_EQ(info.image_internal_format,
gl::BufferFormatToGLInternalFormat(buffer_format));
if (base::Contains(gpu_preferences.texture_target_exception_list,
gfx::BufferUsageAndFormat(gfx::BufferUsage::SCANOUT,
......
......@@ -77,7 +77,7 @@ bool IsAndroid() {
}
class SharedImageBackingFactoryGLTextureTestBase
: public testing::TestWithParam<bool> {
: public testing::TestWithParam<std::tuple<bool, viz::ResourceFormat>> {
public:
SharedImageBackingFactoryGLTextureTestBase(bool is_thread_safe)
: shared_image_manager_(
......@@ -96,6 +96,13 @@ class SharedImageBackingFactoryGLTextureTestBase
feature_info->validators()->compressed_texture_format.IsValid(
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;
preferences.use_passthrough_cmd_decoder = use_passthrough();
backing_factory_ = std::make_unique<SharedImageBackingFactoryGLTexture>(
......@@ -109,9 +116,12 @@ class SharedImageBackingFactoryGLTextureTestBase
}
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_; }
GrContext* gr_context() { return context_state_->gr_context(); }
......@@ -197,7 +207,7 @@ class CreateAndValidateSharedImageRepresentations {
TEST_P(SharedImageBackingFactoryGLTextureTest, Basic) {
auto mailbox = Mailbox::GenerateForSharedImage();
auto format = viz::ResourceFormat::RGBA_8888;
auto format = get_format();
gfx::Size size(256, 256);
auto color_space = gfx::ColorSpace::CreateSRGB();
uint32_t usage = SHARED_IMAGE_USAGE_GLES2;
......@@ -264,6 +274,10 @@ TEST_P(SharedImageBackingFactoryGLTextureTest, Basic) {
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.
auto skia_representation = shared_image_representation_factory_->ProduceSkia(
mailbox, context_state_.get());
......@@ -304,7 +318,7 @@ TEST_P(SharedImageBackingFactoryGLTextureTest, Basic) {
TEST_P(SharedImageBackingFactoryGLTextureTest, Image) {
auto mailbox = Mailbox::GenerateForSharedImage();
auto format = viz::ResourceFormat::RGBA_8888;
auto format = get_format();
gfx::Size size(256, 256);
auto color_space = gfx::ColorSpace::CreateSRGB();
uint32_t usage = SHARED_IMAGE_USAGE_SCANOUT;
......@@ -378,6 +392,10 @@ TEST_P(SharedImageBackingFactoryGLTextureTest, Image) {
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.
auto skia_representation = shared_image_representation_factory_->ProduceSkia(
mailbox, context_state_.get());
......@@ -417,9 +435,9 @@ TEST_P(SharedImageBackingFactoryGLTextureTest, Image) {
if (!use_passthrough() &&
context_state_->feature_info()->feature_flags().ext_texture_rg) {
// Create a R-8 image texture, and check that the internal_format is that of
// the image (GL_RGBA for TextureImageFactory). This only matters for the
// validating decoder.
// Create a R-8 image texture, and check that the internal_format is that
// of the image (GL_RGBA for TextureImageFactory). This only matters for
// the validating decoder.
auto format = viz::ResourceFormat::RED_8;
gpu::SurfaceHandle surface_handle = gpu::kNullSurfaceHandle;
backing = backing_factory_->CreateSharedImage(
......@@ -498,7 +516,7 @@ TEST_P(SharedImageBackingFactoryGLTextureTest, InitialData) {
TEST_P(SharedImageBackingFactoryGLTextureTest, InitialDataImage) {
auto mailbox = Mailbox::GenerateForSharedImage();
auto format = viz::ResourceFormat::RGBA_8888;
auto format = get_format();
gfx::Size size(256, 256);
auto color_space = gfx::ColorSpace::CreateSRGB();
uint32_t usage = SHARED_IMAGE_USAGE_GLES2 | SHARED_IMAGE_USAGE_SCANOUT;
......@@ -537,7 +555,7 @@ TEST_P(SharedImageBackingFactoryGLTextureTest, InitialDataImage) {
TEST_P(SharedImageBackingFactoryGLTextureTest, InitialDataWrongSize) {
auto mailbox = Mailbox::GenerateForSharedImage();
auto format = viz::ResourceFormat::RGBA_8888;
auto format = get_format();
gfx::Size size(256, 256);
auto color_space = gfx::ColorSpace::CreateSRGB();
uint32_t usage = SHARED_IMAGE_USAGE_GLES2;
......@@ -566,7 +584,7 @@ TEST_P(SharedImageBackingFactoryGLTextureTest, InvalidFormat) {
TEST_P(SharedImageBackingFactoryGLTextureTest, InvalidSize) {
auto mailbox = Mailbox::GenerateForSharedImage();
auto format = viz::ResourceFormat::RGBA_8888;
auto format = get_format();
gfx::Size size(0, 0);
auto color_space = gfx::ColorSpace::CreateSRGB();
gpu::SurfaceHandle surface_handle = gpu::kNullSurfaceHandle;
......@@ -585,7 +603,7 @@ TEST_P(SharedImageBackingFactoryGLTextureTest, InvalidSize) {
TEST_P(SharedImageBackingFactoryGLTextureTest, EstimatedSize) {
auto mailbox = Mailbox::GenerateForSharedImage();
auto format = viz::ResourceFormat::RGBA_8888;
auto format = get_format();
gfx::Size size(256, 256);
auto color_space = gfx::ColorSpace::CreateSRGB();
gpu::SurfaceHandle surface_handle = gpu::kNullSurfaceHandle;
......@@ -749,7 +767,7 @@ TEST_P(SharedImageBackingFactoryGLTextureWithGMBTest,
GpuMemoryBufferImportEmpty) {
auto mailbox = Mailbox::GenerateForSharedImage();
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();
uint32_t usage = SHARED_IMAGE_USAGE_GLES2;
......@@ -764,7 +782,7 @@ TEST_P(SharedImageBackingFactoryGLTextureWithGMBTest,
GpuMemoryBufferImportNative) {
auto mailbox = Mailbox::GenerateForSharedImage();
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();
uint32_t usage = SHARED_IMAGE_USAGE_GLES2;
......@@ -792,7 +810,7 @@ TEST_P(SharedImageBackingFactoryGLTextureWithGMBTest,
GpuMemoryBufferImportSharedMemory) {
auto mailbox = Mailbox::GenerateForSharedImage();
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();
uint32_t usage = SHARED_IMAGE_USAGE_GLES2;
......@@ -826,7 +844,7 @@ TEST_P(SharedImageBackingFactoryGLTextureWithGMBTest,
return;
auto mailbox = Mailbox::GenerateForSharedImage();
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();
uint32_t usage = SHARED_IMAGE_USAGE_GLES2;
......@@ -847,7 +865,7 @@ TEST_P(SharedImageBackingFactoryGLTextureWithGMBTest,
EXPECT_TRUE(representation);
EXPECT_TRUE(representation->GetTexture()->service_id());
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(usage, representation->usage());
......@@ -1044,15 +1062,28 @@ CreateAndValidateSharedImageRepresentations::
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,
SharedImageBackingFactoryGLTextureTest,
::testing::Bool());
::testing::Combine(::testing::Bool(),
kResourceFormats));
INSTANTIATE_TEST_SUITE_P(Service,
SharedImageBackingFactoryGLTextureThreadSafeTest,
::testing::Bool());
::testing::Combine(::testing::Bool(),
kResourceFormats));
INSTANTIATE_TEST_SUITE_P(Service,
SharedImageBackingFactoryGLTextureWithGMBTest,
::testing::Bool());
::testing::Combine(::testing::Bool(),
kResourceFormats));
} // anonymous namespace
} // 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