media/omx-plugin/include/ics/hardware/gralloc.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/omx-plugin/include/ics/hardware/gralloc.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,261 @@
     1.4 +/*
     1.5 + * Copyright (C) 2008 The Android Open Source Project
     1.6 + *
     1.7 + * Licensed under the Apache License, Version 2.0 (the "License");
     1.8 + * you may not use this file except in compliance with the License.
     1.9 + * You may obtain a copy of the License at
    1.10 + *
    1.11 + *      http://www.apache.org/licenses/LICENSE-2.0
    1.12 + *
    1.13 + * Unless required by applicable law or agreed to in writing, software
    1.14 + * distributed under the License is distributed on an "AS IS" BASIS,
    1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.16 + * See the License for the specific language governing permissions and
    1.17 + * limitations under the License.
    1.18 + */
    1.19 +
    1.20 +
    1.21 +#ifndef ANDROID_GRALLOC_INTERFACE_H
    1.22 +#define ANDROID_GRALLOC_INTERFACE_H
    1.23 +
    1.24 +#include <system/window.h>
    1.25 +#include <hardware/hardware.h>
    1.26 +
    1.27 +#include <stdint.h>
    1.28 +#include <sys/cdefs.h>
    1.29 +#include <sys/types.h>
    1.30 +
    1.31 +#include <cutils/native_handle.h>
    1.32 +
    1.33 +#include <hardware/hardware.h>
    1.34 +#include <hardware/fb.h>
    1.35 +
    1.36 +__BEGIN_DECLS
    1.37 +
    1.38 +#define GRALLOC_API_VERSION 1
    1.39 +
    1.40 +/**
    1.41 + * The id of this module
    1.42 + */
    1.43 +#define GRALLOC_HARDWARE_MODULE_ID "gralloc"
    1.44 +
    1.45 +/**
    1.46 + * Name of the graphics device to open
    1.47 + */
    1.48 +
    1.49 +#define GRALLOC_HARDWARE_GPU0 "gpu0"
    1.50 +
    1.51 +enum {
    1.52 +    /* buffer is never read in software */
    1.53 +    GRALLOC_USAGE_SW_READ_NEVER         = 0x00000000,
    1.54 +    /* buffer is rarely read in software */
    1.55 +    GRALLOC_USAGE_SW_READ_RARELY        = 0x00000002,
    1.56 +    /* buffer is often read in software */
    1.57 +    GRALLOC_USAGE_SW_READ_OFTEN         = 0x00000003,
    1.58 +    /* mask for the software read values */
    1.59 +    GRALLOC_USAGE_SW_READ_MASK          = 0x0000000F,
    1.60 +    
    1.61 +    /* buffer is never written in software */
    1.62 +    GRALLOC_USAGE_SW_WRITE_NEVER        = 0x00000000,
    1.63 +    /* buffer is never written in software */
    1.64 +    GRALLOC_USAGE_SW_WRITE_RARELY       = 0x00000020,
    1.65 +    /* buffer is never written in software */
    1.66 +    GRALLOC_USAGE_SW_WRITE_OFTEN        = 0x00000030,
    1.67 +    /* mask for the software write values */
    1.68 +    GRALLOC_USAGE_SW_WRITE_MASK         = 0x000000F0,
    1.69 +
    1.70 +    /* buffer will be used as an OpenGL ES texture */
    1.71 +    GRALLOC_USAGE_HW_TEXTURE            = 0x00000100,
    1.72 +    /* buffer will be used as an OpenGL ES render target */
    1.73 +    GRALLOC_USAGE_HW_RENDER             = 0x00000200,
    1.74 +    /* buffer will be used by the 2D hardware blitter */
    1.75 +    GRALLOC_USAGE_HW_2D                 = 0x00000400,
    1.76 +    /* buffer will be used by the HWComposer HAL module */
    1.77 +    GRALLOC_USAGE_HW_COMPOSER           = 0x00000800,
    1.78 +    /* buffer will be used with the framebuffer device */
    1.79 +    GRALLOC_USAGE_HW_FB                 = 0x00001000,
    1.80 +    /* buffer will be used with the HW video encoder */
    1.81 +    GRALLOC_USAGE_HW_VIDEO_ENCODER      = 0x00010000,
    1.82 +    /* mask for the software usage bit-mask */
    1.83 +    GRALLOC_USAGE_HW_MASK               = 0x00011F00,
    1.84 +
    1.85 +    /* buffer should be displayed full-screen on an external display when
    1.86 +     * possible
    1.87 +     */
    1.88 +    GRALLOC_USAGE_EXTERNAL_DISP         = 0x00002000,
    1.89 +
    1.90 +    /* Must have a hardware-protected path to external display sink for
    1.91 +     * this buffer.  If a hardware-protected path is not available, then
    1.92 +     * either don't composite only this buffer (preferred) to the
    1.93 +     * external sink, or (less desirable) do not route the entire
    1.94 +     * composition to the external sink.
    1.95 +     */
    1.96 +    GRALLOC_USAGE_PROTECTED             = 0x00004000,
    1.97 +
    1.98 +    /* implementation-specific private usage flags */
    1.99 +    GRALLOC_USAGE_PRIVATE_0             = 0x10000000,
   1.100 +    GRALLOC_USAGE_PRIVATE_1             = 0x20000000,
   1.101 +    GRALLOC_USAGE_PRIVATE_2             = 0x40000000,
   1.102 +    GRALLOC_USAGE_PRIVATE_3             = 0x80000000,
   1.103 +    GRALLOC_USAGE_PRIVATE_MASK          = 0xF0000000,
   1.104 +};
   1.105 +
   1.106 +/*****************************************************************************/
   1.107 +
   1.108 +/**
   1.109 + * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
   1.110 + * and the fields of this data structure must begin with hw_module_t
   1.111 + * followed by module specific information.
   1.112 + */
   1.113 +typedef struct gralloc_module_t {
   1.114 +    struct hw_module_t common;
   1.115 +    
   1.116 +    /*
   1.117 +     * (*registerBuffer)() must be called before a buffer_handle_t that has not
   1.118 +     * been created with (*alloc_device_t::alloc)() can be used.
   1.119 +     * 
   1.120 +     * This is intended to be used with buffer_handle_t's that have been
   1.121 +     * received in this process through IPC.
   1.122 +     * 
   1.123 +     * This function checks that the handle is indeed a valid one and prepares
   1.124 +     * it for use with (*lock)() and (*unlock)().
   1.125 +     * 
   1.126 +     * It is not necessary to call (*registerBuffer)() on a handle created 
   1.127 +     * with (*alloc_device_t::alloc)().
   1.128 +     * 
   1.129 +     * returns an error if this buffer_handle_t is not valid.
   1.130 +     */
   1.131 +    int (*registerBuffer)(struct gralloc_module_t const* module,
   1.132 +            buffer_handle_t handle);
   1.133 +
   1.134 +    /*
   1.135 +     * (*unregisterBuffer)() is called once this handle is no longer needed in
   1.136 +     * this process. After this call, it is an error to call (*lock)(),
   1.137 +     * (*unlock)(), or (*registerBuffer)().
   1.138 +     * 
   1.139 +     * This function doesn't close or free the handle itself; this is done
   1.140 +     * by other means, usually through libcutils's native_handle_close() and
   1.141 +     * native_handle_free(). 
   1.142 +     * 
   1.143 +     * It is an error to call (*unregisterBuffer)() on a buffer that wasn't
   1.144 +     * explicitly registered first.
   1.145 +     */
   1.146 +    int (*unregisterBuffer)(struct gralloc_module_t const* module,
   1.147 +            buffer_handle_t handle);
   1.148 +    
   1.149 +    /*
   1.150 +     * The (*lock)() method is called before a buffer is accessed for the 
   1.151 +     * specified usage. This call may block, for instance if the h/w needs
   1.152 +     * to finish rendering or if CPU caches need to be synchronized.
   1.153 +     * 
   1.154 +     * The caller promises to modify only pixels in the area specified 
   1.155 +     * by (l,t,w,h).
   1.156 +     * 
   1.157 +     * The content of the buffer outside of the specified area is NOT modified
   1.158 +     * by this call.
   1.159 +     *
   1.160 +     * If usage specifies GRALLOC_USAGE_SW_*, vaddr is filled with the address
   1.161 +     * of the buffer in virtual memory.
   1.162 +     *
   1.163 +     * THREADING CONSIDERATIONS:
   1.164 +     *
   1.165 +     * It is legal for several different threads to lock a buffer from 
   1.166 +     * read access, none of the threads are blocked.
   1.167 +     * 
   1.168 +     * However, locking a buffer simultaneously for write or read/write is
   1.169 +     * undefined, but:
   1.170 +     * - shall not result in termination of the process
   1.171 +     * - shall not block the caller
   1.172 +     * It is acceptable to return an error or to leave the buffer's content
   1.173 +     * into an indeterminate state.
   1.174 +     *
   1.175 +     * If the buffer was created with a usage mask incompatible with the
   1.176 +     * requested usage flags here, -EINVAL is returned. 
   1.177 +     * 
   1.178 +     */
   1.179 +    
   1.180 +    int (*lock)(struct gralloc_module_t const* module,
   1.181 +            buffer_handle_t handle, int usage,
   1.182 +            int l, int t, int w, int h,
   1.183 +            void** vaddr);
   1.184 +
   1.185 +    
   1.186 +    /*
   1.187 +     * The (*unlock)() method must be called after all changes to the buffer
   1.188 +     * are completed.
   1.189 +     */
   1.190 +    
   1.191 +    int (*unlock)(struct gralloc_module_t const* module,
   1.192 +            buffer_handle_t handle);
   1.193 +
   1.194 +
   1.195 +    /* reserved for future use */
   1.196 +    int (*perform)(struct gralloc_module_t const* module,
   1.197 +            int operation, ... );
   1.198 +
   1.199 +    /* reserved for future use */
   1.200 +    void* reserved_proc[7];
   1.201 +} gralloc_module_t;
   1.202 +
   1.203 +/*****************************************************************************/
   1.204 +
   1.205 +/**
   1.206 + * Every device data structure must begin with hw_device_t
   1.207 + * followed by module specific public methods and attributes.
   1.208 + */
   1.209 +
   1.210 +typedef struct alloc_device_t {
   1.211 +    struct hw_device_t common;
   1.212 +
   1.213 +    /* 
   1.214 +     * (*alloc)() Allocates a buffer in graphic memory with the requested
   1.215 +     * parameters and returns a buffer_handle_t and the stride in pixels to
   1.216 +     * allow the implementation to satisfy hardware constraints on the width
   1.217 +     * of a pixmap (eg: it may have to be multiple of 8 pixels). 
   1.218 +     * The CALLER TAKES OWNERSHIP of the buffer_handle_t.
   1.219 +     * 
   1.220 +     * Returns 0 on success or -errno on error.
   1.221 +     */
   1.222 +    
   1.223 +    int (*alloc)(struct alloc_device_t* dev,
   1.224 +            int w, int h, int format, int usage,
   1.225 +            buffer_handle_t* handle, int* stride);
   1.226 +
   1.227 +    /*
   1.228 +     * (*free)() Frees a previously allocated buffer. 
   1.229 +     * Behavior is undefined if the buffer is still mapped in any process,
   1.230 +     * but shall not result in termination of the program or security breaches
   1.231 +     * (allowing a process to get access to another process' buffers).
   1.232 +     * THIS FUNCTION TAKES OWNERSHIP of the buffer_handle_t which becomes
   1.233 +     * invalid after the call. 
   1.234 +     * 
   1.235 +     * Returns 0 on success or -errno on error.
   1.236 +     */
   1.237 +    int (*free)(struct alloc_device_t* dev,
   1.238 +            buffer_handle_t handle);
   1.239 +
   1.240 +    /* This hook is OPTIONAL.
   1.241 +     *
   1.242 +     * If non NULL it will be caused by SurfaceFlinger on dumpsys
   1.243 +     */
   1.244 +    void (*dump)(struct alloc_device_t *dev, char *buff, int buff_len);
   1.245 +
   1.246 +    void* reserved_proc[7];
   1.247 +} alloc_device_t;
   1.248 +
   1.249 +
   1.250 +/** convenience API for opening and closing a supported device */
   1.251 +
   1.252 +static inline int gralloc_open(const struct hw_module_t* module, 
   1.253 +        struct alloc_device_t** device) {
   1.254 +    return module->methods->open(module, 
   1.255 +            GRALLOC_HARDWARE_GPU0, (struct hw_device_t**)device);
   1.256 +}
   1.257 +
   1.258 +static inline int gralloc_close(struct alloc_device_t* device) {
   1.259 +    return device->common.close(&device->common);
   1.260 +}
   1.261 +
   1.262 +__END_DECLS
   1.263 +
   1.264 +#endif  // ANDROID_ALLOC_INTERFACE_H

mercurial