| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/gl/gl_image_ozone_native_pixmap.h" | 5 #include "ui/gl/gl_image_ozone_native_pixmap.h" |
| 6 | 6 |
| 7 #define FOURCC(a, b, c, d) \ | 7 #define FOURCC(a, b, c, d) \ |
| 8 ((static_cast<uint32>(a)) | (static_cast<uint32>(b) << 8) | \ | 8 ((static_cast<uint32>(a)) | (static_cast<uint32>(b) << 8) | \ |
| 9 (static_cast<uint32>(c) << 16) | (static_cast<uint32>(d) << 24)) | 9 (static_cast<uint32>(c) << 16) | (static_cast<uint32>(d) << 24)) |
| 10 | 10 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 } // namespace | 71 } // namespace |
| 72 | 72 |
| 73 GLImageOzoneNativePixmap::GLImageOzoneNativePixmap(const Size& size, | 73 GLImageOzoneNativePixmap::GLImageOzoneNativePixmap(const Size& size, |
| 74 unsigned internalformat) | 74 unsigned internalformat) |
| 75 : GLImageEGL(size), internalformat_(internalformat) {} | 75 : GLImageEGL(size), internalformat_(internalformat) {} |
| 76 | 76 |
| 77 GLImageOzoneNativePixmap::~GLImageOzoneNativePixmap() { | 77 GLImageOzoneNativePixmap::~GLImageOzoneNativePixmap() { |
| 78 DCHECK(!pixmap_); | 78 DCHECK(!pixmap_); |
| 79 } | 79 } |
| 80 | 80 |
| 81 bool GLImageOzoneNativePixmap::Initialize(ui::NativePixmap* pixmap, | 81 bool GLImageOzoneNativePixmap::Initialize( |
| 82 BufferFormat format) { | 82 base::trace_event::GenericSharedMemoryId shared_memory_id, |
| 83 ui::NativePixmap* pixmap, |
| 84 GpuMemoryBuffer::Format format) { |
| 83 DCHECK(!pixmap_); | 85 DCHECK(!pixmap_); |
| 84 | 86 |
| 85 bool result = true; | 87 bool result = true; |
| 86 if (pixmap->GetEGLClientBuffer()) { | 88 if (pixmap->GetEGLClientBuffer()) { |
| 87 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; | 89 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; |
| 88 result = GLImageEGL::Initialize(EGL_NATIVE_PIXMAP_KHR, | 90 result = GLImageEGL::Initialize(shared_memory_id, EGL_NATIVE_PIXMAP_KHR, |
| 89 pixmap->GetEGLClientBuffer(), attrs); | 91 pixmap->GetEGLClientBuffer(), attrs); |
| 90 } else if (pixmap->GetDmaBufFd() >= 0) { | 92 } else if (pixmap->GetDmaBufFd() >= 0) { |
| 91 if (!ValidInternalFormat(internalformat_)) { | 93 if (!ValidInternalFormat(internalformat_)) { |
| 92 LOG(ERROR) << "Invalid internalformat: " << internalformat_; | 94 LOG(ERROR) << "Invalid internalformat: " << internalformat_; |
| 93 return false; | 95 return false; |
| 94 } | 96 } |
| 95 | 97 |
| 96 if (!ValidFormat(format)) { | 98 if (!ValidFormat(format)) { |
| 97 LOG(ERROR) << "Invalid format: " << static_cast<int>(format); | 99 LOG(ERROR) << "Invalid format: " << static_cast<int>(format); |
| 98 return false; | 100 return false; |
| 99 } | 101 } |
| 100 | 102 |
| 101 // Note: If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT | 103 // Note: If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT |
| 102 // target, the EGL will take a reference to the dma_buf. | 104 // target, the EGL will take a reference to the dma_buf. |
| 103 EGLint attrs[] = {EGL_WIDTH, | 105 EGLint attrs[] = {EGL_WIDTH, |
| 104 size_.width(), | 106 size_.width(), |
| 105 EGL_HEIGHT, | 107 EGL_HEIGHT, |
| 106 size_.height(), | 108 size_.height(), |
| 107 EGL_LINUX_DRM_FOURCC_EXT, | 109 EGL_LINUX_DRM_FOURCC_EXT, |
| 108 FourCC(format), | 110 FourCC(format), |
| 109 EGL_DMA_BUF_PLANE0_FD_EXT, | 111 EGL_DMA_BUF_PLANE0_FD_EXT, |
| 110 pixmap->GetDmaBufFd(), | 112 pixmap->GetDmaBufFd(), |
| 111 EGL_DMA_BUF_PLANE0_OFFSET_EXT, | 113 EGL_DMA_BUF_PLANE0_OFFSET_EXT, |
| 112 0, | 114 0, |
| 113 EGL_DMA_BUF_PLANE0_PITCH_EXT, | 115 EGL_DMA_BUF_PLANE0_PITCH_EXT, |
| 114 pixmap->GetDmaBufPitch(), | 116 pixmap->GetDmaBufPitch(), |
| 115 EGL_NONE}; | 117 EGL_NONE}; |
| 116 result = GLImageEGL::Initialize( | 118 result = |
| 117 EGL_LINUX_DMA_BUF_EXT, static_cast<EGLClientBuffer>(nullptr), attrs); | 119 GLImageEGL::Initialize(shared_memory_id, EGL_LINUX_DMA_BUF_EXT, |
| 120 static_cast<EGLClientBuffer>(nullptr), attrs); |
| 118 } | 121 } |
| 119 | 122 |
| 120 if (result) | 123 if (result) |
| 121 pixmap_ = pixmap; | 124 pixmap_ = pixmap; |
| 122 return result; | 125 return result; |
| 123 } | 126 } |
| 124 | 127 |
| 125 unsigned GLImageOzoneNativePixmap::GetInternalFormat() { | 128 unsigned GLImageOzoneNativePixmap::GetInternalFormat() { |
| 126 return internalformat_; | 129 return internalformat_; |
| 127 } | 130 } |
| 128 | 131 |
| 129 void GLImageOzoneNativePixmap::Destroy(bool have_context) { | 132 void GLImageOzoneNativePixmap::Destroy(bool have_context) { |
| 130 GLImageEGL::Destroy(have_context); | 133 GLImageEGL::Destroy(have_context); |
| 131 pixmap_ = nullptr; | 134 pixmap_ = nullptr; |
| 132 } | 135 } |
| 133 | 136 |
| 134 bool GLImageOzoneNativePixmap::ScheduleOverlayPlane(AcceleratedWidget widget, | 137 bool GLImageOzoneNativePixmap::ScheduleOverlayPlane(AcceleratedWidget widget, |
| 135 int z_order, | 138 int z_order, |
| 136 OverlayTransform transform, | 139 OverlayTransform transform, |
| 137 const Rect& bounds_rect, | 140 const Rect& bounds_rect, |
| 138 const RectF& crop_rect) { | 141 const RectF& crop_rect) { |
| 139 DCHECK(pixmap_); | 142 DCHECK(pixmap_); |
| 140 return pixmap_->ScheduleOverlayPlane(widget, z_order, transform, bounds_rect, | 143 return pixmap_->ScheduleOverlayPlane(widget, z_order, transform, bounds_rect, |
| 141 crop_rect); | 144 crop_rect); |
| 142 } | 145 } |
| 143 | 146 |
| 144 } // namespace gfx | 147 } // namespace gfx |
| OLD | NEW |