17ec681f3Smrg/*
27ec681f3Smrg * Copyright (C) 2008 The Android Open Source Project
37ec681f3Smrg *
47ec681f3Smrg * Licensed under the Apache License, Version 2.0 (the "License");
57ec681f3Smrg * you may not use this file except in compliance with the License.
67ec681f3Smrg * You may obtain a copy of the License at
77ec681f3Smrg *
87ec681f3Smrg *      http://www.apache.org/licenses/LICENSE-2.0
97ec681f3Smrg *
107ec681f3Smrg * Unless required by applicable law or agreed to in writing, software
117ec681f3Smrg * distributed under the License is distributed on an "AS IS" BASIS,
127ec681f3Smrg * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
137ec681f3Smrg * See the License for the specific language governing permissions and
147ec681f3Smrg * limitations under the License.
157ec681f3Smrg */
167ec681f3Smrg
177ec681f3Smrg
187ec681f3Smrg#ifndef ANDROID_FB_INTERFACE_H
197ec681f3Smrg#define ANDROID_FB_INTERFACE_H
207ec681f3Smrg
217ec681f3Smrg#include <stdint.h>
227ec681f3Smrg#include <sys/cdefs.h>
237ec681f3Smrg#include <sys/types.h>
247ec681f3Smrg
257ec681f3Smrg#include <cutils/native_handle.h>
267ec681f3Smrg
277ec681f3Smrg#include <hardware/hardware.h>
287ec681f3Smrg
297ec681f3Smrg__BEGIN_DECLS
307ec681f3Smrg
317ec681f3Smrg#define GRALLOC_HARDWARE_FB0 "fb0"
327ec681f3Smrg
337ec681f3Smrg/*****************************************************************************/
347ec681f3Smrg
357ec681f3Smrg
367ec681f3Smrg/*****************************************************************************/
377ec681f3Smrg
387ec681f3Smrgtypedef struct framebuffer_device_t {
397ec681f3Smrg    /**
407ec681f3Smrg     * Common methods of the framebuffer device.  This *must* be the first member of
417ec681f3Smrg     * framebuffer_device_t as users of this structure will cast a hw_device_t to
427ec681f3Smrg     * framebuffer_device_t pointer in contexts where it's known the hw_device_t references a
437ec681f3Smrg     * framebuffer_device_t.
447ec681f3Smrg     */
457ec681f3Smrg    struct hw_device_t common;
467ec681f3Smrg
477ec681f3Smrg    /* flags describing some attributes of the framebuffer */
487ec681f3Smrg    const uint32_t  flags;
497ec681f3Smrg
507ec681f3Smrg    /* dimensions of the framebuffer in pixels */
517ec681f3Smrg    const uint32_t  width;
527ec681f3Smrg    const uint32_t  height;
537ec681f3Smrg
547ec681f3Smrg    /* frambuffer stride in pixels */
557ec681f3Smrg    const int       stride;
567ec681f3Smrg
577ec681f3Smrg    /* framebuffer pixel format */
587ec681f3Smrg    const int       format;
597ec681f3Smrg
607ec681f3Smrg    /* resolution of the framebuffer's display panel in pixel per inch*/
617ec681f3Smrg    const float     xdpi;
627ec681f3Smrg    const float     ydpi;
637ec681f3Smrg
647ec681f3Smrg    /* framebuffer's display panel refresh rate in frames per second */
657ec681f3Smrg    const float     fps;
667ec681f3Smrg
677ec681f3Smrg    /* min swap interval supported by this framebuffer */
687ec681f3Smrg    const int       minSwapInterval;
697ec681f3Smrg
707ec681f3Smrg    /* max swap interval supported by this framebuffer */
717ec681f3Smrg    const int       maxSwapInterval;
727ec681f3Smrg
737ec681f3Smrg    /* Number of framebuffers supported*/
747ec681f3Smrg    const int       numFramebuffers;
757ec681f3Smrg
767ec681f3Smrg    int reserved[7];
777ec681f3Smrg
787ec681f3Smrg    /*
797ec681f3Smrg     * requests a specific swap-interval (same definition than EGL)
807ec681f3Smrg     *
817ec681f3Smrg     * Returns 0 on success or -errno on error.
827ec681f3Smrg     */
837ec681f3Smrg    int (*setSwapInterval)(struct framebuffer_device_t* window,
847ec681f3Smrg            int interval);
857ec681f3Smrg
867ec681f3Smrg    /*
877ec681f3Smrg     * This hook is OPTIONAL.
887ec681f3Smrg     *
897ec681f3Smrg     * It is non NULL If the framebuffer driver supports "update-on-demand"
907ec681f3Smrg     * and the given rectangle is the area of the screen that gets
917ec681f3Smrg     * updated during (*post)().
927ec681f3Smrg     *
937ec681f3Smrg     * This is useful on devices that are able to DMA only a portion of
947ec681f3Smrg     * the screen to the display panel, upon demand -- as opposed to
957ec681f3Smrg     * constantly refreshing the panel 60 times per second, for instance.
967ec681f3Smrg     *
977ec681f3Smrg     * Only the area defined by this rectangle is guaranteed to be valid, that
987ec681f3Smrg     * is, the driver is not allowed to post anything outside of this
997ec681f3Smrg     * rectangle.
1007ec681f3Smrg     *
1017ec681f3Smrg     * The rectangle evaluated during (*post)() and specifies which area
1027ec681f3Smrg     * of the buffer passed in (*post)() shall to be posted.
1037ec681f3Smrg     *
1047ec681f3Smrg     * return -EINVAL if width or height <=0, or if left or top < 0
1057ec681f3Smrg     */
1067ec681f3Smrg    int (*setUpdateRect)(struct framebuffer_device_t* window,
1077ec681f3Smrg            int left, int top, int width, int height);
1087ec681f3Smrg
1097ec681f3Smrg    /*
1107ec681f3Smrg     * Post <buffer> to the display (display it on the screen)
1117ec681f3Smrg     * The buffer must have been allocated with the
1127ec681f3Smrg     *   GRALLOC_USAGE_HW_FB usage flag.
1137ec681f3Smrg     * buffer must be the same width and height as the display and must NOT
1147ec681f3Smrg     * be locked.
1157ec681f3Smrg     *
1167ec681f3Smrg     * The buffer is shown during the next VSYNC.
1177ec681f3Smrg     *
1187ec681f3Smrg     * If the same buffer is posted again (possibly after some other buffer),
1197ec681f3Smrg     * post() will block until the the first post is completed.
1207ec681f3Smrg     *
1217ec681f3Smrg     * Internally, post() is expected to lock the buffer so that a
1227ec681f3Smrg     * subsequent call to gralloc_module_t::(*lock)() with USAGE_RENDER or
1237ec681f3Smrg     * USAGE_*_WRITE will block until it is safe; that is typically once this
1247ec681f3Smrg     * buffer is shown and another buffer has been posted.
1257ec681f3Smrg     *
1267ec681f3Smrg     * Returns 0 on success or -errno on error.
1277ec681f3Smrg     */
1287ec681f3Smrg    int (*post)(struct framebuffer_device_t* dev, buffer_handle_t buffer);
1297ec681f3Smrg
1307ec681f3Smrg
1317ec681f3Smrg    /*
1327ec681f3Smrg     * The (*compositionComplete)() method must be called after the
1337ec681f3Smrg     * compositor has finished issuing GL commands for client buffers.
1347ec681f3Smrg     */
1357ec681f3Smrg
1367ec681f3Smrg    int (*compositionComplete)(struct framebuffer_device_t* dev);
1377ec681f3Smrg
1387ec681f3Smrg    /*
1397ec681f3Smrg     * This hook is OPTIONAL.
1407ec681f3Smrg     *
1417ec681f3Smrg     * If non NULL it will be caused by SurfaceFlinger on dumpsys
1427ec681f3Smrg     */
1437ec681f3Smrg    void (*dump)(struct framebuffer_device_t* dev, char *buff, int buff_len);
1447ec681f3Smrg
1457ec681f3Smrg    /*
1467ec681f3Smrg     * (*enableScreen)() is used to either blank (enable=0) or
1477ec681f3Smrg     * unblank (enable=1) the screen this framebuffer is attached to.
1487ec681f3Smrg     *
1497ec681f3Smrg     * Returns 0 on success or -errno on error.
1507ec681f3Smrg     */
1517ec681f3Smrg    int (*enableScreen)(struct framebuffer_device_t* dev, int enable);
1527ec681f3Smrg
1537ec681f3Smrg    void* reserved_proc[6];
1547ec681f3Smrg
1557ec681f3Smrg} framebuffer_device_t;
1567ec681f3Smrg
1577ec681f3Smrg
1587ec681f3Smrg/** convenience API for opening and closing a supported device */
1597ec681f3Smrg
1607ec681f3Smrgstatic inline int framebuffer_open(const struct hw_module_t* module,
1617ec681f3Smrg        struct framebuffer_device_t** device) {
1627ec681f3Smrg    return module->methods->open(module,
1637ec681f3Smrg            GRALLOC_HARDWARE_FB0, TO_HW_DEVICE_T_OPEN(device));
1647ec681f3Smrg}
1657ec681f3Smrg
1667ec681f3Smrgstatic inline int framebuffer_close(struct framebuffer_device_t* device) {
1677ec681f3Smrg    return device->common.close(&device->common);
1687ec681f3Smrg}
1697ec681f3Smrg
1707ec681f3Smrg
1717ec681f3Smrg__END_DECLS
1727ec681f3Smrg
1737ec681f3Smrg#endif  // ANDROID_FB_INTERFACE_H
174