blob: 14af8232bb15c53306ead0708634fe709cfaab09 [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,
The Android Open Source Project27629322009-01-09 17:51:23 -080046 // Custom pixel-format described by a PixelFormatInfo structure
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070047
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
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080064 PIXEL_FORMAT_BGRA_8888 = GGL_PIXEL_FORMAT_BGRA_8888, // 4x8-bit BGRA
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070065 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,
The Android Open Source Projecta6938ba2009-02-10 15:44:00 -080074 PIXEL_FORMAT_YCbCr_422_P = GGL_PIXEL_FORMAT_YCbCr_422_P,
75 PIXEL_FORMAT_YCbCr_420_P = GGL_PIXEL_FORMAT_YCbCr_420_P,
76 PIXEL_FORMAT_YCbCr_422_I = GGL_PIXEL_FORMAT_YCbCr_422_I,
77 PIXEL_FORMAT_YCbCr_420_I = GGL_PIXEL_FORMAT_YCbCr_420_I,
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070078
79 // New formats can be added if they're also defined in
80 // pixelflinger/format.h
81};
82
83typedef int32_t PixelFormat;
84
85struct PixelFormatInfo
86{
The Android Open Source Projecta6938ba2009-02-10 15:44:00 -080087 enum { // components
88 ALPHA = 1,
89 RGB = 2,
90 RGBA = 3,
91 LUMINANCE = 4,
92 LUMINANCE_ALPHA = 5,
93 Y_CB_CR_SP = 6,
94 Y_CB_CR_P = 7,
95 Y_CB_CR_I = 8,
96 };
97
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070098 inline PixelFormatInfo() : version(sizeof(PixelFormatInfo)) { }
The Android Open Source Projecta6938ba2009-02-10 15:44:00 -080099 size_t getScanlineSize(unsigned int width) const;
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700100 size_t version;
101 PixelFormat format;
102 size_t bytesPerPixel;
103 size_t bitsPerPixel;
104 uint8_t h_alpha;
105 uint8_t l_alpha;
106 uint8_t h_red;
107 uint8_t l_red;
108 uint8_t h_green;
109 uint8_t l_green;
110 uint8_t h_blue;
111 uint8_t l_blue;
The Android Open Source Projecta6938ba2009-02-10 15:44:00 -0800112 uint8_t components;
113 uint8_t reserved0[3];
114 uint32_t reserved1;
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700115};
116
The Android Open Source Project27629322009-01-09 17:51:23 -0800117// Consider caching the results of these functions are they're not
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700118// guaranteed to be fast.
119ssize_t bytesPerPixel(PixelFormat format);
120ssize_t bitsPerPixel(PixelFormat format);
121status_t getPixelFormatInfo(PixelFormat format, PixelFormatInfo* info);
122
123}; // namespace android
124
125#endif // UI_PIXELFORMAT_H