Skip to content

Commit

Permalink
ozone: support gfx::BufferFormat::RGBX_8888 as a native pixmap format.
Browse files Browse the repository at this point in the history
It's follow-up for https://codereview.chromium.org/1401063002/

In addition, this CL fixes content_unittests crash about gfx::BufferFormat::RGBA_8888

TEST=content_unittests --gtest_filter=GpuMemoryBuffer* --ozone-platform=gbm --ozone-use-surfaceless
TEST=chrome --ozone-platform=gbm --ozone-use-surfaceless --ozone-test-single-overlay-support http://www.quirksmode.org/html5/tests/video.html
BUG=538325

Review URL: https://codereview.chromium.org/1483633002

Cr-Commit-Position: refs/heads/master@{#366591}
  • Loading branch information
ds-hwang authored and Commit bot committed Dec 22, 2015
1 parent 6b4f437 commit 466c3f1
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ base::Closure GpuMemoryBufferImplOzoneNativePixmap::AllocateForTesting(
gfx::BufferFormat format,
gfx::BufferUsage usage,
gfx::GpuMemoryBufferHandle* handle) {
DCHECK(IsConfigurationSupported(format, usage));
scoped_refptr<ui::NativePixmap> pixmap =
ui::OzonePlatform::GetInstance()
->GetSurfaceFactoryOzone()
Expand Down
6 changes: 4 additions & 2 deletions ui/gl/gl_image_ozone_native_pixmap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define DRM_FORMAT_ARGB8888 FOURCC('A', 'R', '2', '4')
#define DRM_FORMAT_ABGR8888 FOURCC('A', 'B', '2', '4')
#define DRM_FORMAT_XRGB8888 FOURCC('X', 'R', '2', '4')
#define DRM_FORMAT_XBGR8888 FOURCC('X', 'B', '2', '4')

namespace gfx {
namespace {
Expand All @@ -29,6 +30,7 @@ bool ValidInternalFormat(unsigned internalformat) {
bool ValidFormat(BufferFormat format) {
switch (format) {
case BufferFormat::RGBA_8888:
case BufferFormat::RGBX_8888:
case BufferFormat::BGRA_8888:
case BufferFormat::BGRX_8888:
return true;
Expand All @@ -39,7 +41,6 @@ bool ValidFormat(BufferFormat format) {
case BufferFormat::ETC1:
case BufferFormat::R_8:
case BufferFormat::RGBA_4444:
case BufferFormat::RGBX_8888:
case BufferFormat::YUV_420:
case BufferFormat::YUV_420_BIPLANAR:
case BufferFormat::UYVY_422:
Expand All @@ -54,6 +55,8 @@ EGLint FourCC(BufferFormat format) {
switch (format) {
case BufferFormat::RGBA_8888:
return DRM_FORMAT_ABGR8888;
case BufferFormat::RGBX_8888:
return DRM_FORMAT_XBGR8888;
case BufferFormat::BGRA_8888:
return DRM_FORMAT_ARGB8888;
case BufferFormat::BGRX_8888:
Expand All @@ -65,7 +68,6 @@ EGLint FourCC(BufferFormat format) {
case BufferFormat::ETC1:
case BufferFormat::R_8:
case BufferFormat::RGBA_4444:
case BufferFormat::RGBX_8888:
case BufferFormat::YUV_420:
case BufferFormat::YUV_420_BIPLANAR:
case BufferFormat::UYVY_422:
Expand Down
1 change: 1 addition & 0 deletions ui/ozone/platform/drm/client_native_pixmap_factory_gbm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class ClientNativePixmapFactoryGbm : public ClientNativePixmapFactory {
case gfx::BufferUsage::GPU_READ:
case gfx::BufferUsage::SCANOUT:
return format == gfx::BufferFormat::RGBA_8888 ||
format == gfx::BufferFormat::RGBX_8888 ||
format == gfx::BufferFormat::BGRA_8888 ||
format == gfx::BufferFormat::BGRX_8888;
case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE:
Expand Down
25 changes: 25 additions & 0 deletions ui/ozone/platform/drm/common/drm_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ DisplaySnapshot_Params CreateDisplaySnapshotParams(

int GetFourCCFormatFromBufferFormat(gfx::BufferFormat format) {
switch (format) {
case gfx::BufferFormat::RGBA_8888:
return DRM_FORMAT_ABGR8888;
case gfx::BufferFormat::RGBX_8888:
return DRM_FORMAT_XBGR8888;
case gfx::BufferFormat::BGRA_8888:
return DRM_FORMAT_ARGB8888;
case gfx::BufferFormat::BGRX_8888:
Expand All @@ -288,6 +292,10 @@ int GetFourCCFormatFromBufferFormat(gfx::BufferFormat format) {

gfx::BufferFormat GetBufferFormatFromFourCCFormat(int format) {
switch (format) {
case DRM_FORMAT_ABGR8888:
return gfx::BufferFormat::RGBA_8888;
case DRM_FORMAT_XBGR8888:
return gfx::BufferFormat::RGBX_8888;
case DRM_FORMAT_ARGB8888:
return gfx::BufferFormat::BGRA_8888;
case DRM_FORMAT_XRGB8888:
Expand All @@ -299,4 +307,21 @@ gfx::BufferFormat GetBufferFormatFromFourCCFormat(int format) {
return gfx::BufferFormat::BGRA_8888;
}
}

int GetFourCCFormatForFramebuffer(gfx::BufferFormat format) {
// Currently, drm supports 24 bitcolordepth for hardware overlay.
switch (format) {
case gfx::BufferFormat::RGBA_8888:
case gfx::BufferFormat::RGBX_8888:
return DRM_FORMAT_XBGR8888;
case gfx::BufferFormat::BGRA_8888:
case gfx::BufferFormat::BGRX_8888:
return DRM_FORMAT_XRGB8888;
case gfx::BufferFormat::UYVY_422:
return DRM_FORMAT_UYVY;
default:
NOTREACHED();
return 0;
}
}
} // namespace ui
2 changes: 2 additions & 0 deletions ui/ozone/platform/drm/common/drm_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ DisplaySnapshot_Params CreateDisplaySnapshotParams(
int GetFourCCFormatFromBufferFormat(gfx::BufferFormat format);
gfx::BufferFormat GetBufferFormatFromFourCCFormat(int format);

int GetFourCCFormatForFramebuffer(gfx::BufferFormat format);

} // namespace ui

#endif // UI_OZONE_PLATFORM_DRM_COMMON_DRM_UTIL_H_
7 changes: 1 addition & 6 deletions ui/ozone/platform/drm/gpu/drm_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,7 @@ std::vector<OverlayCheck_Params> DrmWindow::TestPageFlip(
scoped_refptr<ScanoutBuffer> buffer;
// Check if we can re-use existing buffers.
for (const auto& plane : last_submitted_planes_) {
uint32_t format = GetFourCCFormatFromBufferFormat(overlay.format);
// We always use a storage type of XRGB, even if the pixel format
// is ARGB.
if (format == DRM_FORMAT_ARGB8888)
format = DRM_FORMAT_XRGB8888;

uint32_t format = GetFourCCFormatForFramebuffer(overlay.format);
if (plane.buffer->GetFramebufferPixelFormat() == format &&
plane.z_order == overlay.plane_z_order &&
plane.display_bounds == overlay.display_rect &&
Expand Down
8 changes: 4 additions & 4 deletions ui/ozone/platform/drm/gpu/gbm_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ namespace ui {

GbmBuffer::GbmBuffer(const scoped_refptr<GbmDevice>& gbm,
gbm_bo* bo,
gfx::BufferFormat format,
gfx::BufferUsage usage)
: GbmBufferBase(gbm, bo, usage == gfx::BufferUsage::SCANOUT),
usage_(usage) {}
: GbmBufferBase(gbm, bo, format, usage), format_(format), usage_(usage) {}

GbmBuffer::~GbmBuffer() {
if (bo())
Expand All @@ -59,7 +59,7 @@ scoped_refptr<GbmBuffer> GbmBuffer::CreateBuffer(
if (!bo)
return nullptr;

scoped_refptr<GbmBuffer> buffer(new GbmBuffer(gbm, bo, usage));
scoped_refptr<GbmBuffer> buffer(new GbmBuffer(gbm, bo, format, usage));
if (use_scanout && !buffer->GetFramebufferId())
return nullptr;

Expand Down Expand Up @@ -143,7 +143,7 @@ int GbmPixmap::GetDmaBufPitch() const {
}

gfx::BufferFormat GbmPixmap::GetBufferFormat() const {
return GetBufferFormatFromFourCCFormat(buffer_->GetFramebufferPixelFormat());
return buffer_->GetFormat();
}

gfx::Size GbmPixmap::GetBufferSize() const {
Expand Down
3 changes: 3 additions & 0 deletions ui/ozone/platform/drm/gpu/gbm_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ class GbmBuffer : public GbmBufferBase {
gfx::BufferFormat format,
const gfx::Size& size,
gfx::BufferUsage usage);
gfx::BufferFormat GetFormat() const { return format_; }
gfx::BufferUsage GetUsage() const { return usage_; }

private:
GbmBuffer(const scoped_refptr<GbmDevice>& gbm,
gbm_bo* bo,
gfx::BufferFormat format,
gfx::BufferUsage usage);
~GbmBuffer() override;

gfx::BufferFormat format_;
gfx::BufferUsage usage_;

DISALLOW_COPY_AND_ASSIGN(GbmBuffer);
Expand Down
21 changes: 9 additions & 12 deletions ui/ozone/platform/drm/gpu/gbm_buffer_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,18 @@
#include <gbm.h>

#include "base/logging.h"
#include "ui/ozone/platform/drm/common/drm_util.h"
#include "ui/ozone/platform/drm/gpu/drm_device.h"

namespace ui {

GbmBufferBase::GbmBufferBase(const scoped_refptr<DrmDevice>& drm,
gbm_bo* bo,
bool scanout)
gfx::BufferFormat format,
gfx::BufferUsage usage)
: drm_(drm), bo_(bo) {
if (scanout) {
fb_pixel_format_ = gbm_bo_get_format(bo);
if (fb_pixel_format_ == GBM_FORMAT_ARGB8888)
fb_pixel_format_ = GBM_FORMAT_XRGB8888;

// For now, we only support XRGB and UYVY format.
DCHECK(fb_pixel_format_ == GBM_FORMAT_XRGB8888 ||
fb_pixel_format_ == GBM_FORMAT_UYVY);
if (usage == gfx::BufferUsage::SCANOUT) {
framebuffer_pixel_format_ = GetFourCCFormatForFramebuffer(format);

uint32_t handles[4] = {0};
handles[0] = gbm_bo_get_handle(bo).u32;
Expand All @@ -31,8 +27,8 @@ GbmBufferBase::GbmBufferBase(const scoped_refptr<DrmDevice>& drm,
uint32_t offsets[4] = {0};

if (!drm_->AddFramebuffer2(gbm_bo_get_width(bo), gbm_bo_get_height(bo),
fb_pixel_format_, handles, strides, offsets,
&framebuffer_, 0)) {
framebuffer_pixel_format_, handles, strides,
offsets, &framebuffer_, 0)) {
PLOG(ERROR) << "Failed to register buffer";
return;
}
Expand All @@ -57,7 +53,8 @@ gfx::Size GbmBufferBase::GetSize() const {
}

uint32_t GbmBufferBase::GetFramebufferPixelFormat() const {
return fb_pixel_format_;
DCHECK(framebuffer_);
return framebuffer_pixel_format_;
}

bool GbmBufferBase::RequiresGlFinish() const {
Expand Down
7 changes: 5 additions & 2 deletions ui/ozone/platform/drm/gpu/gbm_buffer_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ class GbmBufferBase : public ScanoutBuffer {
bool RequiresGlFinish() const override;

protected:
GbmBufferBase(const scoped_refptr<DrmDevice>& drm, gbm_bo* bo, bool scanout);
GbmBufferBase(const scoped_refptr<DrmDevice>& drm,
gbm_bo* bo,
gfx::BufferFormat format,
gfx::BufferUsage usage);
~GbmBufferBase() override;

private:
scoped_refptr<DrmDevice> drm_;
gbm_bo* bo_;
uint32_t framebuffer_ = 0;
uint32_t fb_pixel_format_ = 0;
uint32_t framebuffer_pixel_format_ = 0;

DISALLOW_COPY_AND_ASSIGN(GbmBufferBase);
};
Expand Down

0 comments on commit 466c3f1

Please sign in to comment.