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"
12 SkColorType
ResourceFormatToSkColorType(ResourceFormat format
) {
15 return kARGB_4444_SkColorType
;
18 return kN32_SkColorType
;
28 return kN32_SkColorType
;
31 int BitsPerPixel(ResourceFormat format
) {
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
[] = {
73 GL_BGRA_EXT
, // BGRA_8888
75 GL_LUMINANCE
, // LUMINANCE_8
77 GL_ETC1_RGB8_OES
, // ETC1
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
) {
93 return gfx::BufferFormat::RGBA_8888
;
95 return gfx::BufferFormat::BGRA_8888
;
97 return gfx::BufferFormat::RGBA_4444
;
106 return gfx::BufferFormat::RGBA_8888
;