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 |
11 #define DRM_FORMAT_ARGB8888 FOURCC('A', 'R', '2', '4') | 11 #define DRM_FORMAT_ARGB8888 FOURCC('A', 'R', '2', '4') |
12 #define DRM_FORMAT_XRGB8888 FOURCC('X', 'R', '2', '4') | 12 #define DRM_FORMAT_XRGB8888 FOURCC('X', 'R', '2', '4') |
13 | 13 |
14 namespace gfx { | 14 namespace gfx { |
15 namespace { | 15 namespace { |
16 | 16 |
17 bool ValidInternalFormat(unsigned internalformat) { | 17 bool ValidInternalFormat(unsigned internalformat) { |
18 switch (internalformat) { | 18 switch (internalformat) { |
19 case GL_RGB: | 19 case GL_RGB: |
20 case GL_BGRA_EXT: | 20 case GL_BGRA_EXT: |
21 return true; | 21 return true; |
22 default: | 22 default: |
23 return false; | 23 return false; |
24 } | 24 } |
25 } | 25 } |
26 | 26 |
27 bool ValidFormat(gfx::GpuMemoryBuffer::Format format) { | 27 bool ValidFormat(gfx::BufferFormat format) { |
28 switch (format) { | 28 switch (format) { |
29 case GpuMemoryBuffer::BGRA_8888: | 29 case BufferFormat::BGRA_8888: |
30 case GpuMemoryBuffer::RGBX_8888: | 30 case BufferFormat::RGBX_8888: |
31 return true; | 31 return true; |
32 case GpuMemoryBuffer::ATC: | 32 case BufferFormat::ATC: |
33 case GpuMemoryBuffer::ATCIA: | 33 case BufferFormat::ATCIA: |
34 case GpuMemoryBuffer::DXT1: | 34 case BufferFormat::DXT1: |
35 case GpuMemoryBuffer::DXT5: | 35 case BufferFormat::DXT5: |
36 case GpuMemoryBuffer::ETC1: | 36 case BufferFormat::ETC1: |
37 case GpuMemoryBuffer::R_8: | 37 case BufferFormat::R_8: |
38 case GpuMemoryBuffer::RGBA_4444: | 38 case BufferFormat::RGBA_4444: |
39 case GpuMemoryBuffer::RGBA_8888: | 39 case BufferFormat::RGBA_8888: |
40 case GpuMemoryBuffer::YUV_420: | 40 case BufferFormat::YUV_420: |
41 return false; | 41 return false; |
42 } | 42 } |
43 | 43 |
44 NOTREACHED(); | 44 NOTREACHED(); |
45 return false; | 45 return false; |
46 } | 46 } |
47 | 47 |
48 EGLint FourCC(gfx::GpuMemoryBuffer::Format format) { | 48 EGLint FourCC(gfx::BufferFormat format) { |
49 switch (format) { | 49 switch (format) { |
50 case GpuMemoryBuffer::BGRA_8888: | 50 case BufferFormat::BGRA_8888: |
51 return DRM_FORMAT_ARGB8888; | 51 return DRM_FORMAT_ARGB8888; |
52 case GpuMemoryBuffer::RGBX_8888: | 52 case BufferFormat::RGBX_8888: |
53 return DRM_FORMAT_XRGB8888; | 53 return DRM_FORMAT_XRGB8888; |
54 case GpuMemoryBuffer::ATC: | 54 case BufferFormat::ATC: |
55 case GpuMemoryBuffer::ATCIA: | 55 case BufferFormat::ATCIA: |
56 case GpuMemoryBuffer::DXT1: | 56 case BufferFormat::DXT1: |
57 case GpuMemoryBuffer::DXT5: | 57 case BufferFormat::DXT5: |
58 case GpuMemoryBuffer::ETC1: | 58 case BufferFormat::ETC1: |
59 case GpuMemoryBuffer::R_8: | 59 case BufferFormat::R_8: |
60 case GpuMemoryBuffer::RGBA_4444: | 60 case BufferFormat::RGBA_4444: |
61 case GpuMemoryBuffer::RGBA_8888: | 61 case BufferFormat::RGBA_8888: |
62 case GpuMemoryBuffer::YUV_420: | 62 case BufferFormat::YUV_420: |
63 NOTREACHED(); | 63 NOTREACHED(); |
64 return 0; | 64 return 0; |
65 } | 65 } |
66 | 66 |
67 NOTREACHED(); | 67 NOTREACHED(); |
68 return 0; | 68 return 0; |
69 } | 69 } |
70 | 70 |
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(ui::NativePixmap* pixmap, |
82 GpuMemoryBuffer::Format format) { | 82 BufferFormat format) { |
83 DCHECK(!pixmap_); | 83 DCHECK(!pixmap_); |
84 | 84 |
85 bool result = true; | 85 bool result = true; |
86 if (pixmap->GetEGLClientBuffer()) { | 86 if (pixmap->GetEGLClientBuffer()) { |
87 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; | 87 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; |
88 result = GLImageEGL::Initialize(EGL_NATIVE_PIXMAP_KHR, | 88 result = GLImageEGL::Initialize(EGL_NATIVE_PIXMAP_KHR, |
89 pixmap->GetEGLClientBuffer(), attrs); | 89 pixmap->GetEGLClientBuffer(), attrs); |
90 } else if (pixmap->GetDmaBufFd() >= 0) { | 90 } else if (pixmap->GetDmaBufFd() >= 0) { |
91 if (!ValidInternalFormat(internalformat_)) { | 91 if (!ValidInternalFormat(internalformat_)) { |
92 LOG(ERROR) << "Invalid internalformat: " << internalformat_; | 92 LOG(ERROR) << "Invalid internalformat: " << internalformat_; |
93 return false; | 93 return false; |
94 } | 94 } |
95 | 95 |
96 if (!ValidFormat(format)) { | 96 if (!ValidFormat(format)) { |
97 LOG(ERROR) << "Invalid format: " << format; | 97 LOG(ERROR) << "Invalid format: " << static_cast<int>(format); |
98 return false; | 98 return false; |
99 } | 99 } |
100 | 100 |
101 // Note: If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT | 101 // Note: If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT |
102 // target, the EGL will take a reference to the dma_buf. | 102 // target, the EGL will take a reference to the dma_buf. |
103 EGLint attrs[] = {EGL_WIDTH, | 103 EGLint attrs[] = {EGL_WIDTH, |
104 size_.width(), | 104 size_.width(), |
105 EGL_HEIGHT, | 105 EGL_HEIGHT, |
106 size_.height(), | 106 size_.height(), |
107 EGL_LINUX_DRM_FOURCC_EXT, | 107 EGL_LINUX_DRM_FOURCC_EXT, |
(...skipping 27 matching lines...) Expand all Loading... |
135 int z_order, | 135 int z_order, |
136 OverlayTransform transform, | 136 OverlayTransform transform, |
137 const Rect& bounds_rect, | 137 const Rect& bounds_rect, |
138 const RectF& crop_rect) { | 138 const RectF& crop_rect) { |
139 DCHECK(pixmap_); | 139 DCHECK(pixmap_); |
140 return pixmap_->ScheduleOverlayPlane(widget, z_order, transform, bounds_rect, | 140 return pixmap_->ScheduleOverlayPlane(widget, z_order, transform, bounds_rect, |
141 crop_rect); | 141 crop_rect); |
142 } | 142 } |
143 | 143 |
144 } // namespace gfx | 144 } // namespace gfx |
OLD | NEW |