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 #include <hardware/hwcomposer2.h> 27 28 struct adf_hwc_helper; 29 30 struct adf_hwc_event_callbacks { 31 /** 32 * Called on vsync (required) 33 */ 34 void (*vsync)(void *data, int disp, uint64_t timestamp); 35 /** 36 * Called on hotplug (required) 37 */ 38 void (*hotplug)(void *data, int disp, bool connected); 39 /** 40 * Called on hardware-custom ADF events (optional) 41 */ 42 void (*custom_event)(void *data, int disp, struct adf_event *event); 43 }; 44 45 /** 46 * Converts HAL pixel formats to equivalent ADF/DRM format FourCCs. 47 */ 48 static inline uint32_t adf_fourcc_for_hal_pixel_format(int format) 49 { 50 switch (format) { 51 case HAL_PIXEL_FORMAT_RGBA_8888: 52 return DRM_FORMAT_RGBA8888; 53 case HAL_PIXEL_FORMAT_RGBX_8888: 54 return DRM_FORMAT_RGBX8888; 55 case HAL_PIXEL_FORMAT_RGB_888: 56 return DRM_FORMAT_RGB888; 57 case HAL_PIXEL_FORMAT_RGB_565: 58 return DRM_FORMAT_RGB565; 59 case HAL_PIXEL_FORMAT_BGRA_8888: 60 return DRM_FORMAT_BGRA8888; 61 case HAL_PIXEL_FORMAT_YV12: 62 return DRM_FORMAT_YVU420; 63 case HAL_PIXEL_FORMAT_YCbCr_422_SP: 64 return DRM_FORMAT_NV16; 65 case HAL_PIXEL_FORMAT_YCrCb_420_SP: 66 return DRM_FORMAT_NV21; 67 case HAL_PIXEL_FORMAT_YCbCr_422_I: 68 return DRM_FORMAT_YUYV; 69 default: 70 return 0; 71 } 72 } 73 74 /** 75 * Converts HAL display types to equivalent ADF interface flags. 76 */ 77 static inline uint32_t adf_hwc_interface_flag_for_disp(int disp) 78 { 79 switch (disp) { 80 case HWC_DISPLAY_PRIMARY: 81 return ADF_INTF_FLAG_PRIMARY; 82 case HWC_DISPLAY_EXTERNAL: 83 return ADF_INTF_FLAG_EXTERNAL; 84 default: 85 return 0; 86 } 87 } 88 89 __BEGIN_DECLS 90 91 /** 92 * Create a HWC helper for the specified ADF interfaces. 93 * 94 * intf_fds must be indexed by HWC display type: e.g., 95 * intf_fds[HWC_DISPLAY_PRIMARY] is the fd for the primary display 96 * interface. n_intfs must be >= 1. 97 * 98 * The caller retains ownership of the fds in intf_fds and must close() 99 * them when they are no longer needed. 100 * 101 * On error, returns -errno. 102 */ 103 int adf_hwc_open(int *intf_fds, size_t n_intfs, 104 const struct adf_hwc_event_callbacks *event_cb, void *event_cb_data, 105 struct adf_hwc_helper **dev); 106 107 /** 108 * Destroys a HWC helper. 109 */ 110 void adf_hwc_close(struct adf_hwc_helper *dev); 111 112 /** 113 * Generic implementations of common HWC ops. 114 * 115 * The HWC should not point its ops directly at these helpers. Instead, the HWC 116 * should provide stub ops which call these helpers after converting the 117 * hwc_composer_device_1* to a struct adf_hwc_helper*. 118 */ 119 int adf_eventControl(struct adf_hwc_helper *dev, int disp, int event, 120 int enabled); 121 int adf_blank(struct adf_hwc_helper *dev, int disp, int blank); 122 int adf_query_display_types_supported(struct adf_hwc_helper *dev, int *value); 123 int adf_getDisplayConfigs(struct adf_hwc_helper *dev, int disp, 124 uint32_t *configs, size_t *numConfigs); 125 int adf_getDisplayAttributes(struct adf_hwc_helper *dev, int disp, 126 uint32_t config, const uint32_t *attributes, int32_t *values); 127 /** 128 * Generic implementation of common HWC2 functions. 129 * 130 * The HWC2 should not return these functions directly through getFunction. 131 * Instead, the HWC2 should return stub functions which call these helpers. 132 */ 133 int adf_getDisplayAttributes_hwc2(struct adf_hwc_helper *dev, int disp, 134 uint32_t config, const uint32_t *attributes, int32_t *values); 135 int adf_set_active_config_hwc2(struct adf_hwc_helper *dev, int disp, 136 uint32_t config); 137 138 __END_DECLS 139 140 #endif /* _LIBADFHWC_ADFHWC_H_ */ 141