Add new HWC 1.1 queries and hotplug callback

Change-Id: I40164e60b33174e98a3843ec99f1680b1bb1c675
diff --git a/include/hardware/hwcomposer.h b/include/hardware/hwcomposer.h
index 29ea54c..0a4d40d 100644
--- a/include/hardware/hwcomposer.h
+++ b/include/hardware/hwcomposer.h
@@ -270,7 +270,7 @@
      * received and HWC_EVENT_VSYNC is enabled on a display
      * (see: hwc_event_control).
      *
-     * the "dpy" parameter indicates which display the vsync event is for.
+     * 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.
      *
@@ -285,7 +285,27 @@
      * 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 dpy, int64_t timestamp);
+    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.
+     *
+     * This callback will be NULL if the h/w composer is using
+     * HWC_DEVICE_API_VERSION_1_0.
+     */
+    void (*hotplug)(const struct hwc_procs* procs, int disp, int connected);
+
 } hwc_procs_t;
 
 
@@ -384,7 +404,7 @@
      * returns -EINVAL if the "event" parameter is not one of the value above
      * or if the "enabled" parameter is not 0 or 1.
      */
-    int (*eventControl)(struct hwc_composer_device_1* dev, int dpy,
+    int (*eventControl)(struct hwc_composer_device_1* dev, int disp,
             int event, int enabled);
 
     /*
@@ -398,7 +418,7 @@
      *
      * returns 0 on success, negative on error.
      */
-    int (*blank)(struct hwc_composer_device_1* dev, int dpy, int blank);
+    int (*blank)(struct hwc_composer_device_1* dev, int disp, int blank);
 
     /*
      * Used to retrieve information about the h/w composer
@@ -425,6 +445,47 @@
     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.
+     *
+     * 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.
+     */
+    void (*getDisplayAttributes)(struct hwc_composer_device_1* dev, int disp,
+            uint32_t config, const uint32_t* attributes, int32_t* values);
+
+    /*
      * Reserved for future use. Must be NULL.
      */
     void* reserved_proc[4];
diff --git a/include/hardware/hwcomposer_defs.h b/include/hardware/hwcomposer_defs.h
index bd9f41c..04f4c2c 100644
--- a/include/hardware/hwcomposer_defs.h
+++ b/include/hardware/hwcomposer_defs.h
@@ -132,24 +132,51 @@
 /* attributes queriable with query() */
 enum {
     /*
-     * availability: HWC_DEVICE_API_VERSION_0_2
-     * must return 1 if the background layer is supported, 0 otherwise
+     * Availability: HWC_DEVICE_API_VERSION_0_2
+     * Must return 1 if the background layer is supported, 0 otherwise.
      */
     HWC_BACKGROUND_LAYER_SUPPORTED      = 0,
 
     /*
-     * availability: HWC_DEVICE_API_VERSION_0_3
-     * returns the vsync period in nanosecond
+     * Availability: HWC_DEVICE_API_VERSION_0_3
+     * Returns the vsync period in nanoseconds.
+     *
+     * This query is not used for HWC_DEVICE_API_VERSION_1_1 and later.
+     * Instead, the per-display attribute HWC_DISPLAY_VSYNC_PERIOD is used.
      */
     HWC_VSYNC_PERIOD                    = 1,
 
     /*
-     * availability: HWC_DEVICE_API_VERSION_1_1
-     * returns a mask of supported display types
+     * Availability: HWC_DEVICE_API_VERSION_1_1
+     * Returns a mask of supported display types.
      */
     HWC_DISPLAY_TYPES_SUPPORTED         = 2,
 };
 
+/* display attributes returned by getDisplayAttributes() */
+enum {
+    /* Indicates the end of an attribute list */
+    HWC_DISPLAY_NO_ATTRIBUTE                = 0,
+
+    /* The vsync period in nanoseconds */
+    HWC_DISPLAY_VSYNC_PERIOD                = 1,
+
+    /* The number of pixels in the horizontal and vertical directions. */
+    HWC_DISPLAY_RESOLUTION_X                = 2,
+    HWC_DISPLAY_RESOLUTION_Y                = 3,
+
+    /* The number of pixels per thousand inches of this configuration.
+     *
+     * Scaling DPI by 1000 allows it to be stored in an int without losing
+     * too much precision.
+     *
+     * If the DPI for a configuration is unavailable or the HWC implementation
+     * considers it unreliable, it should set these attributes to zero.
+     */
+    HWC_DISPLAY_DPI_X                       = 4,
+    HWC_DISPLAY_DPI_Y                       = 5,
+};
+
 /* Allowed events for hwc_methods::eventControl() */
 enum {
     HWC_EVENT_VSYNC     = 0