Home | History | Annotate | Download | only in system
      1 /*
      2  * Copyright (C) 2011 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 #ifndef SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H
     18 #define SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H
     19 
     20 #include <stdint.h>
     21 
     22 #ifdef __cplusplus
     23 extern "C" {
     24 #endif
     25 
     26 /*
     27  * If the HAL needs to create service threads to handle graphics related
     28  * tasks, these threads need to run at HAL_PRIORITY_URGENT_DISPLAY priority
     29  * if they can block the main rendering thread in any way.
     30  *
     31  * the priority of the current thread can be set with:
     32  *
     33  *      #include <sys/resource.h>
     34  *      setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY);
     35  *
     36  */
     37 
     38 #define HAL_PRIORITY_URGENT_DISPLAY     (-8)
     39 
     40 /**
     41  * pixel format definitions
     42  */
     43 
     44 enum {
     45     HAL_PIXEL_FORMAT_RGBA_8888          = 1,
     46     HAL_PIXEL_FORMAT_RGBX_8888          = 2,
     47     HAL_PIXEL_FORMAT_RGB_888            = 3,
     48     HAL_PIXEL_FORMAT_RGB_565            = 4,
     49     HAL_PIXEL_FORMAT_BGRA_8888          = 5,
     50     HAL_PIXEL_FORMAT_RGBA_5551          = 6,
     51     HAL_PIXEL_FORMAT_RGBA_4444          = 7,
     52 
     53     /* 0x8 - 0xFF range unavailable */
     54 
     55     /*
     56      * 0x100 - 0x1FF
     57      *
     58      * This range is reserved for pixel formats that are specific to the HAL
     59      * implementation.  Implementations can use any value in this range to
     60      * communicate video pixel formats between their HAL modules.  These formats
     61      * must not have an alpha channel.  Additionally, an EGLimage created from a
     62      * gralloc buffer of one of these formats must be supported for use with the
     63      * GL_OES_EGL_image_external OpenGL ES extension.
     64      */
     65 
     66     /*
     67      * Android YUV format:
     68      *
     69      * This format is exposed outside of the HAL to software decoders and
     70      * applications.  EGLImageKHR must support it in conjunction with the
     71      * OES_EGL_image_external extension.
     72      *
     73      * YV12 is a 4:2:0 YCrCb planar format comprised of a WxH Y plane followed
     74      * by (W/2) x (H/2) Cr and Cb planes.
     75      *
     76      * This format assumes
     77      * - an even width
     78      * - an even height
     79      * - a horizontal stride multiple of 16 pixels
     80      * - a vertical stride equal to the height
     81      *
     82      *   y_size = stride * height
     83      *   c_stride = ALIGN(stride/2, 16)
     84      *   c_size = c_stride * height/2
     85      *   size = y_size + c_size * 2
     86      *   cr_offset = y_size
     87      *   cb_offset = y_size + c_size
     88      *
     89      */
     90     HAL_PIXEL_FORMAT_YV12   = 0x32315659, // YCrCb 4:2:0 Planar
     91 
     92 
     93     /*
     94      * Android Y8 format:
     95      *
     96      * This format is exposed outside of the HAL to the framework.
     97      * The expected gralloc usage flags are SW_* and HW_CAMERA_*,
     98      * and no other HW_ flags will be used.
     99      *
    100      * Y8 is a YUV planar format comprised of a WxH Y plane,
    101      * with each pixel being represented by 8 bits.
    102      *
    103      * It is equivalent to just the Y plane from YV12.
    104      *
    105      * This format assumes
    106      * - an even width
    107      * - an even height
    108      * - a horizontal stride multiple of 16 pixels
    109      * - a vertical stride equal to the height
    110      *
    111      *   size = stride * height
    112      *
    113      */
    114     HAL_PIXEL_FORMAT_Y8     = 0x20203859,
    115 
    116     /*
    117      * Android Y16 format:
    118      *
    119      * This format is exposed outside of the HAL to the framework.
    120      * The expected gralloc usage flags are SW_* and HW_CAMERA_*,
    121      * and no other HW_ flags will be used.
    122      *
    123      * Y16 is a YUV planar format comprised of a WxH Y plane,
    124      * with each pixel being represented by 16 bits.
    125      *
    126      * It is just like Y8, but has double the bits per pixel (little endian).
    127      *
    128      * This format assumes
    129      * - an even width
    130      * - an even height
    131      * - a horizontal stride multiple of 16 pixels
    132      * - a vertical stride equal to the height
    133      * - strides are specified in pixels, not in bytes
    134      *
    135      *   size = stride * height * 2
    136      *
    137      */
    138     HAL_PIXEL_FORMAT_Y16    = 0x20363159,
    139 
    140     /*
    141      * Android RAW sensor format:
    142      *
    143      * This format is exposed outside of the HAL to applications.
    144      *
    145      * RAW_SENSOR is a single-channel 16-bit format, typically representing raw
    146      * Bayer-pattern images from an image sensor, with minimal processing.
    147      *
    148      * The exact pixel layout of the data in the buffer is sensor-dependent, and
    149      * needs to be queried from the camera device.
    150      *
    151      * Generally, not all 16 bits are used; more common values are 10 or 12
    152      * bits. All parameters to interpret the raw data (black and white points,
    153      * color space, etc) must be queried from the camera device.
    154      *
    155      * This format assumes
    156      * - an even width
    157      * - an even height
    158      * - a horizontal stride multiple of 16 pixels (32 bytes).
    159      */
    160     HAL_PIXEL_FORMAT_RAW_SENSOR = 0x20,
    161 
    162     /*
    163      * Android binary blob graphics buffer format:
    164      *
    165      * This format is used to carry task-specific data which does not have a
    166      * standard image structure. The details of the format are left to the two
    167      * endpoints.
    168      *
    169      * A typical use case is for transporting JPEG-compressed images from the
    170      * Camera HAL to the framework or to applications.
    171      *
    172      * Buffers of this format must have a height of 1, and width equal to their
    173      * size in bytes.
    174      */
    175     HAL_PIXEL_FORMAT_BLOB = 0x21,
    176 
    177     /*
    178      * Android format indicating that the choice of format is entirely up to the
    179      * device-specific Gralloc implementation.
    180      *
    181      * The Gralloc implementation should examine the usage bits passed in when
    182      * allocating a buffer with this format, and it should derive the pixel
    183      * format from those usage flags.  This format will never be used with any
    184      * of the GRALLOC_USAGE_SW_* usage flags.
    185      *
    186      * If a buffer of this format is to be used as an OpenGL ES texture, the
    187      * framework will assume that sampling the texture will always return an
    188      * alpha value of 1.0 (i.e. the buffer contains only opaque pixel values).
    189      *
    190      */
    191     HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED = 0x22,
    192 
    193     /*
    194      * Android flexible YCbCr formats
    195      *
    196      * This format allows platforms to use an efficient YCbCr/YCrCb buffer
    197      * layout, while still describing the buffer layout in a way accessible to
    198      * the CPU in a device-independent manner.  While called YCbCr, it can be
    199      * used to describe formats with either chromatic ordering, as well as
    200      * whole planar or semiplanar layouts.
    201      *
    202      * struct android_ycbcr (below) is the the struct used to describe it.
    203      *
    204      * This format must be accepted by the gralloc module when
    205      * USAGE_HW_CAMERA_WRITE and USAGE_SW_READ_* are set.
    206      *
    207      * This format is locked for use by gralloc's (*lock_ycbcr) method, and
    208      * locking with the (*lock) method will return an error.
    209      */
    210     HAL_PIXEL_FORMAT_YCbCr_420_888 = 0x23,
    211 
    212     /* Legacy formats (deprecated), used by ImageFormat.java */
    213     HAL_PIXEL_FORMAT_YCbCr_422_SP       = 0x10, // NV16
    214     HAL_PIXEL_FORMAT_YCrCb_420_SP       = 0x11, // NV21
    215     HAL_PIXEL_FORMAT_YCbCr_422_I        = 0x14, // YUY2
    216 };
    217 
    218 /*
    219  * Structure for describing YCbCr formats for consumption by applications.
    220  * This is used with HAL_PIXEL_FORMAT_YCbCr_*_888.
    221  *
    222  * Buffer chroma subsampling is defined in the format.
    223  * e.g. HAL_PIXEL_FORMAT_YCbCr_420_888 has subsampling 4:2:0.
    224  *
    225  * Buffers must have a 8 bit depth.
    226  *
    227  * @y, @cb, and @cr point to the first byte of their respective planes.
    228  *
    229  * Stride describes the distance in bytes from the first value of one row of
    230  * the image to the first value of the next row.  It includes the width of the
    231  * image plus padding.
    232  * @ystride is the stride of the luma plane.
    233  * @cstride is the stride of the chroma planes.
    234  *
    235  * @chroma_step is the distance in bytes from one chroma pixel value to the
    236  * next.  This is 2 bytes for semiplanar (because chroma values are interleaved
    237  * and each chroma value is one byte) and 1 for planar.
    238  */
    239 
    240 struct android_ycbcr {
    241     void *y;
    242     void *cb;
    243     void *cr;
    244     size_t ystride;
    245     size_t cstride;
    246     size_t chroma_step;
    247 
    248     /** reserved for future use, set to 0 by gralloc's (*lock_ycbcr)() */
    249     uint32_t reserved[8];
    250 };
    251 
    252 /**
    253  * Transformation definitions
    254  *
    255  * IMPORTANT NOTE:
    256  * HAL_TRANSFORM_ROT_90 is applied CLOCKWISE and AFTER HAL_TRANSFORM_FLIP_{H|V}.
    257  *
    258  */
    259 
    260 enum {
    261     /* flip source image horizontally (around the vertical axis) */
    262     HAL_TRANSFORM_FLIP_H    = 0x01,
    263     /* flip source image vertically (around the horizontal axis)*/
    264     HAL_TRANSFORM_FLIP_V    = 0x02,
    265     /* rotate source image 90 degrees clockwise */
    266     HAL_TRANSFORM_ROT_90    = 0x04,
    267     /* rotate source image 180 degrees */
    268     HAL_TRANSFORM_ROT_180   = 0x03,
    269     /* rotate source image 270 degrees clockwise */
    270     HAL_TRANSFORM_ROT_270   = 0x07,
    271 };
    272 
    273 #ifdef __cplusplus
    274 }
    275 #endif
    276 
    277 #endif /* SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H */
    278