Update V8 to version 4.7.19.
[chromium-blink-merge.git] / ui / gl / gl_image_ozone_native_pixmap.cc
blob16253c32cb3352107cff629521967bab518459b1
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/gl/gl_image_ozone_native_pixmap.h"
7 #define FOURCC(a, b, c, d) \
8 ((static_cast<uint32>(a)) | (static_cast<uint32>(b) << 8) | \
9 (static_cast<uint32>(c) << 16) | (static_cast<uint32>(d) << 24))
11 #define DRM_FORMAT_ARGB8888 FOURCC('A', 'R', '2', '4')
12 #define DRM_FORMAT_XRGB8888 FOURCC('X', 'R', '2', '4')
14 namespace gfx {
15 namespace {
17 bool ValidInternalFormat(unsigned internalformat) {
18 switch (internalformat) {
19 case GL_RGB:
20 case GL_BGRA_EXT:
21 return true;
22 default:
23 return false;
27 bool ValidFormat(gfx::BufferFormat format) {
28 switch (format) {
29 case BufferFormat::BGRA_8888:
30 case BufferFormat::BGRX_8888:
31 return true;
32 case BufferFormat::ATC:
33 case BufferFormat::ATCIA:
34 case BufferFormat::DXT1:
35 case BufferFormat::DXT5:
36 case BufferFormat::ETC1:
37 case BufferFormat::R_8:
38 case BufferFormat::RGBA_4444:
39 case BufferFormat::RGBA_8888:
40 case BufferFormat::YUV_420:
41 case BufferFormat::UYVY_422:
42 return false;
45 NOTREACHED();
46 return false;
49 EGLint FourCC(gfx::BufferFormat format) {
50 switch (format) {
51 case BufferFormat::BGRA_8888:
52 return DRM_FORMAT_ARGB8888;
53 case BufferFormat::BGRX_8888:
54 return DRM_FORMAT_XRGB8888;
55 case BufferFormat::ATC:
56 case BufferFormat::ATCIA:
57 case BufferFormat::DXT1:
58 case BufferFormat::DXT5:
59 case BufferFormat::ETC1:
60 case BufferFormat::R_8:
61 case BufferFormat::RGBA_4444:
62 case BufferFormat::RGBA_8888:
63 case BufferFormat::YUV_420:
64 case BufferFormat::UYVY_422:
65 NOTREACHED();
66 return 0;
69 NOTREACHED();
70 return 0;
73 } // namespace
75 GLImageOzoneNativePixmap::GLImageOzoneNativePixmap(const Size& size,
76 unsigned internalformat)
77 : GLImageEGL(size), internalformat_(internalformat) {}
79 GLImageOzoneNativePixmap::~GLImageOzoneNativePixmap() {
82 bool GLImageOzoneNativePixmap::Initialize(ui::NativePixmap* pixmap,
83 BufferFormat format) {
84 DCHECK(!pixmap_);
86 bool result = true;
87 if (pixmap->GetEGLClientBuffer()) {
88 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
89 result = GLImageEGL::Initialize(EGL_NATIVE_PIXMAP_KHR,
90 pixmap->GetEGLClientBuffer(), attrs);
91 } else if (pixmap->GetDmaBufFd() >= 0) {
92 if (!ValidInternalFormat(internalformat_)) {
93 LOG(ERROR) << "Invalid internalformat: " << internalformat_;
94 return false;
97 if (!ValidFormat(format)) {
98 LOG(ERROR) << "Invalid format: " << static_cast<int>(format);
99 return false;
102 // Note: If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT
103 // target, the EGL will take a reference to the dma_buf.
104 EGLint attrs[] = {EGL_WIDTH,
105 size_.width(),
106 EGL_HEIGHT,
107 size_.height(),
108 EGL_LINUX_DRM_FOURCC_EXT,
109 FourCC(format),
110 EGL_DMA_BUF_PLANE0_FD_EXT,
111 pixmap->GetDmaBufFd(),
112 EGL_DMA_BUF_PLANE0_OFFSET_EXT,
114 EGL_DMA_BUF_PLANE0_PITCH_EXT,
115 pixmap->GetDmaBufPitch(),
116 EGL_NONE};
117 result = GLImageEGL::Initialize(
118 EGL_LINUX_DMA_BUF_EXT, static_cast<EGLClientBuffer>(nullptr), attrs);
121 if (result)
122 pixmap_ = pixmap;
123 return result;
126 unsigned GLImageOzoneNativePixmap::GetInternalFormat() {
127 return internalformat_;
130 void GLImageOzoneNativePixmap::Destroy(bool have_context) {
131 GLImageEGL::Destroy(have_context);
134 bool GLImageOzoneNativePixmap::ScheduleOverlayPlane(AcceleratedWidget widget,
135 int z_order,
136 OverlayTransform transform,
137 const Rect& bounds_rect,
138 const RectF& crop_rect) {
139 DCHECK(pixmap_);
140 return pixmap_->ScheduleOverlayPlane(widget, z_order, transform, bounds_rect,
141 crop_rect);
144 void GLImageOzoneNativePixmap::OnMemoryDump(
145 base::trace_event::ProcessMemoryDump* pmd,
146 uint64_t process_tracing_id,
147 const std::string& dump_name) {
148 // TODO(ericrk): Implement GLImage OnMemoryDump. crbug.com/514914
151 } // namespace gfx