OLD | NEW |
1 // Copyright 2016 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" | 5 #include "ui/ozone/gl/gl_image_ozone_native_pixmap.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ui/gfx/buffer_format_util.h" | 9 #include "ui/gfx/buffer_format_util.h" |
10 #include "ui/gl/gl_surface_egl.h" | 10 #include "ui/gl/gl_surface_egl.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 // Note: If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT | 145 // Note: If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT |
146 // target, the EGL will take a reference to the dma_buf. | 146 // target, the EGL will take a reference to the dma_buf. |
147 std::vector<EGLint> attrs; | 147 std::vector<EGLint> attrs; |
148 attrs.push_back(EGL_WIDTH); | 148 attrs.push_back(EGL_WIDTH); |
149 attrs.push_back(size_.width()); | 149 attrs.push_back(size_.width()); |
150 attrs.push_back(EGL_HEIGHT); | 150 attrs.push_back(EGL_HEIGHT); |
151 attrs.push_back(size_.height()); | 151 attrs.push_back(size_.height()); |
152 attrs.push_back(EGL_LINUX_DRM_FOURCC_EXT); | 152 attrs.push_back(EGL_LINUX_DRM_FOURCC_EXT); |
153 attrs.push_back(FourCC(format)); | 153 attrs.push_back(FourCC(format)); |
154 | 154 |
155 const EGLint kLinuxDrmModifiers[] = {EGL_LINUX_DRM_PLANE0_MODIFIER0_EXT, | 155 const EGLint kLinuxDrmModifiers[] = {EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT, |
156 EGL_LINUX_DRM_PLANE1_MODIFIER0_EXT, | 156 EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT, |
157 EGL_LINUX_DRM_PLANE2_MODIFIER0_EXT}; | 157 EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT}; |
158 bool has_dma_buf_import_modifier = gl::GLSurfaceEGL::HasEGLExtension( | 158 bool has_dma_buf_import_modifier = gl::GLSurfaceEGL::HasEGLExtension( |
159 "EGL_EXT_image_dma_buf_import_modifiers"); | 159 "EGL_EXT_image_dma_buf_import_modifiers"); |
160 | 160 |
161 for (size_t attrs_plane = 0; | 161 for (size_t attrs_plane = 0; |
162 attrs_plane < | 162 attrs_plane < |
163 gfx::NumberOfPlanesForBufferFormat(pixmap->GetBufferFormat()); | 163 gfx::NumberOfPlanesForBufferFormat(pixmap->GetBufferFormat()); |
164 ++attrs_plane) { | 164 ++attrs_plane) { |
165 attrs.push_back(EGL_DMA_BUF_PLANE0_FD_EXT + attrs_plane * 3); | 165 attrs.push_back(EGL_DMA_BUF_PLANE0_FD_EXT + attrs_plane * 3); |
166 | 166 |
167 size_t pixmap_plane = attrs_plane; | 167 size_t pixmap_plane = attrs_plane; |
(...skipping 11 matching lines...) Expand all Loading... |
179 attrs.push_back(modifier & 0xffffffff); | 179 attrs.push_back(modifier & 0xffffffff); |
180 attrs.push_back(kLinuxDrmModifiers[attrs_plane] + 1); | 180 attrs.push_back(kLinuxDrmModifiers[attrs_plane] + 1); |
181 attrs.push_back(static_cast<uint32_t>(modifier >> 32)); | 181 attrs.push_back(static_cast<uint32_t>(modifier >> 32)); |
182 } | 182 } |
183 } | 183 } |
184 attrs.push_back(EGL_NONE); | 184 attrs.push_back(EGL_NONE); |
185 | 185 |
186 if (!GLImageEGL::Initialize(EGL_LINUX_DMA_BUF_EXT, | 186 if (!GLImageEGL::Initialize(EGL_LINUX_DMA_BUF_EXT, |
187 static_cast<EGLClientBuffer>(nullptr), | 187 static_cast<EGLClientBuffer>(nullptr), |
188 &attrs[0])) { | 188 &attrs[0])) { |
| 189 // TODO(hshi): remove this workaround after chrome uprevs and |
| 190 // corresponding driver updates are made. https://crosbug.com/p/58718 |
| 191 if (has_dma_buf_import_modifier) { |
| 192 // If driver rejects the new DMA-BUF import modifer tokens, then try |
| 193 // again with the old token definition. |
| 194 for (size_t i = 0; i < attrs.size(); i += 2) { |
| 195 switch (attrs[i]) { |
| 196 case EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT: |
| 197 attrs[i] = EGL_LINUX_DRM_PLANE0_MODIFIER0_EXT; |
| 198 break; |
| 199 case EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT: |
| 200 attrs[i] = EGL_LINUX_DRM_PLANE0_MODIFIER1_EXT; |
| 201 break; |
| 202 case EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT: |
| 203 attrs[i] = EGL_LINUX_DRM_PLANE1_MODIFIER0_EXT; |
| 204 break; |
| 205 case EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT: |
| 206 attrs[i] = EGL_LINUX_DRM_PLANE1_MODIFIER1_EXT; |
| 207 break; |
| 208 case EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT: |
| 209 attrs[i] = EGL_LINUX_DRM_PLANE2_MODIFIER0_EXT; |
| 210 break; |
| 211 case EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT: |
| 212 attrs[i] = EGL_LINUX_DRM_PLANE2_MODIFIER1_EXT; |
| 213 break; |
| 214 default: |
| 215 break; |
| 216 } |
| 217 if (!GLImageEGL::Initialize(EGL_LINUX_DMA_BUF_EXT, |
| 218 static_cast<EGLClientBuffer>(nullptr), |
| 219 &attrs[0])) { |
| 220 return false; |
| 221 } |
| 222 } |
| 223 } |
189 return false; | 224 return false; |
190 } | 225 } |
191 } | 226 } |
192 | 227 |
193 pixmap_ = pixmap; | 228 pixmap_ = pixmap; |
194 return true; | 229 return true; |
195 } | 230 } |
196 | 231 |
197 unsigned GLImageOzoneNativePixmap::GetInternalFormat() { | 232 unsigned GLImageOzoneNativePixmap::GetInternalFormat() { |
198 return internalformat_; | 233 return internalformat_; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 case gfx::BufferFormat::UYVY_422: | 310 case gfx::BufferFormat::UYVY_422: |
276 NOTREACHED(); | 311 NOTREACHED(); |
277 return GL_NONE; | 312 return GL_NONE; |
278 } | 313 } |
279 | 314 |
280 NOTREACHED(); | 315 NOTREACHED(); |
281 return GL_NONE; | 316 return GL_NONE; |
282 } | 317 } |
283 | 318 |
284 } // namespace ui | 319 } // namespace ui |
OLD | NEW |