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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 case GL_RED: | 29 case GL_RED: |
30 case GL_RGB: | 30 case GL_RGB: |
31 case GL_RGBA: | 31 case GL_RGBA: |
32 case GL_BGRA_EXT: | 32 case GL_BGRA_EXT: |
33 return true; | 33 return true; |
34 default: | 34 default: |
35 return false; | 35 return false; |
36 } | 36 } |
37 } | 37 } |
38 | 38 |
39 bool ValidFormat(BufferFormat format) { | 39 bool ValidFormat(gfx::BufferFormat format) { |
40 switch (format) { | 40 switch (format) { |
41 case BufferFormat::ATC: | 41 case gfx::BufferFormat::ATC: |
42 case BufferFormat::ATCIA: | 42 case gfx::BufferFormat::ATCIA: |
43 case BufferFormat::DXT1: | 43 case gfx::BufferFormat::DXT1: |
44 case BufferFormat::DXT5: | 44 case gfx::BufferFormat::DXT5: |
45 case BufferFormat::ETC1: | 45 case gfx::BufferFormat::ETC1: |
46 case BufferFormat::R_8: | 46 case gfx::BufferFormat::R_8: |
47 case BufferFormat::BGR_565: | 47 case gfx::BufferFormat::BGR_565: |
48 case BufferFormat::RGBA_4444: | 48 case gfx::BufferFormat::RGBA_4444: |
49 case BufferFormat::RGBX_8888: | 49 case gfx::BufferFormat::RGBX_8888: |
50 case BufferFormat::RGBA_8888: | 50 case gfx::BufferFormat::RGBA_8888: |
51 case BufferFormat::BGRX_8888: | 51 case gfx::BufferFormat::BGRX_8888: |
52 case BufferFormat::BGRA_8888: | 52 case gfx::BufferFormat::BGRA_8888: |
53 return true; | 53 return true; |
54 case BufferFormat::YUV_420: | 54 case gfx::BufferFormat::YUV_420: |
55 case BufferFormat::YUV_420_BIPLANAR: | 55 case gfx::BufferFormat::YUV_420_BIPLANAR: |
56 case BufferFormat::UYVY_422: | 56 case gfx::BufferFormat::UYVY_422: |
57 return false; | 57 return false; |
58 } | 58 } |
59 | 59 |
60 NOTREACHED(); | 60 NOTREACHED(); |
61 return false; | 61 return false; |
62 } | 62 } |
63 | 63 |
64 bool IsCompressedFormat(BufferFormat format) { | 64 bool IsCompressedFormat(gfx::BufferFormat format) { |
65 switch (format) { | 65 switch (format) { |
66 case BufferFormat::ATC: | 66 case gfx::BufferFormat::ATC: |
67 case BufferFormat::ATCIA: | 67 case gfx::BufferFormat::ATCIA: |
68 case BufferFormat::DXT1: | 68 case gfx::BufferFormat::DXT1: |
69 case BufferFormat::DXT5: | 69 case gfx::BufferFormat::DXT5: |
70 case BufferFormat::ETC1: | 70 case gfx::BufferFormat::ETC1: |
71 return true; | 71 return true; |
72 case BufferFormat::R_8: | 72 case gfx::BufferFormat::R_8: |
73 case BufferFormat::BGR_565: | 73 case gfx::BufferFormat::BGR_565: |
74 case BufferFormat::RGBA_4444: | 74 case gfx::BufferFormat::RGBA_4444: |
75 case BufferFormat::RGBX_8888: | 75 case gfx::BufferFormat::RGBX_8888: |
76 case BufferFormat::RGBA_8888: | 76 case gfx::BufferFormat::RGBA_8888: |
77 case BufferFormat::BGRX_8888: | 77 case gfx::BufferFormat::BGRX_8888: |
78 case BufferFormat::BGRA_8888: | 78 case gfx::BufferFormat::BGRA_8888: |
79 return false; | 79 return false; |
80 case BufferFormat::YUV_420: | 80 case gfx::BufferFormat::YUV_420: |
81 case BufferFormat::YUV_420_BIPLANAR: | 81 case gfx::BufferFormat::YUV_420_BIPLANAR: |
82 case BufferFormat::UYVY_422: | 82 case gfx::BufferFormat::UYVY_422: |
83 NOTREACHED(); | 83 NOTREACHED(); |
84 return false; | 84 return false; |
85 } | 85 } |
86 | 86 |
87 NOTREACHED(); | 87 NOTREACHED(); |
88 return false; | 88 return false; |
89 } | 89 } |
90 | 90 |
91 GLenum TextureFormat(BufferFormat format) { | 91 GLenum TextureFormat(gfx::BufferFormat format) { |
92 switch (format) { | 92 switch (format) { |
93 case BufferFormat::ATC: | 93 case gfx::BufferFormat::ATC: |
94 return GL_ATC_RGB_AMD; | 94 return GL_ATC_RGB_AMD; |
95 case BufferFormat::ATCIA: | 95 case gfx::BufferFormat::ATCIA: |
96 return GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD; | 96 return GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD; |
97 case BufferFormat::DXT1: | 97 case gfx::BufferFormat::DXT1: |
98 return GL_COMPRESSED_RGB_S3TC_DXT1_EXT; | 98 return GL_COMPRESSED_RGB_S3TC_DXT1_EXT; |
99 case BufferFormat::DXT5: | 99 case gfx::BufferFormat::DXT5: |
100 return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; | 100 return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; |
101 case BufferFormat::ETC1: | 101 case gfx::BufferFormat::ETC1: |
102 return GL_ETC1_RGB8_OES; | 102 return GL_ETC1_RGB8_OES; |
103 case BufferFormat::R_8: | 103 case gfx::BufferFormat::R_8: |
104 return GL_RED; | 104 return GL_RED; |
105 case BufferFormat::RGBA_4444: | 105 case gfx::BufferFormat::RGBA_4444: |
106 case BufferFormat::RGBA_8888: | 106 case gfx::BufferFormat::RGBA_8888: |
107 return GL_RGBA; | 107 return GL_RGBA; |
108 case BufferFormat::BGRA_8888: | 108 case gfx::BufferFormat::BGRA_8888: |
109 return GL_BGRA_EXT; | 109 return GL_BGRA_EXT; |
110 case BufferFormat::BGR_565: | 110 case gfx::BufferFormat::BGR_565: |
111 case BufferFormat::RGBX_8888: | 111 case gfx::BufferFormat::RGBX_8888: |
112 case BufferFormat::BGRX_8888: | 112 case gfx::BufferFormat::BGRX_8888: |
113 return GL_RGB; | 113 return GL_RGB; |
114 case BufferFormat::YUV_420: | 114 case gfx::BufferFormat::YUV_420: |
115 case BufferFormat::YUV_420_BIPLANAR: | 115 case gfx::BufferFormat::YUV_420_BIPLANAR: |
116 case BufferFormat::UYVY_422: | 116 case gfx::BufferFormat::UYVY_422: |
117 NOTREACHED(); | 117 NOTREACHED(); |
118 return 0; | 118 return 0; |
119 } | 119 } |
120 | 120 |
121 NOTREACHED(); | 121 NOTREACHED(); |
122 return 0; | 122 return 0; |
123 } | 123 } |
124 | 124 |
125 GLenum DataFormat(BufferFormat format) { | 125 GLenum DataFormat(gfx::BufferFormat format) { |
126 switch (format) { | 126 switch (format) { |
127 case BufferFormat::RGBX_8888: | 127 case gfx::BufferFormat::RGBX_8888: |
128 return GL_RGBA; | 128 return GL_RGBA; |
129 case BufferFormat::BGRX_8888: | 129 case gfx::BufferFormat::BGRX_8888: |
130 return GL_BGRA_EXT; | 130 return GL_BGRA_EXT; |
131 case BufferFormat::BGR_565: | 131 case gfx::BufferFormat::BGR_565: |
132 case BufferFormat::RGBA_4444: | 132 case gfx::BufferFormat::RGBA_4444: |
133 case BufferFormat::RGBA_8888: | 133 case gfx::BufferFormat::RGBA_8888: |
134 case BufferFormat::BGRA_8888: | 134 case gfx::BufferFormat::BGRA_8888: |
135 case BufferFormat::R_8: | 135 case gfx::BufferFormat::R_8: |
136 case BufferFormat::ATC: | 136 case gfx::BufferFormat::ATC: |
137 case BufferFormat::ATCIA: | 137 case gfx::BufferFormat::ATCIA: |
138 case BufferFormat::DXT1: | 138 case gfx::BufferFormat::DXT1: |
139 case BufferFormat::DXT5: | 139 case gfx::BufferFormat::DXT5: |
140 case BufferFormat::ETC1: | 140 case gfx::BufferFormat::ETC1: |
141 return TextureFormat(format); | 141 return TextureFormat(format); |
142 case BufferFormat::YUV_420: | 142 case gfx::BufferFormat::YUV_420: |
143 case BufferFormat::YUV_420_BIPLANAR: | 143 case gfx::BufferFormat::YUV_420_BIPLANAR: |
144 case BufferFormat::UYVY_422: | 144 case gfx::BufferFormat::UYVY_422: |
145 NOTREACHED(); | 145 NOTREACHED(); |
146 return 0; | 146 return 0; |
147 } | 147 } |
148 | 148 |
149 NOTREACHED(); | 149 NOTREACHED(); |
150 return 0; | 150 return 0; |
151 } | 151 } |
152 | 152 |
153 GLenum DataType(BufferFormat format) { | 153 GLenum DataType(gfx::BufferFormat format) { |
154 switch (format) { | 154 switch (format) { |
155 case BufferFormat::BGR_565: | 155 case gfx::BufferFormat::BGR_565: |
156 return GL_UNSIGNED_SHORT_5_6_5_REV; | 156 return GL_UNSIGNED_SHORT_5_6_5_REV; |
157 case BufferFormat::RGBA_4444: | 157 case gfx::BufferFormat::RGBA_4444: |
158 return GL_UNSIGNED_SHORT_4_4_4_4; | 158 return GL_UNSIGNED_SHORT_4_4_4_4; |
159 case BufferFormat::RGBX_8888: | 159 case gfx::BufferFormat::RGBX_8888: |
160 case BufferFormat::RGBA_8888: | 160 case gfx::BufferFormat::RGBA_8888: |
161 case BufferFormat::BGRX_8888: | 161 case gfx::BufferFormat::BGRX_8888: |
162 case BufferFormat::BGRA_8888: | 162 case gfx::BufferFormat::BGRA_8888: |
163 case BufferFormat::R_8: | 163 case gfx::BufferFormat::R_8: |
164 return GL_UNSIGNED_BYTE; | 164 return GL_UNSIGNED_BYTE; |
165 case BufferFormat::ATC: | 165 case gfx::BufferFormat::ATC: |
166 case BufferFormat::ATCIA: | 166 case gfx::BufferFormat::ATCIA: |
167 case BufferFormat::DXT1: | 167 case gfx::BufferFormat::DXT1: |
168 case BufferFormat::DXT5: | 168 case gfx::BufferFormat::DXT5: |
169 case BufferFormat::ETC1: | 169 case gfx::BufferFormat::ETC1: |
170 case BufferFormat::YUV_420: | 170 case gfx::BufferFormat::YUV_420: |
171 case BufferFormat::YUV_420_BIPLANAR: | 171 case gfx::BufferFormat::YUV_420_BIPLANAR: |
172 case BufferFormat::UYVY_422: | 172 case gfx::BufferFormat::UYVY_422: |
173 NOTREACHED(); | 173 NOTREACHED(); |
174 return 0; | 174 return 0; |
175 } | 175 } |
176 | 176 |
177 NOTREACHED(); | 177 NOTREACHED(); |
178 return 0; | 178 return 0; |
179 } | 179 } |
180 | 180 |
181 GLint DataRowLength(size_t stride, BufferFormat format) { | 181 GLint DataRowLength(size_t stride, gfx::BufferFormat format) { |
182 switch (format) { | 182 switch (format) { |
183 case BufferFormat::BGR_565: | 183 case gfx::BufferFormat::BGR_565: |
184 case BufferFormat::RGBA_4444: | 184 case gfx::BufferFormat::RGBA_4444: |
185 return base::checked_cast<GLint>(stride) / 2; | 185 return base::checked_cast<GLint>(stride) / 2; |
186 case BufferFormat::RGBX_8888: | 186 case gfx::BufferFormat::RGBX_8888: |
187 case BufferFormat::RGBA_8888: | 187 case gfx::BufferFormat::RGBA_8888: |
188 case BufferFormat::BGRX_8888: | 188 case gfx::BufferFormat::BGRX_8888: |
189 case BufferFormat::BGRA_8888: | 189 case gfx::BufferFormat::BGRA_8888: |
190 return base::checked_cast<GLint>(stride) / 4; | 190 return base::checked_cast<GLint>(stride) / 4; |
191 case BufferFormat::R_8: | 191 case gfx::BufferFormat::R_8: |
192 return base::checked_cast<GLint>(stride); | 192 return base::checked_cast<GLint>(stride); |
193 case BufferFormat::ATC: | 193 case gfx::BufferFormat::ATC: |
194 case BufferFormat::ATCIA: | 194 case gfx::BufferFormat::ATCIA: |
195 case BufferFormat::DXT1: | 195 case gfx::BufferFormat::DXT1: |
196 case BufferFormat::DXT5: | 196 case gfx::BufferFormat::DXT5: |
197 case BufferFormat::ETC1: | 197 case gfx::BufferFormat::ETC1: |
198 case BufferFormat::YUV_420: | 198 case gfx::BufferFormat::YUV_420: |
199 case BufferFormat::YUV_420_BIPLANAR: | 199 case gfx::BufferFormat::YUV_420_BIPLANAR: |
200 case BufferFormat::UYVY_422: | 200 case gfx::BufferFormat::UYVY_422: |
201 NOTREACHED(); | 201 NOTREACHED(); |
202 return 0; | 202 return 0; |
203 } | 203 } |
204 | 204 |
205 NOTREACHED(); | 205 NOTREACHED(); |
206 return 0; | 206 return 0; |
207 } | 207 } |
208 | 208 |
209 template <typename F> | 209 template <typename F> |
210 std::unique_ptr<uint8_t[]> GLES2RGBData(const gfx::Size& size, | 210 std::unique_ptr<uint8_t[]> GLES2RGBData(const gfx::Size& size, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 } | 262 } |
263 } | 263 } |
264 | 264 |
265 *data_format = GL_RGB; | 265 *data_format = GL_RGB; |
266 *data_type = GL_UNSIGNED_SHORT_5_6_5; | 266 *data_type = GL_UNSIGNED_SHORT_5_6_5; |
267 *data_row_length = size.width(); | 267 *data_row_length = size.width(); |
268 return gles2_rgb_data; | 268 return gles2_rgb_data; |
269 } | 269 } |
270 | 270 |
271 std::unique_ptr<uint8_t[]> GLES2Data(const gfx::Size& size, | 271 std::unique_ptr<uint8_t[]> GLES2Data(const gfx::Size& size, |
272 BufferFormat format, | 272 gfx::BufferFormat format, |
273 size_t stride, | 273 size_t stride, |
274 const uint8_t* data, | 274 const uint8_t* data, |
275 GLenum* data_format, | 275 GLenum* data_format, |
276 GLenum* data_type, | 276 GLenum* data_type, |
277 GLint* data_row_length) { | 277 GLint* data_row_length) { |
278 TRACE_EVENT2("gpu", "GLES2Data", "width", size.width(), "height", | 278 TRACE_EVENT2("gpu", "GLES2Data", "width", size.width(), "height", |
279 size.height()); | 279 size.height()); |
280 | 280 |
281 switch (format) { | 281 switch (format) { |
282 case BufferFormat::RGBX_8888: | 282 case gfx::BufferFormat::RGBX_8888: |
283 return GLES2RGBData(size, stride, data, | 283 return GLES2RGBData(size, stride, data, |
284 [](const uint8_t* src, uint8_t* dst) { | 284 [](const uint8_t* src, uint8_t* dst) { |
285 dst[0] = src[0]; | 285 dst[0] = src[0]; |
286 dst[1] = src[1]; | 286 dst[1] = src[1]; |
287 dst[2] = src[2]; | 287 dst[2] = src[2]; |
288 }, | 288 }, |
289 data_format, data_type, data_row_length); | 289 data_format, data_type, data_row_length); |
290 case BufferFormat::BGR_565: | 290 case gfx::BufferFormat::BGR_565: |
291 return GLES2RGB565Data(size, stride, data, data_format, data_type, | 291 return GLES2RGB565Data(size, stride, data, data_format, data_type, |
292 data_row_length); | 292 data_row_length); |
293 case BufferFormat::BGRX_8888: | 293 case gfx::BufferFormat::BGRX_8888: |
294 return GLES2RGBData(size, stride, data, | 294 return GLES2RGBData(size, stride, data, |
295 [](const uint8_t* src, uint8_t* dst) { | 295 [](const uint8_t* src, uint8_t* dst) { |
296 dst[0] = src[2]; | 296 dst[0] = src[2]; |
297 dst[1] = src[1]; | 297 dst[1] = src[1]; |
298 dst[2] = src[0]; | 298 dst[2] = src[0]; |
299 }, | 299 }, |
300 data_format, data_type, data_row_length); | 300 data_format, data_type, data_row_length); |
301 case BufferFormat::RGBA_4444: | 301 case gfx::BufferFormat::RGBA_4444: |
302 case BufferFormat::RGBA_8888: | 302 case gfx::BufferFormat::RGBA_8888: |
303 case BufferFormat::BGRA_8888: | 303 case gfx::BufferFormat::BGRA_8888: |
304 case BufferFormat::R_8: { | 304 case gfx::BufferFormat::R_8: { |
305 size_t gles2_data_stride = | 305 size_t gles2_data_stride = |
306 RowSizeForBufferFormat(size.width(), format, 0); | 306 RowSizeForBufferFormat(size.width(), format, 0); |
307 if (stride == gles2_data_stride || | 307 if (stride == gles2_data_stride || |
308 gfx::g_driver_gl.ext.b_GL_EXT_unpack_subimage) | 308 gl::g_driver_gl.ext.b_GL_EXT_unpack_subimage) |
309 return nullptr; // No data conversion needed | 309 return nullptr; // No data conversion needed |
310 | 310 |
311 std::unique_ptr<uint8_t[]> gles2_data( | 311 std::unique_ptr<uint8_t[]> gles2_data( |
312 new uint8_t[gles2_data_stride * size.height()]); | 312 new uint8_t[gles2_data_stride * size.height()]); |
313 for (int y = 0; y < size.height(); ++y) { | 313 for (int y = 0; y < size.height(); ++y) { |
314 memcpy(&gles2_data[y * gles2_data_stride], &data[y * stride], | 314 memcpy(&gles2_data[y * gles2_data_stride], &data[y * stride], |
315 gles2_data_stride); | 315 gles2_data_stride); |
316 } | 316 } |
317 *data_row_length = size.width(); | 317 *data_row_length = size.width(); |
318 return gles2_data; | 318 return gles2_data; |
319 } | 319 } |
320 case BufferFormat::ATC: | 320 case gfx::BufferFormat::ATC: |
321 case BufferFormat::ATCIA: | 321 case gfx::BufferFormat::ATCIA: |
322 case BufferFormat::DXT1: | 322 case gfx::BufferFormat::DXT1: |
323 case BufferFormat::DXT5: | 323 case gfx::BufferFormat::DXT5: |
324 case BufferFormat::ETC1: | 324 case gfx::BufferFormat::ETC1: |
325 return nullptr; // No data conversion needed | 325 return nullptr; // No data conversion needed |
326 case BufferFormat::YUV_420: | 326 case gfx::BufferFormat::YUV_420: |
327 case BufferFormat::YUV_420_BIPLANAR: | 327 case gfx::BufferFormat::YUV_420_BIPLANAR: |
328 case BufferFormat::UYVY_422: | 328 case gfx::BufferFormat::UYVY_422: |
329 NOTREACHED(); | 329 NOTREACHED(); |
330 return nullptr; | 330 return nullptr; |
331 } | 331 } |
332 | 332 |
333 NOTREACHED(); | 333 NOTREACHED(); |
334 return nullptr; | 334 return nullptr; |
335 } | 335 } |
336 | 336 |
337 } // namespace | 337 } // namespace |
338 | 338 |
339 GLImageMemory::GLImageMemory(const gfx::Size& size, unsigned internalformat) | 339 GLImageMemory::GLImageMemory(const gfx::Size& size, unsigned internalformat) |
340 : size_(size), | 340 : size_(size), |
341 internalformat_(internalformat), | 341 internalformat_(internalformat), |
342 memory_(nullptr), | 342 memory_(nullptr), |
343 format_(BufferFormat::RGBA_8888), | 343 format_(gfx::BufferFormat::RGBA_8888), |
344 stride_(0) {} | 344 stride_(0) {} |
345 | 345 |
346 GLImageMemory::~GLImageMemory() { | 346 GLImageMemory::~GLImageMemory() { |
347 DCHECK(!memory_); | 347 DCHECK(!memory_); |
348 } | 348 } |
349 | 349 |
350 bool GLImageMemory::Initialize(const unsigned char* memory, | 350 bool GLImageMemory::Initialize(const unsigned char* memory, |
351 BufferFormat format, | 351 gfx::BufferFormat format, |
352 size_t stride) { | 352 size_t stride) { |
353 if (!ValidInternalFormat(internalformat_)) { | 353 if (!ValidInternalFormat(internalformat_)) { |
354 LOG(ERROR) << "Invalid internalformat: " << internalformat_; | 354 LOG(ERROR) << "Invalid internalformat: " << internalformat_; |
355 return false; | 355 return false; |
356 } | 356 } |
357 | 357 |
358 if (!ValidFormat(format)) { | 358 if (!ValidFormat(format)) { |
359 LOG(ERROR) << "Invalid format: " << static_cast<int>(format); | 359 LOG(ERROR) << "Invalid format: " << static_cast<int>(format); |
360 return false; | 360 return false; |
361 } | 361 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 glCompressedTexImage2D( | 403 glCompressedTexImage2D( |
404 target, 0, TextureFormat(format_), size_.width(), size_.height(), 0, | 404 target, 0, TextureFormat(format_), size_.width(), size_.height(), 0, |
405 static_cast<GLsizei>(BufferSizeForBufferFormat(size_, format_)), | 405 static_cast<GLsizei>(BufferSizeForBufferFormat(size_, format_)), |
406 memory_); | 406 memory_); |
407 } else { | 407 } else { |
408 GLenum data_format = DataFormat(format_); | 408 GLenum data_format = DataFormat(format_); |
409 GLenum data_type = DataType(format_); | 409 GLenum data_type = DataType(format_); |
410 GLint data_row_length = DataRowLength(stride_, format_); | 410 GLint data_row_length = DataRowLength(stride_, format_); |
411 std::unique_ptr<uint8_t[]> gles2_data; | 411 std::unique_ptr<uint8_t[]> gles2_data; |
412 | 412 |
413 if (gfx::GLContext::GetCurrent()->GetVersionInfo()->is_es) { | 413 if (gl::GLContext::GetCurrent()->GetVersionInfo()->is_es) { |
414 gles2_data = GLES2Data(size_, format_, stride_, memory_, &data_format, | 414 gles2_data = GLES2Data(size_, format_, stride_, memory_, &data_format, |
415 &data_type, &data_row_length); | 415 &data_type, &data_row_length); |
416 } | 416 } |
417 | 417 |
418 if (data_row_length != size_.width()) | 418 if (data_row_length != size_.width()) |
419 glPixelStorei(GL_UNPACK_ROW_LENGTH, data_row_length); | 419 glPixelStorei(GL_UNPACK_ROW_LENGTH, data_row_length); |
420 | 420 |
421 glTexImage2D(target, 0, TextureFormat(format_), size_.width(), | 421 glTexImage2D(target, 0, TextureFormat(format_), size_.width(), |
422 size_.height(), 0, data_format, data_type, | 422 size_.height(), 0, data_format, data_type, |
423 gles2_data ? gles2_data.get() : memory_); | 423 gles2_data ? gles2_data.get() : memory_); |
(...skipping 29 matching lines...) Expand all Loading... |
453 target, 0, offset.x(), offset.y(), rect.width(), rect.height(), | 453 target, 0, offset.x(), offset.y(), rect.width(), rect.height(), |
454 DataFormat(format_), | 454 DataFormat(format_), |
455 static_cast<GLsizei>(BufferSizeForBufferFormat(rect.size(), format_)), | 455 static_cast<GLsizei>(BufferSizeForBufferFormat(rect.size(), format_)), |
456 data); | 456 data); |
457 } else { | 457 } else { |
458 GLenum data_format = DataFormat(format_); | 458 GLenum data_format = DataFormat(format_); |
459 GLenum data_type = DataType(format_); | 459 GLenum data_type = DataType(format_); |
460 GLint data_row_length = DataRowLength(stride_, format_); | 460 GLint data_row_length = DataRowLength(stride_, format_); |
461 std::unique_ptr<uint8_t[]> gles2_data; | 461 std::unique_ptr<uint8_t[]> gles2_data; |
462 | 462 |
463 if (gfx::GLContext::GetCurrent()->GetVersionInfo()->is_es) { | 463 if (gl::GLContext::GetCurrent()->GetVersionInfo()->is_es) { |
464 gles2_data = GLES2Data(rect.size(), format_, stride_, data, &data_format, | 464 gles2_data = GLES2Data(rect.size(), format_, stride_, data, &data_format, |
465 &data_type, &data_row_length); | 465 &data_type, &data_row_length); |
466 } | 466 } |
467 | 467 |
468 if (data_row_length != rect.width()) | 468 if (data_row_length != rect.width()) |
469 glPixelStorei(GL_UNPACK_ROW_LENGTH, data_row_length); | 469 glPixelStorei(GL_UNPACK_ROW_LENGTH, data_row_length); |
470 | 470 |
471 glTexSubImage2D(target, 0, offset.x(), offset.y(), rect.width(), | 471 glTexSubImage2D(target, 0, offset.x(), offset.y(), rect.width(), |
472 rect.height(), data_format, data_type, | 472 rect.height(), data_format, data_type, |
473 gles2_data ? gles2_data.get() : data); | 473 gles2_data ? gles2_data.get() : data); |
474 | 474 |
475 if (data_row_length != rect.width()) | 475 if (data_row_length != rect.width()) |
476 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); | 476 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); |
477 } | 477 } |
478 | 478 |
479 return true; | 479 return true; |
480 } | 480 } |
481 | 481 |
482 bool GLImageMemory::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, | 482 bool GLImageMemory::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, |
483 int z_order, | 483 int z_order, |
484 gfx::OverlayTransform transform, | 484 gfx::OverlayTransform transform, |
485 const gfx::Rect& bounds_rect, | 485 const gfx::Rect& bounds_rect, |
486 const gfx::RectF& crop_rect) { | 486 const gfx::RectF& crop_rect) { |
487 return false; | 487 return false; |
488 } | 488 } |
489 | 489 |
490 // static | 490 // static |
491 unsigned GLImageMemory::GetInternalFormatForTesting(BufferFormat format) { | 491 unsigned GLImageMemory::GetInternalFormatForTesting(gfx::BufferFormat format) { |
492 DCHECK(ValidFormat(format)); | 492 DCHECK(ValidFormat(format)); |
493 return TextureFormat(format); | 493 return TextureFormat(format); |
494 } | 494 } |
495 | 495 |
496 } // namespace gl | 496 } // namespace gl |
OLD | NEW |