Chromium Code Reviews| 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_version_info.h" | 15 #include "ui/gl/gl_version_info.h" |
| 16 | 16 |
| 17 using gfx::BufferFormat; | 17 using gfx::BufferFormat; |
| 18 | 18 |
| 19 namespace gl { | 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_ATC_RGB_AMD: | 24 case GL_ATC_RGB_AMD: |
| 25 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: | 25 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: |
| 26 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: | 26 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 27 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: | 27 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: |
| 28 case GL_ETC1_RGB8_OES: | 28 case GL_ETC1_RGB8_OES: |
| 29 case GL_RED: | 29 case GL_R8: |
| 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(BufferFormat format) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 case BufferFormat::ATC: | 91 case BufferFormat::ATC: |
| 92 return GL_ATC_RGB_AMD; | 92 return GL_ATC_RGB_AMD; |
| 93 case BufferFormat::ATCIA: | 93 case BufferFormat::ATCIA: |
| 94 return GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD; | 94 return GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD; |
| 95 case BufferFormat::DXT1: | 95 case BufferFormat::DXT1: |
| 96 return GL_COMPRESSED_RGB_S3TC_DXT1_EXT; | 96 return GL_COMPRESSED_RGB_S3TC_DXT1_EXT; |
| 97 case BufferFormat::DXT5: | 97 case BufferFormat::DXT5: |
| 98 return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; | 98 return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; |
| 99 case BufferFormat::ETC1: | 99 case BufferFormat::ETC1: |
| 100 return GL_ETC1_RGB8_OES; | 100 return GL_ETC1_RGB8_OES; |
| 101 case BufferFormat::R_8: | 101 case BufferFormat::R_8: { |
| 102 return GL_RED; | 102 const gfx::GLVersionInfo* version_info = |
|
reveman
2016/02/20 01:07:55
ditto
Daniele Castagna
2016/02/20 01:16:16
Done.
| |
| 103 gfx::GLContext::GetCurrent()->GetVersionInfo(); | |
| 104 if (version_info->IsAtLeastGL(3, 0) || | |
| 105 version_info->IsAtLeastGLES(3, 0)) { | |
| 106 return GL_R8; | |
| 107 } else { | |
| 108 return GL_RED; | |
| 109 } | |
| 110 } | |
| 103 case BufferFormat::RGBA_4444: | 111 case BufferFormat::RGBA_4444: |
| 104 case BufferFormat::RGBA_8888: | 112 case BufferFormat::RGBA_8888: |
| 105 return GL_RGBA; | 113 return GL_RGBA; |
| 106 case BufferFormat::BGRA_8888: | 114 case BufferFormat::BGRA_8888: |
| 107 return GL_BGRA_EXT; | 115 return GL_BGRA_EXT; |
| 108 case BufferFormat::RGBX_8888: | 116 case BufferFormat::RGBX_8888: |
| 109 case BufferFormat::BGRX_8888: | 117 case BufferFormat::BGRX_8888: |
| 110 return GL_RGB; | 118 return GL_RGB; |
| 111 case BufferFormat::YUV_420: | 119 case BufferFormat::YUV_420: |
| 112 case BufferFormat::YUV_420_BIPLANAR: | 120 case BufferFormat::YUV_420_BIPLANAR: |
| 113 case BufferFormat::UYVY_422: | 121 case BufferFormat::UYVY_422: |
| 114 NOTREACHED(); | 122 NOTREACHED(); |
| 115 return 0; | 123 return 0; |
| 116 } | 124 } |
| 117 | 125 |
| 118 NOTREACHED(); | 126 NOTREACHED(); |
| 119 return 0; | 127 return 0; |
| 120 } | 128 } |
| 121 | 129 |
| 122 GLenum DataFormat(BufferFormat format) { | 130 GLenum DataFormat(BufferFormat format) { |
| 123 switch (format) { | 131 switch (format) { |
| 124 case BufferFormat::RGBX_8888: | 132 case BufferFormat::RGBX_8888: |
| 125 return GL_RGBA; | 133 return GL_RGBA; |
| 126 case BufferFormat::BGRX_8888: | 134 case BufferFormat::BGRX_8888: |
| 127 return GL_BGRA_EXT; | 135 return GL_BGRA_EXT; |
| 136 case BufferFormat::R_8: | |
| 137 return GL_RED; | |
| 128 case BufferFormat::RGBA_4444: | 138 case BufferFormat::RGBA_4444: |
| 129 case BufferFormat::RGBA_8888: | 139 case BufferFormat::RGBA_8888: |
| 130 case BufferFormat::BGRA_8888: | 140 case BufferFormat::BGRA_8888: |
| 131 case BufferFormat::R_8: | |
| 132 case BufferFormat::ATC: | 141 case BufferFormat::ATC: |
| 133 case BufferFormat::ATCIA: | 142 case BufferFormat::ATCIA: |
| 134 case BufferFormat::DXT1: | 143 case BufferFormat::DXT1: |
| 135 case BufferFormat::DXT5: | 144 case BufferFormat::DXT5: |
| 136 case BufferFormat::ETC1: | 145 case BufferFormat::ETC1: |
| 137 return TextureFormat(format); | 146 return TextureFormat(format); |
| 138 case BufferFormat::YUV_420: | 147 case BufferFormat::YUV_420: |
| 139 case BufferFormat::YUV_420_BIPLANAR: | 148 case BufferFormat::YUV_420_BIPLANAR: |
| 140 case BufferFormat::UYVY_422: | 149 case BufferFormat::UYVY_422: |
| 141 NOTREACHED(); | 150 NOTREACHED(); |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 444 return false; | 453 return false; |
| 445 } | 454 } |
| 446 | 455 |
| 447 // static | 456 // static |
| 448 unsigned GLImageMemory::GetInternalFormatForTesting(BufferFormat format) { | 457 unsigned GLImageMemory::GetInternalFormatForTesting(BufferFormat format) { |
| 449 DCHECK(ValidFormat(format)); | 458 DCHECK(ValidFormat(format)); |
| 450 return TextureFormat(format); | 459 return TextureFormat(format); |
| 451 } | 460 } |
| 452 | 461 |
| 453 } // namespace gl | 462 } // namespace gl |
| OLD | NEW |