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" |
11 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
12 #include "ui/gfx/buffer_format_util.h" | 12 #include "ui/gfx/buffer_format_util.h" |
13 #include "ui/gl/gl_bindings.h" | 13 #include "ui/gl/gl_bindings.h" |
14 #include "ui/gl/gl_context.h" | 14 #include "ui/gl/gl_context.h" |
| 15 #include "ui/gl/gl_utils.h" |
15 #include "ui/gl/gl_version_info.h" | 16 #include "ui/gl/gl_version_info.h" |
16 | 17 |
17 using gfx::BufferFormat; | 18 using gfx::BufferFormat; |
18 | 19 |
19 namespace gl { | 20 namespace gl { |
20 namespace { | 21 namespace { |
21 | 22 |
22 bool ValidInternalFormat(unsigned internalformat) { | 23 bool ValidInternalFormat(unsigned internalformat) { |
23 switch (internalformat) { | 24 switch (internalformat) { |
24 case GL_ATC_RGB_AMD: | 25 case GL_ATC_RGB_AMD: |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 case BufferFormat::YUV_420_BIPLANAR: | 80 case BufferFormat::YUV_420_BIPLANAR: |
80 case BufferFormat::UYVY_422: | 81 case BufferFormat::UYVY_422: |
81 NOTREACHED(); | 82 NOTREACHED(); |
82 return false; | 83 return false; |
83 } | 84 } |
84 | 85 |
85 NOTREACHED(); | 86 NOTREACHED(); |
86 return false; | 87 return false; |
87 } | 88 } |
88 | 89 |
89 GLenum TextureFormat(BufferFormat format) { | |
90 switch (format) { | |
91 case BufferFormat::ATC: | |
92 return GL_ATC_RGB_AMD; | |
93 case BufferFormat::ATCIA: | |
94 return GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD; | |
95 case BufferFormat::DXT1: | |
96 return GL_COMPRESSED_RGB_S3TC_DXT1_EXT; | |
97 case BufferFormat::DXT5: | |
98 return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; | |
99 case BufferFormat::ETC1: | |
100 return GL_ETC1_RGB8_OES; | |
101 case BufferFormat::R_8: | |
102 return GL_RED; | |
103 case BufferFormat::RGBA_4444: | |
104 case BufferFormat::RGBA_8888: | |
105 return GL_RGBA; | |
106 case BufferFormat::BGRA_8888: | |
107 return GL_BGRA_EXT; | |
108 case BufferFormat::RGBX_8888: | |
109 case BufferFormat::BGRX_8888: | |
110 return GL_RGB; | |
111 case BufferFormat::YUV_420: | |
112 case BufferFormat::YUV_420_BIPLANAR: | |
113 case BufferFormat::UYVY_422: | |
114 NOTREACHED(); | |
115 return 0; | |
116 } | |
117 | |
118 NOTREACHED(); | |
119 return 0; | |
120 } | |
121 | |
122 GLenum DataFormat(BufferFormat format) { | 90 GLenum DataFormat(BufferFormat format) { |
123 switch (format) { | 91 switch (format) { |
124 case BufferFormat::RGBX_8888: | 92 case BufferFormat::RGBX_8888: |
125 return GL_RGBA; | 93 return GL_RGBA; |
126 case BufferFormat::BGRX_8888: | 94 case BufferFormat::BGRX_8888: |
127 return GL_BGRA_EXT; | 95 return GL_BGRA_EXT; |
128 case BufferFormat::RGBA_4444: | 96 case BufferFormat::RGBA_4444: |
129 case BufferFormat::RGBA_8888: | 97 case BufferFormat::RGBA_8888: |
130 case BufferFormat::BGRA_8888: | 98 case BufferFormat::BGRA_8888: |
131 case BufferFormat::R_8: | 99 case BufferFormat::R_8: |
132 case BufferFormat::ATC: | 100 case BufferFormat::ATC: |
133 case BufferFormat::ATCIA: | 101 case BufferFormat::ATCIA: |
134 case BufferFormat::DXT1: | 102 case BufferFormat::DXT1: |
135 case BufferFormat::DXT5: | 103 case BufferFormat::DXT5: |
136 case BufferFormat::ETC1: | 104 case BufferFormat::ETC1: |
137 return TextureFormat(format); | 105 return GetTextureFormatFrom(format); |
138 case BufferFormat::YUV_420: | 106 case BufferFormat::YUV_420: |
139 case BufferFormat::YUV_420_BIPLANAR: | 107 case BufferFormat::YUV_420_BIPLANAR: |
140 case BufferFormat::UYVY_422: | 108 case BufferFormat::UYVY_422: |
141 NOTREACHED(); | 109 NOTREACHED(); |
142 return 0; | 110 return 0; |
143 } | 111 } |
144 | 112 |
145 NOTREACHED(); | 113 NOTREACHED(); |
146 return 0; | 114 return 0; |
147 } | 115 } |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 bool GLImageMemory::CopyTexImage(unsigned target) { | 318 bool GLImageMemory::CopyTexImage(unsigned target) { |
351 TRACE_EVENT2("gpu", "GLImageMemory::CopyTexImage", "width", size_.width(), | 319 TRACE_EVENT2("gpu", "GLImageMemory::CopyTexImage", "width", size_.width(), |
352 "height", size_.height()); | 320 "height", size_.height()); |
353 | 321 |
354 // GL_TEXTURE_EXTERNAL_OES is not a supported target. | 322 // GL_TEXTURE_EXTERNAL_OES is not a supported target. |
355 if (target == GL_TEXTURE_EXTERNAL_OES) | 323 if (target == GL_TEXTURE_EXTERNAL_OES) |
356 return false; | 324 return false; |
357 | 325 |
358 if (IsCompressedFormat(format_)) { | 326 if (IsCompressedFormat(format_)) { |
359 glCompressedTexImage2D( | 327 glCompressedTexImage2D( |
360 target, 0, TextureFormat(format_), size_.width(), size_.height(), 0, | 328 target, 0, GetTextureFormatFrom(format_), size_.width(), size_.height(), |
361 static_cast<GLsizei>(BufferSizeForBufferFormat(size_, format_)), | 329 0, static_cast<GLsizei>(BufferSizeForBufferFormat(size_, format_)), |
362 memory_); | 330 memory_); |
363 } else { | 331 } else { |
364 GLenum data_format = DataFormat(format_); | 332 GLenum data_format = DataFormat(format_); |
365 GLenum data_type = DataType(format_); | 333 GLenum data_type = DataType(format_); |
366 GLint data_row_length = DataRowLength(stride_, format_); | 334 GLint data_row_length = DataRowLength(stride_, format_); |
367 scoped_ptr<uint8_t[]> gles2_data; | 335 scoped_ptr<uint8_t[]> gles2_data; |
368 | 336 |
369 if (gfx::GLContext::GetCurrent()->GetVersionInfo()->is_es) { | 337 if (gfx::GLContext::GetCurrent()->GetVersionInfo()->is_es) { |
370 gles2_data = GLES2Data(size_, format_, stride_, memory_, &data_format, | 338 gles2_data = GLES2Data(size_, format_, stride_, memory_, &data_format, |
371 &data_type, &data_row_length); | 339 &data_type, &data_row_length); |
372 } | 340 } |
373 | 341 |
374 if (data_row_length != size_.width()) | 342 if (data_row_length != size_.width()) |
375 glPixelStorei(GL_UNPACK_ROW_LENGTH, data_row_length); | 343 glPixelStorei(GL_UNPACK_ROW_LENGTH, data_row_length); |
376 | 344 |
377 glTexImage2D(target, 0, TextureFormat(format_), size_.width(), | 345 glTexImage2D(target, 0, GetTextureFormatFrom(format_), size_.width(), |
378 size_.height(), 0, data_format, data_type, | 346 size_.height(), 0, data_format, data_type, |
379 gles2_data ? gles2_data.get() : memory_); | 347 gles2_data ? gles2_data.get() : memory_); |
380 | 348 |
381 if (data_row_length != size_.width()) | 349 if (data_row_length != size_.width()) |
382 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); | 350 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); |
383 } | 351 } |
384 | 352 |
385 return true; | 353 return true; |
386 } | 354 } |
387 | 355 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 } | 404 } |
437 | 405 |
438 bool GLImageMemory::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, | 406 bool GLImageMemory::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, |
439 int z_order, | 407 int z_order, |
440 gfx::OverlayTransform transform, | 408 gfx::OverlayTransform transform, |
441 const gfx::Rect& bounds_rect, | 409 const gfx::Rect& bounds_rect, |
442 const gfx::RectF& crop_rect) { | 410 const gfx::RectF& crop_rect) { |
443 return false; | 411 return false; |
444 } | 412 } |
445 | 413 |
446 // static | |
447 unsigned GLImageMemory::GetInternalFormatForTesting(BufferFormat format) { | |
448 DCHECK(ValidFormat(format)); | |
449 return TextureFormat(format); | |
450 } | |
451 | |
452 } // namespace gl | 414 } // namespace gl |
OLD | NEW |