gralloc.h revision 97c7c40b73329ee86ce2abe5c320dd82d117ea14
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
21a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#include <cutils/native_handle.h>
22a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
23a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#include <hardware/hardware.h>
24a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
25a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#include <stdint.h>
26a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#include <sys/cdefs.h>
27a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#include <sys/types.h>
28a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
29a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian__BEGIN_DECLS
30a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
31e99520400f228e45b1feff28eb4105b8e5599196Erik Gilling#define GRALLOC_API_VERSION 1
32e99520400f228e45b1feff28eb4105b8e5599196Erik Gilling
33a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/**
34a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * The id of this module
35a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */
36a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#define GRALLOC_HARDWARE_MODULE_ID "gralloc"
37a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
38a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/**
39a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * Name of the graphics device to open
40a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */
41a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
42a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#define GRALLOC_HARDWARE_FB0 "fb0"
43a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#define GRALLOC_HARDWARE_GPU0 "gpu0"
44a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
45a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopianenum {
46a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* buffer is never read in software */
47988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian    GRALLOC_USAGE_SW_READ_NEVER   = 0x00000000,
48a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* buffer is rarely read in software */
49a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    GRALLOC_USAGE_SW_READ_RARELY  = 0x00000002,
50a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* buffer is often read in software */
51a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    GRALLOC_USAGE_SW_READ_OFTEN   = 0x00000003,
52a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* mask for the software read values */
53a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    GRALLOC_USAGE_SW_READ_MASK    = 0x0000000F,
54a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
55a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* buffer is never written in software */
56988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian    GRALLOC_USAGE_SW_WRITE_NEVER  = 0x00000000,
57a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* buffer is never written in software */
58a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    GRALLOC_USAGE_SW_WRITE_RARELY = 0x00000020,
59a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* buffer is never written in software */
60a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    GRALLOC_USAGE_SW_WRITE_OFTEN  = 0x00000030,
61a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* mask for the software write values */
62a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    GRALLOC_USAGE_SW_WRITE_MASK   = 0x000000F0,
63a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
64a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* buffer will be used as an OpenGL ES texture */
65a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    GRALLOC_USAGE_HW_TEXTURE      = 0x00000100,
66a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* buffer will be used as an OpenGL ES render target */
67a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    GRALLOC_USAGE_HW_RENDER       = 0x00000200,
68a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* buffer will be used by the 2D hardware blitter */
69aabb70292351f231bfd4daae8b73edb788eeba1aJamie Gennis    GRALLOC_USAGE_HW_2D           = 0x00000400,
70a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* buffer will be used with the framebuffer device */
71a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    GRALLOC_USAGE_HW_FB           = 0x00001000,
72a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* mask for the software usage bit-mask */
73a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    GRALLOC_USAGE_HW_MASK         = 0x00001F00,
7495d78bef32edd183fb8c16b7775bf0a069948420Jamie Gennis
757edeaf91a8d066e6797f875451f8aa9e9a4682f6Jamie Gennis    /* buffer should be displayed full-screen on an external display when
767edeaf91a8d066e6797f875451f8aa9e9a4682f6Jamie Gennis     * possible
777edeaf91a8d066e6797f875451f8aa9e9a4682f6Jamie Gennis     */
787edeaf91a8d066e6797f875451f8aa9e9a4682f6Jamie Gennis    GRALLOC_USAGE_EXTERNAL_DISP   = 0x00002000,
797edeaf91a8d066e6797f875451f8aa9e9a4682f6Jamie Gennis
807cb277a5c26447df01196bb19650235603062e93Glenn Kasten    /* Must have a hardware-protected path to external display sink for
817cb277a5c26447df01196bb19650235603062e93Glenn Kasten     * this buffer.  If a hardware-protected path is not available, then
827cb277a5c26447df01196bb19650235603062e93Glenn Kasten     * either don't composite only this buffer (preferred) to the
837cb277a5c26447df01196bb19650235603062e93Glenn Kasten     * external sink, or (less desirable) do not route the entire
847cb277a5c26447df01196bb19650235603062e93Glenn Kasten     * composition to the external sink.
857cb277a5c26447df01196bb19650235603062e93Glenn Kasten     */
867cb277a5c26447df01196bb19650235603062e93Glenn Kasten    GRALLOC_USAGE_PROTECTED       = 0x00004000,
877cb277a5c26447df01196bb19650235603062e93Glenn Kasten
8895d78bef32edd183fb8c16b7775bf0a069948420Jamie Gennis    /* implementation-specific private usage flags */
8995d78bef32edd183fb8c16b7775bf0a069948420Jamie Gennis    GRALLOC_USAGE_PRIVATE_0       = 0x10000000,
9095d78bef32edd183fb8c16b7775bf0a069948420Jamie Gennis    GRALLOC_USAGE_PRIVATE_1       = 0x20000000,
9195d78bef32edd183fb8c16b7775bf0a069948420Jamie Gennis    GRALLOC_USAGE_PRIVATE_2       = 0x40000000,
9295d78bef32edd183fb8c16b7775bf0a069948420Jamie Gennis    GRALLOC_USAGE_PRIVATE_3       = 0x80000000,
9395d78bef32edd183fb8c16b7775bf0a069948420Jamie Gennis    GRALLOC_USAGE_PRIVATE_MASK    = 0xF0000000,
94a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian};
95a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
96a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/*****************************************************************************/
97a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
98a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopiantypedef const native_handle* buffer_handle_t;
99a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
100cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopianenum {
101cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian    /* FIXME: this only exists to work-around some issues with
102cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian     * the video and camera frameworks. don't implement unless
103cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian     * you know what you're doing.
104cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian     */
105cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian    GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER = 0x080000001,
106cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian};
107cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian
108a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/**
109a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
110a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * and the fields of this data structure must begin with hw_module_t
111a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * followed by module specific information.
112a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */
1139d82c1a447a72a2c086b9cd34c5b73b163d7acbcMathias Agopiantypedef struct gralloc_module_t {
114a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    struct hw_module_t common;
115a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
116988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian    /*
117988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * (*registerBuffer)() must be called before a buffer_handle_t that has not
118988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * been created with (*alloc_device_t::alloc)() can be used.
119988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     *
120988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * This is intended to be used with buffer_handle_t's that have been
121988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * received in this process through IPC.
122988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     *
123988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * This function checks that the handle is indeed a valid one and prepares
124988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * it for use with (*lock)() and (*unlock)().
125988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     *
126988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * It is not necessary to call (*registerBuffer)() on a handle created
127988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * with (*alloc_device_t::alloc)().
128a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     *
129988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * returns an error if this buffer_handle_t is not valid.
130a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     */
131988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian    int (*registerBuffer)(struct gralloc_module_t const* module,
132988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian            buffer_handle_t handle);
133a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
134a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /*
135988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * (*unregisterBuffer)() is called once this handle is no longer needed in
136988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * this process. After this call, it is an error to call (*lock)(),
137988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * (*unlock)(), or (*registerBuffer)().
138988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     *
139988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * This function doesn't close or free the handle itself; this is done
140988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * by other means, usually through libcutils's native_handle_close() and
141988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * native_handle_free().
142a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     *
143988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * It is an error to call (*unregisterBuffer)() on a buffer that wasn't
144988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * explicitly registered first.
145a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     */
146988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian    int (*unregisterBuffer)(struct gralloc_module_t const* module,
147988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian            buffer_handle_t handle);
148a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
149a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /*
150a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * The (*lock)() method is called before a buffer is accessed for the
151a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * specified usage. This call may block, for instance if the h/w needs
152a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * to finish rendering or if CPU caches need to be synchronized.
153a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     *
154988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * The caller promises to modify only pixels in the area specified
155988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * by (l,t,w,h).
156a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     *
157a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * The content of the buffer outside of the specified area is NOT modified
158a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * by this call.
159988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     *
160988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * If usage specifies GRALLOC_USAGE_SW_*, vaddr is filled with the address
161988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * of the buffer in virtual memory.
162988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     *
163485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian     * THREADING CONSIDERATIONS:
164485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian     *
165485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian     * It is legal for several different threads to lock a buffer from
166485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian     * read access, none of the threads are blocked.
167485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian     *
168485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian     * However, locking a buffer simultaneously for write or read/write is
169485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian     * undefined, but:
170485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian     * - shall not result in termination of the process
171485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian     * - shall not block the caller
172485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian     * It is acceptable to return an error or to leave the buffer's content
173485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian     * into an indeterminate state.
174485e69809aef8bf301b6bf19c03dc2d7693aaa1aMathias Agopian     *
175988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * If the buffer was created with a usage mask incompatible with the
176988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian     * requested usage flags here, -EINVAL is returned.
177a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     *
178a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     */
179a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
180a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    int (*lock)(struct gralloc_module_t const* module,
181a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian            buffer_handle_t handle, int usage,
182988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian            int l, int t, int w, int h,
183988b8bd553180e8d71b4028ecb721f46312efe62Mathias Agopian            void** vaddr);
184a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
185a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
186a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /*
187a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * The (*unlock)() method must be called after all changes to the buffer
188a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * are completed.
189a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     */
190a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
191a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    int (*unlock)(struct gralloc_module_t const* module,
192a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian            buffer_handle_t handle);
193a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
194cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian
195cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian    /* reserved for future use */
196cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian    int (*perform)(struct gralloc_module_t const* module,
197cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian            int operation, ... );
198cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian
1998255d9d3b62ddf90269ddbb54e6f92b29908fa75Mathias Agopian    /* reserved for future use */
200cd2433f3804a537aedc26f595b1c05f95a05244aMathias Agopian    void* reserved_proc[7];
2019d82c1a447a72a2c086b9cd34c5b73b163d7acbcMathias Agopian} gralloc_module_t;
202a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
203a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/*****************************************************************************/
204a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
205a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/**
206a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * Every device data structure must begin with hw_device_t
207a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian * followed by module specific public methods and attributes.
208a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian */
209a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
2109d82c1a447a72a2c086b9cd34c5b73b163d7acbcMathias Agopiantypedef struct alloc_device_t {
211a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    struct hw_device_t common;
212a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
213a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /*
214a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * (*alloc)() Allocates a buffer in graphic memory with the requested
215a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * parameters and returns a buffer_handle_t and the stride in pixels to
216a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * allow the implementation to satisfy hardware constraints on the width
217a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * of a pixmap (eg: it may have to be multiple of 8 pixels).
218a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * The CALLER TAKES OWNERSHIP of the buffer_handle_t.
219a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     *
220a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * Returns 0 on success or -errno on error.
221a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     */
222a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
223a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    int (*alloc)(struct alloc_device_t* dev,
224a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian            int w, int h, int format, int usage,
225a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian            buffer_handle_t* handle, int* stride);
226a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
227a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /*
228a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * (*free)() Frees a previously allocated buffer.
229a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * Behavior is undefined if the buffer is still mapped in any process,
230a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * but shall not result in termination of the program or security breaches
231a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * (allowing a process to get access to another process' buffers).
232a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * THIS FUNCTION TAKES OWNERSHIP of the buffer_handle_t which becomes
233a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * invalid after the call.
234a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     *
235a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * Returns 0 on success or -errno on error.
236a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     */
237a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    int (*free)(struct alloc_device_t* dev,
238a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian            buffer_handle_t handle);
239a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
240158549c89405186d9ecaefd3811cfae3949056eeErik Gilling    /* This hook is OPTIONAL.
241158549c89405186d9ecaefd3811cfae3949056eeErik Gilling     *
242158549c89405186d9ecaefd3811cfae3949056eeErik Gilling     * If non NULL it will be caused by SurfaceFlinger on dumpsys
243158549c89405186d9ecaefd3811cfae3949056eeErik Gilling     */
244158549c89405186d9ecaefd3811cfae3949056eeErik Gilling    void (*dump)(struct alloc_device_t *dev, char *buff, int buff_len);
245158549c89405186d9ecaefd3811cfae3949056eeErik Gilling
246158549c89405186d9ecaefd3811cfae3949056eeErik Gilling    void* reserved_proc[7];
2479d82c1a447a72a2c086b9cd34c5b73b163d7acbcMathias Agopian} alloc_device_t;
248a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
249a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
2509d82c1a447a72a2c086b9cd34c5b73b163d7acbcMathias Agopiantypedef struct framebuffer_device_t {
251a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    struct hw_device_t common;
252a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
253a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* flags describing some attributes of the framebuffer */
254a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    const uint32_t  flags;
255a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
256a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* dimensions of the framebuffer in pixels */
257a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    const uint32_t  width;
258a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    const uint32_t  height;
259a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
260a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* frambuffer stride in pixels */
261a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    const int       stride;
262a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
263a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* framebuffer pixel format */
264a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    const int       format;
265a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
266a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* resolution of the framebuffer's display panel in pixel per inch*/
267a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    const float     xdpi;
268a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    const float     ydpi;
269a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
270a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* framebuffer's display panel refresh rate in frames per second */
271a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    const float     fps;
272a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
273a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* min swap interval supported by this framebuffer */
274a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    const int       minSwapInterval;
275a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
276a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /* max swap interval supported by this framebuffer */
277a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    const int       maxSwapInterval;
278a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
279a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    int reserved[8];
280a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
281a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /*
282a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * requests a specific swap-interval (same definition than EGL)
283a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     *
284a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * Returns 0 on success or -errno on error.
285a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     */
286a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    int (*setSwapInterval)(struct framebuffer_device_t* window,
287a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian            int interval);
288a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
289a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /*
290f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian     * This hook is OPTIONAL.
291f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian     *
292f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian     * It is non NULL If the framebuffer driver supports "update-on-demand"
293f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian     * and the given rectangle is the area of the screen that gets
294f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian     * updated during (*post)().
295f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian     *
296f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian     * This is useful on devices that are able to DMA only a portion of
297f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian     * the screen to the display panel, upon demand -- as opposed to
298f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian     * constantly refreshing the panel 60 times per second, for instance.
299f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian     *
3008255d9d3b62ddf90269ddbb54e6f92b29908fa75Mathias Agopian     * Only the area defined by this rectangle is guaranteed to be valid, that
301f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian     * is, the driver is not allowed to post anything outside of this
302f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian     * rectangle.
303f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian     *
304f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian     * The rectangle evaluated during (*post)() and specifies which area
305f5cf8f842a5736281098ef1f8f837ab688b35707Mathias Agopian     * of the buffer passed in (*post)() shall to be posted.
306a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     *
307a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * return -EINVAL if width or height <=0, or if left or top < 0
308a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     */
309a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    int (*setUpdateRect)(struct framebuffer_device_t* window,
310a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian            int left, int top, int width, int height);
311a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
312a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    /*
313a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * Post <buffer> to the display (display it on the screen)
314a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * The buffer must have been allocated with the
315a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     *   GRALLOC_USAGE_HW_FB usage flag.
316a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * buffer must be the same width and height as the display and must NOT
317a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * be locked.
318a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     *
319a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * The buffer is shown during the next VSYNC.
320a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     *
321a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * If the same buffer is posted again (possibly after some other buffer),
322a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * post() will block until the the first post is completed.
323a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     *
324a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * Internally, post() is expected to lock the buffer so that a
325a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * subsequent call to gralloc_module_t::(*lock)() with USAGE_RENDER or
326a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * USAGE_*_WRITE will block until it is safe; that is typically once this
327a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * buffer is shown and another buffer has been posted.
328a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     *
329a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     * Returns 0 on success or -errno on error.
330a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian     */
331a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    int (*post)(struct framebuffer_device_t* dev, buffer_handle_t buffer);
332a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
3338255d9d3b62ddf90269ddbb54e6f92b29908fa75Mathias Agopian
3348255d9d3b62ddf90269ddbb54e6f92b29908fa75Mathias Agopian    /*
3358255d9d3b62ddf90269ddbb54e6f92b29908fa75Mathias Agopian     * The (*compositionComplete)() method must be called after the
3368255d9d3b62ddf90269ddbb54e6f92b29908fa75Mathias Agopian     * compositor has finished issuing GL commands for client buffers.
3378255d9d3b62ddf90269ddbb54e6f92b29908fa75Mathias Agopian     */
3388255d9d3b62ddf90269ddbb54e6f92b29908fa75Mathias Agopian
3398255d9d3b62ddf90269ddbb54e6f92b29908fa75Mathias Agopian    int (*compositionComplete)(struct framebuffer_device_t* dev);
3408255d9d3b62ddf90269ddbb54e6f92b29908fa75Mathias Agopian
341158549c89405186d9ecaefd3811cfae3949056eeErik Gilling    /*
342158549c89405186d9ecaefd3811cfae3949056eeErik Gilling     * This hook is OPTIONAL.
343158549c89405186d9ecaefd3811cfae3949056eeErik Gilling     *
344158549c89405186d9ecaefd3811cfae3949056eeErik Gilling     * If non NULL it will be caused by SurfaceFlinger on dumpsys
345158549c89405186d9ecaefd3811cfae3949056eeErik Gilling     */
346158549c89405186d9ecaefd3811cfae3949056eeErik Gilling    void (*dump)(struct framebuffer_device_t* dev, char *buff, int buff_len);
3478255d9d3b62ddf90269ddbb54e6f92b29908fa75Mathias Agopian
34897c7c40b73329ee86ce2abe5c320dd82d117ea14Mathias Agopian    /*
34997c7c40b73329ee86ce2abe5c320dd82d117ea14Mathias Agopian     * (*enableScreen)() is used to either blank (enable=0) or
35097c7c40b73329ee86ce2abe5c320dd82d117ea14Mathias Agopian     * unblank (enable=1) the screen this framebuffer is attached to.
35197c7c40b73329ee86ce2abe5c320dd82d117ea14Mathias Agopian     *
35297c7c40b73329ee86ce2abe5c320dd82d117ea14Mathias Agopian     * Returns 0 on success or -errno on error.
35397c7c40b73329ee86ce2abe5c320dd82d117ea14Mathias Agopian     */
35497c7c40b73329ee86ce2abe5c320dd82d117ea14Mathias Agopian    int (*enableScreen)(struct framebuffer_device_t* dev, int enable);
35597c7c40b73329ee86ce2abe5c320dd82d117ea14Mathias Agopian
35697c7c40b73329ee86ce2abe5c320dd82d117ea14Mathias Agopian    void* reserved_proc[6];
3579d82c1a447a72a2c086b9cd34c5b73b163d7acbcMathias Agopian
3589d82c1a447a72a2c086b9cd34c5b73b163d7acbcMathias Agopian} framebuffer_device_t;
359a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
360a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
361a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian/** convenience API for opening and closing a supported device */
362a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
363a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopianstatic inline int gralloc_open(const struct hw_module_t* module,
364a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian        struct alloc_device_t** device) {
365a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    return module->methods->open(module,
366a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian            GRALLOC_HARDWARE_GPU0, (struct hw_device_t**)device);
367a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian}
368a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
369a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopianstatic inline int gralloc_close(struct alloc_device_t* device) {
370a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    return device->common.close(&device->common);
371a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian}
372a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
373a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
374a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopianstatic inline int framebuffer_open(const struct hw_module_t* module,
375a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian        struct framebuffer_device_t** device) {
376a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    return module->methods->open(module,
377a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian            GRALLOC_HARDWARE_FB0, (struct hw_device_t**)device);
378a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian}
379a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
380a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopianstatic inline int framebuffer_close(struct framebuffer_device_t* device) {
381a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian    return device->common.close(&device->common);
382a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian}
383a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
384a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
385a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian__END_DECLS
386a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian
387a8a75166a2d3c7639a7432a67075c98796165206Mathias Agopian#endif  // ANDROID_ALLOC_INTERFACE_H
388