Home | History | Annotate | Download | only in hardware
      1 /*
      2  * Copyright (C) 2008 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 ANDROID_COPYBIT_INTERFACE_H
     18 #define ANDROID_COPYBIT_INTERFACE_H
     19 
     20 #include <hardware/hardware.h>
     21 
     22 #include <stdint.h>
     23 #include <sys/cdefs.h>
     24 #include <sys/types.h>
     25 
     26 __BEGIN_DECLS
     27 
     28 /**
     29  * The id of this module
     30  */
     31 #define COPYBIT_HARDWARE_MODULE_ID "copybit"
     32 
     33 /**
     34  * Name of the graphics device to open
     35  */
     36 #define COPYBIT_HARDWARE_COPYBIT0 "copybit0"
     37 
     38 /* supported pixel-formats. these must be compatible with
     39  * graphics/PixelFormat.java, ui/PixelFormat.h, pixelflinger/format.h
     40  */
     41 enum {
     42     COPYBIT_FORMAT_RGBA_8888    = HAL_PIXEL_FORMAT_RGBA_8888,
     43     COPYBIT_FORMAT_RGBX_8888    = HAL_PIXEL_FORMAT_RGBX_8888,
     44     COPYBIT_FORMAT_RGB_888      = HAL_PIXEL_FORMAT_RGB_888,
     45     COPYBIT_FORMAT_RGB_565      = HAL_PIXEL_FORMAT_RGB_565,
     46     COPYBIT_FORMAT_BGRA_8888    = HAL_PIXEL_FORMAT_BGRA_8888,
     47     COPYBIT_FORMAT_RGBA_5551    = HAL_PIXEL_FORMAT_RGBA_5551,
     48     COPYBIT_FORMAT_RGBA_4444    = HAL_PIXEL_FORMAT_RGBA_4444,
     49     COPYBIT_FORMAT_YCbCr_422_SP = HAL_PIXEL_FORMAT_YCbCr_422_SP,
     50     COPYBIT_FORMAT_YCbCr_420_SP = HAL_PIXEL_FORMAT_YCbCr_420_SP,
     51     COPYBIT_FORMAT_YCrCb_422_SP = HAL_PIXEL_FORMAT_YCrCb_422_SP,
     52     COPYBIT_FORMAT_YCrCb_420_SP = HAL_PIXEL_FORMAT_YCrCb_420_SP,
     53 };
     54 
     55 /* name for copybit_set_parameter */
     56 enum {
     57     /* rotation of the source image in degrees (0 to 359) */
     58     COPYBIT_ROTATION_DEG    = 1,
     59     /* plane alpha value */
     60     COPYBIT_PLANE_ALPHA     = 2,
     61     /* enable or disable dithering */
     62     COPYBIT_DITHER          = 3,
     63     /* transformation applied (this is a superset of COPYBIT_ROTATION_DEG) */
     64     COPYBIT_TRANSFORM       = 4,
     65     /* blurs the copied bitmap. The amount of blurring cannot be changed
     66      * at this time. */
     67     COPYBIT_BLUR            = 5
     68 };
     69 
     70 /* values for copybit_set_parameter(COPYBIT_TRANSFORM) */
     71 enum {
     72     /* flip source image horizontally */
     73     COPYBIT_TRANSFORM_FLIP_H    = HAL_TRANSFORM_FLIP_H,
     74     /* flip source image vertically */
     75     COPYBIT_TRANSFORM_FLIP_V    = HAL_TRANSFORM_FLIP_V,
     76     /* rotate source image 90 degres */
     77     COPYBIT_TRANSFORM_ROT_90    = HAL_TRANSFORM_ROT_90,
     78     /* rotate source image 180 degres */
     79     COPYBIT_TRANSFORM_ROT_180   = HAL_TRANSFORM_ROT_180,
     80     /* rotate source image 270 degres */
     81     COPYBIT_TRANSFORM_ROT_270   = HAL_TRANSFORM_ROT_270,
     82 };
     83 
     84 /* enable/disable value copybit_set_parameter */
     85 enum {
     86     COPYBIT_DISABLE = 0,
     87     COPYBIT_ENABLE  = 1
     88 };
     89 
     90 /* use get_static_info() to query static informations about the hardware */
     91 enum {
     92     /* Maximum amount of minification supported by the hardware*/
     93     COPYBIT_MINIFICATION_LIMIT  = 1,
     94     /* Maximum amount of magnification supported by the hardware */
     95     COPYBIT_MAGNIFICATION_LIMIT = 2,
     96     /* Number of fractional bits support by the scaling engine */
     97     COPYBIT_SCALING_FRAC_BITS   = 3,
     98     /* Supported rotation step in degres. */
     99     COPYBIT_ROTATION_STEP_DEG   = 4,
    100 };
    101 
    102 /* Image structure */
    103 struct copybit_image_t {
    104     /* width */
    105     uint32_t    w;
    106     /* height */
    107     uint32_t    h;
    108     /* format COPYBIT_FORMAT_xxx */
    109     int32_t     format;
    110     /* base of buffer with image */
    111     void        *base;
    112     /* handle to the image */
    113     native_handle_t* handle;
    114 };
    115 
    116 /* Rectangle */
    117 struct copybit_rect_t {
    118     /* left */
    119     int l;
    120     /* top */
    121     int t;
    122     /* right */
    123     int r;
    124     /* bottom */
    125     int b;
    126 };
    127 
    128 /* Region */
    129 struct copybit_region_t {
    130     int (*next)(struct copybit_region_t const *region, struct copybit_rect_t *rect);
    131 };
    132 
    133 /**
    134  * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
    135  * and the fields of this data structure must begin with hw_module_t
    136  * followed by module specific information.
    137  */
    138 struct copybit_module_t {
    139     struct hw_module_t common;
    140 };
    141 
    142 /**
    143  * Every device data structure must begin with hw_device_t
    144  * followed by module specific public methods and attributes.
    145  */
    146 struct copybit_device_t {
    147     struct hw_device_t common;
    148 
    149     /**
    150      * Set a copybit parameter.
    151      *
    152      * @param dev from open
    153      * @param name one for the COPYBIT_NAME_xxx
    154      * @param value one of the COPYBIT_VALUE_xxx
    155      *
    156      * @return 0 if successful
    157      */
    158     int (*set_parameter)(struct copybit_device_t *dev, int name, int value);
    159 
    160     /**
    161      * Get a static copybit information.
    162      *
    163      * @param dev from open
    164      * @param name one of the COPYBIT_STATIC_xxx
    165      *
    166      * @return value or -EINVAL if error
    167      */
    168     int (*get)(struct copybit_device_t *dev, int name);
    169 
    170     /**
    171      * Execute the bit blit copy operation
    172      *
    173      * @param dev from open
    174      * @param dst is the destination image
    175      * @param src is the source image
    176      * @param region the clip region
    177      *
    178      * @return 0 if successful
    179      */
    180     int (*blit)(struct copybit_device_t *dev,
    181                 struct copybit_image_t const *dst,
    182                 struct copybit_image_t const *src,
    183                 struct copybit_region_t const *region);
    184 
    185     /**
    186      * Execute the stretch bit blit copy operation
    187      *
    188      * @param dev from open
    189      * @param dst is the destination image
    190      * @param src is the source image
    191      * @param dst_rect is the destination rectangle
    192      * @param src_rect is the source rectangle
    193      * @param region the clip region
    194      *
    195      * @return 0 if successful
    196      */
    197     int (*stretch)(struct copybit_device_t *dev,
    198                    struct copybit_image_t const *dst,
    199                    struct copybit_image_t const *src,
    200                    struct copybit_rect_t const *dst_rect,
    201                    struct copybit_rect_t const *src_rect,
    202                    struct copybit_region_t const *region);
    203 };
    204 
    205 
    206 /** convenience API for opening and closing a device */
    207 
    208 static inline int copybit_open(const struct hw_module_t* module,
    209         struct copybit_device_t** device) {
    210     return module->methods->open(module,
    211             COPYBIT_HARDWARE_COPYBIT0, (struct hw_device_t**)device);
    212 }
    213 
    214 static inline int copybit_close(struct copybit_device_t* device) {
    215     return device->common.close(&device->common);
    216 }
    217 
    218 
    219 __END_DECLS
    220 
    221 #endif  // ANDROID_COPYBIT_INTERFACE_H
    222