Vectorize website settings icons in omnibox
[chromium-blink-merge.git] / cc / resources / resource_format.cc
blobc62ae934d728f5d749514164f5da80fc9094c4bd
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
3 // found in the LICENSE file.
5 #include "cc/resources/resource_format.h"
7 #include "third_party/khronos/GLES2/gl2.h"
8 #include "third_party/khronos/GLES2/gl2ext.h"
10 namespace cc {
12 SkColorType ResourceFormatToSkColorType(ResourceFormat format) {
13 switch (format) {
14 case RGBA_4444:
15 return kARGB_4444_SkColorType;
16 case RGBA_8888:
17 case BGRA_8888:
18 return kN32_SkColorType;
19 case ETC1:
20 case ALPHA_8:
21 case LUMINANCE_8:
22 case RGB_565:
23 case RED_8:
24 NOTREACHED();
25 break;
27 NOTREACHED();
28 return kN32_SkColorType;
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;
46 NOTREACHED();
47 return 0;
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
62 static_assert(arraysize(format_gl_data_type) == (RESOURCE_FORMAT_MAX + 1),
63 "format_gl_data_type does not handle all cases.");
65 return format_gl_data_type[format];
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
80 static_assert(arraysize(format_gl_data_format) == (RESOURCE_FORMAT_MAX + 1),
81 "format_gl_data_format does not handle all cases.");
83 return format_gl_data_format[format];
86 GLenum GLInternalFormat(ResourceFormat format) {
87 return GLDataFormat(format);
90 gfx::BufferFormat BufferFormat(ResourceFormat format) {
91 switch (format) {
92 case RGBA_8888:
93 return gfx::BufferFormat::RGBA_8888;
94 case BGRA_8888:
95 return gfx::BufferFormat::BGRA_8888;
96 case RGBA_4444:
97 return gfx::BufferFormat::RGBA_4444;
98 case ALPHA_8:
99 case LUMINANCE_8:
100 case RGB_565:
101 case ETC1:
102 case RED_8:
103 break;
105 NOTREACHED();
106 return gfx::BufferFormat::RGBA_8888;
109 } // namespace cc