The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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> |
Mathias Agopian | 8f2423e | 2010-02-16 17:33:37 -0800 | [diff] [blame] | 33 | #include <hardware/hardware.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | |
| 35 | namespace android { |
| 36 | |
| 37 | enum { |
| 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 Agopian | 8f2423e | 2010-02-16 17:33:37 -0800 | [diff] [blame] | 61 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | // New formats can be added if they're also defined in |
| 74 | // pixelflinger/format.h |
| 75 | }; |
| 76 | |
| 77 | typedef int32_t PixelFormat; |
| 78 | |
| 79 | struct PixelFormatInfo |
| 80 | { |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 81 | enum { |
| 82 | INDEX_ALPHA = 0, |
| 83 | INDEX_RED = 1, |
| 84 | INDEX_GREEN = 2, |
| 85 | INDEX_BLUE = 3 |
| 86 | }; |
| 87 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | enum { // components |
| 89 | ALPHA = 1, |
| 90 | RGB = 2, |
| 91 | RGBA = 3, |
| 92 | LUMINANCE = 4, |
Mathias Agopian | 102f49f | 2010-02-16 20:43:39 -0800 | [diff] [blame] | 93 | LUMINANCE_ALPHA = 5, |
| 94 | OTHER = 0xFF |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | }; |
| 96 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 97 | struct szinfo { |
| 98 | uint8_t h; |
| 99 | uint8_t l; |
| 100 | }; |
| 101 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | inline PixelFormatInfo() : version(sizeof(PixelFormatInfo)) { } |
| 103 | size_t getScanlineSize(unsigned int width) const; |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 104 | size_t getSize(size_t ci) const { |
| 105 | return (ci <= 3) ? (cinfo[ci].h - cinfo[ci].l) : 0; |
| 106 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | size_t version; |
| 108 | PixelFormat format; |
| 109 | size_t bytesPerPixel; |
| 110 | size_t bitsPerPixel; |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 111 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | 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. |
| 131 | ssize_t bytesPerPixel(PixelFormat format); |
| 132 | ssize_t bitsPerPixel(PixelFormat format); |
| 133 | status_t getPixelFormatInfo(PixelFormat format, PixelFormatInfo* info); |
| 134 | |
| 135 | }; // namespace android |
| 136 | |
| 137 | #endif // UI_PIXELFORMAT_H |