PixelFormat.h revision 276293246ea9cbc0a578a7697cc48930376ec0e9
1/*
2 * Copyright (C) 2005 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//
18
19// Pixel formats used across the system.
20// These formats might not all be supported by all renderers, for instance
21// skia or SurfaceFlinger are not required to support all of these formats
22// (either as source or destination)
23
24// XXX: we should consolidate these formats and skia's
25
26#ifndef UI_PIXELFORMAT_H
27#define UI_PIXELFORMAT_H
28
29#include <stdint.h>
30#include <sys/types.h>
31#include <utils/Errors.h>
32#include <pixelflinger/format.h>
33
34namespace android {
35
36enum {
37    //
38    // these constants need to match those
39    // in graphics/PixelFormat.java & pixelflinger/format.h
40    //
41    PIXEL_FORMAT_UNKNOWN    =   0,
42    PIXEL_FORMAT_NONE       =   0,
43
44    // logical pixel formats used by the SurfaceFlinger -----------------------
45    PIXEL_FORMAT_CUSTOM         = -4,
46        // Custom pixel-format described by a PixelFormatInfo structure
47
48    PIXEL_FORMAT_TRANSLUCENT    = -3,
49        // System chooses a format that supports translucency (many alpha bits)
50
51    PIXEL_FORMAT_TRANSPARENT    = -2,
52        // System chooses a format that supports transparency
53        // (at least 1 alpha bit)
54
55    PIXEL_FORMAT_OPAQUE         = -1,
56        // System chooses an opaque format (no alpha bits required)
57
58    // real pixel formats supported for rendering -----------------------------
59
60    PIXEL_FORMAT_RGBA_8888   = GGL_PIXEL_FORMAT_RGBA_8888,  // 4x8-bit RGBA
61    PIXEL_FORMAT_RGBX_8888   = GGL_PIXEL_FORMAT_RGBX_8888,  // 4x8-bit RGB0
62    PIXEL_FORMAT_RGB_888     = GGL_PIXEL_FORMAT_RGB_888,    // 3x8-bit RGB
63    PIXEL_FORMAT_RGB_565     = GGL_PIXEL_FORMAT_RGB_565,    // 16-bit RGB
64    PIXEL_FORMAT_BGRA_8888   = GGL_PIXEL_FORMAT_BGRA_8888,  // 4x8-bit BGRA
65    PIXEL_FORMAT_RGBA_5551   = GGL_PIXEL_FORMAT_RGBA_5551,  // 16-bit ARGB
66    PIXEL_FORMAT_RGBA_4444   = GGL_PIXEL_FORMAT_RGBA_4444,  // 16-bit ARGB
67    PIXEL_FORMAT_A_8         = GGL_PIXEL_FORMAT_A_8,        // 8-bit A
68    PIXEL_FORMAT_L_8         = GGL_PIXEL_FORMAT_L_8,        // 8-bit L (R=G=B=L)
69    PIXEL_FORMAT_LA_88       = GGL_PIXEL_FORMAT_LA_88,      // 16-bit LA
70    PIXEL_FORMAT_RGB_332     = GGL_PIXEL_FORMAT_RGB_332,    // 8-bit RGB
71
72    PIXEL_FORMAT_YCbCr_422_SP= GGL_PIXEL_FORMAT_YCbCr_422_SP,
73    PIXEL_FORMAT_YCbCr_420_SP= GGL_PIXEL_FORMAT_YCbCr_420_SP,
74
75    // New formats can be added if they're also defined in
76    // pixelflinger/format.h
77};
78
79typedef int32_t PixelFormat;
80
81struct PixelFormatInfo
82{
83    inline PixelFormatInfo() : version(sizeof(PixelFormatInfo)) { }
84    size_t      version;
85    PixelFormat format;
86    size_t      bytesPerPixel;
87    size_t      bitsPerPixel;
88    uint8_t     h_alpha;
89    uint8_t     l_alpha;
90    uint8_t     h_red;
91    uint8_t     l_red;
92    uint8_t     h_green;
93    uint8_t     l_green;
94    uint8_t     h_blue;
95    uint8_t     l_blue;
96    uint32_t    reserved[2];
97};
98
99// Consider caching the results of these functions are they're not
100// guaranteed to be fast.
101ssize_t     bytesPerPixel(PixelFormat format);
102ssize_t     bitsPerPixel(PixelFormat format);
103status_t    getPixelFormatInfo(PixelFormat format, PixelFormatInfo* info);
104
105}; // namespace android
106
107#endif // UI_PIXELFORMAT_H
108