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/gfx/buffer_format_util.h" | 5 #include "ui/gfx/buffer_format_util.h" |
6 #include "ui/gl/gl_image_ozone_native_pixmap.h" | 6 #include "ui/gl/gl_image_ozone_native_pixmap.h" |
7 | 7 |
8 #define FOURCC(a, b, c, d) \ | 8 #define FOURCC(a, b, c, d) \ |
9 ((static_cast<uint32_t>(a)) | (static_cast<uint32_t>(b) << 8) | \ | 9 ((static_cast<uint32_t>(a)) | (static_cast<uint32_t>(b) << 8) | \ |
10 (static_cast<uint32_t>(c) << 16) | (static_cast<uint32_t>(d) << 24)) | 10 (static_cast<uint32_t>(c) << 16) | (static_cast<uint32_t>(d) << 24)) |
11 | 11 |
12 #define DRM_FORMAT_R8 FOURCC('R', '8', ' ', ' ') | 12 #define DRM_FORMAT_R8 FOURCC('R', '8', ' ', ' ') |
13 #define DRM_FORMAT_RGB565 FOURCC('R', 'G', '1', '6') | 13 #define DRM_FORMAT_RGB565 FOURCC('R', 'G', '1', '6') |
14 #define DRM_FORMAT_ARGB8888 FOURCC('A', 'R', '2', '4') | 14 #define DRM_FORMAT_ARGB8888 FOURCC('A', 'R', '2', '4') |
15 #define DRM_FORMAT_ABGR8888 FOURCC('A', 'B', '2', '4') | 15 #define DRM_FORMAT_ABGR8888 FOURCC('A', 'B', '2', '4') |
16 #define DRM_FORMAT_XRGB8888 FOURCC('X', 'R', '2', '4') | 16 #define DRM_FORMAT_XRGB8888 FOURCC('X', 'R', '2', '4') |
17 #define DRM_FORMAT_XBGR8888 FOURCC('X', 'B', '2', '4') | 17 #define DRM_FORMAT_XBGR8888 FOURCC('X', 'B', '2', '4') |
18 | 18 |
19 namespace gfx { | 19 namespace gl { |
20 namespace { | 20 namespace { |
21 | 21 |
22 bool ValidInternalFormat(unsigned internalformat) { | 22 bool ValidInternalFormat(unsigned internalformat) { |
23 switch (internalformat) { | 23 switch (internalformat) { |
24 case GL_RGB: | 24 case GL_RGB: |
25 case GL_RGBA: | 25 case GL_RGBA: |
26 case GL_BGRA_EXT: | 26 case GL_BGRA_EXT: |
27 case GL_RED_EXT: | 27 case GL_RED_EXT: |
28 return true; | 28 return true; |
29 default: | 29 default: |
30 return false; | 30 return false; |
31 } | 31 } |
32 } | 32 } |
33 | 33 |
34 bool ValidFormat(BufferFormat format) { | 34 bool ValidFormat(gfx::BufferFormat format) { |
35 switch (format) { | 35 switch (format) { |
36 case BufferFormat::R_8: | 36 case gfx::BufferFormat::R_8: |
37 case BufferFormat::BGR_565: | 37 case gfx::BufferFormat::BGR_565: |
38 case BufferFormat::RGBA_8888: | 38 case gfx::BufferFormat::RGBA_8888: |
39 case BufferFormat::RGBX_8888: | 39 case gfx::BufferFormat::RGBX_8888: |
40 case BufferFormat::BGRA_8888: | 40 case gfx::BufferFormat::BGRA_8888: |
41 case BufferFormat::BGRX_8888: | 41 case gfx::BufferFormat::BGRX_8888: |
42 return true; | 42 return true; |
43 case BufferFormat::ATC: | 43 case gfx::BufferFormat::ATC: |
44 case BufferFormat::ATCIA: | 44 case gfx::BufferFormat::ATCIA: |
45 case BufferFormat::DXT1: | 45 case gfx::BufferFormat::DXT1: |
46 case BufferFormat::DXT5: | 46 case gfx::BufferFormat::DXT5: |
47 case BufferFormat::ETC1: | 47 case gfx::BufferFormat::ETC1: |
48 case BufferFormat::RGBA_4444: | 48 case gfx::BufferFormat::RGBA_4444: |
49 case BufferFormat::YUV_420: | 49 case gfx::BufferFormat::YUV_420: |
50 case BufferFormat::YUV_420_BIPLANAR: | 50 case gfx::BufferFormat::YUV_420_BIPLANAR: |
51 case BufferFormat::UYVY_422: | 51 case gfx::BufferFormat::UYVY_422: |
52 return false; | 52 return false; |
53 } | 53 } |
54 | 54 |
55 NOTREACHED(); | 55 NOTREACHED(); |
56 return false; | 56 return false; |
57 } | 57 } |
58 | 58 |
59 EGLint FourCC(BufferFormat format) { | 59 EGLint FourCC(gfx::BufferFormat format) { |
60 switch (format) { | 60 switch (format) { |
61 case BufferFormat::R_8: | 61 case gfx::BufferFormat::R_8: |
62 return DRM_FORMAT_R8; | 62 return DRM_FORMAT_R8; |
63 case BufferFormat::BGR_565: | 63 case gfx::BufferFormat::BGR_565: |
64 return DRM_FORMAT_RGB565; | 64 return DRM_FORMAT_RGB565; |
65 case BufferFormat::RGBA_8888: | 65 case gfx::BufferFormat::RGBA_8888: |
66 return DRM_FORMAT_ABGR8888; | 66 return DRM_FORMAT_ABGR8888; |
67 case BufferFormat::RGBX_8888: | 67 case gfx::BufferFormat::RGBX_8888: |
68 return DRM_FORMAT_XBGR8888; | 68 return DRM_FORMAT_XBGR8888; |
69 case BufferFormat::BGRA_8888: | 69 case gfx::BufferFormat::BGRA_8888: |
70 return DRM_FORMAT_ARGB8888; | 70 return DRM_FORMAT_ARGB8888; |
71 case BufferFormat::BGRX_8888: | 71 case gfx::BufferFormat::BGRX_8888: |
72 return DRM_FORMAT_XRGB8888; | 72 return DRM_FORMAT_XRGB8888; |
73 case BufferFormat::ATC: | 73 case gfx::BufferFormat::ATC: |
74 case BufferFormat::ATCIA: | 74 case gfx::BufferFormat::ATCIA: |
75 case BufferFormat::DXT1: | 75 case gfx::BufferFormat::DXT1: |
76 case BufferFormat::DXT5: | 76 case gfx::BufferFormat::DXT5: |
77 case BufferFormat::ETC1: | 77 case gfx::BufferFormat::ETC1: |
78 case BufferFormat::RGBA_4444: | 78 case gfx::BufferFormat::RGBA_4444: |
79 case BufferFormat::YUV_420: | 79 case gfx::BufferFormat::YUV_420: |
80 case BufferFormat::YUV_420_BIPLANAR: | 80 case gfx::BufferFormat::YUV_420_BIPLANAR: |
81 case BufferFormat::UYVY_422: | 81 case gfx::BufferFormat::UYVY_422: |
82 NOTREACHED(); | 82 NOTREACHED(); |
83 return 0; | 83 return 0; |
84 } | 84 } |
85 | 85 |
86 NOTREACHED(); | 86 NOTREACHED(); |
87 return 0; | 87 return 0; |
88 } | 88 } |
89 | 89 |
90 } // namespace | 90 } // namespace |
91 | 91 |
92 GLImageOzoneNativePixmap::GLImageOzoneNativePixmap(const Size& size, | 92 GLImageOzoneNativePixmap::GLImageOzoneNativePixmap(const gfx::Size& size, |
93 unsigned internalformat) | 93 unsigned internalformat) |
94 : gl::GLImageEGL(size), internalformat_(internalformat) {} | 94 : gl::GLImageEGL(size), internalformat_(internalformat) {} |
95 | 95 |
96 GLImageOzoneNativePixmap::~GLImageOzoneNativePixmap() { | 96 GLImageOzoneNativePixmap::~GLImageOzoneNativePixmap() { |
97 } | 97 } |
98 | 98 |
99 bool GLImageOzoneNativePixmap::Initialize(ui::NativePixmap* pixmap, | 99 bool GLImageOzoneNativePixmap::Initialize(ui::NativePixmap* pixmap, |
100 BufferFormat format) { | 100 gfx::BufferFormat format) { |
101 DCHECK(!pixmap_); | 101 DCHECK(!pixmap_); |
102 if (pixmap->GetEGLClientBuffer()) { | 102 if (pixmap->GetEGLClientBuffer()) { |
103 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; | 103 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; |
104 if (!gl::GLImageEGL::Initialize(EGL_NATIVE_PIXMAP_KHR, | 104 if (!gl::GLImageEGL::Initialize(EGL_NATIVE_PIXMAP_KHR, |
105 pixmap->GetEGLClientBuffer(), attrs)) { | 105 pixmap->GetEGLClientBuffer(), attrs)) { |
106 return false; | 106 return false; |
107 } | 107 } |
108 } else if (pixmap->AreDmaBufFdsValid()) { | 108 } else if (pixmap->AreDmaBufFdsValid()) { |
109 if (!ValidInternalFormat(internalformat_)) { | 109 if (!ValidInternalFormat(internalformat_)) { |
110 LOG(ERROR) << "Invalid internalformat: " << internalformat_; | 110 LOG(ERROR) << "Invalid internalformat: " << internalformat_; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 // don't draw with uninitialized texture. | 163 // don't draw with uninitialized texture. |
164 std::vector<unsigned char> data(size_.width() * size_.height() * 4); | 164 std::vector<unsigned char> data(size_.width() * size_.height() * 4); |
165 glTexImage2D(target, 0, GL_RGBA, size_.width(), | 165 glTexImage2D(target, 0, GL_RGBA, size_.width(), |
166 size_.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, | 166 size_.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, |
167 data.data()); | 167 data.data()); |
168 return true; | 168 return true; |
169 } | 169 } |
170 return GLImageEGL::CopyTexImage(target); | 170 return GLImageEGL::CopyTexImage(target); |
171 } | 171 } |
172 | 172 |
173 bool GLImageOzoneNativePixmap::ScheduleOverlayPlane(AcceleratedWidget widget, | 173 bool GLImageOzoneNativePixmap::ScheduleOverlayPlane( |
174 int z_order, | 174 gfx::AcceleratedWidget widget, |
175 OverlayTransform transform, | 175 int z_order, |
176 const Rect& bounds_rect, | 176 gfx::OverlayTransform transform, |
177 const RectF& crop_rect) { | 177 const gfx::Rect& bounds_rect, |
| 178 const gfx::RectF& crop_rect) { |
178 DCHECK(pixmap_); | 179 DCHECK(pixmap_); |
179 return pixmap_->ScheduleOverlayPlane(widget, z_order, transform, bounds_rect, | 180 return pixmap_->ScheduleOverlayPlane(widget, z_order, transform, bounds_rect, |
180 crop_rect); | 181 crop_rect); |
181 } | 182 } |
182 | 183 |
183 void GLImageOzoneNativePixmap::OnMemoryDump( | 184 void GLImageOzoneNativePixmap::OnMemoryDump( |
184 base::trace_event::ProcessMemoryDump* pmd, | 185 base::trace_event::ProcessMemoryDump* pmd, |
185 uint64_t process_tracing_id, | 186 uint64_t process_tracing_id, |
186 const std::string& dump_name) { | 187 const std::string& dump_name) { |
187 // TODO(ericrk): Implement GLImage OnMemoryDump. crbug.com/514914 | 188 // TODO(ericrk): Implement GLImage OnMemoryDump. crbug.com/514914 |
188 } | 189 } |
189 | 190 |
190 } // namespace gfx | 191 } // namespace gl |
OLD | NEW |