adfhwc.h revision ebb26c71fe59c1904dc198b00948c581d31bd412
1/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _LIBADFHWC_ADFHWC_H_
18#define _LIBADFHWC_ADFHWC_H_
19
20#include <stdbool.h>
21#include <stdint.h>
22#include <sys/cdefs.h>
23#include <video/adf.h>
24
25#include <hardware/hwcomposer.h>
26
27struct adf_hwc_helper;
28
29struct adf_hwc_event_callbacks {
30    /**
31     * Called on vsync (required)
32     */
33    void (*vsync)(void *data, int disp, uint64_t timestamp);
34    /**
35     * Called on hotplug (required)
36     */
37    void (*hotplug)(void *data, int disp, bool connected);
38    /**
39     * Called on hardware-custom ADF events (optional)
40     */
41    void (*custom_event)(void *data, int disp, struct adf_event *event);
42};
43
44/**
45 * Converts HAL pixel formats to equivalent ADF/DRM format FourCCs.
46 */
47static inline uint32_t adf_fourcc_for_hal_pixel_format(int format)
48{
49    switch (format) {
50    case HAL_PIXEL_FORMAT_RGBA_8888:
51        return DRM_FORMAT_RGBA8888;
52    case HAL_PIXEL_FORMAT_RGBX_8888:
53        return DRM_FORMAT_RGBX8888;
54    case HAL_PIXEL_FORMAT_RGB_888:
55        return DRM_FORMAT_RGB888;
56    case HAL_PIXEL_FORMAT_RGB_565:
57        return DRM_FORMAT_RGB565;
58    case HAL_PIXEL_FORMAT_BGRA_8888:
59        return DRM_FORMAT_BGRA8888;
60    case HAL_PIXEL_FORMAT_YV12:
61        return DRM_FORMAT_YVU420;
62    case HAL_PIXEL_FORMAT_YCbCr_422_SP:
63        return DRM_FORMAT_NV16;
64    case HAL_PIXEL_FORMAT_YCrCb_420_SP:
65        return DRM_FORMAT_NV21;
66    case HAL_PIXEL_FORMAT_YCbCr_422_I:
67        return DRM_FORMAT_YUYV;
68    default:
69        return 0;
70    }
71}
72
73/**
74 * Converts HAL display types to equivalent ADF interface flags.
75 */
76static inline uint32_t adf_hwc_interface_flag_for_disp(int disp)
77{
78    switch (disp) {
79    case HWC_DISPLAY_PRIMARY:
80        return ADF_INTF_FLAG_PRIMARY;
81    case HWC_DISPLAY_EXTERNAL:
82        return ADF_INTF_FLAG_EXTERNAL;
83    default:
84        return 0;
85    }
86}
87
88__BEGIN_DECLS
89
90/**
91 * Create a HWC helper for the specified ADF interfaces.
92 *
93 * intf_fds must be indexed by HWC display type: e.g.,
94 * intf_fds[HWC_DISPLAY_PRIMARY] is the fd for the primary display
95 * interface.  n_intfs must be >= 1.
96 *
97 * The caller retains ownership of the fds in intf_fds and must close()
98 * them when they are no longer needed.
99 *
100 * On error, returns -errno.
101 */
102int adf_hwc_open(int *intf_fds, size_t n_intfs,
103        const struct adf_hwc_event_callbacks *event_cb, void *event_cb_data,
104        struct adf_hwc_helper **dev);
105
106/**
107 * Destroys a HWC helper.
108 */
109void adf_hwc_close(struct adf_hwc_helper *dev);
110
111/**
112 * Generic implementations of common HWC ops.
113 *
114 * The HWC should not point its ops directly at these helpers.  Instead, the HWC
115 * should provide stub ops which call these helpers after converting the
116 * hwc_composer_device_1* to a struct adf_hwc_helper*.
117 */
118int adf_eventControl(struct adf_hwc_helper *dev, int disp, int event,
119        int enabled);
120int adf_blank(struct adf_hwc_helper *dev, int disp, int blank);
121int adf_query_display_types_supported(struct adf_hwc_helper *dev, int *value);
122int adf_getDisplayConfigs(struct adf_hwc_helper *dev, int disp,
123        uint32_t *configs, size_t *numConfigs);
124int adf_getDisplayAttributes(struct adf_hwc_helper *dev, int disp,
125        uint32_t config, const uint32_t *attributes, int32_t *values);
126
127__END_DECLS
128
129#endif /* _LIBADFHWC_ADFHWC_H_ */
130