| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "cc/resources/resource_format.h" | 5 #include "cc/resources/resource_format.h" |
| 6 | 6 |
| 7 #include "third_party/khronos/GLES2/gl2.h" | 7 #include "third_party/khronos/GLES2/gl2.h" |
| 8 #include "third_party/khronos/GLES2/gl2ext.h" | 8 #include "third_party/khronos/GLES2/gl2ext.h" |
| 9 | 9 |
| 10 namespace cc { | 10 namespace cc { |
| 11 | 11 |
| 12 int BitsPerPixel(ResourceFormat format) { | 12 int BitsPerPixel(ResourceFormat format) { |
| 13 switch (format) { | 13 switch (format) { |
| 14 case BGRA_8888: | 14 case BGRA_8888: |
| 15 case RGBA_8888: | 15 case RGBA_8888: |
| 16 return 32; | 16 return 32; |
| 17 case RGBA_4444: | 17 case RGBA_4444: |
| 18 case RGB_565: | 18 case RGB_565: |
| 19 case LUMINANCE_F16: | 19 case LUMINANCE_F16: |
| 20 case RG_88: |
| 20 return 16; | 21 return 16; |
| 21 case ALPHA_8: | 22 case ALPHA_8: |
| 22 case LUMINANCE_8: | 23 case LUMINANCE_8: |
| 23 case RED_8: | 24 case RED_8: |
| 24 return 8; | 25 return 8; |
| 25 case ETC1: | 26 case ETC1: |
| 26 return 4; | 27 return 4; |
| 27 } | 28 } |
| 28 NOTREACHED(); | 29 NOTREACHED(); |
| 29 return 0; | 30 return 0; |
| 30 } | 31 } |
| 31 | 32 |
| 32 GLenum GLDataType(ResourceFormat format) { | 33 GLenum GLDataType(ResourceFormat format) { |
| 33 DCHECK_LE(format, RESOURCE_FORMAT_MAX); | 34 DCHECK_LE(format, RESOURCE_FORMAT_MAX); |
| 34 static const GLenum format_gl_data_type[] = { | 35 static const GLenum format_gl_data_type[] = { |
| 35 GL_UNSIGNED_BYTE, // RGBA_8888 | 36 GL_UNSIGNED_BYTE, // RGBA_8888 |
| 36 GL_UNSIGNED_SHORT_4_4_4_4, // RGBA_4444 | 37 GL_UNSIGNED_SHORT_4_4_4_4, // RGBA_4444 |
| 37 GL_UNSIGNED_BYTE, // BGRA_8888 | 38 GL_UNSIGNED_BYTE, // BGRA_8888 |
| 38 GL_UNSIGNED_BYTE, // ALPHA_8 | 39 GL_UNSIGNED_BYTE, // ALPHA_8 |
| 39 GL_UNSIGNED_BYTE, // LUMINANCE_8 | 40 GL_UNSIGNED_BYTE, // LUMINANCE_8 |
| 40 GL_UNSIGNED_SHORT_5_6_5, // RGB_565, | 41 GL_UNSIGNED_SHORT_5_6_5, // RGB_565, |
| 41 GL_UNSIGNED_BYTE, // ETC1 | 42 GL_UNSIGNED_BYTE, // ETC1 |
| 42 GL_UNSIGNED_BYTE, // RED_8 | 43 GL_UNSIGNED_BYTE, // RED_8 |
| 43 GL_HALF_FLOAT_OES, // LUMINANCE_F16 | 44 GL_HALF_FLOAT_OES, // LUMINANCE_F16 |
| 45 GL_UNSIGNED_BYTE, // RG_88 |
| 44 }; | 46 }; |
| 45 static_assert(arraysize(format_gl_data_type) == (RESOURCE_FORMAT_MAX + 1), | 47 static_assert(arraysize(format_gl_data_type) == (RESOURCE_FORMAT_MAX + 1), |
| 46 "format_gl_data_type does not handle all cases."); | 48 "format_gl_data_type does not handle all cases."); |
| 47 | 49 |
| 48 return format_gl_data_type[format]; | 50 return format_gl_data_type[format]; |
| 49 } | 51 } |
| 50 | 52 |
| 51 GLenum GLDataFormat(ResourceFormat format) { | 53 GLenum GLDataFormat(ResourceFormat format) { |
| 52 DCHECK_LE(format, RESOURCE_FORMAT_MAX); | 54 DCHECK_LE(format, RESOURCE_FORMAT_MAX); |
| 53 static const GLenum format_gl_data_format[] = { | 55 static const GLenum format_gl_data_format[] = { |
| 54 GL_RGBA, // RGBA_8888 | 56 GL_RGBA, // RGBA_8888 |
| 55 GL_RGBA, // RGBA_4444 | 57 GL_RGBA, // RGBA_4444 |
| 56 GL_BGRA_EXT, // BGRA_8888 | 58 GL_BGRA_EXT, // BGRA_8888 |
| 57 GL_ALPHA, // ALPHA_8 | 59 GL_ALPHA, // ALPHA_8 |
| 58 GL_LUMINANCE, // LUMINANCE_8 | 60 GL_LUMINANCE, // LUMINANCE_8 |
| 59 GL_RGB, // RGB_565 | 61 GL_RGB, // RGB_565 |
| 60 GL_ETC1_RGB8_OES, // ETC1 | 62 GL_ETC1_RGB8_OES, // ETC1 |
| 61 GL_RED_EXT, // RED_8 | 63 GL_R8_EXT, // RED_8 |
| 62 GL_LUMINANCE, // LUMINANCE_F16 | 64 GL_LUMINANCE, // LUMINANCE_F16 |
| 65 GL_RG_EXT, // RG_88 |
| 63 }; | 66 }; |
| 64 static_assert(arraysize(format_gl_data_format) == (RESOURCE_FORMAT_MAX + 1), | 67 static_assert(arraysize(format_gl_data_format) == (RESOURCE_FORMAT_MAX + 1), |
| 65 "format_gl_data_format does not handle all cases."); | 68 "format_gl_data_format does not handle all cases."); |
| 66 return format_gl_data_format[format]; | 69 return format_gl_data_format[format]; |
| 67 } | 70 } |
| 68 | 71 |
| 69 GLenum GLInternalFormat(ResourceFormat format) { | 72 GLenum GLInternalFormat(ResourceFormat format) { |
| 70 // In GLES2, the internal format must match the texture format. (It no longer | 73 // In GLES2, the internal format must match the texture format. (It no longer |
| 71 // is true in GLES3, however it still holds for the BGRA extension.) | 74 // is true in GLES3, however it still holds for the BGRA extension.) |
| 72 return GLDataFormat(format); | 75 return GLDataFormat(format); |
| 73 } | 76 } |
| 74 | 77 |
| 75 GLenum GLCopyTextureInternalFormat(ResourceFormat format) { | 78 GLenum GLCopyTextureInternalFormat(ResourceFormat format) { |
| 76 // In GLES2, valid formats for glCopyTexImage2D are: GL_ALPHA, GL_LUMINANCE, | 79 // In GLES2, valid formats for glCopyTexImage2D are: GL_ALPHA, GL_LUMINANCE, |
| 77 // GL_LUMINANCE_ALPHA, GL_RGB, or GL_RGBA. | 80 // GL_LUMINANCE_ALPHA, GL_RGB, or GL_RGBA. |
| 78 // Extensions typically used for glTexImage2D do not also work for | 81 // Extensions typically used for glTexImage2D do not also work for |
| 79 // glCopyTexImage2D. For instance GL_BGRA_EXT may not be used for | 82 // glCopyTexImage2D. For instance GL_BGRA_EXT may not be used for |
| 80 // anything but gl(Sub)TexImage2D: | 83 // anything but gl(Sub)TexImage2D: |
| 81 // https://www.khronos.org/registry/gles/extensions/EXT/EXT_texture_format_BGR
A8888.txt | 84 // https://www.khronos.org/registry/gles/extensions/EXT/EXT_texture_format_BGR
A8888.txt |
| 82 DCHECK_LE(format, RESOURCE_FORMAT_MAX); | 85 DCHECK_LE(format, RESOURCE_FORMAT_MAX); |
| 83 static const GLenum format_gl_data_format[] = { | 86 static const GLenum format_gl_data_format[] = { |
| 84 GL_RGBA, // RGBA_8888 | 87 GL_RGBA, // RGBA_8888 |
| 85 GL_RGBA, // RGBA_4444 | 88 GL_RGBA, // RGBA_4444 |
| 86 GL_RGBA, // BGRA_8888 | 89 GL_RGBA, // BGRA_8888 |
| 87 GL_ALPHA, // ALPHA_8 | 90 GL_ALPHA, // ALPHA_8 |
| 88 GL_LUMINANCE, // LUMINANCE_8 | 91 GL_LUMINANCE, // LUMINANCE_8 |
| 89 GL_RGB, // RGB_565 | 92 GL_RGB, // RGB_565 |
| 90 GL_RGB, // ETC1 | 93 GL_RGB, // ETC1 |
| 91 GL_LUMINANCE, // RED_8 | 94 GL_R8_EXT, // RED_8 |
| 92 GL_LUMINANCE, // LUMINANCE_F16 | 95 GL_LUMINANCE, // LUMINANCE_F16 |
| 96 GL_RG8_EXT, // RG_88 |
| 93 }; | 97 }; |
| 94 static_assert(arraysize(format_gl_data_format) == (RESOURCE_FORMAT_MAX + 1), | 98 static_assert(arraysize(format_gl_data_format) == (RESOURCE_FORMAT_MAX + 1), |
| 95 "format_gl_data_format does not handle all cases."); | 99 "format_gl_data_format does not handle all cases."); |
| 96 return format_gl_data_format[format]; | 100 return format_gl_data_format[format]; |
| 97 } | 101 } |
| 98 | 102 |
| 99 gfx::BufferFormat BufferFormat(ResourceFormat format) { | 103 gfx::BufferFormat BufferFormat(ResourceFormat format) { |
| 100 switch (format) { | 104 switch (format) { |
| 101 case BGRA_8888: | 105 case BGRA_8888: |
| 102 return gfx::BufferFormat::BGRA_8888; | 106 return gfx::BufferFormat::BGRA_8888; |
| 103 case RED_8: | 107 case RED_8: |
| 104 return gfx::BufferFormat::R_8; | 108 return gfx::BufferFormat::R_8; |
| 109 case RG_88: |
| 110 return gfx::BufferFormat::RG_88; |
| 105 case RGBA_4444: | 111 case RGBA_4444: |
| 106 return gfx::BufferFormat::RGBA_4444; | 112 return gfx::BufferFormat::RGBA_4444; |
| 107 case RGBA_8888: | 113 case RGBA_8888: |
| 108 return gfx::BufferFormat::RGBA_8888; | 114 return gfx::BufferFormat::RGBA_8888; |
| 109 case ETC1: | 115 case ETC1: |
| 110 return gfx::BufferFormat::ETC1; | 116 return gfx::BufferFormat::ETC1; |
| 111 case ALPHA_8: | 117 case ALPHA_8: |
| 112 case LUMINANCE_8: | 118 case LUMINANCE_8: |
| 113 case RGB_565: | 119 case RGB_565: |
| 114 case LUMINANCE_F16: | 120 case LUMINANCE_F16: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 127 case RGBA_4444: | 133 case RGBA_4444: |
| 128 case RGBA_8888: | 134 case RGBA_8888: |
| 129 case BGRA_8888: | 135 case BGRA_8888: |
| 130 case ALPHA_8: | 136 case ALPHA_8: |
| 131 return true; | 137 return true; |
| 132 case LUMINANCE_8: | 138 case LUMINANCE_8: |
| 133 case RGB_565: | 139 case RGB_565: |
| 134 case ETC1: | 140 case ETC1: |
| 135 case RED_8: | 141 case RED_8: |
| 136 case LUMINANCE_F16: | 142 case LUMINANCE_F16: |
| 143 case RG_88: |
| 137 return false; | 144 return false; |
| 138 } | 145 } |
| 139 NOTREACHED(); | 146 NOTREACHED(); |
| 140 return false; | 147 return false; |
| 141 } | 148 } |
| 142 | 149 |
| 143 } // namespace cc | 150 } // namespace cc |
| OLD | NEW |