Commit 5e2ef705 authored by Miguel Casas's avatar Miguel Casas Committed by Commit Bot

ozone/drm: support AR30/AB30 framebuffers

Intel Display Controller does not support AR30/AB30 framebuffers,
but only their opaque XR30/XB30 versions. This CL adds a provision
for these formats to |prefer_opaque| when importing a buffer.

This CL was split off crrev.com/c/2072621, and is used for supporting
high bit-depth framebuffers for HDR composition. Tested with that CL
and by playing an HDR video: the primary framebuffer format in
/sys/kernel/debug/dri/0//state correctly changes to XB30, whereas
when there are not HDR quads in the BufferQueue, it's XR24.

Bug: 776093
Change-Id: Iacd0414ea0f0a9dd359796c982ed60d0ee74a737
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2078655
Commit-Queue: Miguel Casas <mcasas@chromium.org>
Reviewed-by: default avatarDaniel Nicoara <dnicoara@chromium.org>
Reviewed-by: default avatarDaniele Castagna <dcastagna@chromium.org>
Cr-Commit-Position: refs/heads/master@{#745256}
parent 6f438016
......@@ -6,6 +6,7 @@
#include <utility>
#include "ui/gfx/buffer_format_util.h"
#include "ui/gfx/linux/drm_util_linux.h"
#include "ui/gfx/linux/gbm_buffer.h"
#include "ui/ozone/platform/drm/common/drm_util.h"
......@@ -28,8 +29,18 @@ scoped_refptr<DrmFramebuffer> DrmFramebuffer::AddFramebuffer(
modifiers[i] = params.modifier;
}
const auto fourcc_format = GetBufferFormatFromFourCCFormat(params.format);
const uint32_t opaque_format =
GetFourCCFormatForOpaqueFramebuffer(fourcc_format);
// Intel Display Controller won't support AR/B30 framebuffers, only XR/B30,
// but that doesn't matter because anyway those two bits of alpha are useless;
// use the opaque directly in this case.
const bool force_opaque = AlphaBitsForBufferFormat(fourcc_format) == 2;
const auto drm_format = force_opaque ? opaque_format : params.format;
uint32_t framebuffer_id = 0;
if (!drm_device->AddFramebuffer2(params.width, params.height, params.format,
if (!drm_device->AddFramebuffer2(params.width, params.height, drm_format,
params.handles, params.strides,
params.offsets, modifiers, &framebuffer_id,
params.flags)) {
......@@ -37,10 +48,8 @@ scoped_refptr<DrmFramebuffer> DrmFramebuffer::AddFramebuffer(
return nullptr;
}
uint32_t opaque_format = GetFourCCFormatForOpaqueFramebuffer(
GetBufferFormatFromFourCCFormat(params.format));
uint32_t opaque_framebuffer_id = 0;
if (opaque_format != params.format &&
if (opaque_format != drm_format &&
!drm_device->AddFramebuffer2(params.width, params.height, opaque_format,
params.handles, params.strides,
params.offsets, modifiers,
......@@ -51,9 +60,9 @@ scoped_refptr<DrmFramebuffer> DrmFramebuffer::AddFramebuffer(
}
return base::MakeRefCounted<DrmFramebuffer>(
std::move(drm_device), framebuffer_id, params.format,
opaque_framebuffer_id, opaque_format, params.modifier,
params.preferred_modifiers, gfx::Size(params.width, params.height));
std::move(drm_device), framebuffer_id, drm_format, opaque_framebuffer_id,
opaque_format, params.modifier, params.preferred_modifiers,
gfx::Size(params.width, params.height));
}
// static
......
......@@ -18,7 +18,9 @@
#include "ui/display/types/gamma_ramp_rgb_entry.h"
#include "ui/gfx/gpu_fence.h"
#include "ui/gfx/gpu_fence_handle.h"
#include "ui/gfx/linux/drm_util_linux.h"
#include "ui/gfx/linux/gbm_buffer.h"
#include "ui/ozone/platform/drm/common/drm_util.h"
#include "ui/ozone/platform/drm/gpu/crtc_controller.h"
#include "ui/ozone/platform/drm/gpu/drm_framebuffer.h"
#include "ui/ozone/platform/drm/gpu/drm_gpu_util.h"
......@@ -937,6 +939,29 @@ TEST_P(HardwareDisplayPlaneManagerTest,
property_names_, use_atomic_));
}
// Verifies that formats with 2 bits of alpha decay to opaques for AddFB2().
TEST_P(HardwareDisplayPlaneManagerTest, ForceOpaqueFormatsForAddFramebuffer) {
InitializeDrmState(/*crtc_count=*/3, /*planes_per_crtc=*/1);
struct {
uint32_t input_fourcc; // FourCC presented to AddFramebuffer.
uint32_t used_fourcc; // FourCC expected to be used in AddFramebuffer.
} kFourCCFormats[] = {
{DRM_FORMAT_ABGR2101010, DRM_FORMAT_XBGR2101010},
// TODO(mcasas): use AR30 when the CLs in crrev.com/c/2068722 have landed.
{DRM_FORMAT_XRGB2101010, DRM_FORMAT_XRGB2101010},
};
for (const auto& format_pair : kFourCCFormats) {
scoped_refptr<ui::DrmFramebuffer> drm_fb =
CreateBufferWithFormat(kDefaultBufferSize, format_pair.input_fourcc);
EXPECT_EQ(drm_fb->framebuffer_pixel_format(), format_pair.used_fourcc);
EXPECT_EQ(drm_fb->opaque_framebuffer_pixel_format(),
format_pair.used_fourcc);
}
}
INSTANTIATE_TEST_SUITE_P(All,
HardwareDisplayPlaneManagerTest,
testing::Values(false, true));
......
......@@ -121,6 +121,8 @@ std::unique_ptr<GbmBuffer> MockGbmDevice::CreateBufferWithModifiers(
switch (format) {
case DRM_FORMAT_XRGB8888:
case DRM_FORMAT_ARGB8888:
case DRM_FORMAT_XRGB2101010:
case DRM_FORMAT_ABGR2101010:
bytes_per_pixel = 4;
break;
case DRM_FORMAT_NV12:
......
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