The Android Open Source Project | edbf3b6 | 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 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | |
| 25 | #ifndef UI_PIXELFORMAT_H |
| 26 | #define UI_PIXELFORMAT_H |
| 27 | |
| 28 | #include <stdint.h> |
| 29 | #include <sys/types.h> |
| 30 | #include <utils/Errors.h> |
Mathias Agopian | 54ed4f6 | 2010-02-16 17:33:37 -0800 | [diff] [blame] | 31 | #include <hardware/hardware.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | |
| 33 | namespace android { |
| 34 | |
| 35 | enum { |
| 36 | // |
| 37 | // these constants need to match those |
| 38 | // in graphics/PixelFormat.java & pixelflinger/format.h |
| 39 | // |
| 40 | PIXEL_FORMAT_UNKNOWN = 0, |
| 41 | PIXEL_FORMAT_NONE = 0, |
| 42 | |
| 43 | // logical pixel formats used by the SurfaceFlinger ----------------------- |
| 44 | PIXEL_FORMAT_CUSTOM = -4, |
| 45 | // Custom pixel-format described by a PixelFormatInfo structure |
| 46 | |
| 47 | PIXEL_FORMAT_TRANSLUCENT = -3, |
| 48 | // System chooses a format that supports translucency (many alpha bits) |
| 49 | |
| 50 | PIXEL_FORMAT_TRANSPARENT = -2, |
| 51 | // System chooses a format that supports transparency |
| 52 | // (at least 1 alpha bit) |
| 53 | |
| 54 | PIXEL_FORMAT_OPAQUE = -1, |
| 55 | // System chooses an opaque format (no alpha bits required) |
Pannag Sanketi | acb7b5d | 2011-06-10 18:30:30 -0700 | [diff] [blame] | 56 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | // real pixel formats supported for rendering ----------------------------- |
| 58 | |
Mathias Agopian | 54ed4f6 | 2010-02-16 17:33:37 -0800 | [diff] [blame] | 59 | PIXEL_FORMAT_RGBA_8888 = HAL_PIXEL_FORMAT_RGBA_8888, // 4x8-bit RGBA |
| 60 | PIXEL_FORMAT_RGBX_8888 = HAL_PIXEL_FORMAT_RGBX_8888, // 4x8-bit RGB0 |
| 61 | PIXEL_FORMAT_RGB_888 = HAL_PIXEL_FORMAT_RGB_888, // 3x8-bit RGB |
| 62 | PIXEL_FORMAT_RGB_565 = HAL_PIXEL_FORMAT_RGB_565, // 16-bit RGB |
| 63 | PIXEL_FORMAT_BGRA_8888 = HAL_PIXEL_FORMAT_BGRA_8888, // 4x8-bit BGRA |
| 64 | PIXEL_FORMAT_RGBA_5551 = HAL_PIXEL_FORMAT_RGBA_5551, // 16-bit ARGB |
| 65 | PIXEL_FORMAT_RGBA_4444 = HAL_PIXEL_FORMAT_RGBA_4444, // 16-bit ARGB |
Mathias Agopian | 42e2458 | 2012-02-21 18:56:08 -0800 | [diff] [blame] | 66 | PIXEL_FORMAT_A_8 = 8, // 8-bit A |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | // New formats can be added if they're also defined in |
| 69 | // pixelflinger/format.h |
| 70 | }; |
| 71 | |
| 72 | typedef int32_t PixelFormat; |
| 73 | |
Mathias Agopian | 42e2458 | 2012-02-21 18:56:08 -0800 | [diff] [blame] | 74 | struct PixelFormatInfo { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 75 | enum { |
| 76 | INDEX_ALPHA = 0, |
| 77 | INDEX_RED = 1, |
| 78 | INDEX_GREEN = 2, |
| 79 | INDEX_BLUE = 3 |
| 80 | }; |
Pannag Sanketi | acb7b5d | 2011-06-10 18:30:30 -0700 | [diff] [blame] | 81 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | enum { // components |
| 83 | ALPHA = 1, |
| 84 | RGB = 2, |
| 85 | RGBA = 3, |
Mathias Agopian | 3db2164 | 2010-02-16 20:43:39 -0800 | [diff] [blame] | 86 | OTHER = 0xFF |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | }; |
| 88 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 89 | struct szinfo { |
| 90 | uint8_t h; |
| 91 | uint8_t l; |
| 92 | }; |
Pannag Sanketi | acb7b5d | 2011-06-10 18:30:30 -0700 | [diff] [blame] | 93 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | inline PixelFormatInfo() : version(sizeof(PixelFormatInfo)) { } |
| 95 | size_t getScanlineSize(unsigned int width) const; |
Pannag Sanketi | acb7b5d | 2011-06-10 18:30:30 -0700 | [diff] [blame] | 96 | size_t getSize(size_t ci) const { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 97 | return (ci <= 3) ? (cinfo[ci].h - cinfo[ci].l) : 0; |
| 98 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | size_t version; |
| 100 | PixelFormat format; |
| 101 | size_t bytesPerPixel; |
| 102 | size_t bitsPerPixel; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 103 | union { |
| 104 | szinfo cinfo[4]; |
| 105 | struct { |
| 106 | uint8_t h_alpha; |
Pannag Sanketi | acb7b5d | 2011-06-10 18:30:30 -0700 | [diff] [blame] | 107 | uint8_t l_alpha; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 108 | uint8_t h_red; |
| 109 | uint8_t l_red; |
| 110 | uint8_t h_green; |
| 111 | uint8_t l_green; |
| 112 | uint8_t h_blue; |
| 113 | uint8_t l_blue; |
| 114 | }; |
| 115 | }; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | uint8_t components; |
| 117 | uint8_t reserved0[3]; |
| 118 | uint32_t reserved1; |
| 119 | }; |
| 120 | |
| 121 | // Consider caching the results of these functions are they're not |
| 122 | // guaranteed to be fast. |
| 123 | ssize_t bytesPerPixel(PixelFormat format); |
| 124 | ssize_t bitsPerPixel(PixelFormat format); |
| 125 | status_t getPixelFormatInfo(PixelFormat format, PixelFormatInfo* info); |
| 126 | |
| 127 | }; // namespace android |
| 128 | |
| 129 | #endif // UI_PIXELFORMAT_H |