1a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/*
2a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * Copyright (C) 2008 The Android Open Source Project
3a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian *
4a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * Licensed under the Apache License, Version 2.0 (the "License");
5a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * you may not use this file except in compliance with the License.
6a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * You may obtain a copy of the License at
7a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian *
8a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian *      http://www.apache.org/licenses/LICENSE-2.0
9a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian *
10a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * Unless required by applicable law or agreed to in writing, software
11a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * distributed under the License is distributed on an "AS IS" BASIS,
12a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * See the License for the specific language governing permissions and
14a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * limitations under the License.
15a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */
16a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
17a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
18a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#ifndef ANDROID_GRALLOC_INTERFACE_H
19a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#define ANDROID_GRALLOC_INTERFACE_H
20a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
2133c0fe022e166007547d9c7390e7e6dbba5122e7Iliyan Malchev#include <system/window.h>
22a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#include <hardware/hardware.h>
23a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
24a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#include <stdint.h>
25a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#include <sys/cdefs.h>
26a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#include <sys/types.h>
27a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
285337b102898cfd48eda7215df15baaf3bc96521fMathias Agopian#include <cutils/native_handle.h>
295337b102898cfd48eda7215df15baaf3bc96521fMathias Agopian
305337b102898cfd48eda7215df15baaf3bc96521fMathias Agopian#include <hardware/hardware.h>
315337b102898cfd48eda7215df15baaf3bc96521fMathias Agopian#include <hardware/fb.h>
325337b102898cfd48eda7215df15baaf3bc96521fMathias Agopian
33a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian__BEGIN_DECLS
34a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
35e99520400f228e45b1feff28eb4105b8e5599196Erik Gilling#define GRALLOC_API_VERSION 1
36e99520400f228e45b1feff28eb4105b8e5599196Erik Gilling
37a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/**
38a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * The id of this module
39a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */
40a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#define GRALLOC_HARDWARE_MODULE_ID "gralloc"
41a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
42a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/**
43a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * Name of the graphics device to open
44a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */
45a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
46a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#define GRALLOC_HARDWARE_GPU0 "gpu0"
47a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
48a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopianenum {
49a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* buffer is never read in software */
5029ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis    GRALLOC_USAGE_SW_READ_NEVER         = 0x00000000,
51a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* buffer is rarely read in software */
5229ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis    GRALLOC_USAGE_SW_READ_RARELY        = 0x00000002,
53a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* buffer is often read in software */
5429ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis    GRALLOC_USAGE_SW_READ_OFTEN         = 0x00000003,
55a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* mask for the software read values */
5629ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis    GRALLOC_USAGE_SW_READ_MASK          = 0x0000000F,
57a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
58a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* buffer is never written in software */
5929ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis    GRALLOC_USAGE_SW_WRITE_NEVER        = 0x00000000,
60a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* buffer is never written in software */
6129ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis    GRALLOC_USAGE_SW_WRITE_RARELY       = 0x00000020,
62a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* buffer is never written in software */
6329ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis    GRALLOC_USAGE_SW_WRITE_OFTEN        = 0x00000030,
64a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* mask for the software write values */
6529ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis    GRALLOC_USAGE_SW_WRITE_MASK         = 0x000000F0,
66a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
67a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* buffer will be used as an OpenGL ES texture */
6829ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis    GRALLOC_USAGE_HW_TEXTURE            = 0x00000100,
69a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* buffer will be used as an OpenGL ES render target */
7029ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis    GRALLOC_USAGE_HW_RENDER             = 0x00000200,
71a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* buffer will be used by the 2D hardware blitter */
7229ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis    GRALLOC_USAGE_HW_2D                 = 0x00000400,
734b560d5563ee4699cd24938c2f13b4a416408273Jamie Gennis    /* buffer will be used by the HWComposer HAL module */
7429ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis    GRALLOC_USAGE_HW_COMPOSER           = 0x00000800,
75a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* buffer will be used with the framebuffer device */
7629ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis    GRALLOC_USAGE_HW_FB                 = 0x00001000,
7729ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis    /* buffer will be used with the HW video encoder */
7829ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis    GRALLOC_USAGE_HW_VIDEO_ENCODER      = 0x00010000,
79a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* mask for the software usage bit-mask */
8029ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis    GRALLOC_USAGE_HW_MASK               = 0x00011F00,
8195d78bef32edd183fb8c16b7775bf0a069948420Jamie Gennis
827edeaf91a8d066e6797f875451f8aa9e9a4682f6Jamie Gennis    /* buffer should be displayed full-screen on an external display when
837edeaf91a8d066e6797f875451f8aa9e9a4682f6Jamie Gennis     * possible
847edeaf91a8d066e6797f875451f8aa9e9a4682f6Jamie Gennis     */
8529ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis    GRALLOC_USAGE_EXTERNAL_DISP         = 0x00002000,
867edeaf91a8d066e6797f875451f8aa9e9a4682f6Jamie Gennis
877cb277a5c26447df01196bb19650235603062e93Glenn Kasten    /* Must have a hardware-protected path to external display sink for
887cb277a5c26447df01196bb19650235603062e93Glenn Kasten     * this buffer.  If a hardware-protected path is not available, then
897cb277a5c26447df01196bb19650235603062e93Glenn Kasten     * either don't composite only this buffer (preferred) to the
907cb277a5c26447df01196bb19650235603062e93Glenn Kasten     * external sink, or (less desirable) do not route the entire
917cb277a5c26447df01196bb19650235603062e93Glenn Kasten     * composition to the external sink.
927cb277a5c26447df01196bb19650235603062e93Glenn Kasten     */
9329ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis    GRALLOC_USAGE_PROTECTED             = 0x00004000,
947cb277a5c26447df01196bb19650235603062e93Glenn Kasten
9595d78bef32edd183fb8c16b7775bf0a069948420Jamie Gennis    /* implementation-specific private usage flags */
9629ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis    GRALLOC_USAGE_PRIVATE_0             = 0x10000000,
9729ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis    GRALLOC_USAGE_PRIVATE_1             = 0x20000000,
9829ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis    GRALLOC_USAGE_PRIVATE_2             = 0x40000000,
9929ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis    GRALLOC_USAGE_PRIVATE_3             = 0x80000000,
10029ead941b377cb87bcc7fe48208b96d84d649d43Jamie Gennis    GRALLOC_USAGE_PRIVATE_MASK          = 0xF0000000,
101a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian};
102a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
103a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/*****************************************************************************/
104a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
105a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/**
106a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
107a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * and the fields of this data structure must begin with hw_module_t
108a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * followed by module specific information.
109a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */
1109d82c1a447a72a2c086b9cd34c5b73b163d7acbcMathias Agopiantypedef struct gralloc_module_t {
111a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    struct hw_module_t common;
112a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
113988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian    /*
114988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * (*registerBuffer)() must be called before a buffer_handle_t that has not
115988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * been created with (*alloc_device_t::alloc)() can be used.
116988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     *
117988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * This is intended to be used with buffer_handle_t's that have been
118988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * received in this process through IPC.
119988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     *
120988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * This function checks that the handle is indeed a valid one and prepares
121988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * it for use with (*lock)() and (*unlock)().
122988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     *
123988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * It is not necessary to call (*registerBuffer)() on a handle created
124988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * with (*alloc_device_t::alloc)().
125a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     *
126988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * returns an error if this buffer_handle_t is not valid.
127a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     */
128988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian    int (*registerBuffer)(struct gralloc_module_t const* module,
129988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian            buffer_handle_t handle);
130a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
131a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /*
132988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * (*unregisterBuffer)() is called once this handle is no longer needed in
133988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * this process. After this call, it is an error to call (*lock)(),
134988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * (*unlock)(), or (*registerBuffer)().
135988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     *
136988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * This function doesn't close or free the handle itself; this is done
137988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * by other means, usually through libcutils's native_handle_close() and
138988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * native_handle_free().
139a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     *
140988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * It is an error to call (*unregisterBuffer)() on a buffer that wasn't
141988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * explicitly registered first.
142a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     */
143988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian    int (*unregisterBuffer)(struct gralloc_module_t const* module,
144988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian            buffer_handle_t handle);
145a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
146a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /*
147a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * The (*lock)() method is called before a buffer is accessed for the
148a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * specified usage. This call may block, for instance if the h/w needs
149a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * to finish rendering or if CPU caches need to be synchronized.
150a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     *
151988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * The caller promises to modify only pixels in the area specified
152988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * by (l,t,w,h).
153a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     *
154a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * The content of the buffer outside of the specified area is NOT modified
155a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * by this call.
156988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     *
157988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * If usage specifies GRALLOC_USAGE_SW_*, vaddr is filled with the address
158988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * of the buffer in virtual memory.
159988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     *
160485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian     * THREADING CONSIDERATIONS:
161485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian     *
162485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian     * It is legal for several different threads to lock a buffer from
163485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian     * read access, none of the threads are blocked.
164485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian     *
165485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian     * However, locking a buffer simultaneously for write or read/write is
166485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian     * undefined, but:
167485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian     * - shall not result in termination of the process
168485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian     * - shall not block the caller
169485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian     * It is acceptable to return an error or to leave the buffer's content
170485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian     * into an indeterminate state.
171485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian     *
172988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * If the buffer was created with a usage mask incompatible with the
173988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * requested usage flags here, -EINVAL is returned.
174a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     *
175a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     */
176a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
177a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    int (*lock)(struct gralloc_module_t const* module,
178a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian            buffer_handle_t handle, int usage,
179988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian            int l, int t, int w, int h,
180988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian            void** vaddr);
181a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
182a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
183a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /*
184a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * The (*unlock)() method must be called after all changes to the buffer
185a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * are completed.
186a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     */
187a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
188a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    int (*unlock)(struct gralloc_module_t const* module,
189a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian            buffer_handle_t handle);
190a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
191cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian
192cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian    /* reserved for future use */
193cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian    int (*perform)(struct gralloc_module_t const* module,
194cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian            int operation, ... );
195cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian
1968255d9d3b62ddf90269ddbb54e6f92b29908fa75Mathias Agopian    /* reserved for future use */
197cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian    void* reserved_proc[7];
1989d82c1a447a72a2c086b9cd34c5b73b163d7acbcMathias Agopian} gralloc_module_t;
199a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
200a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/*****************************************************************************/
201a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
202a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/**
203a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * Every device data structure must begin with hw_device_t
204a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * followed by module specific public methods and attributes.
205a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */
206a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
2079d82c1a447a72a2c086b9cd34c5b73b163d7acbcMathias Agopiantypedef struct alloc_device_t {
208a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    struct hw_device_t common;
209a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
210a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /*
211a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * (*alloc)() Allocates a buffer in graphic memory with the requested
212a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * parameters and returns a buffer_handle_t and the stride in pixels to
213a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * allow the implementation to satisfy hardware constraints on the width
214a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * of a pixmap (eg: it may have to be multiple of 8 pixels).
215a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * The CALLER TAKES OWNERSHIP of the buffer_handle_t.
216a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     *
217a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * Returns 0 on success or -errno on error.
218a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     */
219a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
220a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    int (*alloc)(struct alloc_device_t* dev,
221a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian            int w, int h, int format, int usage,
222a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian            buffer_handle_t* handle, int* stride);
223a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
224a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /*
225a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * (*free)() Frees a previously allocated buffer.
226a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * Behavior is undefined if the buffer is still mapped in any process,
227a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * but shall not result in termination of the program or security breaches
228a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * (allowing a process to get access to another process' buffers).
229a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * THIS FUNCTION TAKES OWNERSHIP of the buffer_handle_t which becomes
230a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * invalid after the call.
231a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     *
232a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * Returns 0 on success or -errno on error.
233a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     */
234a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    int (*free)(struct alloc_device_t* dev,
235a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian            buffer_handle_t handle);
236a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
237158549c89405186d9ecaefd3811cfae3949056eeErik Gilling    /* This hook is OPTIONAL.
238158549c89405186d9ecaefd3811cfae3949056eeErik Gilling     *
239158549c89405186d9ecaefd3811cfae3949056eeErik Gilling     * If non NULL it will be caused by SurfaceFlinger on dumpsys
240158549c89405186d9ecaefd3811cfae3949056eeErik Gilling     */
241158549c89405186d9ecaefd3811cfae3949056eeErik Gilling    void (*dump)(struct alloc_device_t *dev, char *buff, int buff_len);
242158549c89405186d9ecaefd3811cfae3949056eeErik Gilling
243158549c89405186d9ecaefd3811cfae3949056eeErik Gilling    void* reserved_proc[7];
2449d82c1a447a72a2c086b9cd34c5b73b163d7acbcMathias Agopian} alloc_device_t;
245a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
246a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
247a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/** convenience API for opening and closing a supported device */
248a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
249a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopianstatic inline int gralloc_open(const struct hw_module_t* module,
250a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian        struct alloc_device_t** device) {
251a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    return module->methods->open(module,
252a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian            GRALLOC_HARDWARE_GPU0, (struct hw_device_t**)device);
253a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian}
254a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
255a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopianstatic inline int gralloc_close(struct alloc_device_t* device) {
256a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    return device->common.close(&device->common);
257a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian}
258a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
259a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian__END_DECLS
260a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
261a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#endif  // ANDROID_ALLOC_INTERFACE_H
262