OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_memory.h" | 5 #include "ui/gl/gl_image_memory.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/trace_event/trace_event.h" | 8 #include "base/trace_event/trace_event.h" |
9 #include "ui/gl/gl_bindings.h" | 9 #include "ui/gl/gl_bindings.h" |
10 #include "ui/gl/scoped_binders.h" | 10 #include "ui/gl/scoped_binders.h" |
11 | 11 |
12 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ | 12 #if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID) || \ |
13 defined(USE_OZONE) | 13 defined(USE_OZONE) |
14 #include "ui/gl/gl_surface_egl.h" | 14 #include "ui/gl/gl_surface_egl.h" |
15 #endif | 15 #endif |
16 | 16 |
17 namespace gfx { | 17 namespace gfx { |
18 namespace { | 18 namespace { |
19 | 19 |
20 bool ValidInternalFormat(unsigned internalformat) { | 20 bool ValidInternalFormat(unsigned internalformat) { |
21 switch (internalformat) { | 21 switch (internalformat) { |
| 22 case GL_R8: |
22 case GL_RGBA: | 23 case GL_RGBA: |
23 case GL_BGRA_EXT: | 24 case GL_BGRA_EXT: |
24 return true; | 25 return true; |
25 default: | 26 default: |
26 return false; | 27 return false; |
27 } | 28 } |
28 } | 29 } |
29 | 30 |
30 bool ValidFormat(gfx::GpuMemoryBuffer::Format format) { | 31 bool ValidFormat(gfx::GpuMemoryBuffer::Format format) { |
31 switch (format) { | 32 switch (format) { |
32 case gfx::GpuMemoryBuffer::ATC: | 33 case gfx::GpuMemoryBuffer::ATC: |
33 case gfx::GpuMemoryBuffer::ATCIA: | 34 case gfx::GpuMemoryBuffer::ATCIA: |
34 case gfx::GpuMemoryBuffer::DXT1: | 35 case gfx::GpuMemoryBuffer::DXT1: |
35 case gfx::GpuMemoryBuffer::DXT5: | 36 case gfx::GpuMemoryBuffer::DXT5: |
36 case gfx::GpuMemoryBuffer::ETC1: | 37 case gfx::GpuMemoryBuffer::ETC1: |
| 38 case gfx::GpuMemoryBuffer::R_8: |
37 case gfx::GpuMemoryBuffer::RGBA_8888: | 39 case gfx::GpuMemoryBuffer::RGBA_8888: |
38 case gfx::GpuMemoryBuffer::BGRA_8888: | 40 case gfx::GpuMemoryBuffer::BGRA_8888: |
39 return true; | 41 return true; |
40 case gfx::GpuMemoryBuffer::RGBX_8888: | 42 case gfx::GpuMemoryBuffer::RGBX_8888: |
41 case gfx::GpuMemoryBuffer::YUV_420: | 43 case gfx::GpuMemoryBuffer::YUV_420: |
42 return false; | 44 return false; |
43 } | 45 } |
44 | 46 |
45 NOTREACHED(); | 47 NOTREACHED(); |
46 return false; | 48 return false; |
47 } | 49 } |
48 | 50 |
49 bool IsCompressedFormat(gfx::GpuMemoryBuffer::Format format) { | 51 bool IsCompressedFormat(gfx::GpuMemoryBuffer::Format format) { |
50 switch (format) { | 52 switch (format) { |
51 case gfx::GpuMemoryBuffer::ATC: | 53 case gfx::GpuMemoryBuffer::ATC: |
52 case gfx::GpuMemoryBuffer::ATCIA: | 54 case gfx::GpuMemoryBuffer::ATCIA: |
53 case gfx::GpuMemoryBuffer::DXT1: | 55 case gfx::GpuMemoryBuffer::DXT1: |
54 case gfx::GpuMemoryBuffer::DXT5: | 56 case gfx::GpuMemoryBuffer::DXT5: |
55 case gfx::GpuMemoryBuffer::ETC1: | 57 case gfx::GpuMemoryBuffer::ETC1: |
56 case gfx::GpuMemoryBuffer::YUV_420: | 58 case gfx::GpuMemoryBuffer::YUV_420: |
57 return true; | 59 return true; |
| 60 case gfx::GpuMemoryBuffer::R_8: |
58 case gfx::GpuMemoryBuffer::RGBA_8888: | 61 case gfx::GpuMemoryBuffer::RGBA_8888: |
59 case gfx::GpuMemoryBuffer::BGRA_8888: | 62 case gfx::GpuMemoryBuffer::BGRA_8888: |
60 case gfx::GpuMemoryBuffer::RGBX_8888: | 63 case gfx::GpuMemoryBuffer::RGBX_8888: |
61 return false; | 64 return false; |
62 } | 65 } |
63 | 66 |
64 NOTREACHED(); | 67 NOTREACHED(); |
65 return false; | 68 return false; |
66 } | 69 } |
67 | 70 |
68 GLenum TextureFormat(gfx::GpuMemoryBuffer::Format format) { | 71 GLenum TextureFormat(gfx::GpuMemoryBuffer::Format format) { |
69 switch (format) { | 72 switch (format) { |
70 case gfx::GpuMemoryBuffer::ATC: | 73 case gfx::GpuMemoryBuffer::ATC: |
71 return GL_ATC_RGB_AMD; | 74 return GL_ATC_RGB_AMD; |
72 case gfx::GpuMemoryBuffer::ATCIA: | 75 case gfx::GpuMemoryBuffer::ATCIA: |
73 return GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD; | 76 return GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD; |
74 case gfx::GpuMemoryBuffer::DXT1: | 77 case gfx::GpuMemoryBuffer::DXT1: |
75 return GL_COMPRESSED_RGB_S3TC_DXT1_EXT; | 78 return GL_COMPRESSED_RGB_S3TC_DXT1_EXT; |
76 case gfx::GpuMemoryBuffer::DXT5: | 79 case gfx::GpuMemoryBuffer::DXT5: |
77 return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; | 80 return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; |
78 case gfx::GpuMemoryBuffer::ETC1: | 81 case gfx::GpuMemoryBuffer::ETC1: |
79 return GL_ETC1_RGB8_OES; | 82 return GL_ETC1_RGB8_OES; |
| 83 case gfx::GpuMemoryBuffer::R_8: |
| 84 return GL_RED; |
80 case gfx::GpuMemoryBuffer::RGBA_8888: | 85 case gfx::GpuMemoryBuffer::RGBA_8888: |
81 return GL_RGBA; | 86 return GL_RGBA; |
82 case gfx::GpuMemoryBuffer::BGRA_8888: | 87 case gfx::GpuMemoryBuffer::BGRA_8888: |
83 return GL_BGRA_EXT; | 88 return GL_BGRA_EXT; |
84 case gfx::GpuMemoryBuffer::RGBX_8888: | 89 case gfx::GpuMemoryBuffer::RGBX_8888: |
85 case gfx::GpuMemoryBuffer::YUV_420: | 90 case gfx::GpuMemoryBuffer::YUV_420: |
86 NOTREACHED(); | 91 NOTREACHED(); |
87 return 0; | 92 return 0; |
88 } | 93 } |
89 | 94 |
90 NOTREACHED(); | 95 NOTREACHED(); |
91 return 0; | 96 return 0; |
92 } | 97 } |
93 | 98 |
94 GLenum DataFormat(gfx::GpuMemoryBuffer::Format format) { | 99 GLenum DataFormat(gfx::GpuMemoryBuffer::Format format) { |
95 return TextureFormat(format); | 100 return TextureFormat(format); |
96 } | 101 } |
97 | 102 |
98 GLenum DataType(gfx::GpuMemoryBuffer::Format format) { | 103 GLenum DataType(gfx::GpuMemoryBuffer::Format format) { |
99 switch (format) { | 104 switch (format) { |
100 case gfx::GpuMemoryBuffer::RGBA_8888: | 105 case gfx::GpuMemoryBuffer::RGBA_8888: |
101 case gfx::GpuMemoryBuffer::BGRA_8888: | 106 case gfx::GpuMemoryBuffer::BGRA_8888: |
| 107 case gfx::GpuMemoryBuffer::R_8: |
102 return GL_UNSIGNED_BYTE; | 108 return GL_UNSIGNED_BYTE; |
103 case gfx::GpuMemoryBuffer::ATC: | 109 case gfx::GpuMemoryBuffer::ATC: |
104 case gfx::GpuMemoryBuffer::ATCIA: | 110 case gfx::GpuMemoryBuffer::ATCIA: |
105 case gfx::GpuMemoryBuffer::DXT1: | 111 case gfx::GpuMemoryBuffer::DXT1: |
106 case gfx::GpuMemoryBuffer::DXT5: | 112 case gfx::GpuMemoryBuffer::DXT5: |
107 case gfx::GpuMemoryBuffer::ETC1: | 113 case gfx::GpuMemoryBuffer::ETC1: |
108 case gfx::GpuMemoryBuffer::RGBX_8888: | 114 case gfx::GpuMemoryBuffer::RGBX_8888: |
109 case gfx::GpuMemoryBuffer::YUV_420: | 115 case gfx::GpuMemoryBuffer::YUV_420: |
110 NOTREACHED(); | 116 NOTREACHED(); |
111 return 0; | 117 return 0; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 defined(USE_OZONE) | 154 defined(USE_OZONE) |
149 DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_); | 155 DCHECK_EQ(EGL_NO_IMAGE_KHR, egl_image_); |
150 DCHECK_EQ(0u, egl_texture_id_); | 156 DCHECK_EQ(0u, egl_texture_id_); |
151 #endif | 157 #endif |
152 } | 158 } |
153 | 159 |
154 // static | 160 // static |
155 bool GLImageMemory::StrideInBytes(size_t width, | 161 bool GLImageMemory::StrideInBytes(size_t width, |
156 gfx::GpuMemoryBuffer::Format format, | 162 gfx::GpuMemoryBuffer::Format format, |
157 size_t* stride_in_bytes) { | 163 size_t* stride_in_bytes) { |
158 base::CheckedNumeric<size_t> s = width; | 164 base::CheckedNumeric<size_t> checked_stride = width; |
159 switch (format) { | 165 switch (format) { |
160 case gfx::GpuMemoryBuffer::ATC: | |
161 case gfx::GpuMemoryBuffer::DXT1: | |
162 case gfx::GpuMemoryBuffer::ETC1: | |
163 DCHECK_EQ(width % 2, 0U); | |
164 s /= 2; | |
165 if (!s.IsValid()) | |
166 return false; | |
167 *stride_in_bytes = s.ValueOrDie(); | |
168 return true; | |
169 case gfx::GpuMemoryBuffer::ATCIA: | 166 case gfx::GpuMemoryBuffer::ATCIA: |
170 case gfx::GpuMemoryBuffer::DXT5: | 167 case gfx::GpuMemoryBuffer::DXT5: |
171 *stride_in_bytes = width; | 168 *stride_in_bytes = width; |
172 return true; | 169 return true; |
| 170 case gfx::GpuMemoryBuffer::ATC: |
| 171 case gfx::GpuMemoryBuffer::DXT1: |
| 172 case gfx::GpuMemoryBuffer::ETC1: |
| 173 DCHECK_EQ(width % 2, 0u); |
| 174 *stride_in_bytes = width / 2; |
| 175 return true; |
| 176 case gfx::GpuMemoryBuffer::R_8: |
| 177 checked_stride += 3; |
| 178 if (!checked_stride.IsValid()) |
| 179 return false; |
| 180 *stride_in_bytes = checked_stride.ValueOrDie() & ~0x3; |
| 181 return true; |
173 case gfx::GpuMemoryBuffer::RGBA_8888: | 182 case gfx::GpuMemoryBuffer::RGBA_8888: |
174 case gfx::GpuMemoryBuffer::BGRA_8888: | 183 case gfx::GpuMemoryBuffer::BGRA_8888: |
175 s *= 4; | 184 checked_stride *= 4; |
176 if (!s.IsValid()) | 185 if (!checked_stride.IsValid()) |
177 return false; | 186 return false; |
178 *stride_in_bytes = s.ValueOrDie(); | 187 *stride_in_bytes = checked_stride.ValueOrDie(); |
179 return true; | 188 return true; |
180 case gfx::GpuMemoryBuffer::RGBX_8888: | 189 case gfx::GpuMemoryBuffer::RGBX_8888: |
181 case gfx::GpuMemoryBuffer::YUV_420: | 190 case gfx::GpuMemoryBuffer::YUV_420: |
182 NOTREACHED(); | 191 NOTREACHED(); |
183 return false; | 192 return false; |
184 } | 193 } |
185 | 194 |
186 NOTREACHED(); | 195 NOTREACHED(); |
187 return false; | 196 return false; |
188 } | 197 } |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 } else { | 360 } else { |
352 ScopedTextureBinder texture_binder(GL_TEXTURE_2D, egl_texture_id_); | 361 ScopedTextureBinder texture_binder(GL_TEXTURE_2D, egl_texture_id_); |
353 | 362 |
354 if (IsCompressedFormat(format_)) { | 363 if (IsCompressedFormat(format_)) { |
355 glCompressedTexSubImage2D(GL_TEXTURE_2D, | 364 glCompressedTexSubImage2D(GL_TEXTURE_2D, |
356 0, // mip level | 365 0, // mip level |
357 0, // x-offset | 366 0, // x-offset |
358 0, // y-offset | 367 0, // y-offset |
359 size_.width(), size_.height(), | 368 size_.width(), size_.height(), |
360 DataFormat(format_), | 369 DataFormat(format_), |
361 SizeInBytes(size_, format_), | 370 SizeInBytes(size_, format_), memory_); |
362 memory_); | |
363 } else { | 371 } else { |
364 glTexSubImage2D(GL_TEXTURE_2D, | 372 glTexSubImage2D(GL_TEXTURE_2D, |
365 0, // mip level | 373 0, // mip level |
366 0, // x-offset | 374 0, // x-offset |
367 0, // y-offset | 375 0, // y-offset |
368 size_.width(), | 376 size_.width(), |
369 size_.height(), | 377 size_.height(), |
370 DataFormat(format_), | 378 DataFormat(format_), |
371 DataType(format_), | 379 DataType(format_), |
372 memory_); | 380 memory_); |
(...skipping 21 matching lines...) Expand all Loading... |
394 size_.width(), | 402 size_.width(), |
395 size_.height(), | 403 size_.height(), |
396 0, // border | 404 0, // border |
397 DataFormat(format_), | 405 DataFormat(format_), |
398 DataType(format_), | 406 DataType(format_), |
399 memory_); | 407 memory_); |
400 } | 408 } |
401 } | 409 } |
402 | 410 |
403 } // namespace gfx | 411 } // namespace gfx |
OLD | NEW |