17ec681f3Smrg/*
27ec681f3Smrg * Copyright (C) 2011 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#ifndef SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H
187ec681f3Smrg#define SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H
197ec681f3Smrg
207ec681f3Smrg#include <stddef.h>
217ec681f3Smrg#include <stdint.h>
227ec681f3Smrg
237ec681f3Smrg/*
247ec681f3Smrg * Some of the enums are now defined in HIDL in hardware/interfaces and are
257ec681f3Smrg * generated.
267ec681f3Smrg */
277ec681f3Smrg#include "graphics-base.h"
287ec681f3Smrg#include "graphics-sw.h"
297ec681f3Smrg
307ec681f3Smrg#ifdef __cplusplus
317ec681f3Smrgextern "C" {
327ec681f3Smrg#endif
337ec681f3Smrg
347ec681f3Smrg/* for compatibility */
357ec681f3Smrg#define HAL_PIXEL_FORMAT_YCbCr_420_888 HAL_PIXEL_FORMAT_YCBCR_420_888
367ec681f3Smrg#define HAL_PIXEL_FORMAT_YCbCr_422_SP HAL_PIXEL_FORMAT_YCBCR_422_SP
377ec681f3Smrg#define HAL_PIXEL_FORMAT_YCrCb_420_SP HAL_PIXEL_FORMAT_YCRCB_420_SP
387ec681f3Smrg#define HAL_PIXEL_FORMAT_YCbCr_422_I HAL_PIXEL_FORMAT_YCBCR_422_I
397ec681f3Smrgtypedef android_pixel_format_t android_pixel_format;
407ec681f3Smrgtypedef android_transform_t android_transform;
417ec681f3Smrgtypedef android_dataspace_t android_dataspace;
427ec681f3Smrgtypedef android_color_mode_t android_color_mode;
437ec681f3Smrgtypedef android_color_transform_t android_color_transform;
447ec681f3Smrgtypedef android_hdr_t android_hdr;
457ec681f3Smrg
467ec681f3Smrg/*
477ec681f3Smrg * If the HAL needs to create service threads to handle graphics related
487ec681f3Smrg * tasks, these threads need to run at HAL_PRIORITY_URGENT_DISPLAY priority
497ec681f3Smrg * if they can block the main rendering thread in any way.
507ec681f3Smrg *
517ec681f3Smrg * the priority of the current thread can be set with:
527ec681f3Smrg *
537ec681f3Smrg *      #include <sys/resource.h>
547ec681f3Smrg *      setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY);
557ec681f3Smrg *
567ec681f3Smrg */
577ec681f3Smrg
587ec681f3Smrg#define HAL_PRIORITY_URGENT_DISPLAY     (-8)
597ec681f3Smrg
607ec681f3Smrg/*
617ec681f3Smrg * Structure for describing YCbCr formats for consumption by applications.
627ec681f3Smrg * This is used with HAL_PIXEL_FORMAT_YCbCr_*_888.
637ec681f3Smrg *
647ec681f3Smrg * Buffer chroma subsampling is defined in the format.
657ec681f3Smrg * e.g. HAL_PIXEL_FORMAT_YCbCr_420_888 has subsampling 4:2:0.
667ec681f3Smrg *
677ec681f3Smrg * Buffers must have a 8 bit depth.
687ec681f3Smrg *
697ec681f3Smrg * y, cb, and cr point to the first byte of their respective planes.
707ec681f3Smrg *
717ec681f3Smrg * Stride describes the distance in bytes from the first value of one row of
727ec681f3Smrg * the image to the first value of the next row.  It includes the width of the
737ec681f3Smrg * image plus padding.
747ec681f3Smrg * ystride is the stride of the luma plane.
757ec681f3Smrg * cstride is the stride of the chroma planes.
767ec681f3Smrg *
777ec681f3Smrg * chroma_step is the distance in bytes from one chroma pixel value to the
787ec681f3Smrg * next.  This is 2 bytes for semiplanar (because chroma values are interleaved
797ec681f3Smrg * and each chroma value is one byte) and 1 for planar.
807ec681f3Smrg */
817ec681f3Smrg
827ec681f3Smrgstruct android_ycbcr {
837ec681f3Smrg    void *y;
847ec681f3Smrg    void *cb;
857ec681f3Smrg    void *cr;
867ec681f3Smrg    size_t ystride;
877ec681f3Smrg    size_t cstride;
887ec681f3Smrg    size_t chroma_step;
897ec681f3Smrg
907ec681f3Smrg    /** reserved for future use, set to 0 by gralloc's (*lock_ycbcr)() */
917ec681f3Smrg    uint32_t reserved[8];
927ec681f3Smrg};
937ec681f3Smrg
947ec681f3Smrg/*
957ec681f3Smrg * Structures for describing flexible YUVA/RGBA formats for consumption by
967ec681f3Smrg * applications. Such flexible formats contain a plane for each component (e.g.
977ec681f3Smrg * red, green, blue), where each plane is laid out in a grid-like pattern
987ec681f3Smrg * occupying unique byte addresses and with consistent byte offsets between
997ec681f3Smrg * neighboring pixels.
1007ec681f3Smrg *
1017ec681f3Smrg * The android_flex_layout structure is used with any pixel format that can be
1027ec681f3Smrg * represented by it, such as:
1037ec681f3Smrg *  - HAL_PIXEL_FORMAT_YCbCr_*_888
1047ec681f3Smrg *  - HAL_PIXEL_FORMAT_FLEX_RGB*_888
1057ec681f3Smrg *  - HAL_PIXEL_FORMAT_RGB[AX]_888[8],BGRA_8888,RGB_888
1067ec681f3Smrg *  - HAL_PIXEL_FORMAT_YV12,Y8,Y16,YCbCr_422_SP/I,YCrCb_420_SP
1077ec681f3Smrg *  - even implementation defined formats that can be represented by
1087ec681f3Smrg *    the structures
1097ec681f3Smrg *
1107ec681f3Smrg * Vertical increment (aka. row increment or stride) describes the distance in
1117ec681f3Smrg * bytes from the first pixel of one row to the first pixel of the next row
1127ec681f3Smrg * (below) for the component plane. This can be negative.
1137ec681f3Smrg *
1147ec681f3Smrg * Horizontal increment (aka. column or pixel increment) describes the distance
1157ec681f3Smrg * in bytes from one pixel to the next pixel (to the right) on the same row for
1167ec681f3Smrg * the component plane. This can be negative.
1177ec681f3Smrg *
1187ec681f3Smrg * Each plane can be subsampled either vertically or horizontally by
1197ec681f3Smrg * a power-of-two factor.
1207ec681f3Smrg *
1217ec681f3Smrg * The bit-depth of each component can be arbitrary, as long as the pixels are
1227ec681f3Smrg * laid out on whole bytes, in native byte-order, using the most significant
1237ec681f3Smrg * bits of each unit.
1247ec681f3Smrg */
1257ec681f3Smrg
1267ec681f3Smrgtypedef enum android_flex_component {
1277ec681f3Smrg    /* luma */
1287ec681f3Smrg    FLEX_COMPONENT_Y = 1 << 0,
1297ec681f3Smrg    /* chroma blue */
1307ec681f3Smrg    FLEX_COMPONENT_Cb = 1 << 1,
1317ec681f3Smrg    /* chroma red */
1327ec681f3Smrg    FLEX_COMPONENT_Cr = 1 << 2,
1337ec681f3Smrg
1347ec681f3Smrg    /* red */
1357ec681f3Smrg    FLEX_COMPONENT_R = 1 << 10,
1367ec681f3Smrg    /* green */
1377ec681f3Smrg    FLEX_COMPONENT_G = 1 << 11,
1387ec681f3Smrg    /* blue */
1397ec681f3Smrg    FLEX_COMPONENT_B = 1 << 12,
1407ec681f3Smrg
1417ec681f3Smrg    /* alpha */
1427ec681f3Smrg    FLEX_COMPONENT_A = 1 << 30,
1437ec681f3Smrg} android_flex_component_t;
1447ec681f3Smrg
1457ec681f3Smrgtypedef struct android_flex_plane {
1467ec681f3Smrg    /* pointer to the first byte of the top-left pixel of the plane. */
1477ec681f3Smrg    uint8_t *top_left;
1487ec681f3Smrg
1497ec681f3Smrg    android_flex_component_t component;
1507ec681f3Smrg
1517ec681f3Smrg    /* bits allocated for the component in each pixel. Must be a positive
1527ec681f3Smrg       multiple of 8. */
1537ec681f3Smrg    int32_t bits_per_component;
1547ec681f3Smrg    /* number of the most significant bits used in the format for this
1557ec681f3Smrg       component. Must be between 1 and bits_per_component, inclusive. */
1567ec681f3Smrg    int32_t bits_used;
1577ec681f3Smrg
1587ec681f3Smrg    /* horizontal increment */
1597ec681f3Smrg    int32_t h_increment;
1607ec681f3Smrg    /* vertical increment */
1617ec681f3Smrg    int32_t v_increment;
1627ec681f3Smrg    /* horizontal subsampling. Must be a positive power of 2. */
1637ec681f3Smrg    int32_t h_subsampling;
1647ec681f3Smrg    /* vertical subsampling. Must be a positive power of 2. */
1657ec681f3Smrg    int32_t v_subsampling;
1667ec681f3Smrg} android_flex_plane_t;
1677ec681f3Smrg
1687ec681f3Smrgtypedef enum android_flex_format {
1697ec681f3Smrg    /* not a flexible format */
1707ec681f3Smrg    FLEX_FORMAT_INVALID = 0x0,
1717ec681f3Smrg    FLEX_FORMAT_Y = FLEX_COMPONENT_Y,
1727ec681f3Smrg    FLEX_FORMAT_YCbCr = FLEX_COMPONENT_Y | FLEX_COMPONENT_Cb | FLEX_COMPONENT_Cr,
1737ec681f3Smrg    FLEX_FORMAT_YCbCrA = FLEX_FORMAT_YCbCr | FLEX_COMPONENT_A,
1747ec681f3Smrg    FLEX_FORMAT_RGB = FLEX_COMPONENT_R | FLEX_COMPONENT_G | FLEX_COMPONENT_B,
1757ec681f3Smrg    FLEX_FORMAT_RGBA = FLEX_FORMAT_RGB | FLEX_COMPONENT_A,
1767ec681f3Smrg} android_flex_format_t;
1777ec681f3Smrg
1787ec681f3Smrgtypedef struct android_flex_layout {
1797ec681f3Smrg    /* the kind of flexible format */
1807ec681f3Smrg    android_flex_format_t format;
1817ec681f3Smrg
1827ec681f3Smrg    /* number of planes; 0 for FLEX_FORMAT_INVALID */
1837ec681f3Smrg    uint32_t num_planes;
1847ec681f3Smrg    /* a plane for each component; ordered in increasing component value order.
1857ec681f3Smrg       E.g. FLEX_FORMAT_RGBA maps 0 -> R, 1 -> G, etc.
1867ec681f3Smrg       Can be NULL for FLEX_FORMAT_INVALID */
1877ec681f3Smrg    android_flex_plane_t *planes;
1887ec681f3Smrg} android_flex_layout_t;
1897ec681f3Smrg
1907ec681f3Smrg/**
1917ec681f3Smrg * Structure used to define depth point clouds for format HAL_PIXEL_FORMAT_BLOB
1927ec681f3Smrg * with dataSpace value of HAL_DATASPACE_DEPTH.
1937ec681f3Smrg * When locking a native buffer of the above format and dataSpace value,
1947ec681f3Smrg * the vaddr pointer can be cast to this structure.
1957ec681f3Smrg *
1967ec681f3Smrg * A variable-length list of (x,y,z, confidence) 3D points, as floats.  (x, y,
1977ec681f3Smrg * z) represents a measured point's position, with the coordinate system defined
1987ec681f3Smrg * by the data source.  Confidence represents the estimated likelihood that this
1997ec681f3Smrg * measurement is correct. It is between 0.f and 1.f, inclusive, with 1.f ==
2007ec681f3Smrg * 100% confidence.
2017ec681f3Smrg *
2027ec681f3Smrg * num_points is the number of points in the list
2037ec681f3Smrg *
2047ec681f3Smrg * xyz_points is the flexible array of floating-point values.
2057ec681f3Smrg *   It contains (num_points) * 4 floats.
2067ec681f3Smrg *
2077ec681f3Smrg *   For example:
2087ec681f3Smrg *     android_depth_points d = get_depth_buffer();
2097ec681f3Smrg *     struct {
2107ec681f3Smrg *       float x; float y; float z; float confidence;
2117ec681f3Smrg *     } firstPoint, lastPoint;
2127ec681f3Smrg *
2137ec681f3Smrg *     firstPoint.x = d.xyzc_points[0];
2147ec681f3Smrg *     firstPoint.y = d.xyzc_points[1];
2157ec681f3Smrg *     firstPoint.z = d.xyzc_points[2];
2167ec681f3Smrg *     firstPoint.confidence = d.xyzc_points[3];
2177ec681f3Smrg *     lastPoint.x = d.xyzc_points[(d.num_points - 1) * 4 + 0];
2187ec681f3Smrg *     lastPoint.y = d.xyzc_points[(d.num_points - 1) * 4 + 1];
2197ec681f3Smrg *     lastPoint.z = d.xyzc_points[(d.num_points - 1) * 4 + 2];
2207ec681f3Smrg *     lastPoint.confidence = d.xyzc_points[(d.num_points - 1) * 4 + 3];
2217ec681f3Smrg */
2227ec681f3Smrg
2237ec681f3Smrgstruct android_depth_points {
2247ec681f3Smrg    uint32_t num_points;
2257ec681f3Smrg
2267ec681f3Smrg    /** reserved for future use, set to 0 by gralloc's (*lock)() */
2277ec681f3Smrg    uint32_t reserved[8];
2287ec681f3Smrg
2297ec681f3Smrg#if defined(__clang__)
2307ec681f3Smrg#pragma clang diagnostic push
2317ec681f3Smrg#pragma clang diagnostic ignored "-Wc99-extensions"
2327ec681f3Smrg#endif
2337ec681f3Smrg    float xyzc_points[];
2347ec681f3Smrg#if defined(__clang__)
2357ec681f3Smrg#pragma clang diagnostic pop
2367ec681f3Smrg#endif
2377ec681f3Smrg};
2387ec681f3Smrg
2397ec681f3Smrg/**
2407ec681f3Smrg  * These structures are used to define the reference display's
2417ec681f3Smrg  * capabilities for HDR content. Display engine can use this
2427ec681f3Smrg  * to better tone map content to user's display.
2437ec681f3Smrg  * Color is defined in CIE XYZ coordinates
2447ec681f3Smrg  */
2457ec681f3Smrgstruct android_xy_color {
2467ec681f3Smrg    float x;
2477ec681f3Smrg    float y;
2487ec681f3Smrg};
2497ec681f3Smrg
2507ec681f3Smrgstruct android_smpte2086_metadata {
2517ec681f3Smrg    struct android_xy_color displayPrimaryRed;
2527ec681f3Smrg    struct android_xy_color displayPrimaryGreen;
2537ec681f3Smrg    struct android_xy_color displayPrimaryBlue;
2547ec681f3Smrg    struct android_xy_color whitePoint;
2557ec681f3Smrg    float maxLuminance;
2567ec681f3Smrg    float minLuminance;
2577ec681f3Smrg};
2587ec681f3Smrg
2597ec681f3Smrgstruct android_cta861_3_metadata {
2607ec681f3Smrg    float maxContentLightLevel;
2617ec681f3Smrg    float maxFrameAverageLightLevel;
2627ec681f3Smrg};
2637ec681f3Smrg
2647ec681f3Smrg#ifdef __cplusplus
2657ec681f3Smrg}
2667ec681f3Smrg#endif
2677ec681f3Smrg
2687ec681f3Smrg#endif /* SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H */
269