Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Unified Diff: ui/gl/gl_image_ozone_native_pixmap.cc

Issue 1258713002: ozone: unify GpuMemoryBufferFactoryOzoneNativePixmap in content/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix linux_chromium_gn_dgb build Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gl/gl_image_ozone_native_pixmap.h ('k') | ui/gl/gl_surface_ozone.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gl/gl_image_ozone_native_pixmap.cc
diff --git a/ui/gl/gl_image_ozone_native_pixmap.cc b/ui/gl/gl_image_ozone_native_pixmap.cc
new file mode 100644
index 0000000000000000000000000000000000000000..30518b9207a88d8f4348eff5076dbd8ac03f9d00
--- /dev/null
+++ b/ui/gl/gl_image_ozone_native_pixmap.cc
@@ -0,0 +1,144 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/gl/gl_image_ozone_native_pixmap.h"
+
+#define FOURCC(a, b, c, d) \
+ ((static_cast<uint32>(a)) | (static_cast<uint32>(b) << 8) | \
+ (static_cast<uint32>(c) << 16) | (static_cast<uint32>(d) << 24))
+
+#define DRM_FORMAT_ARGB8888 FOURCC('A', 'R', '2', '4')
+#define DRM_FORMAT_XRGB8888 FOURCC('X', 'R', '2', '4')
+
+namespace gfx {
+namespace {
+
+bool ValidInternalFormat(unsigned internalformat) {
+ switch (internalformat) {
+ case GL_RGB:
+ case GL_BGRA_EXT:
+ return true;
+ default:
+ return false;
+ }
+}
+
+bool ValidFormat(gfx::GpuMemoryBuffer::Format format) {
+ switch (format) {
+ case GpuMemoryBuffer::BGRA_8888:
+ case GpuMemoryBuffer::RGBX_8888:
+ return true;
+ case GpuMemoryBuffer::ATC:
+ case GpuMemoryBuffer::ATCIA:
+ case GpuMemoryBuffer::DXT1:
+ case GpuMemoryBuffer::DXT5:
+ case GpuMemoryBuffer::ETC1:
+ case GpuMemoryBuffer::R_8:
+ case GpuMemoryBuffer::RGBA_4444:
+ case GpuMemoryBuffer::RGBA_8888:
+ case GpuMemoryBuffer::YUV_420:
+ return false;
+ }
+
+ NOTREACHED();
+ return false;
+}
+
+EGLint FourCC(gfx::GpuMemoryBuffer::Format format) {
+ switch (format) {
+ case GpuMemoryBuffer::BGRA_8888:
+ return DRM_FORMAT_ARGB8888;
+ case GpuMemoryBuffer::RGBX_8888:
+ return DRM_FORMAT_XRGB8888;
+ case GpuMemoryBuffer::ATC:
+ case GpuMemoryBuffer::ATCIA:
+ case GpuMemoryBuffer::DXT1:
+ case GpuMemoryBuffer::DXT5:
+ case GpuMemoryBuffer::ETC1:
+ case GpuMemoryBuffer::R_8:
+ case GpuMemoryBuffer::RGBA_4444:
+ case GpuMemoryBuffer::RGBA_8888:
+ case GpuMemoryBuffer::YUV_420:
+ NOTREACHED();
+ return 0;
+ }
+
+ NOTREACHED();
+ return 0;
+}
+
+} // namespace
+
+GLImageOzoneNativePixmap::GLImageOzoneNativePixmap(const Size& size,
+ unsigned internalformat)
+ : GLImageEGL(size), internalformat_(internalformat) {}
+
+GLImageOzoneNativePixmap::~GLImageOzoneNativePixmap() {
+ DCHECK(!pixmap_);
+}
+
+bool GLImageOzoneNativePixmap::Initialize(ui::NativePixmap* pixmap,
+ GpuMemoryBuffer::Format format) {
+ DCHECK(!pixmap_);
+
+ bool result = true;
+ if (pixmap->GetEGLClientBuffer()) {
+ EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
+ result = GLImageEGL::Initialize(EGL_NATIVE_PIXMAP_KHR,
+ pixmap->GetEGLClientBuffer(), attrs);
+ } else if (pixmap->GetDmaBufFd() >= 0) {
+ if (!ValidInternalFormat(internalformat_)) {
+ LOG(ERROR) << "Invalid internalformat: " << internalformat_;
+ return false;
+ }
+
+ if (!ValidFormat(format)) {
+ LOG(ERROR) << "Invalid format: " << format;
+ return false;
+ }
+
+ // Note: If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT
+ // target, the EGL will take a reference to the dma_buf.
+ EGLint attrs[] = {EGL_WIDTH,
+ size_.width(),
+ EGL_HEIGHT,
+ size_.height(),
+ EGL_LINUX_DRM_FOURCC_EXT,
+ FourCC(format),
+ EGL_DMA_BUF_PLANE0_FD_EXT,
+ pixmap->GetDmaBufFd(),
+ EGL_DMA_BUF_PLANE0_OFFSET_EXT,
+ 0,
+ EGL_DMA_BUF_PLANE0_PITCH_EXT,
+ pixmap->GetDmaBufPitch(),
+ EGL_NONE};
+ result = GLImageEGL::Initialize(
+ EGL_LINUX_DMA_BUF_EXT, static_cast<EGLClientBuffer>(nullptr), attrs);
+ }
+
+ if (result)
+ pixmap_ = pixmap;
+ return result;
+}
+
+unsigned GLImageOzoneNativePixmap::GetInternalFormat() {
+ return internalformat_;
+}
+
+void GLImageOzoneNativePixmap::Destroy(bool have_context) {
+ GLImageEGL::Destroy(have_context);
+ pixmap_ = nullptr;
+}
+
+bool GLImageOzoneNativePixmap::ScheduleOverlayPlane(AcceleratedWidget widget,
+ int z_order,
+ OverlayTransform transform,
+ const Rect& bounds_rect,
+ const RectF& crop_rect) {
+ DCHECK(pixmap_);
+ return pixmap_->ScheduleOverlayPlane(widget, z_order, transform, bounds_rect,
+ crop_rect);
+}
+
+} // namespace gfx
« no previous file with comments | « ui/gl/gl_image_ozone_native_pixmap.h ('k') | ui/gl/gl_surface_ozone.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698