1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CC_BASE_UTIL_H_
#define CC_BASE_UTIL_H_
#include <limits>
#include "base/basictypes.h"
#include "cc/resources/resource_provider.h"
#include "third_party/khronos/GLES2/gl2.h"
#include "third_party/khronos/GLES2/gl2ext.h"
namespace cc {
template <typename T> T RoundUp(T n, T mul) {
COMPILE_ASSERT(std::numeric_limits<T>::is_integer, type_must_be_integral);
return (n > 0) ? ((n + mul - 1) / mul) * mul
: (n / mul) * mul;
}
template <typename T> T RoundDown(T n, T mul) {
COMPILE_ASSERT(std::numeric_limits<T>::is_integer, type_must_be_integral);
return (n > 0) ? (n / mul) * mul
: (n == 0) ? 0
: ((n - mul + 1) / mul) * mul;
}
inline GLenum GLDataType(ResourceFormat format) {
DCHECK_LE(format, RESOURCE_FORMAT_MAX);
static const unsigned format_gl_data_type[RESOURCE_FORMAT_MAX + 1] = {
GL_UNSIGNED_BYTE, // RGBA_8888
GL_UNSIGNED_SHORT_4_4_4_4, // RGBA_4444
GL_UNSIGNED_BYTE, // BGRA_8888
GL_UNSIGNED_BYTE, // LUMINANCE_8
GL_UNSIGNED_SHORT_5_6_5, // RGB_565,
GL_UNSIGNED_BYTE // ETC1
};
return format_gl_data_type[format];
}
inline GLenum GLDataFormat(ResourceFormat format) {
DCHECK_LE(format, RESOURCE_FORMAT_MAX);
static const unsigned format_gl_data_format[RESOURCE_FORMAT_MAX + 1] = {
GL_RGBA, // RGBA_8888
GL_RGBA, // RGBA_4444
GL_BGRA_EXT, // BGRA_8888
GL_LUMINANCE, // LUMINANCE_8
GL_RGB, // RGB_565
GL_ETC1_RGB8_OES // ETC1
};
return format_gl_data_format[format];
}
inline GLenum GLInternalFormat(ResourceFormat format) {
return GLDataFormat(format);
}
} // namespace cc
#endif // CC_BASE_UTIL_H_
|