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" |
| 8 #include "third_party/khronos/GLES2/gl2ext.h" |
| 9 |
7 namespace cc { | 10 namespace cc { |
8 | 11 |
9 SkColorType ResourceFormatToSkColorType(ResourceFormat format) { | 12 SkColorType ResourceFormatToSkColorType(ResourceFormat format) { |
10 switch (format) { | 13 switch (format) { |
11 case RGBA_4444: | 14 case RGBA_4444: |
12 return kARGB_4444_SkColorType; | 15 return kARGB_4444_SkColorType; |
13 case RGBA_8888: | 16 case RGBA_8888: |
14 case BGRA_8888: | 17 case BGRA_8888: |
15 return kN32_SkColorType; | 18 return kN32_SkColorType; |
16 case ETC1: | 19 case ETC1: |
17 case ALPHA_8: | 20 case ALPHA_8: |
18 case LUMINANCE_8: | 21 case LUMINANCE_8: |
19 case RGB_565: | 22 case RGB_565: |
20 case RED_8: | 23 case RED_8: |
21 NOTREACHED(); | 24 NOTREACHED(); |
22 break; | 25 break; |
23 } | 26 } |
24 NOTREACHED(); | 27 NOTREACHED(); |
25 return kN32_SkColorType; | 28 return kN32_SkColorType; |
26 } | 29 } |
27 | 30 |
| 31 int BitsPerPixel(ResourceFormat format) { |
| 32 switch (format) { |
| 33 case BGRA_8888: |
| 34 case RGBA_8888: |
| 35 return 32; |
| 36 case RGBA_4444: |
| 37 case RGB_565: |
| 38 return 16; |
| 39 case ALPHA_8: |
| 40 case LUMINANCE_8: |
| 41 case RED_8: |
| 42 return 8; |
| 43 case ETC1: |
| 44 return 4; |
| 45 } |
| 46 NOTREACHED(); |
| 47 return 0; |
| 48 } |
| 49 |
| 50 GLenum GLDataType(ResourceFormat format) { |
| 51 DCHECK_LE(format, RESOURCE_FORMAT_MAX); |
| 52 static const GLenum format_gl_data_type[] = { |
| 53 GL_UNSIGNED_BYTE, // RGBA_8888 |
| 54 GL_UNSIGNED_SHORT_4_4_4_4, // RGBA_4444 |
| 55 GL_UNSIGNED_BYTE, // BGRA_8888 |
| 56 GL_UNSIGNED_BYTE, // ALPHA_8 |
| 57 GL_UNSIGNED_BYTE, // LUMINANCE_8 |
| 58 GL_UNSIGNED_SHORT_5_6_5, // RGB_565, |
| 59 GL_UNSIGNED_BYTE, // ETC1 |
| 60 GL_UNSIGNED_BYTE // RED_8 |
| 61 }; |
| 62 static_assert(arraysize(format_gl_data_type) == (RESOURCE_FORMAT_MAX + 1), |
| 63 "format_gl_data_type does not handle all cases."); |
| 64 |
| 65 return format_gl_data_type[format]; |
| 66 } |
| 67 |
| 68 GLenum GLDataFormat(ResourceFormat format) { |
| 69 DCHECK_LE(format, RESOURCE_FORMAT_MAX); |
| 70 static const GLenum format_gl_data_format[] = { |
| 71 GL_RGBA, // RGBA_8888 |
| 72 GL_RGBA, // RGBA_4444 |
| 73 GL_BGRA_EXT, // BGRA_8888 |
| 74 GL_ALPHA, // ALPHA_8 |
| 75 GL_LUMINANCE, // LUMINANCE_8 |
| 76 GL_RGB, // RGB_565 |
| 77 GL_ETC1_RGB8_OES, // ETC1 |
| 78 GL_RED_EXT // RED_8 |
| 79 }; |
| 80 static_assert(arraysize(format_gl_data_format) == (RESOURCE_FORMAT_MAX + 1), |
| 81 "format_gl_data_format does not handle all cases."); |
| 82 |
| 83 return format_gl_data_format[format]; |
| 84 } |
| 85 |
| 86 GLenum GLInternalFormat(ResourceFormat format) { |
| 87 return GLDataFormat(format); |
| 88 } |
| 89 |
28 } // namespace cc | 90 } // namespace cc |
OLD | NEW |