| 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 RG_88: |
| 19 case LUMINANCE_F16: | 20 case LUMINANCE_F16: |
| 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_RED_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 | 69 |
| 67 return format_gl_data_format[format]; | 70 return format_gl_data_format[format]; |
| 68 } | 71 } |
| 69 | 72 |
| 70 GLenum GLInternalFormat(ResourceFormat format) { | 73 GLenum GLInternalFormat(ResourceFormat format) { |
| 71 return GLDataFormat(format); | 74 return GLDataFormat(format); |
| 72 } | 75 } |
| 73 | 76 |
| 74 gfx::BufferFormat BufferFormat(ResourceFormat format) { | 77 gfx::BufferFormat BufferFormat(ResourceFormat format) { |
| 75 switch (format) { | 78 switch (format) { |
| 76 case BGRA_8888: | 79 case BGRA_8888: |
| 77 return gfx::BufferFormat::BGRA_8888; | 80 return gfx::BufferFormat::BGRA_8888; |
| 78 case RED_8: | 81 case RED_8: |
| 79 return gfx::BufferFormat::R_8; | 82 return gfx::BufferFormat::R_8; |
| 80 case RGBA_4444: | 83 case RGBA_4444: |
| 81 return gfx::BufferFormat::RGBA_4444; | 84 return gfx::BufferFormat::RGBA_4444; |
| 82 case RGBA_8888: | 85 case RGBA_8888: |
| 83 return gfx::BufferFormat::RGBA_8888; | 86 return gfx::BufferFormat::RGBA_8888; |
| 84 case ETC1: | 87 case ETC1: |
| 85 return gfx::BufferFormat::ETC1; | 88 return gfx::BufferFormat::ETC1; |
| 86 case ALPHA_8: | 89 case ALPHA_8: |
| 87 case LUMINANCE_8: | 90 case LUMINANCE_8: |
| 88 case RGB_565: | 91 case RGB_565: |
| 89 case LUMINANCE_F16: | 92 case LUMINANCE_F16: |
| 93 case RG_88: |
| 90 break; | 94 break; |
| 91 } | 95 } |
| 92 NOTREACHED(); | 96 NOTREACHED(); |
| 93 return gfx::BufferFormat::RGBA_8888; | 97 return gfx::BufferFormat::RGBA_8888; |
| 94 } | 98 } |
| 95 | 99 |
| 96 bool IsResourceFormatCompressed(ResourceFormat format) { | 100 bool IsResourceFormatCompressed(ResourceFormat format) { |
| 97 return format == ETC1; | 101 return format == ETC1; |
| 98 } | 102 } |
| 99 | 103 |
| 100 bool DoesResourceFormatSupportAlpha(ResourceFormat format) { | 104 bool DoesResourceFormatSupportAlpha(ResourceFormat format) { |
| 101 switch (format) { | 105 switch (format) { |
| 102 case RGBA_4444: | 106 case RGBA_4444: |
| 103 case RGBA_8888: | 107 case RGBA_8888: |
| 104 case BGRA_8888: | 108 case BGRA_8888: |
| 105 case ALPHA_8: | 109 case ALPHA_8: |
| 106 return true; | 110 return true; |
| 107 case LUMINANCE_8: | 111 case LUMINANCE_8: |
| 108 case RGB_565: | 112 case RGB_565: |
| 109 case ETC1: | 113 case ETC1: |
| 110 case RED_8: | 114 case RED_8: |
| 111 case LUMINANCE_F16: | 115 case LUMINANCE_F16: |
| 116 case RG_88: |
| 112 return false; | 117 return false; |
| 113 } | 118 } |
| 114 NOTREACHED(); | 119 NOTREACHED(); |
| 115 return false; | 120 return false; |
| 116 } | 121 } |
| 117 | 122 |
| 118 } // namespace cc | 123 } // namespace cc |
| OLD | NEW |