blob: d56a4a75c956a56f32d397ab1cabcbad8606fb7f [file] [log] [blame]
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -07001/*
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 sructure
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_RGBA_5551 = GGL_PIXEL_FORMAT_RGBA_5551, // 16-bit ARGB
65 PIXEL_FORMAT_RGBA_4444 = GGL_PIXEL_FORMAT_RGBA_4444, // 16-bit ARGB
66 PIXEL_FORMAT_A_8 = GGL_PIXEL_FORMAT_A_8, // 8-bit A
67 PIXEL_FORMAT_L_8 = GGL_PIXEL_FORMAT_L_8, // 8-bit L (R=G=B=L)
68 PIXEL_FORMAT_LA_88 = GGL_PIXEL_FORMAT_LA_88, // 16-bit LA
69 PIXEL_FORMAT_RGB_332 = GGL_PIXEL_FORMAT_RGB_332, // 8-bit RGB
70
71 PIXEL_FORMAT_YCbCr_422_SP= GGL_PIXEL_FORMAT_YCbCr_422_SP,
72 PIXEL_FORMAT_YCbCr_420_SP= GGL_PIXEL_FORMAT_YCbCr_420_SP,
73
74 // New formats can be added if they're also defined in
75 // pixelflinger/format.h
76};
77
78typedef int32_t PixelFormat;
79
80struct PixelFormatInfo
81{
82 inline PixelFormatInfo() : version(sizeof(PixelFormatInfo)) { }
83 size_t version;
84 PixelFormat format;
85 size_t bytesPerPixel;
86 size_t bitsPerPixel;
87 uint8_t h_alpha;
88 uint8_t l_alpha;
89 uint8_t h_red;
90 uint8_t l_red;
91 uint8_t h_green;
92 uint8_t l_green;
93 uint8_t h_blue;
94 uint8_t l_blue;
95 uint32_t reserved[2];
96};
97
98// considere caching the results of these functions are they're not
99// guaranteed to be fast.
100ssize_t bytesPerPixel(PixelFormat format);
101ssize_t bitsPerPixel(PixelFormat format);
102status_t getPixelFormatInfo(PixelFormat format, PixelFormatInfo* info);
103
104}; // namespace android
105
106#endif // UI_PIXELFORMAT_H