diff options
Diffstat (limited to 'include/hardware/hwcomposer.h')
-rw-r--r-- | include/hardware/hwcomposer.h | 450 |
1 files changed, 311 insertions, 139 deletions
diff --git a/include/hardware/hwcomposer.h b/include/hardware/hwcomposer.h index e30c736..ac3aa42 100644 --- a/include/hardware/hwcomposer.h +++ b/include/hardware/hwcomposer.h @@ -30,11 +30,25 @@ __BEGIN_DECLS /*****************************************************************************/ -// for compatibility +/* for compatibility */ #define HWC_MODULE_API_VERSION HWC_MODULE_API_VERSION_0_1 #define HWC_DEVICE_API_VERSION HWC_DEVICE_API_VERSION_0_1 #define HWC_API_VERSION HWC_DEVICE_API_VERSION +/* Users of this header can define HWC_REMOVE_DEPRECATED_VERSIONS to test that + * they still work with just the current version declared, before the + * deprecated versions are actually removed. + * + * To find code that still depends on the old versions, set the #define to 1 + * here. Code that explicitly sets it to zero (rather than simply not defining + * it) will still see the old versions. + */ +#if !defined(HWC_REMOVE_DEPRECATED_VERSIONS) +#define HWC_REMOVE_DEPRECATED_VERSIONS 0 +#endif + +/*****************************************************************************/ + /** * The id of this module */ @@ -45,44 +59,6 @@ __BEGIN_DECLS */ #define HWC_HARDWARE_COMPOSER "composer" - -struct hwc_composer_device; - -/* - * availability: HWC_DEVICE_API_VERSION_0_3 - * - * struct hwc_methods cannot be embedded in other structures as - * sizeof(struct hwc_methods) cannot be relied upon. - * - */ -typedef struct hwc_methods { - - /************************************************************************* - * HWC_DEVICE_API_VERSION_0_3 - *************************************************************************/ - - /* - * eventControl(..., event, value) - * Enables or disables h/w composer events. - * - * eventControl can be called from any thread and takes effect - * immediately. - * - * Supported events are: - * HWC_EVENT_VSYNC - * HWC_EVENT_ORIENTATION - * - * returns -EINVAL if the "event" parameter is not one of the value above - * or if the "value" parameter is not 0 or 1 for HWC_EVENT_VSYNC. - * and if the "value" parameter is not going to be just 0 or 1 for - * HWC_EVENT_ORIENTATION - */ - - int (*eventControl)( - struct hwc_composer_device* dev, int event, int value); - -} hwc_methods_t; - typedef struct hwc_rect { int left; int top; @@ -102,22 +78,31 @@ typedef struct hwc_color { uint8_t a; } hwc_color_t; -typedef struct hwc_layer { +typedef struct hwc_layer_1 { /* - * initially set to HWC_FRAMEBUFFER or HWC_BACKGROUND. + * Initially set to HWC_FRAMEBUFFER, HWC_BACKGROUND, or + * HWC_FRAMEBUFFER_TARGET. + * * HWC_FRAMEBUFFER - * indicates the layer will be drawn into the framebuffer - * using OpenGL ES. - * The HWC can toggle this value to HWC_OVERLAY, to indicate - * it will handle the layer. + * Indicates the layer will be drawn into the framebuffer + * using OpenGL ES. The HWC can toggle this value to HWC_OVERLAY to + * indicate it will handle the layer. * * HWC_BACKGROUND - * indicates this is a special "background" layer. The only valid - * field is backgroundColor. HWC_BACKGROUND can only be used with - * HWC_API_VERSION >= 0.2 - * The HWC can toggle this value to HWC_FRAMEBUFFER, to indicate - * it CANNOT handle the background color + * Indicates this is a special "background" layer. The only valid field + * is backgroundColor. The HWC can toggle this value to HWC_FRAMEBUFFER + * to indicate it CANNOT handle the background color. + * + * HWC_FRAMEBUFFER_TARGET + * Indicates this layer is the framebuffer surface used as the target of + * OpenGL ES composition. If the HWC sets all other layers to HWC_OVERLAY + * or HWC_BACKGROUND, then no OpenGL ES composition will be done, and + * this layer should be ignored during set(). * + * This flag (and the framebuffer surface layer) will only be used if the + * HWC version is HWC_DEVICE_API_VERSION_1_1 or higher. In older versions, + * the OpenGL ES target surface is communicated by the (dpy, sur) fields + * in hwc_compositor_device_1_t. */ int32_t compositionType; @@ -166,42 +151,137 @@ typedef struct hwc_layer { * The visible region INCLUDES areas overlapped by a translucent layer. */ hwc_region_t visibleRegionScreen; + + /* Sync fence object that will be signaled when the buffer's + * contents are available. May be -1 if the contents are already + * available. This field is only valid during set(), and should be + * ignored during prepare(). The set() call must not wait for the + * fence to be signaled before returning, but the HWC must wait for + * all buffers to be signaled before reading from them. + * + * HWC_FRAMEBUFFER layers will never have an acquire fence, since + * reads from them are complete before the framebuffer is ready for + * display. + * + * The HWC takes ownership of the acquireFenceFd and is responsible + * for closing it when no longer needed. + */ + int acquireFenceFd; + + /* During set() the HWC must set this field to a file descriptor for + * a sync fence object that will signal after the HWC has finished + * reading from the buffer. The field is ignored by prepare(). Each + * layer should have a unique file descriptor, even if more than one + * refer to the same underlying fence object; this allows each to be + * closed independently. + * + * If buffer reads can complete at significantly different times, + * then using independent fences is preferred. For example, if the + * HWC handles some layers with a blit engine and others with + * overlays, then the blit layers can be reused immediately after + * the blit completes, but the overlay layers can't be reused until + * a subsequent frame has been displayed. + * + * Since HWC doesn't read from HWC_FRAMEBUFFER layers, it shouldn't + * produce a release fence for them. The releaseFenceFd will be -1 + * for these layers when set() is called. + * + * The HWC client taks ownership of the releaseFenceFd and is + * responsible for closing it when no longer needed. + */ + int releaseFenceFd; }; }; -} hwc_layer_t; + /* Allow for expansion w/o breaking binary compatibility. + * Pad layer to 96 bytes, assuming 32-bit pointers. + */ + int32_t reserved[24 - 18]; + +} hwc_layer_1_t; + +/* This represents a display, typically an EGLDisplay object */ +typedef void* hwc_display_t; + +/* This represents a surface, typically an EGLSurface object */ +typedef void* hwc_surface_t; /* - * hwc_layer_list_t::flags values + * hwc_display_contents_1_t::flags values */ enum { /* * HWC_GEOMETRY_CHANGED is set by SurfaceFlinger to indicate that the list - * passed to (*prepare)() has changed by more than just the buffer handles. + * passed to (*prepare)() has changed by more than just the buffer handles + * and acquire fences. */ HWC_GEOMETRY_CHANGED = 0x00000001, }; /* - * List of layers. - * The handle members of hwLayers elements must be unique. + * Description of the contents to output on a display. + * + * This is the top-level structure passed to the prepare and set calls to + * negotiate and commit the composition of a display image. */ -typedef struct hwc_layer_list { - uint32_t flags; - size_t numHwLayers; - hwc_layer_t hwLayers[0]; -} hwc_layer_list_t; +typedef struct hwc_display_contents_1 { + /* File descriptor referring to a Sync HAL fence object which will signal + * when this composition is retired. For a physical display, a composition + * is retired when it has been replaced on-screen by a subsequent set. For + * a virtual display, the composition is retired when the writes to + * outputBuffer are complete and can be read. The fence object is created + * and returned by the set call; this field will be -1 on entry to prepare + * and set. SurfaceFlinger will close the returned file descriptor. + */ + int retireFenceFd; -/* This represents a display, typically an EGLDisplay object */ -typedef void* hwc_display_t; + union { + /* Fields only relevant for HWC_DEVICE_VERSION_1_0. */ + struct { + /* (dpy, sur) is the target of SurfaceFlinger's OpenGL ES + * composition for HWC_DEVICE_VERSION_1_0. They aren't relevant to + * prepare. The set call should commit this surface atomically to + * the display along with any overlay layers. + */ + hwc_display_t dpy; + hwc_surface_t sur; + }; -/* This represents a surface, typically an EGLSurface object */ -typedef void* hwc_surface_t; + /* Fields only relevant for HWC_DEVICE_VERSION_1_2 and later. */ + struct { + /* outbuf is the buffer that receives the composed image for + * virtual displays. Writes to the outbuf must wait until + * outbufAcquireFenceFd signals. A fence that will signal when + * writes to outbuf are complete should be returned in + * retireFenceFd. + * + * For physical displays, outbuf will be NULL. + */ + buffer_handle_t outbuf; + + /* File descriptor for a fence that will signal when outbuf is + * ready to be written. The h/w composer is responsible for closing + * this when no longer needed. + * + * Will be -1 whenever outbuf is NULL, or when the outbuf can be + * written immediately. + */ + int outbufAcquireFenceFd; + }; + }; + /* List of layers that will be composed on the display. The buffer handles + * in the list will be unique. If numHwLayers is 0, all composition will be + * performed by SurfaceFlinger. + */ + uint32_t flags; + size_t numHwLayers; + hwc_layer_1_t hwLayers[0]; + +} hwc_display_contents_1_t; /* see hwc_composer_device::registerProcs() - * Any of the callbacks can be NULL, in which case the corresponding - * functionality is not supported. + * All of the callbacks are required and non-NULL unless otherwise noted. */ typedef struct hwc_procs { /* @@ -213,13 +293,14 @@ typedef struct hwc_procs { * it is safe to call invalidate() from any of hwc_composer_device * hooks, unless noted otherwise. */ - void (*invalidate)(struct hwc_procs* procs); + void (*invalidate)(const struct hwc_procs* procs); /* * (*vsync)() is called by the h/w composer HAL when a vsync event is - * received and HWC_EVENT_VSYNC is enabled (see: hwc_event_control). + * received and HWC_EVENT_VSYNC is enabled on a display + * (see: hwc_event_control). * - * the "zero" parameter must always be 0. + * the "disp" parameter indicates which display the vsync event is for. * the "timestamp" parameter is the system monotonic clock timestamp in * nanosecond of when the vsync event happened. * @@ -233,9 +314,31 @@ typedef struct hwc_procs { * hwc_composer_device.set(..., 0, 0, 0) (screen off). The implementation * can either stop or continue to process VSYNC events, but must not * crash or cause other problems. + */ + void (*vsync)(const struct hwc_procs* procs, int disp, int64_t timestamp); + + /* + * (*hotplug)() is called by the h/w composer HAL when a display is + * connected or disconnected. The PRIMARY display is always connected and + * the hotplug callback should not be called for it. * + * The disp parameter indicates which display type this event is for. + * The connected parameter indicates whether the display has just been + * connected (1) or disconnected (0). + * + * The hotplug() callback may call back into the h/w composer on the same + * thread to query refresh rate and dpi for the display. Additionally, + * other threads may be calling into the h/w composer while the callback + * is in progress. + * + * The h/w composer must serialize calls to the hotplug callback; only + * one thread may call it at a time. + * + * This callback will be NULL if the h/w composer is using + * HWC_DEVICE_API_VERSION_1_0. */ - void (*vsync)(struct hwc_procs* procs, int zero, int64_t timestamp); + void (*hotplug)(const struct hwc_procs* procs, int disp, int connected); + } hwc_procs_t; @@ -245,8 +348,7 @@ typedef struct hwc_module { struct hw_module_t common; } hwc_module_t; - -typedef struct hwc_composer_device { +typedef struct hwc_composer_device_1 { struct hw_device_t common; /* @@ -255,134 +357,204 @@ typedef struct hwc_composer_device { * * (*prepare)() can be called more than once, the last call prevails. * - * The HWC responds by setting the compositionType field to either - * HWC_FRAMEBUFFER or HWC_OVERLAY. In the former case, the composition for - * this layer is handled by SurfaceFlinger with OpenGL ES, in the later - * case, the HWC will have to handle this layer's composition. + * The HWC responds by setting the compositionType field in each layer to + * either HWC_FRAMEBUFFER or HWC_OVERLAY. In the former case, the + * composition for the layer is handled by SurfaceFlinger with OpenGL ES, + * in the later case, the HWC will have to handle the layer's composition. * * (*prepare)() is called with HWC_GEOMETRY_CHANGED to indicate that the * list's geometry has changed, that is, when more than just the buffer's * handles have been updated. Typically this happens (but is not limited to) * when a window is added, removed, resized or moved. * - * a NULL list parameter or a numHwLayers of zero indicates that the - * entire composition will be handled by SurfaceFlinger with OpenGL ES. + * For HWC 1.0, numDisplays will always be one, and displays[0] will be + * non-NULL. + * + * For HWC 1.1, numDisplays will always be HWC_NUM_DISPLAY_TYPES. Entries + * for unsupported or disabled/disconnected display types will be NULL. + * + * For HWC 1.2 and later, numDisplays will be HWC_NUM_DISPLAY_TYPES or more. + * The extra entries correspond to enabled virtual displays, and will be + * non-NULL. In HWC 1.2, support for one virtual display is required, and + * no more than one will be used. Future HWC versions might require more. * * returns: 0 on success. An negative error code on error. If an error is * returned, SurfaceFlinger will assume that none of the layer will be * handled by the HWC. */ - int (*prepare)(struct hwc_composer_device *dev, hwc_layer_list_t* list); - + int (*prepare)(struct hwc_composer_device_1 *dev, + size_t numDisplays, hwc_display_contents_1_t** displays); /* * (*set)() is used in place of eglSwapBuffers(), and assumes the same * functionality, except it also commits the work list atomically with * the actual eglSwapBuffers(). * - * The list parameter is guaranteed to be the same as the one returned - * from the last call to (*prepare)(). + * The layer lists are guaranteed to be the same as the ones returned from + * the last call to (*prepare)(). * - * When this call returns the caller assumes that: + * When this call returns the caller assumes that the displays will be + * updated in the near future with the content of their work lists, without + * artifacts during the transition from the previous frame. * - * - the display will be updated in the near future with the content - * of the work list, without artifacts during the transition from the - * previous frame. + * A display with zero layers indicates that the entire composition has + * been handled by SurfaceFlinger with OpenGL ES. In this case, (*set)() + * behaves just like eglSwapBuffers(). * - * - all objects are available for immediate access or destruction, in - * particular, hwc_region_t::rects data and hwc_layer_t::layer's buffer. - * Note that this means that immediately accessing (potentially from a - * different process) a buffer used in this call will not result in - * screen corruption, the driver must apply proper synchronization or - * scheduling (eg: block the caller, such as gralloc_module_t::lock(), - * OpenGL ES, Camera, Codecs, etc..., or schedule the caller's work - * after the buffer is freed from the actual composition). + * For HWC 1.0, numDisplays will always be one, and displays[0] will be + * non-NULL. * - * a NULL list parameter or a numHwLayers of zero indicates that the - * entire composition has been handled by SurfaceFlinger with OpenGL ES. - * In this case, (*set)() behaves just like eglSwapBuffers(). + * For HWC 1.1, numDisplays will always be HWC_NUM_DISPLAY_TYPES. Entries + * for unsupported or disabled/disconnected display types will be NULL. * - * dpy, sur, and list are set to NULL to indicate that the screen is - * turning off. This happens WITHOUT prepare() being called first. - * This is a good time to free h/w resources and/or power - * the relevant h/w blocks down. + * For HWC 1.2 and later, numDisplays will be HWC_NUM_DISPLAY_TYPES or more. + * The extra entries correspond to enabled virtual displays, and will be + * non-NULL. In HWC 1.2, support for one virtual display is required, and + * no more than one will be used. Future HWC versions might require more. * - * IMPORTANT NOTE: there is an implicit layer containing opaque black - * pixels behind all the layers in the list. - * It is the responsibility of the hwcomposer module to make - * sure black pixels are output (or blended from). + * IMPORTANT NOTE: There is an implicit layer containing opaque black + * pixels behind all the layers in the list. It is the responsibility of + * the hwcomposer module to make sure black pixels are output (or blended + * from). * - * returns: 0 on success. An negative error code on error: - * HWC_EGL_ERROR: eglGetError() will provide the proper error code - * Another code for non EGL errors. + * IMPORTANT NOTE: In the event of an error this call *MUST* still cause + * any fences returned in the previous call to set to eventually become + * signaled. The caller may have already issued wait commands on these + * fences, and having set return without causing those fences to signal + * will likely result in a deadlock. * + * returns: 0 on success. A negative error code on error: + * HWC_EGL_ERROR: eglGetError() will provide the proper error code (only + * allowed prior to HWComposer 1.1) + * Another code for non EGL errors. */ - int (*set)(struct hwc_composer_device *dev, - hwc_display_t dpy, - hwc_surface_t sur, - hwc_layer_list_t* list); + int (*set)(struct hwc_composer_device_1 *dev, + size_t numDisplays, hwc_display_contents_1_t** displays); + /* - * This field is OPTIONAL and can be NULL. + * eventControl(..., event, enabled) + * Enables or disables h/w composer events for a display. * - * If non NULL it will be called by SurfaceFlinger on dumpsys + * eventControl can be called from any thread and takes effect + * immediately. + * + * Supported events are: + * HWC_EVENT_VSYNC + * + * returns -EINVAL if the "event" parameter is not one of the value above + * or if the "enabled" parameter is not 0 or 1. */ - void (*dump)(struct hwc_composer_device* dev, char *buff, int buff_len); + int (*eventControl)(struct hwc_composer_device_1* dev, int disp, + int event, int enabled); /* - * This field is OPTIONAL and can be NULL. + * blank(..., blank) + * Blanks or unblanks a display's screen. * - * (*registerProcs)() registers a set of callbacks the h/w composer HAL - * can later use. It is FORBIDDEN to call any of the callbacks from - * within registerProcs(). registerProcs() must save the hwc_procs_t pointer - * which is needed when calling a registered callback. - * Each call to registerProcs replaces the previous set of callbacks. - * registerProcs is called with NULL to unregister all callbacks. + * Turns the screen off when blank is nonzero, on when blank is zero. + * Multiple sequential calls with the same blank value must be supported. + * The screen state transition must be be complete when the function + * returns. * - * Any of the callbacks can be NULL, in which case the corresponding - * functionality is not supported. + * returns 0 on success, negative on error. */ - void (*registerProcs)(struct hwc_composer_device* dev, - hwc_procs_t const* procs); + int (*blank)(struct hwc_composer_device_1* dev, int disp, int blank); /* - * This field is OPTIONAL and can be NULL. - * availability: HWC_DEVICE_API_VERSION_0_2 - * * Used to retrieve information about the h/w composer * * Returns 0 on success or -errno on error. */ - int (*query)(struct hwc_composer_device* dev, int what, int* value); + int (*query)(struct hwc_composer_device_1* dev, int what, int* value); /* - * Reserved for future use. Must be NULL. + * (*registerProcs)() registers callbacks that the h/w composer HAL can + * later use. It will be called immediately after the composer device is + * opened with non-NULL procs. It is FORBIDDEN to call any of the callbacks + * from within registerProcs(). registerProcs() must save the hwc_procs_t + * pointer which is needed when calling a registered callback. */ - void* reserved_proc[4]; + void (*registerProcs)(struct hwc_composer_device_1* dev, + hwc_procs_t const* procs); /* * This field is OPTIONAL and can be NULL. - * availability: HWC_DEVICE_API_VERSION_0_3 + * + * If non NULL it will be called by SurfaceFlinger on dumpsys + */ + void (*dump)(struct hwc_composer_device_1* dev, char *buff, int buff_len); + + /* + * (*getDisplayConfigs)() returns handles for the configurations available + * on the connected display. These handles must remain valid as long as the + * display is connected. + * + * Configuration handles are written to configs. The number of entries + * allocated by the caller is passed in *numConfigs; getDisplayConfigs must + * not try to write more than this number of config handles. On return, the + * total number of configurations available for the display is returned in + * *numConfigs. If *numConfigs is zero on entry, then configs may be NULL. + * + * HWC_DEVICE_API_VERSION_1_1 does not provide a way to choose a config. + * For displays that support multiple configurations, the h/w composer + * implementation should choose one and report it as the first config in + * the list. Reporting the not-chosen configs is not required. + * + * Returns 0 on success or -errno on error. If disp is a hotpluggable + * display type and no display is connected, an error should be returned. + * + * This field is REQUIRED for HWC_DEVICE_API_VERSION_1_1 and later. + * It should be NULL for previous versions. + */ + int (*getDisplayConfigs)(struct hwc_composer_device_1* dev, int disp, + uint32_t* configs, size_t* numConfigs); + + /* + * (*getDisplayAttributes)() returns attributes for a specific config of a + * connected display. The config parameter is one of the config handles + * returned by getDisplayConfigs. + * + * The list of attributes to return is provided in the attributes + * parameter, terminated by HWC_DISPLAY_NO_ATTRIBUTE. The value for each + * requested attribute is written in order to the values array. The + * HWC_DISPLAY_NO_ATTRIBUTE attribute does not have a value, so the values + * array will have one less value than the attributes array. + * + * This field is REQUIRED for HWC_DEVICE_API_VERSION_1_1 and later. + * It should be NULL for previous versions. + * + * If disp is a hotpluggable display type and no display is connected, + * or if config is not a valid configuration for the display, a negative + * value should be returned. */ - hwc_methods_t const *methods; + int (*getDisplayAttributes)(struct hwc_composer_device_1* dev, int disp, + uint32_t config, const uint32_t* attributes, int32_t* values); -} hwc_composer_device_t; + /* + * Reserved for future use. Must be NULL. + */ + void* reserved_proc[4]; +} hwc_composer_device_1_t; /** convenience API for opening and closing a device */ -static inline int hwc_open(const struct hw_module_t* module, - hwc_composer_device_t** device) { +static inline int hwc_open_1(const struct hw_module_t* module, + hwc_composer_device_1_t** device) { return module->methods->open(module, HWC_HARDWARE_COMPOSER, (struct hw_device_t**)device); } -static inline int hwc_close(hwc_composer_device_t* device) { +static inline int hwc_close_1(hwc_composer_device_1_t* device) { return device->common.close(&device->common); } - /*****************************************************************************/ +#if !HWC_REMOVE_DEPRECATED_VERSIONS +#include <hardware/hwcomposer_v0.h> +#endif + __END_DECLS #endif /* ANDROID_INCLUDE_HARDWARE_HWCOMPOSER_H */ |