michael@0: /* michael@0: * Copyright (C) 2005 The Android Open Source Project michael@0: * michael@0: * Licensed under the Apache License, Version 2.0 (the "License"); michael@0: * you may not use this file except in compliance with the License. michael@0: * You may obtain a copy of the License at michael@0: * michael@0: * http://www.apache.org/licenses/LICENSE-2.0 michael@0: * michael@0: * Unless required by applicable law or agreed to in writing, software michael@0: * distributed under the License is distributed on an "AS IS" BASIS, michael@0: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. michael@0: * See the License for the specific language governing permissions and michael@0: * limitations under the License. michael@0: */ michael@0: michael@0: // michael@0: michael@0: // Pixel formats used across the system. michael@0: // These formats might not all be supported by all renderers, for instance michael@0: // skia or SurfaceFlinger are not required to support all of these formats michael@0: // (either as source or destination) michael@0: michael@0: // XXX: we should consolidate these formats and skia's michael@0: michael@0: #ifndef UI_PIXELFORMAT_H michael@0: #define UI_PIXELFORMAT_H michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: namespace android { michael@0: michael@0: enum { michael@0: // michael@0: // these constants need to match those michael@0: // in graphics/PixelFormat.java & pixelflinger/format.h michael@0: // michael@0: PIXEL_FORMAT_UNKNOWN = 0, michael@0: PIXEL_FORMAT_NONE = 0, michael@0: michael@0: // logical pixel formats used by the SurfaceFlinger ----------------------- michael@0: PIXEL_FORMAT_CUSTOM = -4, michael@0: // Custom pixel-format described by a PixelFormatInfo structure michael@0: michael@0: PIXEL_FORMAT_TRANSLUCENT = -3, michael@0: // System chooses a format that supports translucency (many alpha bits) michael@0: michael@0: PIXEL_FORMAT_TRANSPARENT = -2, michael@0: // System chooses a format that supports transparency michael@0: // (at least 1 alpha bit) michael@0: michael@0: PIXEL_FORMAT_OPAQUE = -1, michael@0: // System chooses an opaque format (no alpha bits required) michael@0: michael@0: // real pixel formats supported for rendering ----------------------------- michael@0: michael@0: PIXEL_FORMAT_RGBA_8888 = HAL_PIXEL_FORMAT_RGBA_8888, // 4x8-bit RGBA michael@0: PIXEL_FORMAT_RGBX_8888 = HAL_PIXEL_FORMAT_RGBX_8888, // 4x8-bit RGB0 michael@0: PIXEL_FORMAT_RGB_888 = HAL_PIXEL_FORMAT_RGB_888, // 3x8-bit RGB michael@0: PIXEL_FORMAT_RGB_565 = HAL_PIXEL_FORMAT_RGB_565, // 16-bit RGB michael@0: PIXEL_FORMAT_BGRA_8888 = HAL_PIXEL_FORMAT_BGRA_8888, // 4x8-bit BGRA michael@0: PIXEL_FORMAT_RGBA_5551 = HAL_PIXEL_FORMAT_RGBA_5551, // 16-bit ARGB michael@0: PIXEL_FORMAT_RGBA_4444 = HAL_PIXEL_FORMAT_RGBA_4444, // 16-bit ARGB michael@0: PIXEL_FORMAT_A_8 = GGL_PIXEL_FORMAT_A_8, // 8-bit A michael@0: PIXEL_FORMAT_L_8 = GGL_PIXEL_FORMAT_L_8, // 8-bit L (R=G=B=L) michael@0: PIXEL_FORMAT_LA_88 = GGL_PIXEL_FORMAT_LA_88, // 16-bit LA michael@0: PIXEL_FORMAT_RGB_332 = GGL_PIXEL_FORMAT_RGB_332, // 8-bit RGB michael@0: michael@0: // New formats can be added if they're also defined in michael@0: // pixelflinger/format.h michael@0: }; michael@0: michael@0: typedef int32_t PixelFormat; michael@0: michael@0: struct PixelFormatInfo michael@0: { michael@0: enum { michael@0: INDEX_ALPHA = 0, michael@0: INDEX_RED = 1, michael@0: INDEX_GREEN = 2, michael@0: INDEX_BLUE = 3 michael@0: }; michael@0: michael@0: enum { // components michael@0: ALPHA = 1, michael@0: RGB = 2, michael@0: RGBA = 3, michael@0: LUMINANCE = 4, michael@0: LUMINANCE_ALPHA = 5, michael@0: OTHER = 0xFF michael@0: }; michael@0: michael@0: struct szinfo { michael@0: uint8_t h; michael@0: uint8_t l; michael@0: }; michael@0: michael@0: inline PixelFormatInfo() : version(sizeof(PixelFormatInfo)) { } michael@0: size_t getScanlineSize(unsigned int width) const; michael@0: size_t getSize(size_t ci) const { michael@0: return (ci <= 3) ? (cinfo[ci].h - cinfo[ci].l) : 0; michael@0: } michael@0: size_t version; michael@0: PixelFormat format; michael@0: size_t bytesPerPixel; michael@0: size_t bitsPerPixel; michael@0: union { michael@0: szinfo cinfo[4]; michael@0: struct { michael@0: uint8_t h_alpha; michael@0: uint8_t l_alpha; michael@0: uint8_t h_red; michael@0: uint8_t l_red; michael@0: uint8_t h_green; michael@0: uint8_t l_green; michael@0: uint8_t h_blue; michael@0: uint8_t l_blue; michael@0: }; michael@0: }; michael@0: uint8_t components; michael@0: uint8_t reserved0[3]; michael@0: uint32_t reserved1; michael@0: }; michael@0: michael@0: // Consider caching the results of these functions are they're not michael@0: // guaranteed to be fast. michael@0: ssize_t bytesPerPixel(PixelFormat format); michael@0: ssize_t bitsPerPixel(PixelFormat format); michael@0: status_t getPixelFormatInfo(PixelFormat format, PixelFormatInfo* info); michael@0: michael@0: }; // namespace android michael@0: michael@0: #endif // UI_PIXELFORMAT_H