OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #include "ui/ozone/gl/gl_image_ozone_native_pixmap.h" |
| 6 |
| 7 #include <vector> |
| 8 |
5 #include "ui/gfx/buffer_format_util.h" | 9 #include "ui/gfx/buffer_format_util.h" |
6 #include "ui/gl/gl_image_ozone_native_pixmap.h" | |
7 #include "ui/gl/gl_surface_egl.h" | 10 #include "ui/gl/gl_surface_egl.h" |
8 | 11 |
9 #define FOURCC(a, b, c, d) \ | 12 #define FOURCC(a, b, c, d) \ |
10 ((static_cast<uint32_t>(a)) | (static_cast<uint32_t>(b) << 8) | \ | 13 ((static_cast<uint32_t>(a)) | (static_cast<uint32_t>(b) << 8) | \ |
11 (static_cast<uint32_t>(c) << 16) | (static_cast<uint32_t>(d) << 24)) | 14 (static_cast<uint32_t>(c) << 16) | (static_cast<uint32_t>(d) << 24)) |
12 | 15 |
13 #define DRM_FORMAT_R8 FOURCC('R', '8', ' ', ' ') | 16 #define DRM_FORMAT_R8 FOURCC('R', '8', ' ', ' ') |
14 #define DRM_FORMAT_RGB565 FOURCC('R', 'G', '1', '6') | 17 #define DRM_FORMAT_RGB565 FOURCC('R', 'G', '1', '6') |
15 #define DRM_FORMAT_ARGB8888 FOURCC('A', 'R', '2', '4') | 18 #define DRM_FORMAT_ARGB8888 FOURCC('A', 'R', '2', '4') |
16 #define DRM_FORMAT_ABGR8888 FOURCC('A', 'B', '2', '4') | 19 #define DRM_FORMAT_ABGR8888 FOURCC('A', 'B', '2', '4') |
17 #define DRM_FORMAT_XRGB8888 FOURCC('X', 'R', '2', '4') | 20 #define DRM_FORMAT_XRGB8888 FOURCC('X', 'R', '2', '4') |
18 #define DRM_FORMAT_XBGR8888 FOURCC('X', 'B', '2', '4') | 21 #define DRM_FORMAT_XBGR8888 FOURCC('X', 'B', '2', '4') |
19 #define DRM_FORMAT_YV12 FOURCC('Y', 'V', '1', '2') | 22 #define DRM_FORMAT_YV12 FOURCC('Y', 'V', '1', '2') |
20 | 23 |
21 namespace gl { | 24 namespace ui { |
22 namespace { | 25 namespace { |
23 | 26 |
24 bool ValidInternalFormat(unsigned internalformat, gfx::BufferFormat format) { | 27 bool ValidInternalFormat(unsigned internalformat, gfx::BufferFormat format) { |
25 switch (internalformat) { | 28 switch (internalformat) { |
26 case GL_RGB: | 29 case GL_RGB: |
27 return format == gfx::BufferFormat::BGR_565 || | 30 return format == gfx::BufferFormat::BGR_565 || |
28 format == gfx::BufferFormat::RGBX_8888 || | 31 format == gfx::BufferFormat::RGBX_8888 || |
29 format == gfx::BufferFormat::BGRX_8888; | 32 format == gfx::BufferFormat::BGRX_8888; |
30 case GL_RGB_YCRCB_420_CHROMIUM: | 33 case GL_RGB_YCRCB_420_CHROMIUM: |
31 return format == gfx::BufferFormat::YVU_420; | 34 return format == gfx::BufferFormat::YVU_420; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 NOTREACHED(); | 99 NOTREACHED(); |
97 return 0; | 100 return 0; |
98 } | 101 } |
99 | 102 |
100 } // namespace | 103 } // namespace |
101 | 104 |
102 GLImageOzoneNativePixmap::GLImageOzoneNativePixmap(const gfx::Size& size, | 105 GLImageOzoneNativePixmap::GLImageOzoneNativePixmap(const gfx::Size& size, |
103 unsigned internalformat) | 106 unsigned internalformat) |
104 : GLImageEGL(size), internalformat_(internalformat) {} | 107 : GLImageEGL(size), internalformat_(internalformat) {} |
105 | 108 |
106 GLImageOzoneNativePixmap::~GLImageOzoneNativePixmap() { | 109 GLImageOzoneNativePixmap::~GLImageOzoneNativePixmap() {} |
107 } | |
108 | 110 |
109 bool GLImageOzoneNativePixmap::Initialize(ui::NativePixmap* pixmap, | 111 bool GLImageOzoneNativePixmap::Initialize(NativePixmap* pixmap, |
110 gfx::BufferFormat format) { | 112 gfx::BufferFormat format) { |
111 DCHECK(!pixmap_); | 113 DCHECK(!pixmap_); |
112 if (pixmap->GetEGLClientBuffer()) { | 114 if (pixmap->GetEGLClientBuffer()) { |
113 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; | 115 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; |
114 if (!GLImageEGL::Initialize(EGL_NATIVE_PIXMAP_KHR, | 116 if (!GLImageEGL::Initialize(EGL_NATIVE_PIXMAP_KHR, |
115 pixmap->GetEGLClientBuffer(), attrs)) { | 117 pixmap->GetEGLClientBuffer(), attrs)) { |
116 return false; | 118 return false; |
117 } | 119 } |
118 } else if (pixmap->AreDmaBufFdsValid()) { | 120 } else if (pixmap->AreDmaBufFdsValid()) { |
119 | |
120 if (!ValidFormat(format)) { | 121 if (!ValidFormat(format)) { |
121 LOG(ERROR) << "Invalid format: " << static_cast<int>(format); | 122 LOG(ERROR) << "Invalid format: " << static_cast<int>(format); |
122 return false; | 123 return false; |
123 } | 124 } |
124 | 125 |
125 if (!ValidInternalFormat(internalformat_, format)) { | 126 if (!ValidInternalFormat(internalformat_, format)) { |
126 LOG(ERROR) << "Invalid internalformat: " << internalformat_ | 127 LOG(ERROR) << "Invalid internalformat: " << internalformat_ |
127 << " for format: " << static_cast<int>(format); | 128 << " for format: " << static_cast<int>(format); |
128 return false; | 129 return false; |
129 } | 130 } |
130 | 131 |
131 // Note: If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT | 132 // Note: If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT |
132 // target, the EGL will take a reference to the dma_buf. | 133 // target, the EGL will take a reference to the dma_buf. |
133 std::vector<EGLint> attrs; | 134 std::vector<EGLint> attrs; |
134 attrs.push_back(EGL_WIDTH); | 135 attrs.push_back(EGL_WIDTH); |
135 attrs.push_back(size_.width()); | 136 attrs.push_back(size_.width()); |
136 attrs.push_back(EGL_HEIGHT); | 137 attrs.push_back(EGL_HEIGHT); |
137 attrs.push_back(size_.height()); | 138 attrs.push_back(size_.height()); |
138 attrs.push_back(EGL_LINUX_DRM_FOURCC_EXT); | 139 attrs.push_back(EGL_LINUX_DRM_FOURCC_EXT); |
139 attrs.push_back(FourCC(format)); | 140 attrs.push_back(FourCC(format)); |
140 | 141 |
141 const EGLint kLinuxDrmModifiers[] = {EGL_LINUX_DRM_PLANE0_MODIFIER0_EXT, | 142 const EGLint kLinuxDrmModifiers[] = {EGL_LINUX_DRM_PLANE0_MODIFIER0_EXT, |
142 EGL_LINUX_DRM_PLANE1_MODIFIER0_EXT, | 143 EGL_LINUX_DRM_PLANE1_MODIFIER0_EXT, |
143 EGL_LINUX_DRM_PLANE2_MODIFIER0_EXT}; | 144 EGL_LINUX_DRM_PLANE2_MODIFIER0_EXT}; |
144 bool has_dma_buf_import_modifier = | 145 bool has_dma_buf_import_modifier = gl::GLSurfaceEGL::HasEGLExtension( |
145 GLSurfaceEGL::HasEGLExtension("EGL_EXT_image_dma_buf_import_modifiers"); | 146 "EGL_EXT_image_dma_buf_import_modifiers"); |
146 | 147 |
147 for (size_t plane = 0; | 148 for (size_t plane = 0; |
148 plane < gfx::NumberOfPlanesForBufferFormat(pixmap->GetBufferFormat()); | 149 plane < gfx::NumberOfPlanesForBufferFormat(pixmap->GetBufferFormat()); |
149 ++plane) { | 150 ++plane) { |
150 attrs.push_back(EGL_DMA_BUF_PLANE0_FD_EXT + plane * 3); | 151 attrs.push_back(EGL_DMA_BUF_PLANE0_FD_EXT + plane * 3); |
151 attrs.push_back( | 152 attrs.push_back( |
152 pixmap->GetDmaBufFd(plane < pixmap->GetDmaBufFdCount() ? plane : 0)); | 153 pixmap->GetDmaBufFd(plane < pixmap->GetDmaBufFdCount() ? plane : 0)); |
153 attrs.push_back(EGL_DMA_BUF_PLANE0_OFFSET_EXT + plane * 3); | 154 attrs.push_back(EGL_DMA_BUF_PLANE0_OFFSET_EXT + plane * 3); |
154 attrs.push_back(pixmap->GetDmaBufOffset(plane)); | 155 attrs.push_back(pixmap->GetDmaBufOffset(plane)); |
155 attrs.push_back(EGL_DMA_BUF_PLANE0_PITCH_EXT + plane * 3); | 156 attrs.push_back(EGL_DMA_BUF_PLANE0_PITCH_EXT + plane * 3); |
(...skipping 26 matching lines...) Expand all Loading... |
182 | 183 |
183 void GLImageOzoneNativePixmap::Destroy(bool have_context) { | 184 void GLImageOzoneNativePixmap::Destroy(bool have_context) { |
184 GLImageEGL::Destroy(have_context); | 185 GLImageEGL::Destroy(have_context); |
185 } | 186 } |
186 | 187 |
187 bool GLImageOzoneNativePixmap::CopyTexImage(unsigned target) { | 188 bool GLImageOzoneNativePixmap::CopyTexImage(unsigned target) { |
188 if (egl_image_ == EGL_NO_IMAGE_KHR) { | 189 if (egl_image_ == EGL_NO_IMAGE_KHR) { |
189 // Pass-through image type fails to bind and copy; make sure we | 190 // Pass-through image type fails to bind and copy; make sure we |
190 // don't draw with uninitialized texture. | 191 // don't draw with uninitialized texture. |
191 std::vector<unsigned char> data(size_.width() * size_.height() * 4); | 192 std::vector<unsigned char> data(size_.width() * size_.height() * 4); |
192 glTexImage2D(target, 0, GL_RGBA, size_.width(), | 193 glTexImage2D(target, 0, GL_RGBA, size_.width(), size_.height(), 0, GL_RGBA, |
193 size_.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, | 194 GL_UNSIGNED_BYTE, data.data()); |
194 data.data()); | |
195 return true; | 195 return true; |
196 } | 196 } |
197 return GLImageEGL::CopyTexImage(target); | 197 return GLImageEGL::CopyTexImage(target); |
198 } | 198 } |
199 | 199 |
200 bool GLImageOzoneNativePixmap::ScheduleOverlayPlane( | 200 bool GLImageOzoneNativePixmap::ScheduleOverlayPlane( |
201 gfx::AcceleratedWidget widget, | 201 gfx::AcceleratedWidget widget, |
202 int z_order, | 202 int z_order, |
203 gfx::OverlayTransform transform, | 203 gfx::OverlayTransform transform, |
204 const gfx::Rect& bounds_rect, | 204 const gfx::Rect& bounds_rect, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 case gfx::BufferFormat::YUV_420_BIPLANAR: | 240 case gfx::BufferFormat::YUV_420_BIPLANAR: |
241 case gfx::BufferFormat::UYVY_422: | 241 case gfx::BufferFormat::UYVY_422: |
242 NOTREACHED(); | 242 NOTREACHED(); |
243 return GL_NONE; | 243 return GL_NONE; |
244 } | 244 } |
245 | 245 |
246 NOTREACHED(); | 246 NOTREACHED(); |
247 return GL_NONE; | 247 return GL_NONE; |
248 } | 248 } |
249 | 249 |
250 } // namespace gl | 250 } // namespace ui |
OLD | NEW |