1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _PIXELFLINGER2_FORMAT_H_
18#define _PIXELFLINGER2_FORMAT_H_
19
20#include <stdint.h>
21#include <sys/types.h>
22
23enum GGLPixelFormat {
24    // these constants need to match those
25    // in graphics/PixelFormat.java, ui/PixelFormat.h, BlitHardware.h
26    GGL_PIXEL_FORMAT_UNKNOWN    =   0,
27    GGL_PIXEL_FORMAT_NONE       =   0,
28
29    GGL_PIXEL_FORMAT_RGBA_8888   =   1,  // 4x8-bit ARGB
30    GGL_PIXEL_FORMAT_RGBX_8888   =   2,  // 3x8-bit RGB stored in 32-bit chunks
31    GGL_PIXEL_FORMAT_RGB_888     =   3,  // 3x8-bit RGB
32    GGL_PIXEL_FORMAT_RGB_565     =   4,  // 16-bit RGB
33    GGL_PIXEL_FORMAT_BGRA_8888   =   5,  // 4x8-bit BGRA
34    GGL_PIXEL_FORMAT_RGBA_5551   =   6,  // 16-bit RGBA
35    GGL_PIXEL_FORMAT_RGBA_4444   =   7,  // 16-bit RGBA
36
37    GGL_PIXEL_FORMAT_A_8         =   8,  // 8-bit A
38    GGL_PIXEL_FORMAT_L_8         =   9,  // 8-bit L (R=G=B = L)
39    GGL_PIXEL_FORMAT_LA_88       = 0xA,  // 16-bit LA
40    GGL_PIXEL_FORMAT_RGB_332     = 0xB,  // 8-bit RGB (non paletted)
41
42    // reserved range. don't use.
43    GGL_PIXEL_FORMAT_RESERVED_10 = 0x10,
44    GGL_PIXEL_FORMAT_RESERVED_11 = 0x11,
45    GGL_PIXEL_FORMAT_RESERVED_12 = 0x12,
46    GGL_PIXEL_FORMAT_RESERVED_13 = 0x13,
47    GGL_PIXEL_FORMAT_RESERVED_14 = 0x14,
48    GGL_PIXEL_FORMAT_RESERVED_15 = 0x15,
49    GGL_PIXEL_FORMAT_RESERVED_16 = 0x16,
50    GGL_PIXEL_FORMAT_RESERVED_17 = 0x17,
51
52    // reserved/special formats
53    GGL_PIXEL_FORMAT_Z_16       =  0x18,
54    GGL_PIXEL_FORMAT_S_8        =  0x19,
55    GGL_PIXEL_FORMAT_SZ_24      =  0x1A,
56    GGL_PIXEL_FORMAT_SZ_8       =  0x1B,
57
58    GGL_PIXEL_FORMAT_Z_32       = 0x1C,
59
60    // reserved range. don't use.
61    GGL_PIXEL_FORMAT_RESERVED_20 = 0x20,
62    GGL_PIXEL_FORMAT_RESERVED_21 = 0x21,
63
64
65    // must be last
66    GGL_PIXEL_FORMAT_COUNT      = 0xFF
67};
68
69enum GGLFormatComponents {
70        GGL_STENCIL_INDEX               = 0x1901,
71        GGL_DEPTH_COMPONENT             = 0x1902,
72        GGL_ALPHA                       = 0x1906,
73        GGL_RGB                         = 0x1907,
74        GGL_RGBA                        = 0x1908,
75        GGL_LUMINANCE                   = 0x1909,
76        GGL_LUMINANCE_ALPHA             = 0x190A,
77};
78
79enum GGLFormatComponentIndex {
80    GGL_INDEX_ALPHA   = 0,
81    GGL_INDEX_RED     = 1,
82    GGL_INDEX_GREEN   = 2,
83    GGL_INDEX_BLUE    = 3,
84    GGL_INDEX_STENCIL = 0,
85    GGL_INDEX_DEPTH   = 1,
86    GGL_INDEX_Y       = 0,
87    GGL_INDEX_CB      = 1,
88    GGL_INDEX_CR      = 2,
89};
90
91typedef struct {
92#ifdef __cplusplus
93    enum {
94        ALPHA   = GGL_INDEX_ALPHA,
95        RED     = GGL_INDEX_RED,
96        GREEN   = GGL_INDEX_GREEN,
97        BLUE    = GGL_INDEX_BLUE,
98        STENCIL = GGL_INDEX_STENCIL,
99        DEPTH   = GGL_INDEX_DEPTH,
100        LUMA    = GGL_INDEX_Y,
101        CHROMAB = GGL_INDEX_CB,
102        CHROMAR = GGL_INDEX_CR,
103    };
104    inline uint32_t mask(int i) const {
105            return ((1<<(c[i].h-c[i].l))-1)<<c[i].l;
106    }
107    inline uint32_t bits(int i) const {
108            return c[i].h - c[i].l;
109    }
110#endif
111    uint8_t     size;       // bytes per pixel
112    uint8_t     bitsPerPixel;
113    union {
114        struct {
115            uint8_t     ah;             // alpha high bit position + 1
116            uint8_t     al;             // alpha low bit position
117            uint8_t     rh;             // red high bit position + 1
118            uint8_t     rl;             // red low bit position
119            uint8_t     gh;             // green high bit position + 1
120            uint8_t     gl;             // green low bit position
121            uint8_t     bh;             // blue high bit position + 1
122            uint8_t     bl;             // blue low bit position
123        };
124        struct {
125            uint8_t h;
126            uint8_t l;
127        } __attribute__((__packed__)) c[4];
128    } __attribute__((__packed__));
129        uint16_t    components; // GGLFormatComponents
130} GGLFormat;
131
132
133#ifdef __cplusplus
134extern "C" const GGLFormat* gglGetPixelFormatTable(size_t* numEntries = 0);
135#else
136const GGLFormat* gglGetPixelFormatTable(size_t* numEntries);
137#endif
138
139#endif // _PIXELFLINGER2_FORMAT_H_
140