| 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 #include "ui/gfx/gpu_memory_buffer.h" | 9 #include "ui/gfx/gpu_memory_buffer.h" |
| 10 | 10 |
| 11 namespace cc { | 11 namespace cc { |
| 12 | 12 |
| 13 int BitsPerPixel(ResourceFormat format) { | 13 int BitsPerPixel(ResourceFormat format) { |
| 14 switch (format) { | 14 switch (format) { |
| 15 case RGBA_F16: | |
| 16 return 64; | |
| 17 case BGRA_8888: | 15 case BGRA_8888: |
| 18 case RGBA_8888: | 16 case RGBA_8888: |
| 19 return 32; | 17 return 32; |
| 20 case RGBA_4444: | 18 case RGBA_4444: |
| 21 case RGB_565: | 19 case RGB_565: |
| 22 case LUMINANCE_F16: | 20 case LUMINANCE_F16: |
| 23 return 16; | 21 return 16; |
| 24 case ALPHA_8: | 22 case ALPHA_8: |
| 25 case LUMINANCE_8: | 23 case LUMINANCE_8: |
| 26 case RED_8: | 24 case RED_8: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 37 static const GLenum format_gl_data_type[] = { | 35 static const GLenum format_gl_data_type[] = { |
| 38 GL_UNSIGNED_BYTE, // RGBA_8888 | 36 GL_UNSIGNED_BYTE, // RGBA_8888 |
| 39 GL_UNSIGNED_SHORT_4_4_4_4, // RGBA_4444 | 37 GL_UNSIGNED_SHORT_4_4_4_4, // RGBA_4444 |
| 40 GL_UNSIGNED_BYTE, // BGRA_8888 | 38 GL_UNSIGNED_BYTE, // BGRA_8888 |
| 41 GL_UNSIGNED_BYTE, // ALPHA_8 | 39 GL_UNSIGNED_BYTE, // ALPHA_8 |
| 42 GL_UNSIGNED_BYTE, // LUMINANCE_8 | 40 GL_UNSIGNED_BYTE, // LUMINANCE_8 |
| 43 GL_UNSIGNED_SHORT_5_6_5, // RGB_565, | 41 GL_UNSIGNED_SHORT_5_6_5, // RGB_565, |
| 44 GL_UNSIGNED_BYTE, // ETC1 | 42 GL_UNSIGNED_BYTE, // ETC1 |
| 45 GL_UNSIGNED_BYTE, // RED_8 | 43 GL_UNSIGNED_BYTE, // RED_8 |
| 46 GL_HALF_FLOAT_OES, // LUMINANCE_F16 | 44 GL_HALF_FLOAT_OES, // LUMINANCE_F16 |
| 47 GL_HALF_FLOAT_OES, // RGBA_F16 | |
| 48 }; | 45 }; |
| 49 static_assert(arraysize(format_gl_data_type) == (RESOURCE_FORMAT_MAX + 1), | 46 static_assert(arraysize(format_gl_data_type) == (RESOURCE_FORMAT_MAX + 1), |
| 50 "format_gl_data_type does not handle all cases."); | 47 "format_gl_data_type does not handle all cases."); |
| 51 | 48 |
| 52 return format_gl_data_type[format]; | 49 return format_gl_data_type[format]; |
| 53 } | 50 } |
| 54 | 51 |
| 55 GLenum GLDataFormat(ResourceFormat format) { | 52 GLenum GLDataFormat(ResourceFormat format) { |
| 56 DCHECK_LE(format, RESOURCE_FORMAT_MAX); | 53 DCHECK_LE(format, RESOURCE_FORMAT_MAX); |
| 57 static const GLenum format_gl_data_format[] = { | 54 static const GLenum format_gl_data_format[] = { |
| 58 GL_RGBA, // RGBA_8888 | 55 GL_RGBA, // RGBA_8888 |
| 59 GL_RGBA, // RGBA_4444 | 56 GL_RGBA, // RGBA_4444 |
| 60 GL_BGRA_EXT, // BGRA_8888 | 57 GL_BGRA_EXT, // BGRA_8888 |
| 61 GL_ALPHA, // ALPHA_8 | 58 GL_ALPHA, // ALPHA_8 |
| 62 GL_LUMINANCE, // LUMINANCE_8 | 59 GL_LUMINANCE, // LUMINANCE_8 |
| 63 GL_RGB, // RGB_565 | 60 GL_RGB, // RGB_565 |
| 64 GL_ETC1_RGB8_OES, // ETC1 | 61 GL_ETC1_RGB8_OES, // ETC1 |
| 65 GL_RED_EXT, // RED_8 | 62 GL_RED_EXT, // RED_8 |
| 66 GL_LUMINANCE, // LUMINANCE_F16 | 63 GL_LUMINANCE, // LUMINANCE_F16 |
| 67 GL_RGBA, // RGBA_F16 | |
| 68 }; | 64 }; |
| 69 static_assert(arraysize(format_gl_data_format) == (RESOURCE_FORMAT_MAX + 1), | 65 static_assert(arraysize(format_gl_data_format) == (RESOURCE_FORMAT_MAX + 1), |
| 70 "format_gl_data_format does not handle all cases."); | 66 "format_gl_data_format does not handle all cases."); |
| 71 return format_gl_data_format[format]; | 67 return format_gl_data_format[format]; |
| 72 } | 68 } |
| 73 | 69 |
| 74 GLenum GLInternalFormat(ResourceFormat format) { | 70 GLenum GLInternalFormat(ResourceFormat format) { |
| 75 // In GLES2, the internal format must match the texture format. (It no longer | 71 // In GLES2, the internal format must match the texture format. (It no longer |
| 76 // is true in GLES3, however it still holds for the BGRA extension.) | 72 // is true in GLES3, however it still holds for the BGRA extension.) |
| 77 return GLDataFormat(format); | 73 return GLDataFormat(format); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 88 static const GLenum format_gl_data_format[] = { | 84 static const GLenum format_gl_data_format[] = { |
| 89 GL_RGBA, // RGBA_8888 | 85 GL_RGBA, // RGBA_8888 |
| 90 GL_RGBA, // RGBA_4444 | 86 GL_RGBA, // RGBA_4444 |
| 91 GL_RGBA, // BGRA_8888 | 87 GL_RGBA, // BGRA_8888 |
| 92 GL_ALPHA, // ALPHA_8 | 88 GL_ALPHA, // ALPHA_8 |
| 93 GL_LUMINANCE, // LUMINANCE_8 | 89 GL_LUMINANCE, // LUMINANCE_8 |
| 94 GL_RGB, // RGB_565 | 90 GL_RGB, // RGB_565 |
| 95 GL_RGB, // ETC1 | 91 GL_RGB, // ETC1 |
| 96 GL_LUMINANCE, // RED_8 | 92 GL_LUMINANCE, // RED_8 |
| 97 GL_LUMINANCE, // LUMINANCE_F16 | 93 GL_LUMINANCE, // LUMINANCE_F16 |
| 98 GL_RGBA, // RGBA_F16 | |
| 99 }; | 94 }; |
| 100 static_assert(arraysize(format_gl_data_format) == (RESOURCE_FORMAT_MAX + 1), | 95 static_assert(arraysize(format_gl_data_format) == (RESOURCE_FORMAT_MAX + 1), |
| 101 "format_gl_data_format does not handle all cases."); | 96 "format_gl_data_format does not handle all cases."); |
| 102 return format_gl_data_format[format]; | 97 return format_gl_data_format[format]; |
| 103 } | 98 } |
| 104 | 99 |
| 105 gfx::BufferFormat BufferFormat(ResourceFormat format) { | 100 gfx::BufferFormat BufferFormat(ResourceFormat format) { |
| 106 switch (format) { | 101 switch (format) { |
| 107 case BGRA_8888: | 102 case BGRA_8888: |
| 108 return gfx::BufferFormat::BGRA_8888; | 103 return gfx::BufferFormat::BGRA_8888; |
| 109 case RED_8: | 104 case RED_8: |
| 110 return gfx::BufferFormat::R_8; | 105 return gfx::BufferFormat::R_8; |
| 111 case RGBA_4444: | 106 case RGBA_4444: |
| 112 return gfx::BufferFormat::RGBA_4444; | 107 return gfx::BufferFormat::RGBA_4444; |
| 113 case RGBA_8888: | 108 case RGBA_8888: |
| 114 return gfx::BufferFormat::RGBA_8888; | 109 return gfx::BufferFormat::RGBA_8888; |
| 115 case ETC1: | 110 case ETC1: |
| 116 return gfx::BufferFormat::ETC1; | 111 return gfx::BufferFormat::ETC1; |
| 117 case ALPHA_8: | 112 case ALPHA_8: |
| 118 case LUMINANCE_8: | 113 case LUMINANCE_8: |
| 119 case RGB_565: | 114 case RGB_565: |
| 120 case LUMINANCE_F16: | 115 case LUMINANCE_F16: |
| 121 case RGBA_F16: | |
| 122 break; | 116 break; |
| 123 } | 117 } |
| 124 NOTREACHED(); | 118 NOTREACHED(); |
| 125 return gfx::BufferFormat::RGBA_8888; | 119 return gfx::BufferFormat::RGBA_8888; |
| 126 } | 120 } |
| 127 | 121 |
| 128 bool IsResourceFormatCompressed(ResourceFormat format) { | 122 bool IsResourceFormatCompressed(ResourceFormat format) { |
| 129 return format == ETC1; | 123 return format == ETC1; |
| 130 } | 124 } |
| 131 | 125 |
| 132 bool DoesResourceFormatSupportAlpha(ResourceFormat format) { | 126 bool DoesResourceFormatSupportAlpha(ResourceFormat format) { |
| 133 switch (format) { | 127 switch (format) { |
| 134 case RGBA_4444: | 128 case RGBA_4444: |
| 135 case RGBA_8888: | 129 case RGBA_8888: |
| 136 case BGRA_8888: | 130 case BGRA_8888: |
| 137 case ALPHA_8: | 131 case ALPHA_8: |
| 138 case RGBA_F16: | |
| 139 return true; | 132 return true; |
| 140 case LUMINANCE_8: | 133 case LUMINANCE_8: |
| 141 case RGB_565: | 134 case RGB_565: |
| 142 case ETC1: | 135 case ETC1: |
| 143 case RED_8: | 136 case RED_8: |
| 144 case LUMINANCE_F16: | 137 case LUMINANCE_F16: |
| 145 return false; | 138 return false; |
| 146 } | 139 } |
| 147 NOTREACHED(); | 140 NOTREACHED(); |
| 148 return false; | 141 return false; |
| 149 } | 142 } |
| 150 | 143 |
| 151 } // namespace cc | 144 } // namespace cc |
| OLD | NEW |