blob: f46f25c36d14e4802d6478e17bb7d836c685a2cf [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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>
Mathias Agopian8f2423e2010-02-16 17:33:37 -080033#include <hardware/hardware.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034
35namespace android {
36
37enum {
38 //
39 // these constants need to match those
40 // in graphics/PixelFormat.java & pixelflinger/format.h
41 //
42 PIXEL_FORMAT_UNKNOWN = 0,
43 PIXEL_FORMAT_NONE = 0,
44
45 // logical pixel formats used by the SurfaceFlinger -----------------------
46 PIXEL_FORMAT_CUSTOM = -4,
47 // Custom pixel-format described by a PixelFormatInfo structure
48
49 PIXEL_FORMAT_TRANSLUCENT = -3,
50 // System chooses a format that supports translucency (many alpha bits)
51
52 PIXEL_FORMAT_TRANSPARENT = -2,
53 // System chooses a format that supports transparency
54 // (at least 1 alpha bit)
55
56 PIXEL_FORMAT_OPAQUE = -1,
57 // System chooses an opaque format (no alpha bits required)
58
59 // real pixel formats supported for rendering -----------------------------
60
Mathias Agopian8f2423e2010-02-16 17:33:37 -080061 PIXEL_FORMAT_RGBA_8888 = HAL_PIXEL_FORMAT_RGBA_8888, // 4x8-bit RGBA
62 PIXEL_FORMAT_RGBX_8888 = HAL_PIXEL_FORMAT_RGBX_8888, // 4x8-bit RGB0
63 PIXEL_FORMAT_RGB_888 = HAL_PIXEL_FORMAT_RGB_888, // 3x8-bit RGB
64 PIXEL_FORMAT_RGB_565 = HAL_PIXEL_FORMAT_RGB_565, // 16-bit RGB
65 PIXEL_FORMAT_BGRA_8888 = HAL_PIXEL_FORMAT_BGRA_8888, // 4x8-bit BGRA
66 PIXEL_FORMAT_RGBA_5551 = HAL_PIXEL_FORMAT_RGBA_5551, // 16-bit ARGB
67 PIXEL_FORMAT_RGBA_4444 = HAL_PIXEL_FORMAT_RGBA_4444, // 16-bit ARGB
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068 PIXEL_FORMAT_A_8 = GGL_PIXEL_FORMAT_A_8, // 8-bit A
69 PIXEL_FORMAT_L_8 = GGL_PIXEL_FORMAT_L_8, // 8-bit L (R=G=B=L)
70 PIXEL_FORMAT_LA_88 = GGL_PIXEL_FORMAT_LA_88, // 16-bit LA
71 PIXEL_FORMAT_RGB_332 = GGL_PIXEL_FORMAT_RGB_332, // 8-bit RGB
72
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073 // New formats can be added if they're also defined in
74 // pixelflinger/format.h
75};
76
77typedef int32_t PixelFormat;
78
79struct PixelFormatInfo
80{
Mathias Agopian1473f462009-04-10 14:24:30 -070081 enum {
82 INDEX_ALPHA = 0,
83 INDEX_RED = 1,
84 INDEX_GREEN = 2,
85 INDEX_BLUE = 3
86 };
87
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080088 enum { // components
89 ALPHA = 1,
90 RGB = 2,
91 RGBA = 3,
92 LUMINANCE = 4,
Mathias Agopian102f49f2010-02-16 20:43:39 -080093 LUMINANCE_ALPHA = 5,
94 OTHER = 0xFF
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080095 };
96
Mathias Agopian1473f462009-04-10 14:24:30 -070097 struct szinfo {
98 uint8_t h;
99 uint8_t l;
100 };
101
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800102 inline PixelFormatInfo() : version(sizeof(PixelFormatInfo)) { }
103 size_t getScanlineSize(unsigned int width) const;
Mathias Agopian1473f462009-04-10 14:24:30 -0700104 size_t getSize(size_t ci) const {
105 return (ci <= 3) ? (cinfo[ci].h - cinfo[ci].l) : 0;
106 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107 size_t version;
108 PixelFormat format;
109 size_t bytesPerPixel;
110 size_t bitsPerPixel;
Mathias Agopian1473f462009-04-10 14:24:30 -0700111 union {
112 szinfo cinfo[4];
113 struct {
114 uint8_t h_alpha;
115 uint8_t l_alpha;
116 uint8_t h_red;
117 uint8_t l_red;
118 uint8_t h_green;
119 uint8_t l_green;
120 uint8_t h_blue;
121 uint8_t l_blue;
122 };
123 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800124 uint8_t components;
125 uint8_t reserved0[3];
126 uint32_t reserved1;
127};
128
129// Consider caching the results of these functions are they're not
130// guaranteed to be fast.
131ssize_t bytesPerPixel(PixelFormat format);
132ssize_t bitsPerPixel(PixelFormat format);
133status_t getPixelFormatInfo(PixelFormat format, PixelFormatInfo* info);
134
135}; // namespace android
136
137#endif // UI_PIXELFORMAT_H