summaryrefslogtreecommitdiffstats
path: root/cc/platform_color.h
blob: 8706114ee895663f64abcde332cab12a7abe2875 (plain)
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
// Copyright 2011 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_PLATFORM_COLOR_H_
#define CC_PLATFORM_COLOR_H_

#include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h"
#include "third_party/khronos/GLES2/gl2.h"
#include "third_party/khronos/GLES2/gl2ext.h"
#include "third_party/skia/include/core/SkTypes.h"

namespace cc {

class PlatformColor {
public:
    enum SourceDataFormat { SourceFormatRGBA8, SourceFormatBGRA8 };

    static SourceDataFormat format()
    {
        return SK_B32_SHIFT ? SourceFormatRGBA8 : SourceFormatBGRA8;
    }

    // Returns the most efficient texture format for this platform.
    static GLenum bestTextureFormat(WebKit::WebGraphicsContext3D* context, bool supportsBGRA8888)
    {
        GLenum textureFormat = GL_RGBA;
        switch (format()) {
        case SourceFormatRGBA8:
            break;
        case SourceFormatBGRA8:
            if (supportsBGRA8888)
                textureFormat = GL_BGRA_EXT;
            break;
        default:
            NOTREACHED();
            break;
        }
        return textureFormat;
    }

    // Return true if the given texture format has the same component order
    // as the color on this platform.
    static bool sameComponentOrder(GLenum textureFormat)
    {
        switch (format()) {
        case SourceFormatRGBA8:
            return textureFormat == GL_RGBA;
        case SourceFormatBGRA8:
            return textureFormat == GL_BGRA_EXT;
        default:
            NOTREACHED();
            return false;
        }
    }
};

} // namespace cc

#endif  // CC_PLATFORM_COLOR_H_