Merge changes from topic 'hwc-hal'
* changes:
graphics: add a default implementation for IComposer
graphics: add HIDL definition for HW composer
diff --git a/Android.bp b/Android.bp
index 9098afc..dace522 100644
--- a/Android.bp
+++ b/Android.bp
@@ -7,6 +7,8 @@
"biometrics/fingerprint/2.1",
"graphics/allocator/2.0",
"graphics/allocator/2.0/default",
+ "graphics/composer/2.1",
+ "graphics/composer/2.1/default",
"graphics/mapper/2.0",
"graphics/mapper/2.0/default",
"light/2.0",
diff --git a/graphics/composer/2.1/Android.bp b/graphics/composer/2.1/Android.bp
new file mode 100644
index 0000000..3c63a68
--- /dev/null
+++ b/graphics/composer/2.1/Android.bp
@@ -0,0 +1,55 @@
+// This file is autogenerated by hidl-gen. Do not edit manually.
+
+genrule {
+ name: "android.hardware.graphics.composer@2.1_genc++",
+ tool: "hidl-gen",
+ cmd: "$tool -o $genDir -Lc++ -randroid.hardware:hardware/interfaces android.hardware.graphics.composer@2.1",
+ srcs: [
+ "types.hal",
+ "IComposer.hal",
+ "IComposerCallback.hal",
+ ],
+ out: [
+ "android/hardware/graphics/composer/2.1/types.cpp",
+ "android/hardware/graphics/composer/2.1/ComposerAll.cpp",
+ "android/hardware/graphics/composer/2.1/ComposerCallbackAll.cpp",
+ ],
+}
+
+genrule {
+ name: "android.hardware.graphics.composer@2.1_genc++_headers",
+ tool: "hidl-gen",
+ cmd: "$tool -o $genDir -Lc++ -randroid.hardware:hardware/interfaces android.hardware.graphics.composer@2.1",
+ srcs: [
+ "types.hal",
+ "IComposer.hal",
+ "IComposerCallback.hal",
+ ],
+ out: [
+ "android/hardware/graphics/composer/2.1/types.h",
+ "android/hardware/graphics/composer/2.1/IComposer.h",
+ "android/hardware/graphics/composer/2.1/IHwComposer.h",
+ "android/hardware/graphics/composer/2.1/BnComposer.h",
+ "android/hardware/graphics/composer/2.1/BpComposer.h",
+ "android/hardware/graphics/composer/2.1/BsComposer.h",
+ "android/hardware/graphics/composer/2.1/IComposerCallback.h",
+ "android/hardware/graphics/composer/2.1/IHwComposerCallback.h",
+ "android/hardware/graphics/composer/2.1/BnComposerCallback.h",
+ "android/hardware/graphics/composer/2.1/BpComposerCallback.h",
+ "android/hardware/graphics/composer/2.1/BsComposerCallback.h",
+ ],
+}
+
+cc_library_shared {
+ name: "android.hardware.graphics.composer@2.1",
+ generated_sources: ["android.hardware.graphics.composer@2.1_genc++"],
+ generated_headers: ["android.hardware.graphics.composer@2.1_genc++_headers"],
+ export_generated_headers: ["android.hardware.graphics.composer@2.1_genc++_headers"],
+ shared_libs: [
+ "libhidl",
+ "libhwbinder",
+ "libutils",
+ "libcutils",
+ "android.hardware.graphics.allocator@2.0",
+ ],
+}
diff --git a/graphics/composer/2.1/IComposer.hal b/graphics/composer/2.1/IComposer.hal
new file mode 100644
index 0000000..7bfa22b
--- /dev/null
+++ b/graphics/composer/2.1/IComposer.hal
@@ -0,0 +1,1166 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.hardware.graphics.composer@2.1;
+
+import android.hardware.graphics.allocator@2.0::PixelFormat;
+import IComposerCallback;
+
+interface IComposer {
+ /*
+ * Optional capabilities which may be supported by some devices. The
+ * particular set of supported capabilities for a given device may be
+ * retrieved using getCapabilities.
+ */
+ enum Capability : int32_t {
+ INVALID = 0,
+
+ /*
+ * Specifies that the device supports sideband stream layers, for
+ * which buffer content updates and other synchronization will not be
+ * provided through the usual validate/present cycle and must be
+ * handled by an external implementation-defined mechanism. Only
+ * changes to layer state (such as position, size, etc.) need to be
+ * performed through the validate/present cycle.
+ */
+ SIDEBAND_STREAM = 1,
+
+ /*
+ * Specifies that the device will apply a color transform even when
+ * either the client or the device has chosen that all layers should
+ * be composed by the client. This will prevent the client from
+ * applying the color transform during its composition step.
+ */
+ SKIP_CLIENT_COLOR_TRANSFORM = 2,
+ };
+
+ /* Display attributes queryable through getDisplayAttribute. */
+ enum Attribute : int32_t {
+ INVALID = 0,
+
+ /* Dimensions in pixels */
+ WIDTH = 1,
+ HEIGHT = 2,
+
+ /* Vsync period in nanoseconds */
+ VSYNC_PERIOD = 3,
+
+ /*
+ * Dots per thousand inches (DPI * 1000). Scaling by 1000 allows these
+ * numbers to be stored in an int32_t without losing too much
+ * precision. If the DPI for a configuration is unavailable or is
+ * considered unreliable, the device may return UNSUPPORTED instead.
+ */
+ DPI_X = 4,
+ DPI_Y = 5,
+ };
+
+ /* Display requests returned by getDisplayRequests. */
+ enum DisplayRequest : uint32_t {
+ /*
+ * Instructs the client to provide a new client target buffer, even if
+ * no layers are marked for client composition.
+ */
+ FLIP_CLIENT_TARGET = 1 << 0,
+
+ /*
+ * Instructs the client to write the result of client composition
+ * directly into the virtual display output buffer. If any of the
+ * layers are not marked as Composition::CLIENT or the given display
+ * is not a virtual display, this request has no effect.
+ */
+ WRITE_CLIENT_TARGET_TO_OUTPUT = 1 << 1,
+ };
+
+ /* Layer requests returned from getDisplayRequests. */
+ enum LayerRequest : uint32_t {
+ /*
+ * The client should clear its target with transparent pixels where
+ * this layer would be. The client may ignore this request if the
+ * layer must be blended.
+ */
+ CLEAR_CLIENT_TARGET = 1 << 0,
+ };
+
+ /* Power modes for use with setPowerMode. */
+ enum PowerMode : int32_t {
+ /* The display is fully off (blanked). */
+ OFF = 0,
+
+ /*
+ * These are optional low power modes. getDozeSupport may be called to
+ * determine whether a given display supports these modes.
+ */
+
+ /*
+ * The display is turned on and configured in a low power state that
+ * is suitable for presenting ambient information to the user,
+ * possibly with lower fidelity than ON, but with greater efficiency.
+ */
+ DOZE = 1,
+
+ /*
+ * The display is configured as in DOZE but may stop applying display
+ * updates from the client. This is effectively a hint to the device
+ * that drawing to the display has been suspended and that the the
+ * device should remain on in a low power state and continue
+ * displaying its current contents indefinitely until the power mode
+ * changes.
+ *
+ * This mode may also be used as a signal to enable hardware-based
+ * doze functionality. In this case, the device is free to take over
+ * the display and manage it autonomously to implement a low power
+ * always-on display.
+ */
+ DOZE_SUSPEND = 3,
+
+ /* The display is fully on. */
+ ON = 2,
+ };
+
+ /* Vsync values passed to setVsyncEnabled. */
+ enum Vsync : int32_t {
+ INVALID = 0,
+
+ /* Enable vsync. */
+ ENABLE = 1,
+
+ /* Disable vsync. */
+ DISABLE = 2,
+ };
+
+ /* Blend modes, settable per layer. */
+ enum BlendMode : int32_t {
+ INVALID = 0,
+
+ /* colorOut = colorSrc */
+ NONE = 1,
+
+ /* colorOut = colorSrc + colorDst * (1 - alphaSrc) */
+ PREMULTIPLIED = 2,
+
+ /* colorOut = colorSrc * alphaSrc + colorDst * (1 - alphaSrc) */
+ COVERAGE = 3,
+ };
+
+ /* Possible composition types for a given layer. */
+ enum Composition : int32_t {
+ INVALID = 0,
+
+ /*
+ * The client will composite this layer into the client target buffer
+ * (provided to the device through setClientTarget).
+ *
+ * The device must not request any composition type changes for layers
+ * of this type.
+ */
+ CLIENT = 1,
+
+ /*
+ * The device will handle the composition of this layer through a
+ * hardware overlay or other similar means.
+ *
+ * Upon validateDisplay, the device may request a change from this
+ * type to CLIENT.
+ */
+ DEVICE = 2,
+
+ /*
+ * The device will render this layer using the color set through
+ * setLayerColor. If this functionality is not supported on a layer
+ * that the client sets to SOLID_COLOR, the device must request that
+ * the composition type of that layer is changed to CLIENT upon the
+ * next call to validateDisplay.
+ *
+ * Upon validateDisplay, the device may request a change from this
+ * type to CLIENT.
+ */
+ SOLID_COLOR = 3,
+
+ /*
+ * Similar to DEVICE, but the position of this layer may also be set
+ * asynchronously through setCursorPosition. If this functionality is
+ * not supported on a layer that the client sets to CURSOR, the device
+ * must request that the composition type of that layer is changed to
+ * CLIENT upon the next call to validateDisplay.
+ *
+ * Upon validateDisplay, the device may request a change from this
+ * type to either DEVICE or CLIENT. Changing to DEVICE will prevent
+ * the use of setCursorPosition but still permit the device to
+ * composite the layer.
+ */
+ CURSOR = 4,
+
+ /*
+ * The device will handle the composition of this layer, as well as
+ * its buffer updates and content synchronization. Only supported on
+ * devices which provide Capability::SIDEBAND_STREAM.
+ *
+ * Upon validateDisplay, the device may request a change from this
+ * type to either DEVICE or CLIENT, but it is unlikely that content
+ * will display correctly in these cases.
+ */
+ SIDEBAND = 5,
+ };
+
+ /* Display types returned by getDisplayType. */
+ enum DisplayType : int32_t {
+ INVALID = 0,
+
+ /*
+ * All physical displays, including both internal displays and
+ * hotpluggable external displays.
+ */
+ PHYSICAL = 1,
+
+ /* Virtual displays created by createVirtualDisplay. */
+ VIRTUAL = 2,
+ };
+
+ struct Rect {
+ int32_t left;
+ int32_t top;
+ int32_t right;
+ int32_t bottom;
+ };
+
+ struct FRect {
+ float left;
+ float top;
+ float right;
+ float bottom;
+ };
+
+ struct Color {
+ uint8_t r;
+ uint8_t g;
+ uint8_t b;
+ uint8_t a;
+ };
+
+ /*
+ * Provides a list of supported capabilities (as described in the
+ * definition of Capability above). This list must not change after
+ * initialization.
+ *
+ * @return capabilities is a list of supported capabilities.
+ */
+ getCapabilities() generates (vec<Capability> capabilities);
+
+ /*
+ * Retrieves implementation-defined debug information, which will be
+ * displayed during, for example, `dumpsys SurfaceFlinger`.
+ *
+ * @return debugInfo is a string of debug information.
+ */
+ dumpDebugInfo() generates (string debugInfo);
+
+ /*
+ * Provides a IComposerCallback object for the device to call.
+ *
+ * @param callback is the IComposerCallback object.
+ */
+ registerCallback(IComposerCallback callback);
+
+ /*
+ * Returns the maximum number of virtual displays supported by this device
+ * (which may be 0). The client will not attempt to create more than this
+ * many virtual displays on this device. This number must not change for
+ * the lifetime of the device.
+ */
+ getMaxVirtualDisplayCount() generates (uint32_t count);
+
+ /*
+ * Creates a new virtual display with the given width and height. The
+ * format passed into this function is the default format requested by the
+ * consumer of the virtual display output buffers.
+ *
+ * The display will be assumed to be on from the time the first frame is
+ * presented until the display is destroyed.
+ *
+ * @param width is the width in pixels.
+ * @param height is the height in pixels.
+ * @param formatHint is the default output buffer format selected by
+ * the consumer.
+ * @return error is NONE upon success. Otherwise,
+ * UNSUPPORTED when the width or height is too large for the
+ * device to be able to create a virtual display.
+ * NO_RESOURCES when the device is unable to create a new virtual
+ * display at this time.
+ * @return display is the newly-created virtual display.
+ * @return format is the format of the buffer the device will produce.
+ */
+ createVirtualDisplay(uint32_t width,
+ uint32_t height,
+ PixelFormat formatHint)
+ generates (Error error,
+ Display display,
+ PixelFormat format);
+
+ /*
+ * Destroys a virtual display. After this call all resources consumed by
+ * this display may be freed by the device and any operations performed on
+ * this display should fail.
+ *
+ * @param display is the virtual display to destroy.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * BAD_PARAMETER when the display handle which was passed in does
+ * not refer to a virtual display.
+ */
+ destroyVirtualDisplay(Display display) generates (Error error);
+
+ /*
+ * Accepts the changes required by the device from the previous
+ * validateDisplay call (which may be queried using
+ * getChangedCompositionTypes) and revalidates the display. This function
+ * is equivalent to requesting the changed types from
+ * getChangedCompositionTypes, setting those types on the corresponding
+ * layers, and then calling validateDisplay again.
+ *
+ * After this call it must be valid to present this display. Calling this
+ * after validateDisplay returns 0 changes must succeed with NONE, but
+ * should have no other effect.
+ *
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * NOT_VALIDATED when validateDisplay has not been called.
+ */
+ acceptDisplayChanges(Display display) generates (Error error);
+
+ /*
+ * Creates a new layer on the given display.
+ *
+ * @param display is the display on which to create the layer.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * NO_RESOURCES when the device was unable to create a layer this
+ * time.
+ * @return layer is the handle of the new layer.
+ */
+ createLayer(Display display) generates (Error error, Layer layer);
+
+ /*
+ * Destroys the given layer.
+ *
+ * @param display is the display on which the layer was created.
+ * @param layer is the layer to destroy.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * BAD_LAYER when an invalid layer handle was passed in.
+ */
+ destroyLayer(Display display, Layer layer) generates (Error error);
+
+ /*
+ * Retrieves which display configuration is currently active.
+ *
+ * If no display configuration is currently active, this function must
+ * return BAD_CONFIG. It is the responsibility of the client to call
+ * setActiveConfig with a valid configuration before attempting to present
+ * anything on the display.
+ *
+ * @param display is the display to which the active config is queried.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * BAD_CONFIG when no configuration is currently active.
+ * @return config is the currently active display configuration.
+ */
+ getActiveConfig(Display display) generates (Error error, Config config);
+
+ /*
+ * Retrieves the layers for which the device requires a different
+ * composition type than had been set prior to the last call to
+ * validateDisplay. The client will either update its state with these
+ * types and call acceptDisplayChanges, or will set new types and attempt
+ * to validate the display again.
+ *
+ * The number of changed layers must be the same as the value returned in
+ * numTypes from the last call to validateDisplay.
+ *
+ * @param display is the display to query.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * NOT_VALIDATED when validateDisplay has not been called.
+ * @return layers is an array of layer handles.
+ * @return types is an array of composition types, each corresponding to
+ * an element of layers.
+ */
+ getChangedCompositionTypes(Display display)
+ generates (Error error,
+ vec<Layer> layers,
+ vec<Composition> types);
+
+ /*
+ * Returns whether a client target with the given properties can be
+ * handled by the device.
+ *
+ * This function must return true for a client target with width and
+ * height equal to the active display configuration dimensions,
+ * PixelFormat::RGBA_8888, and Dataspace::UNKNOWN. It is not required to
+ * return true for any other configuration.
+ *
+ * @param display is the display to query.
+ * @param width is the client target width in pixels.
+ * @param height is the client target height in pixels.
+ * @param format is the client target format.
+ * @param dataspace is the client target dataspace, as described in
+ * setLayerDataspace.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * UNSUPPORTED when the given configuration is not supported.
+ */
+ getClientTargetSupport(Display display,
+ uint32_t width,
+ uint32_t height,
+ PixelFormat format,
+ Dataspace dataspace)
+ generates (Error error);
+
+ /*
+ * Returns the color modes supported on this display.
+ *
+ * All devices must support at least ColorMode::NATIVE.
+ *
+ * @param display is the display to query.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * @return modes is an array of color modes.
+ */
+ getColorModes(Display display)
+ generates (Error error,
+ vec<ColorMode> modes);
+
+ /*
+ * Returns a display attribute value for a particular display
+ * configuration.
+ *
+ * @param display is the display to query.
+ * @param config is the display configuration for which to return
+ * attribute values.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * BAD_CONFIG when config does not name a valid configuration for
+ * this display.
+ * BAD_PARAMETER when attribute is unrecognized.
+ * UNSUPPORTED when attribute cannot be queried for the config.
+ * @return value is the value of the attribute.
+ */
+ getDisplayAttribute(Display display,
+ Config config,
+ Attribute attribute)
+ generates (Error error,
+ int32_t value);
+
+ /*
+ * Returns handles for all of the valid display configurations on this
+ * display.
+ *
+ * @param display is the display to query.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * @return configs is an array of configuration handles.
+ */
+ getDisplayConfigs(Display display)
+ generates (Error error,
+ vec<Config> configs);
+
+ /*
+ * Returns a human-readable version of the display's name.
+ *
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * @return name is the name of the display.
+ */
+ getDisplayName(Display display) generates (Error error, string name);
+
+ /*
+ * Returns the display requests and the layer requests required for the
+ * last validated configuration.
+ *
+ * Display requests provide information about how the client should handle
+ * the client target. Layer requests provide information about how the
+ * client should handle an individual layer.
+ *
+ * The number of layer requests must be equal to the value returned in
+ * numRequests from the last call to validateDisplay.
+ *
+ * @param display is the display to query.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * NOT_VALIDATED when validateDisplay has not been called.
+ * @return displayRequestMask is the display requests for the current
+ * validated state.
+ * @return layers is an array of layers which all have at least one
+ * request.
+ * @return layerRequestMasks is the requests corresponding to each element
+ * of layers.
+ */
+ getDisplayRequests(Display display)
+ generates (Error error,
+ uint32_t displayRequestMask,
+ vec<Layer> layers,
+ vec<uint32_t> layerRequestMasks);
+
+ /*
+ * Returns whether the given display is a physical or virtual display.
+ *
+ * @param display is the display to query.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * @return type is the type of the display.
+ */
+ getDisplayType(Display display) generates (Error error, DisplayType type);
+
+ /*
+ * Returns whether the given display supports PowerMode::DOZE and
+ * PowerMode::DOZE_SUSPEND. DOZE_SUSPEND may not provide any benefit over
+ * DOZE (see the definition of PowerMode for more information), but if
+ * both DOZE and DOZE_SUSPEND are no different from PowerMode::ON, the
+ * device should not claim support.
+ *
+ * @param display is the display to query.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * @return support is true only when the display supports doze modes.
+ */
+ getDozeSupport(Display display) generates (Error error, bool support);
+
+ /*
+ * Returns the high dynamic range (HDR) capabilities of the given display,
+ * which are invariant with regard to the active configuration.
+ *
+ * Displays which are not HDR-capable must return no types.
+ *
+ * @param display is the display to query.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * @return types is an array of HDR types, may have 0 elements if the
+ * display is not HDR-capable.
+ * @return maxLuminance is the desired content maximum luminance for this
+ * display in cd/m^2.
+ * @return maxAverageLuminance - the desired content maximum frame-average
+ * luminance for this display in cd/m^2.
+ * @return minLuminance is the desired content minimum luminance for this
+ * display in cd/m^2.
+ */
+ getHdrCapabilities(Display display)
+ generates (Error error,
+ vec<Hdr> types,
+ float maxLuminance,
+ float maxAverageLuminance,
+ float minLuminance);
+
+ /*
+ * Retrieves the release fences for device layers on this display which
+ * will receive new buffer contents this frame.
+ *
+ * A release fence is a file descriptor referring to a sync fence object
+ * which will be signaled after the device has finished reading from the
+ * buffer presented in the prior frame. This indicates that it is safe to
+ * start writing to the buffer again. If a given layer's fence is not
+ * returned from this function, it will be assumed that the buffer
+ * presented on the previous frame is ready to be written.
+ *
+ * The fences returned by this function should be unique for each layer
+ * (even if they point to the same underlying sync object).
+ *
+ * @param display is the display to query.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * @return layers is an array of layer handles.
+ * @return fences is handle that contains an array of sync fence file
+ * descriptors as described above, each corresponding to an
+ * element of layers.
+ */
+ getReleaseFences(Display display)
+ generates (Error error,
+ vec<Layer> layers,
+ handle releaseFences);
+
+ /*
+ * Presents the current display contents on the screen (or in the case of
+ * virtual displays, into the output buffer).
+ *
+ * Prior to calling this function, the display must be successfully
+ * validated with validateDisplay. Note that setLayerBuffer and
+ * setLayerSurfaceDamage specifically do not count as layer state, so if
+ * there are no other changes to the layer state (or to the buffer's
+ * properties as described in setLayerBuffer), then it is safe to call
+ * this function without first validating the display.
+ *
+ * If this call succeeds, presentFence will be populated with a file
+ * descriptor referring to a present sync fence object. For physical
+ * displays, this fence will be signaled at the vsync when the result of
+ * composition of this frame starts to appear (for video-mode panels) or
+ * starts to transfer to panel memory (for command-mode panels). For
+ * virtual displays, this fence will be signaled when writes to the output
+ * buffer have completed and it is safe to read from it.
+ *
+ * @param display is the display to present.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * NO_RESOURCES when no valid output buffer has been set for a
+ * virtual display.
+ * NOT_VALIDATED when validateDisplay has not successfully been
+ * called for this display.
+ * @return presentFence is a sync fence file descriptor as described
+ * above.
+ */
+ presentDisplay(Display display)
+ generates (Error error,
+ handle presentFence);
+
+ /*
+ * Sets the active configuration for this display. Upon returning, the
+ * given display configuration should be active and remain so until either
+ * this function is called again or the display is disconnected.
+ *
+ * @param display is the display to which the active config is set.
+ * @param config is the new display configuration.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * BAD_CONFIG when the configuration handle passed in is not valid
+ * for this display.
+ */
+ setActiveConfig(Display display, Config config) generates (Error error);
+
+ /*
+ * Sets the buffer handle which will receive the output of client
+ * composition. Layers marked as Composition::CLIENT will be composited
+ * into this buffer prior to the call to presentDisplay, and layers not
+ * marked as Composition::CLIENT should be composited with this buffer by
+ * the device.
+ *
+ * The buffer handle provided may be empty if no layers are being
+ * composited by the client. This must not result in an error (unless an
+ * invalid display handle is also provided).
+ *
+ * Also provides a file descriptor referring to an acquire sync fence
+ * object, which will be signaled when it is safe to read from the client
+ * target buffer. If it is already safe to read from this buffer, an
+ * empty handle may be passed instead.
+ *
+ * For more about dataspaces, see setLayerDataspace.
+ *
+ * The damage parameter describes a surface damage region as defined in
+ * the description of setLayerSurfaceDamage.
+ *
+ * Will be called before presentDisplay if any of the layers are marked as
+ * Composition::CLIENT. If no layers are so marked, then it is not
+ * necessary to call this function. It is not necessary to call
+ * validateDisplay after changing the target through this function.
+ *
+ * @param display is the display to which the client target is set.
+ * @param target is the new target buffer.
+ * @param acquireFence is a sync fence file descriptor as described above.
+ * @param dataspace is the dataspace of the buffer, as described in
+ * setLayerDataspace.
+ * @param damage is the surface damage region.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * BAD_PARAMETER when the new target handle was invalid.
+ */
+ setClientTarget(Display display,
+ handle target,
+ handle acquireFence,
+ Dataspace dataspace,
+ vec<Rect> damage)
+ generates (Error error);
+
+ /*
+ * Sets the color mode of the given display.
+ *
+ * Upon returning from this function, the color mode change must have
+ * fully taken effect.
+ *
+ * All devices must support at least ColorMode::NATIVE, and displays are
+ * assumed to be in this mode upon hotplug.
+ *
+ * @param display is the display to which the color mode is set.
+ * @param mode is the mode to set to.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * BAD_PARAMETER when mode is not a valid color mode.
+ * UNSUPPORTED when mode is not supported on this display.
+ */
+ setColorMode(Display display, ColorMode mode) generates (Error error);
+
+ /*
+ * Sets a color transform which will be applied after composition.
+ *
+ * If hint is not ColorTransform::ARBITRARY, then the device may use the
+ * hint to apply the desired color transform instead of using the color
+ * matrix directly.
+ *
+ * If the device is not capable of either using the hint or the matrix to
+ * apply the desired color transform, it should force all layers to client
+ * composition during validateDisplay.
+ *
+ * If Capability::SKIP_CLIENT_COLOR_TRANSFORM is present, then the client
+ * will never apply the color transform during client composition, even if
+ * all layers are being composed by the client.
+ *
+ * The matrix provided is an affine color transformation of the following
+ * form:
+ *
+ * |r.r r.g r.b 0|
+ * |g.r g.g g.b 0|
+ * |b.r b.g b.b 0|
+ * |Tr Tg Tb 1|
+ *
+ * This matrix will be provided in row-major form:
+ *
+ * {r.r, r.g, r.b, 0, g.r, ...}.
+ *
+ * Given a matrix of this form and an input color [R_in, G_in, B_in], the
+ * output color [R_out, G_out, B_out] will be:
+ *
+ * R_out = R_in * r.r + G_in * g.r + B_in * b.r + Tr
+ * G_out = R_in * r.g + G_in * g.g + B_in * b.g + Tg
+ * B_out = R_in * r.b + G_in * g.b + B_in * b.b + Tb
+ *
+ * @param display is the display to which the color transform is set.
+ * @param matrix is a 4x4 transform matrix (16 floats) as described above.
+ * @param hint is a hint value which may be used instead of the given
+ * matrix unless it is ColorTransform::ARBITRARY.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * BAD_PARAMETER when hint is not a valid color transform hint.
+ */
+ setColorTransform(Display display,
+ vec<float> matrix,
+ ColorTransform hint)
+ generates (Error error);
+
+ /*
+ * Sets the output buffer for a virtual display. That is, the buffer to
+ * which the composition result will be written.
+ *
+ * Also provides a file descriptor referring to a release sync fence
+ * object, which will be signaled when it is safe to write to the output
+ * buffer. If it is already safe to write to the output buffer, an empty
+ * handle may be passed instead.
+ *
+ * Must be called at least once before presentDisplay, but does not have
+ * any interaction with layer state or display validation.
+ *
+ * @param display is the virtual display to which the output buffer is
+ * set.
+ * @param buffer is the new output buffer.
+ * @param releaseFence is a sync fence file descriptor as described above.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * BAD_PARAMETER when the new output buffer handle was invalid.
+ * UNSUPPORTED when display does not refer to a virtual display.
+ */
+ setOutputBuffer(Display display,
+ handle buffer,
+ handle releaseFence)
+ generates (Error error);
+
+ /*
+ * Sets the power mode of the given display. The transition must be
+ * complete when this function returns. It is valid to call this function
+ * multiple times with the same power mode.
+ *
+ * All displays must support PowerMode::ON and PowerMode::OFF. Whether a
+ * display supports PowerMode::DOZE or PowerMode::DOZE_SUSPEND may be
+ * queried using getDozeSupport.
+ *
+ * @param display is the display to which the power mode is set.
+ * @param mode is the new power mode.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * BAD_PARAMETER when mode was not a valid power mode.
+ * UNSUPPORTED when mode is not supported on this display.
+ */
+ setPowerMode(Display display, PowerMode mode) generates (Error error);
+
+ /*
+ * Enables or disables the vsync signal for the given display. Virtual
+ * displays never generate vsync callbacks, and any attempt to enable
+ * vsync for a virtual display though this function must succeed and have
+ * no other effect.
+ *
+ * @param display is the display to which the vsync mode is set.
+ * @param enabled indicates whether to enable or disable vsync
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * BAD_PARAMETER when enabled was an invalid value.
+ */
+ setVsyncEnabled(Display display, Vsync enabled) generates (Error error);
+
+ /*
+ * Instructs the device to inspect all of the layer state and determine if
+ * there are any composition type changes necessary before presenting the
+ * display. Permitted changes are described in the definition of
+ * Composition above.
+ *
+ * Also returns the number of layer requests required by the given layer
+ * configuration.
+ *
+ * @param display is the display to validate.
+ * @return error is NONE or HAS_CHANGES upon success.
+ * NONE when no changes are necessary and it is safe to present
+ * the display using the current layer state.
+ * HAS_CHANGES when composition type changes are needed.
+ * Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * @return numTypes is the number of composition type changes required by
+ * the device; if greater than 0, the client must either set and
+ * validate new types, or call acceptDisplayChanges to accept the
+ * changes returned by getChangedCompositionTypes. It must be the
+ * same as the number of changes returned by
+ * getChangedCompositionTypes (see the declaration of that
+ * function for more information).
+ * @return numRequests is the number of layer requests required by this
+ * layer configuration. It must be equal to the number of layer
+ * requests returned by getDisplayRequests (see the declaration of
+ * that function for more information).
+ */
+ validateDisplay(Display display)
+ generates (Error error,
+ uint32_t numTypes,
+ uint32_t numRequests);
+
+ /*
+ * Layer Functions
+ *
+ * These are functions which operate on layers, but which do not modify
+ * state that must be validated before use. See also 'Layer State
+ * Functions' below.
+ */
+
+ /*
+ * Asynchonously sets the position of a cursor layer.
+ *
+ * Prior to validateDisplay, a layer may be marked as Composition::CURSOR.
+ * If validation succeeds (i.e., the device does not request a composition
+ * change for that layer), then once a buffer has been set for the layer
+ * and it has been presented, its position may be set by this function at
+ * any time between presentDisplay and any subsequent validateDisplay
+ * calls for this display.
+ *
+ * Once validateDisplay is called, this function will not be called again
+ * until the validate/present sequence is completed.
+ *
+ * May be called from any thread so long as it is not interleaved with the
+ * validate/present sequence as described above.
+ *
+ * @param display is the display on which the layer was created.
+ * @param layer is the layer to which the position is set.
+ * @param x is the new x coordinate (in pixels from the left of the
+ * screen).
+ * @param y is the new y coordinate (in pixels from the top of the
+ * screen).
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * BAD_LAYER when the layer is invalid or is not currently marked
+ * as Composition::CURSOR.
+ * NOT_VALIDATED when the device is currently in the middle of the
+ * validate/present sequence.
+ */
+ setCursorPosition(Display display,
+ Layer layer,
+ int32_t x,
+ int32_t y)
+ generates (Error error);
+
+ /*
+ * Sets the buffer handle to be displayed for this layer. If the buffer
+ * properties set at allocation time (width, height, format, and usage)
+ * have not changed since the previous frame, it is not necessary to call
+ * validateDisplay before calling presentDisplay unless new state needs to
+ * be validated in the interim.
+ *
+ * Also provides a file descriptor referring to an acquire sync fence
+ * object, which will be signaled when it is safe to read from the given
+ * buffer. If it is already safe to read from the buffer, an empty handle
+ * may be passed instead.
+ *
+ * This function must return NONE and have no other effect if called for a
+ * layer with a composition type of Composition::SOLID_COLOR (because it
+ * has no buffer) or Composition::SIDEBAND or Composition::CLIENT (because
+ * synchronization and buffer updates for these layers are handled
+ * elsewhere).
+ *
+ * @param display is the display on which the layer was created.
+ * @param layer is the layer to which the buffer is set.
+ * @param buffer is the buffer handle to set.
+ * @param acquireFence is a sync fence file descriptor as described above.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * BAD_LAYER when an invalid layer handle was passed in.
+ * BAD_PARAMETER when the buffer handle passed in was invalid.
+ */
+ setLayerBuffer(Display display,
+ Layer layer,
+ handle buffer,
+ handle acquireFence)
+ generates (Error error);
+
+ /*
+ * Provides the region of the source buffer which has been modified since
+ * the last frame. This region does not need to be validated before
+ * calling presentDisplay.
+ *
+ * Once set through this function, the damage region remains the same
+ * until a subsequent call to this function.
+ *
+ * If damage is non-empty, then it may be assumed that any portion of the
+ * source buffer not covered by one of the rects has not been modified
+ * this frame. If damage is empty, then the whole source buffer must be
+ * treated as if it has been modified.
+ *
+ * If the layer's contents are not modified relative to the prior frame,
+ * damage will contain exactly one empty rect([0, 0, 0, 0]).
+ *
+ * The damage rects are relative to the pre-transformed buffer, and their
+ * origin is the top-left corner. They will not exceed the dimensions of
+ * the latched buffer.
+ *
+ * @param display is the display on which the layer was created.
+ * @param layer is the layer to which the damage region is set.
+ * @param damage is the new surface damage region.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * BAD_LAYER when an invalid layer handle was passed in.
+ */
+ setLayerSurfaceDamage(Display display,
+ Layer layer,
+ vec<Rect> damage)
+ generates (Error error);
+
+ /*
+ * Layer State Functions
+ *
+ * These functions modify the state of a given layer. They do not take
+ * effect until the display configuration is successfully validated with
+ * validateDisplay and the display contents are presented with
+ * presentDisplay.
+ */
+
+ /*
+ * Sets the blend mode of the given layer.
+ *
+ * @param display is the display on which the layer was created.
+ * @param layer is the layer to which the blend mode is set.
+ * @param mode is the new blend mode.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * BAD_LAYER when an invalid layer handle was passed in.
+ * BAD_PARAMETER when an invalid blend mode was passed in.
+ */
+ setLayerBlendMode(Display display,
+ Layer layer,
+ BlendMode mode)
+ generates (Error error);
+
+ /*
+ * Sets the color of the given layer. If the composition type of the layer
+ * is not Composition::SOLID_COLOR, this call must succeed and have no
+ * other effect.
+ *
+ * @param display is the display on which the layer was created.
+ * @param layer is the layer to which the blend mode is set.
+ * @param color is the new color.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * BAD_LAYER when an invalid layer handle was passed in.
+ */
+ setLayerColor(Display display,
+ Layer layer,
+ Color color)
+ generates (Error error);
+
+ /*
+ * Sets the desired composition type of the given layer. During
+ * validateDisplay, the device may request changes to the composition
+ * types of any of the layers as described in the definition of
+ * Composition above.
+ *
+ * @param display is the display on which the layer was created.
+ * @param layer is the layer to which the blend mode is set.
+ * @param type is the new composition type.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * BAD_LAYER when an invalid layer handle was passed in.
+ * BAD_PARAMETER when an invalid composition type was passed in.
+ * UNSUPPORTED when a valid composition type was passed in, but it
+ * is not supported by this device.
+ */
+ setLayerCompositionType(Display display,
+ Layer layer,
+ Composition type)
+ generates (Error error);
+
+ /*
+ * Sets the dataspace that the current buffer on this layer is in.
+ *
+ * The dataspace provides more information about how to interpret the
+ * buffer contents, such as the encoding standard and color transform.
+ *
+ * See the values of Dataspace for more information.
+ *
+ * @param display is the display on which the layer was created.
+ * @param layer is the layer to which the dataspace is set.
+ * @param dataspace is the new dataspace.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * BAD_LAYER when an invalid layer handle was passed in.
+ */
+ setLayerDataspace(Display display,
+ Layer layer,
+ Dataspace dataspace)
+ generates (Error error);
+
+ /*
+ * Sets the display frame (the portion of the display covered by a layer)
+ * of the given layer. This frame will not exceed the display dimensions.
+ *
+ * @param display is the display on which the layer was created.
+ * @param layer is the layer to which the frame is set.
+ * @param frame is the new display frame.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * BAD_LAYER when an invalid layer handle was passed in.
+ */
+ setLayerDisplayFrame(Display display,
+ Layer layer,
+ Rect frame)
+ generates (Error error);
+
+ /*
+ * Sets an alpha value (a floating point value in the range [0.0, 1.0])
+ * which will be applied to the whole layer. It can be conceptualized as a
+ * preprocessing step which applies the following function:
+ * if (blendMode == BlendMode::PREMULTIPLIED)
+ * out.rgb = in.rgb * planeAlpha
+ * out.a = in.a * planeAlpha
+ *
+ * If the device does not support this operation on a layer which is
+ * marked Composition::DEVICE, it must request a composition type change
+ * to Composition::CLIENT upon the next validateDisplay call.
+ *
+ * @param display is the display on which the layer was created.
+ * @param layer is the layer to which the plane alpha is set.
+ * @param alpha is the plane alpha value to apply.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * BAD_LAYER when an invalid layer handle was passed in.
+ */
+ setLayerPlaneAlpha(Display display,
+ Layer layer,
+ float alpha)
+ generates (Error error);
+
+ /*
+ * Sets the sideband stream for this layer. If the composition type of the
+ * given layer is not Composition::SIDEBAND, this call must succeed and
+ * have no other effect.
+ *
+ * @param display is the display on which the layer was created.
+ * @param layer is the layer to which the sideband stream is set.
+ * @param stream is the new sideband stream.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * BAD_LAYER when an invalid layer handle was passed in.
+ * BAD_PARAMETER when an invalid sideband stream was passed in.
+ */
+ setLayerSidebandStream(Display display,
+ Layer layer,
+ handle stream)
+ generates (Error error);
+
+ /*
+ * Sets the source crop (the portion of the source buffer which will fill
+ * the display frame) of the given layer. This crop rectangle will not
+ * exceed the dimensions of the latched buffer.
+ *
+ * If the device is not capable of supporting a true float source crop
+ * (i.e., it will truncate or round the floats to integers), it should set
+ * this layer to Composition::CLIENT when crop is non-integral for the
+ * most accurate rendering.
+ *
+ * If the device cannot support float source crops, but still wants to
+ * handle the layer, it should use the following code (or similar) to
+ * convert to an integer crop:
+ * intCrop.left = (int) ceilf(crop.left);
+ * intCrop.top = (int) ceilf(crop.top);
+ * intCrop.right = (int) floorf(crop.right);
+ * intCrop.bottom = (int) floorf(crop.bottom);
+ *
+ * @param display is the display on which the layer was created.
+ * @param layer is the layer to which the source crop is set.
+ * @param crop is the new source crop.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * BAD_LAYER when an invalid layer handle was passed in.
+ */
+ setLayerSourceCrop(Display display,
+ Layer layer,
+ FRect crop)
+ generates (Error error);
+
+ /*
+ * Sets the transform (rotation/flip) of the given layer.
+ *
+ * @param display is the display on which the layer was created.
+ * @param layer is the layer to which the transform is set.
+ * @param transform is the new transform.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * BAD_LAYER when an invalid layer handle was passed in.
+ * BAD_PARAMETER when an invalid transform was passed in.
+ */
+ setLayerTransform(Display display,
+ Layer layer,
+ Transform transform)
+ generates (Error error);
+
+ /*
+ * Specifies the portion of the layer that is visible, including portions
+ * under translucent areas of other layers. The region is in screen space,
+ * and will not exceed the dimensions of the screen.
+ *
+ * @param display is the display on which the layer was created.
+ * @param layer is the layer to which the visible region is set.
+ * @param visible is the new visible region, in screen space.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * BAD_LAYER when an invalid layer handle was passed in.
+ */
+ setLayerVisibleRegion(Display display,
+ Layer layer,
+ vec<Rect> visible)
+ generates (Error error);
+
+ /*
+ * Sets the desired Z order (height) of the given layer. A layer with a
+ * greater Z value occludes a layer with a lesser Z value.
+ *
+ * @param display is the display on which the layer was created.
+ * @param layer is the layer to which the Z order is set.
+ * @param z is the new Z order.
+ * @return error is NONE upon success. Otherwise,
+ * BAD_DISPLAY when an invalid display handle was passed in.
+ * BAD_LAYER when an invalid layer handle was passed in.
+ */
+ setLayerZOrder(Display display,
+ Layer layer,
+ uint32_t z)
+ generates (Error error);
+};
diff --git a/graphics/composer/2.1/IComposerCallback.hal b/graphics/composer/2.1/IComposerCallback.hal
new file mode 100644
index 0000000..a8ca168
--- /dev/null
+++ b/graphics/composer/2.1/IComposerCallback.hal
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.hardware.graphics.composer@2.1;
+
+interface IComposerCallback {
+ enum Connection : int32_t {
+ INVALID = 0,
+
+ /* The display has been connected */
+ CONNECTED = 1,
+ /* The display has been disconnected */
+ DISCONNECTED = 2,
+ };
+
+ /*
+ * Notifies the client that the given display has either been connected or
+ * disconnected. Every active display (even a built-in physical display)
+ * must trigger at least one hotplug notification, even if it only occurs
+ * immediately after callback registration.
+ *
+ * Displays which have been connected are assumed to be in PowerMode::OFF,
+ * and the onVsync callback should not be called for a display until vsync
+ * has been enabled with setVsyncEnabled.
+ *
+ * The client may call back into the device while the callback is in
+ * progress. The device must serialize calls to this callback such that
+ * only one thread is calling it at a time.
+ *
+ * @param display is the display that triggers the hotplug event.
+ * @param connected indicates whether the display is connected or
+ * disconnected.
+ */
+ onHotplug(Display display, Connection connected);
+
+ /*
+ * Notifies the client to trigger a screen refresh. This forces all layer
+ * state for this display to be resent, and the display to be validated
+ * and presented, even if there have been no changes.
+
+ * This refresh will occur some time after the callback is initiated, but
+ * not necessarily before it returns. It is safe to trigger this callback
+ * from other functions which call into the device.
+ *
+ * @param display is the display to refresh.
+ */
+ oneway onRefresh(Display display);
+
+ /*
+ * Notifies the client that a vsync event has occurred. This callback must
+ * only be triggered when vsync is enabled for this display (through
+ * setVsyncEnabled).
+ *
+ * @param display is the display which has received a vsync event
+ * @param timestamp is the CLOCK_MONOTONIC time at which the vsync event
+ * occurred, in nanoseconds.
+ */
+ oneway onVsync(Display display, int64_t timestamp);
+};
diff --git a/graphics/composer/2.1/default/Android.bp b/graphics/composer/2.1/default/Android.bp
new file mode 100644
index 0000000..f91c9a2
--- /dev/null
+++ b/graphics/composer/2.1/default/Android.bp
@@ -0,0 +1,16 @@
+cc_library_shared {
+ name: "android.hardware.graphics.composer@2.1-impl",
+ relative_install_path: "hw",
+ srcs: ["Hwc.cpp"],
+ shared_libs: [
+ "android.hardware.graphics.allocator@2.0",
+ "android.hardware.graphics.composer@2.1",
+ "libbase",
+ "libcutils",
+ "libhardware",
+ "libhidl",
+ "libhwbinder",
+ "liblog",
+ "libutils",
+ ],
+}
diff --git a/graphics/composer/2.1/default/Hwc.cpp b/graphics/composer/2.1/default/Hwc.cpp
new file mode 100644
index 0000000..09c62f0
--- /dev/null
+++ b/graphics/composer/2.1/default/Hwc.cpp
@@ -0,0 +1,1292 @@
+/*
+ * Copyright 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "HwcPassthrough"
+
+#include <mutex>
+#include <type_traits>
+#include <unordered_map>
+#include <unordered_set>
+#include <utility>
+#include <vector>
+
+#include <hardware/gralloc.h>
+#include <hardware/gralloc1.h>
+#include <hardware/hwcomposer2.h>
+#include <log/log.h>
+
+#include "Hwc.h"
+
+namespace android {
+namespace hardware {
+namespace graphics {
+namespace composer {
+namespace V2_1 {
+namespace implementation {
+
+using android::hardware::graphics::allocator::V2_0::PixelFormat;
+
+namespace {
+
+class HandleImporter {
+public:
+ HandleImporter() : mInitialized(false) {}
+
+ bool initialize()
+ {
+ // allow only one client
+ if (mInitialized) {
+ return false;
+ }
+
+ if (!openGralloc()) {
+ return false;
+ }
+
+ mInitialized = true;
+ return true;
+ }
+
+ void cleanup()
+ {
+ if (!mInitialized) {
+ return;
+ }
+
+ closeGralloc();
+ mInitialized = false;
+ }
+
+ // In IComposer, any buffer_handle_t is owned by the caller and we need to
+ // make a clone for hwcomposer2. We also need to translate empty handle
+ // to nullptr. This function does that, in-place.
+ bool importBuffer(buffer_handle_t& handle)
+ {
+ if (!handle->numFds && !handle->numInts) {
+ handle = nullptr;
+ return true;
+ }
+
+ buffer_handle_t clone = cloneBuffer(handle);
+ if (!clone) {
+ return false;
+ }
+
+ handle = clone;
+ return true;
+ }
+
+ void freeBuffer(buffer_handle_t handle)
+ {
+ if (!handle) {
+ return;
+ }
+
+ releaseBuffer(handle);
+ }
+
+ bool importFence(const native_handle_t* handle, int& fd)
+ {
+ if (handle->numFds == 0) {
+ fd = -1;
+ } else if (handle->numFds == 1) {
+ fd = dup(handle->data[0]);
+ if (fd < 0) {
+ ALOGE("failed to dup fence fd %d", handle->data[0]);
+ return false;
+ }
+ } else {
+ ALOGE("invalid fence handle with %d file descriptors",
+ handle->numFds);
+ return false;
+ }
+
+ return true;
+ }
+
+ void closeFence(int fd)
+ {
+ if (fd >= 0) {
+ close(fd);
+ }
+ }
+
+private:
+ bool mInitialized;
+
+ // Some existing gralloc drivers do not support retaining more than once,
+ // when we are in passthrough mode.
+#ifdef BINDERIZED
+ bool openGralloc()
+ {
+ const hw_module_t* module;
+ int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module);
+ if (err) {
+ ALOGE("failed to get gralloc module");
+ return false;
+ }
+
+ uint8_t major = (module->module_api_version >> 8) & 0xff;
+ if (major > 1) {
+ ALOGE("unknown gralloc module major version %d", major);
+ return false;
+ }
+
+ if (major == 1) {
+ err = gralloc1_open(module, &mDevice);
+ if (err) {
+ ALOGE("failed to open gralloc1 device");
+ return false;
+ }
+
+ mRetain = reinterpret_cast<GRALLOC1_PFN_RETAIN>(
+ mDevice->getFunction(mDevice, GRALLOC1_FUNCTION_RETAIN));
+ mRelease = reinterpret_cast<GRALLOC1_PFN_RELEASE>(
+ mDevice->getFunction(mDevice, GRALLOC1_FUNCTION_RELEASE));
+ if (!mRetain || !mRelease) {
+ ALOGE("invalid gralloc1 device");
+ gralloc1_close(mDevice);
+ return false;
+ }
+ } else {
+ mModule = reinterpret_cast<const gralloc_module_t*>(module);
+ }
+
+ return true;
+ }
+
+ void closeGralloc()
+ {
+ if (mDevice) {
+ gralloc1_close(mDevice);
+ }
+ }
+
+ buffer_handle_t cloneBuffer(buffer_handle_t handle)
+ {
+ native_handle_t* clone = native_handle_clone(handle);
+ if (!clone) {
+ ALOGE("failed to clone buffer %p", handle);
+ return nullptr;
+ }
+
+ bool err;
+ if (mDevice) {
+ err = (mRetain(mDevice, clone) != GRALLOC1_ERROR_NONE);
+ } else {
+ err = (mModule->registerBuffer(mModule, clone) != 0);
+ }
+
+ if (err) {
+ ALOGE("failed to retain/register buffer %p", clone);
+ native_handle_close(clone);
+ native_handle_delete(clone);
+ return nullptr;
+ }
+
+ return clone;
+ }
+
+ void releaseBuffer(buffer_handle_t handle)
+ {
+ if (mDevice) {
+ mRelease(mDevice, handle);
+ } else {
+ mModule->unregisterBuffer(mModule, handle);
+ native_handle_close(handle);
+ native_handle_delete(const_cast<native_handle_t*>(handle));
+ }
+ }
+
+ // gralloc1
+ gralloc1_device_t* mDevice;
+ GRALLOC1_PFN_RETAIN mRetain;
+ GRALLOC1_PFN_RELEASE mRelease;
+
+ // gralloc0
+ const gralloc_module_t* mModule;
+#else
+ bool openGralloc() { return true; }
+ void closeGralloc() {}
+ buffer_handle_t cloneBuffer(buffer_handle_t handle) { return handle; }
+ void releaseBuffer(buffer_handle_t) {}
+#endif
+};
+
+HandleImporter sHandleImporter;
+
+class BufferClone {
+public:
+ BufferClone() : mHandle(nullptr) {}
+
+ BufferClone(BufferClone&& other)
+ {
+ mHandle = other.mHandle;
+ other.mHandle = nullptr;
+ }
+
+ BufferClone(const BufferClone& other) = delete;
+ BufferClone& operator=(const BufferClone& other) = delete;
+
+ BufferClone& operator=(buffer_handle_t handle)
+ {
+ clear();
+ mHandle = handle;
+ return *this;
+ }
+
+ ~BufferClone()
+ {
+ clear();
+ }
+
+private:
+ void clear()
+ {
+ if (mHandle) {
+ sHandleImporter.freeBuffer(mHandle);
+ }
+ }
+
+ buffer_handle_t mHandle;
+};
+
+} // anonymous namespace
+
+class HwcHal : public IComposer {
+public:
+ HwcHal(const hw_module_t* module);
+ virtual ~HwcHal();
+
+ // IComposer interface
+ Return<void> getCapabilities(getCapabilities_cb hidl_cb) override;
+ Return<void> dumpDebugInfo(dumpDebugInfo_cb hidl_cb) override;
+ Return<void> registerCallback(const sp<IComposerCallback>& callback) override;
+ Return<uint32_t> getMaxVirtualDisplayCount() override;
+ Return<void> createVirtualDisplay(uint32_t width, uint32_t height,
+ PixelFormat formatHint, createVirtualDisplay_cb hidl_cb) override;
+ Return<Error> destroyVirtualDisplay(Display display) override;
+ Return<Error> acceptDisplayChanges(Display display) override;
+ Return<void> createLayer(Display display,
+ createLayer_cb hidl_cb) override;
+ Return<Error> destroyLayer(Display display, Layer layer) override;
+ Return<void> getActiveConfig(Display display,
+ getActiveConfig_cb hidl_cb) override;
+ Return<void> getChangedCompositionTypes(Display display,
+ getChangedCompositionTypes_cb hidl_cb) override;
+ Return<Error> getClientTargetSupport(Display display,
+ uint32_t width, uint32_t height,
+ PixelFormat format, Dataspace dataspace) override;
+ Return<void> getColorModes(Display display,
+ getColorModes_cb hidl_cb) override;
+ Return<void> getDisplayAttribute(Display display,
+ Config config, Attribute attribute,
+ getDisplayAttribute_cb hidl_cb) override;
+ Return<void> getDisplayConfigs(Display display,
+ getDisplayConfigs_cb hidl_cb) override;
+ Return<void> getDisplayName(Display display,
+ getDisplayName_cb hidl_cb) override;
+ Return<void> getDisplayRequests(Display display,
+ getDisplayRequests_cb hidl_cb) override;
+ Return<void> getDisplayType(Display display,
+ getDisplayType_cb hidl_cb) override;
+ Return<void> getDozeSupport(Display display,
+ getDozeSupport_cb hidl_cb) override;
+ Return<void> getHdrCapabilities(Display display,
+ getHdrCapabilities_cb hidl_cb) override;
+ Return<void> getReleaseFences(Display display,
+ getReleaseFences_cb hidl_cb) override;
+ Return<void> presentDisplay(Display display,
+ presentDisplay_cb hidl_cb) override;
+ Return<Error> setActiveConfig(Display display, Config config) override;
+ Return<Error> setClientTarget(Display display,
+ const native_handle_t* target,
+ const native_handle_t* acquireFence,
+ Dataspace dataspace, const hidl_vec<Rect>& damage) override;
+ Return<Error> setColorMode(Display display, ColorMode mode) override;
+ Return<Error> setColorTransform(Display display,
+ const hidl_vec<float>& matrix, ColorTransform hint) override;
+ Return<Error> setOutputBuffer(Display display,
+ const native_handle_t* buffer,
+ const native_handle_t* releaseFence) override;
+ Return<Error> setPowerMode(Display display, PowerMode mode) override;
+ Return<Error> setVsyncEnabled(Display display, Vsync enabled) override;
+ Return<void> validateDisplay(Display display,
+ validateDisplay_cb hidl_cb) override;
+ Return<Error> setCursorPosition(Display display,
+ Layer layer, int32_t x, int32_t y) override;
+ Return<Error> setLayerBuffer(Display display,
+ Layer layer, const native_handle_t* buffer,
+ const native_handle_t* acquireFence) override;
+ Return<Error> setLayerSurfaceDamage(Display display,
+ Layer layer, const hidl_vec<Rect>& damage) override;
+ Return<Error> setLayerBlendMode(Display display,
+ Layer layer, BlendMode mode) override;
+ Return<Error> setLayerColor(Display display,
+ Layer layer, const Color& color) override;
+ Return<Error> setLayerCompositionType(Display display,
+ Layer layer, Composition type) override;
+ Return<Error> setLayerDataspace(Display display,
+ Layer layer, Dataspace dataspace) override;
+ Return<Error> setLayerDisplayFrame(Display display,
+ Layer layer, const Rect& frame) override;
+ Return<Error> setLayerPlaneAlpha(Display display,
+ Layer layer, float alpha) override;
+ Return<Error> setLayerSidebandStream(Display display,
+ Layer layer, const native_handle_t* stream) override;
+ Return<Error> setLayerSourceCrop(Display display,
+ Layer layer, const FRect& crop) override;
+ Return<Error> setLayerTransform(Display display,
+ Layer layer, Transform transform) override;
+ Return<Error> setLayerVisibleRegion(Display display,
+ Layer layer, const hidl_vec<Rect>& visible) override;
+ Return<Error> setLayerZOrder(Display display,
+ Layer layer, uint32_t z) override;
+
+private:
+ void initCapabilities();
+
+ template<typename T>
+ void initDispatch(T& func, hwc2_function_descriptor_t desc);
+ void initDispatch();
+
+ bool hasCapability(Capability capability) const;
+
+ static void hotplugHook(hwc2_callback_data_t callbackData,
+ hwc2_display_t display, int32_t connected);
+ static void refreshHook(hwc2_callback_data_t callbackData,
+ hwc2_display_t display);
+ static void vsyncHook(hwc2_callback_data_t callbackData,
+ hwc2_display_t display, int64_t timestamp);
+
+ hwc2_device_t* mDevice;
+
+ std::unordered_set<Capability> mCapabilities;
+
+ struct {
+ HWC2_PFN_ACCEPT_DISPLAY_CHANGES acceptDisplayChanges;
+ HWC2_PFN_CREATE_LAYER createLayer;
+ HWC2_PFN_CREATE_VIRTUAL_DISPLAY createVirtualDisplay;
+ HWC2_PFN_DESTROY_LAYER destroyLayer;
+ HWC2_PFN_DESTROY_VIRTUAL_DISPLAY destroyVirtualDisplay;
+ HWC2_PFN_DUMP dump;
+ HWC2_PFN_GET_ACTIVE_CONFIG getActiveConfig;
+ HWC2_PFN_GET_CHANGED_COMPOSITION_TYPES getChangedCompositionTypes;
+ HWC2_PFN_GET_CLIENT_TARGET_SUPPORT getClientTargetSupport;
+ HWC2_PFN_GET_COLOR_MODES getColorModes;
+ HWC2_PFN_GET_DISPLAY_ATTRIBUTE getDisplayAttribute;
+ HWC2_PFN_GET_DISPLAY_CONFIGS getDisplayConfigs;
+ HWC2_PFN_GET_DISPLAY_NAME getDisplayName;
+ HWC2_PFN_GET_DISPLAY_REQUESTS getDisplayRequests;
+ HWC2_PFN_GET_DISPLAY_TYPE getDisplayType;
+ HWC2_PFN_GET_DOZE_SUPPORT getDozeSupport;
+ HWC2_PFN_GET_HDR_CAPABILITIES getHdrCapabilities;
+ HWC2_PFN_GET_MAX_VIRTUAL_DISPLAY_COUNT getMaxVirtualDisplayCount;
+ HWC2_PFN_GET_RELEASE_FENCES getReleaseFences;
+ HWC2_PFN_PRESENT_DISPLAY presentDisplay;
+ HWC2_PFN_REGISTER_CALLBACK registerCallback;
+ HWC2_PFN_SET_ACTIVE_CONFIG setActiveConfig;
+ HWC2_PFN_SET_CLIENT_TARGET setClientTarget;
+ HWC2_PFN_SET_COLOR_MODE setColorMode;
+ HWC2_PFN_SET_COLOR_TRANSFORM setColorTransform;
+ HWC2_PFN_SET_CURSOR_POSITION setCursorPosition;
+ HWC2_PFN_SET_LAYER_BLEND_MODE setLayerBlendMode;
+ HWC2_PFN_SET_LAYER_BUFFER setLayerBuffer;
+ HWC2_PFN_SET_LAYER_COLOR setLayerColor;
+ HWC2_PFN_SET_LAYER_COMPOSITION_TYPE setLayerCompositionType;
+ HWC2_PFN_SET_LAYER_DATASPACE setLayerDataspace;
+ HWC2_PFN_SET_LAYER_DISPLAY_FRAME setLayerDisplayFrame;
+ HWC2_PFN_SET_LAYER_PLANE_ALPHA setLayerPlaneAlpha;
+ HWC2_PFN_SET_LAYER_SIDEBAND_STREAM setLayerSidebandStream;
+ HWC2_PFN_SET_LAYER_SOURCE_CROP setLayerSourceCrop;
+ HWC2_PFN_SET_LAYER_SURFACE_DAMAGE setLayerSurfaceDamage;
+ HWC2_PFN_SET_LAYER_TRANSFORM setLayerTransform;
+ HWC2_PFN_SET_LAYER_VISIBLE_REGION setLayerVisibleRegion;
+ HWC2_PFN_SET_LAYER_Z_ORDER setLayerZOrder;
+ HWC2_PFN_SET_OUTPUT_BUFFER setOutputBuffer;
+ HWC2_PFN_SET_POWER_MODE setPowerMode;
+ HWC2_PFN_SET_VSYNC_ENABLED setVsyncEnabled;
+ HWC2_PFN_VALIDATE_DISPLAY validateDisplay;
+ } mDispatch;
+
+ // cloned buffers for a display
+ struct DisplayBuffers {
+ BufferClone ClientTarget;
+ BufferClone OutputBuffer;
+
+ std::unordered_map<Layer, BufferClone> LayerBuffers;
+ std::unordered_map<Layer, BufferClone> LayerSidebandStreams;
+ };
+
+ std::mutex mCallbackMutex;
+ sp<IComposerCallback> mCallback;
+
+ std::mutex mDisplayMutex;
+ std::unordered_map<Display, DisplayBuffers> mDisplays;
+};
+
+HwcHal::HwcHal(const hw_module_t* module)
+ : mDevice(nullptr), mDispatch()
+{
+ if (!sHandleImporter.initialize()) {
+ LOG_ALWAYS_FATAL("failed to initialize handle importer");
+ }
+
+ int status = hwc2_open(module, &mDevice);
+ if (status) {
+ LOG_ALWAYS_FATAL("failed to open hwcomposer2 device: %s",
+ strerror(-status));
+ }
+
+ initCapabilities();
+ initDispatch();
+}
+
+HwcHal::~HwcHal()
+{
+ hwc2_close(mDevice);
+ mDisplays.clear();
+ sHandleImporter.cleanup();
+}
+
+void HwcHal::initCapabilities()
+{
+ uint32_t count = 0;
+ mDevice->getCapabilities(mDevice, &count, nullptr);
+
+ std::vector<Capability> caps(count);
+ mDevice->getCapabilities(mDevice, &count, reinterpret_cast<
+ std::underlying_type<Capability>::type*>(caps.data()));
+ caps.resize(count);
+
+ mCapabilities.insert(caps.cbegin(), caps.cend());
+}
+
+template<typename T>
+void HwcHal::initDispatch(T& func, hwc2_function_descriptor_t desc)
+{
+ auto pfn = mDevice->getFunction(mDevice, desc);
+ if (!pfn) {
+ LOG_ALWAYS_FATAL("failed to get hwcomposer2 function %d", desc);
+ }
+
+ func = reinterpret_cast<T>(pfn);
+}
+
+void HwcHal::initDispatch()
+{
+ initDispatch(mDispatch.acceptDisplayChanges,
+ HWC2_FUNCTION_ACCEPT_DISPLAY_CHANGES);
+ initDispatch(mDispatch.createLayer, HWC2_FUNCTION_CREATE_LAYER);
+ initDispatch(mDispatch.createVirtualDisplay,
+ HWC2_FUNCTION_CREATE_VIRTUAL_DISPLAY);
+ initDispatch(mDispatch.destroyLayer, HWC2_FUNCTION_DESTROY_LAYER);
+ initDispatch(mDispatch.destroyVirtualDisplay,
+ HWC2_FUNCTION_DESTROY_VIRTUAL_DISPLAY);
+ initDispatch(mDispatch.dump, HWC2_FUNCTION_DUMP);
+ initDispatch(mDispatch.getActiveConfig, HWC2_FUNCTION_GET_ACTIVE_CONFIG);
+ initDispatch(mDispatch.getChangedCompositionTypes,
+ HWC2_FUNCTION_GET_CHANGED_COMPOSITION_TYPES);
+ initDispatch(mDispatch.getClientTargetSupport,
+ HWC2_FUNCTION_GET_CLIENT_TARGET_SUPPORT);
+ initDispatch(mDispatch.getColorModes, HWC2_FUNCTION_GET_COLOR_MODES);
+ initDispatch(mDispatch.getDisplayAttribute,
+ HWC2_FUNCTION_GET_DISPLAY_ATTRIBUTE);
+ initDispatch(mDispatch.getDisplayConfigs,
+ HWC2_FUNCTION_GET_DISPLAY_CONFIGS);
+ initDispatch(mDispatch.getDisplayName, HWC2_FUNCTION_GET_DISPLAY_NAME);
+ initDispatch(mDispatch.getDisplayRequests,
+ HWC2_FUNCTION_GET_DISPLAY_REQUESTS);
+ initDispatch(mDispatch.getDisplayType, HWC2_FUNCTION_GET_DISPLAY_TYPE);
+ initDispatch(mDispatch.getDozeSupport, HWC2_FUNCTION_GET_DOZE_SUPPORT);
+ initDispatch(mDispatch.getHdrCapabilities,
+ HWC2_FUNCTION_GET_HDR_CAPABILITIES);
+ initDispatch(mDispatch.getMaxVirtualDisplayCount,
+ HWC2_FUNCTION_GET_MAX_VIRTUAL_DISPLAY_COUNT);
+ initDispatch(mDispatch.getReleaseFences,
+ HWC2_FUNCTION_GET_RELEASE_FENCES);
+ initDispatch(mDispatch.presentDisplay, HWC2_FUNCTION_PRESENT_DISPLAY);
+ initDispatch(mDispatch.registerCallback, HWC2_FUNCTION_REGISTER_CALLBACK);
+ initDispatch(mDispatch.setActiveConfig, HWC2_FUNCTION_SET_ACTIVE_CONFIG);
+ initDispatch(mDispatch.setClientTarget, HWC2_FUNCTION_SET_CLIENT_TARGET);
+ initDispatch(mDispatch.setColorMode, HWC2_FUNCTION_SET_COLOR_MODE);
+ initDispatch(mDispatch.setColorTransform,
+ HWC2_FUNCTION_SET_COLOR_TRANSFORM);
+ initDispatch(mDispatch.setCursorPosition,
+ HWC2_FUNCTION_SET_CURSOR_POSITION);
+ initDispatch(mDispatch.setLayerBlendMode,
+ HWC2_FUNCTION_SET_LAYER_BLEND_MODE);
+ initDispatch(mDispatch.setLayerBuffer, HWC2_FUNCTION_SET_LAYER_BUFFER);
+ initDispatch(mDispatch.setLayerColor, HWC2_FUNCTION_SET_LAYER_COLOR);
+ initDispatch(mDispatch.setLayerCompositionType,
+ HWC2_FUNCTION_SET_LAYER_COMPOSITION_TYPE);
+ initDispatch(mDispatch.setLayerDataspace,
+ HWC2_FUNCTION_SET_LAYER_DATASPACE);
+ initDispatch(mDispatch.setLayerDisplayFrame,
+ HWC2_FUNCTION_SET_LAYER_DISPLAY_FRAME);
+ initDispatch(mDispatch.setLayerPlaneAlpha,
+ HWC2_FUNCTION_SET_LAYER_PLANE_ALPHA);
+
+ if (hasCapability(Capability::SIDEBAND_STREAM)) {
+ initDispatch(mDispatch.setLayerSidebandStream,
+ HWC2_FUNCTION_SET_LAYER_SIDEBAND_STREAM);
+ }
+
+ initDispatch(mDispatch.setLayerSourceCrop,
+ HWC2_FUNCTION_SET_LAYER_SOURCE_CROP);
+ initDispatch(mDispatch.setLayerSurfaceDamage,
+ HWC2_FUNCTION_SET_LAYER_SURFACE_DAMAGE);
+ initDispatch(mDispatch.setLayerTransform,
+ HWC2_FUNCTION_SET_LAYER_TRANSFORM);
+ initDispatch(mDispatch.setLayerVisibleRegion,
+ HWC2_FUNCTION_SET_LAYER_VISIBLE_REGION);
+ initDispatch(mDispatch.setLayerZOrder, HWC2_FUNCTION_SET_LAYER_Z_ORDER);
+ initDispatch(mDispatch.setOutputBuffer, HWC2_FUNCTION_SET_OUTPUT_BUFFER);
+ initDispatch(mDispatch.setPowerMode, HWC2_FUNCTION_SET_POWER_MODE);
+ initDispatch(mDispatch.setVsyncEnabled, HWC2_FUNCTION_SET_VSYNC_ENABLED);
+ initDispatch(mDispatch.validateDisplay, HWC2_FUNCTION_VALIDATE_DISPLAY);
+}
+
+bool HwcHal::hasCapability(Capability capability) const
+{
+ return (mCapabilities.count(capability) > 0);
+}
+
+Return<void> HwcHal::getCapabilities(getCapabilities_cb hidl_cb)
+{
+ std::vector<Capability> caps(
+ mCapabilities.cbegin(), mCapabilities.cend());
+
+ hidl_vec<Capability> caps_reply;
+ caps_reply.setToExternal(caps.data(), caps.size());
+ hidl_cb(caps_reply);
+
+ return Void();
+}
+
+Return<void> HwcHal::dumpDebugInfo(dumpDebugInfo_cb hidl_cb)
+{
+ uint32_t len;
+ mDispatch.dump(mDevice, &len, nullptr);
+
+ std::vector<char> buf(len + 1);
+ mDispatch.dump(mDevice, &len, buf.data());
+ buf.resize(len + 1);
+ buf[len] = '\0';
+
+ hidl_string buf_reply;
+ buf_reply.setToExternal(buf.data(), len);
+ hidl_cb(buf_reply);
+
+ return Void();
+}
+
+void HwcHal::hotplugHook(hwc2_callback_data_t callbackData,
+ hwc2_display_t display, int32_t connected)
+{
+ auto hal = reinterpret_cast<HwcHal*>(callbackData);
+
+ {
+ std::lock_guard<std::mutex> lock(hal->mDisplayMutex);
+
+ if (connected == HWC2_CONNECTION_CONNECTED) {
+ hal->mDisplays.emplace(display, DisplayBuffers());
+ } else if (connected == HWC2_CONNECTION_DISCONNECTED) {
+ hal->mDisplays.erase(display);
+ }
+ }
+
+ hal->mCallback->onHotplug(display,
+ static_cast<IComposerCallback::Connection>(connected));
+}
+
+void HwcHal::refreshHook(hwc2_callback_data_t callbackData,
+ hwc2_display_t display)
+{
+ auto hal = reinterpret_cast<HwcHal*>(callbackData);
+ hal->mCallback->onRefresh(display);
+}
+
+void HwcHal::vsyncHook(hwc2_callback_data_t callbackData,
+ hwc2_display_t display, int64_t timestamp)
+{
+ auto hal = reinterpret_cast<HwcHal*>(callbackData);
+ hal->mCallback->onVsync(display, timestamp);
+}
+
+Return<void> HwcHal::registerCallback(const sp<IComposerCallback>& callback)
+{
+ std::lock_guard<std::mutex> lock(mCallbackMutex);
+
+ mCallback = callback;
+
+ mDispatch.registerCallback(mDevice, HWC2_CALLBACK_HOTPLUG, this,
+ reinterpret_cast<hwc2_function_pointer_t>(hotplugHook));
+ mDispatch.registerCallback(mDevice, HWC2_CALLBACK_REFRESH, this,
+ reinterpret_cast<hwc2_function_pointer_t>(refreshHook));
+ mDispatch.registerCallback(mDevice, HWC2_CALLBACK_VSYNC, this,
+ reinterpret_cast<hwc2_function_pointer_t>(vsyncHook));
+
+ return Void();
+}
+
+Return<uint32_t> HwcHal::getMaxVirtualDisplayCount()
+{
+ return mDispatch.getMaxVirtualDisplayCount(mDevice);
+}
+
+Return<void> HwcHal::createVirtualDisplay(uint32_t width, uint32_t height,
+ PixelFormat formatHint, createVirtualDisplay_cb hidl_cb)
+{
+ int32_t format = static_cast<int32_t>(formatHint);
+ hwc2_display_t display;
+ auto error = mDispatch.createVirtualDisplay(mDevice, width, height,
+ &format, &display);
+ if (error == HWC2_ERROR_NONE) {
+ std::lock_guard<std::mutex> lock(mDisplayMutex);
+
+ mDisplays.emplace(display, DisplayBuffers());
+ }
+
+ hidl_cb(static_cast<Error>(error), display,
+ static_cast<PixelFormat>(format));
+
+ return Void();
+}
+
+Return<Error> HwcHal::destroyVirtualDisplay(Display display)
+{
+ auto error = mDispatch.destroyVirtualDisplay(mDevice, display);
+ if (error == HWC2_ERROR_NONE) {
+ std::lock_guard<std::mutex> lock(mDisplayMutex);
+
+ mDisplays.erase(display);
+ }
+
+ return static_cast<Error>(error);
+}
+
+Return<Error> HwcHal::acceptDisplayChanges(Display display)
+{
+ auto error = mDispatch.acceptDisplayChanges(mDevice, display);
+ return static_cast<Error>(error);
+}
+
+Return<void> HwcHal::createLayer(Display display, createLayer_cb hidl_cb)
+{
+ hwc2_layer_t layer;
+ auto error = mDispatch.createLayer(mDevice, display, &layer);
+
+ hidl_cb(static_cast<Error>(error), layer);
+
+ return Void();
+}
+
+Return<Error> HwcHal::destroyLayer(Display display, Layer layer)
+{
+ auto error = mDispatch.destroyLayer(mDevice, display, layer);
+ return static_cast<Error>(error);
+}
+
+Return<void> HwcHal::getActiveConfig(Display display,
+ getActiveConfig_cb hidl_cb)
+{
+ hwc2_config_t config;
+ auto error = mDispatch.getActiveConfig(mDevice, display, &config);
+
+ hidl_cb(static_cast<Error>(error), config);
+
+ return Void();
+}
+
+Return<void> HwcHal::getChangedCompositionTypes(Display display,
+ getChangedCompositionTypes_cb hidl_cb)
+{
+ uint32_t count = 0;
+ auto error = mDispatch.getChangedCompositionTypes(mDevice, display,
+ &count, nullptr, nullptr);
+ if (error != HWC2_ERROR_NONE) {
+ count = 0;
+ }
+
+ std::vector<hwc2_layer_t> layers(count);
+ std::vector<Composition> types(count);
+ error = mDispatch.getChangedCompositionTypes(mDevice, display,
+ &count, layers.data(),
+ reinterpret_cast<std::underlying_type<Composition>::type*>(
+ types.data()));
+ if (error != HWC2_ERROR_NONE) {
+ count = 0;
+ }
+ layers.resize(count);
+ types.resize(count);
+
+ hidl_vec<Layer> layers_reply;
+ layers_reply.setToExternal(layers.data(), layers.size());
+
+ hidl_vec<Composition> types_reply;
+ types_reply.setToExternal(types.data(), types.size());
+
+ hidl_cb(static_cast<Error>(error), layers_reply, types_reply);
+
+ return Void();
+}
+
+Return<Error> HwcHal::getClientTargetSupport(Display display,
+ uint32_t width, uint32_t height,
+ PixelFormat format, Dataspace dataspace)
+{
+ auto error = mDispatch.getClientTargetSupport(mDevice, display,
+ width, height, static_cast<int32_t>(format),
+ static_cast<int32_t>(dataspace));
+ return static_cast<Error>(error);
+}
+
+Return<void> HwcHal::getColorModes(Display display, getColorModes_cb hidl_cb)
+{
+ uint32_t count = 0;
+ auto error = mDispatch.getColorModes(mDevice, display, &count, nullptr);
+ if (error != HWC2_ERROR_NONE) {
+ count = 0;
+ }
+
+ std::vector<ColorMode> modes(count);
+ error = mDispatch.getColorModes(mDevice, display, &count,
+ reinterpret_cast<std::underlying_type<ColorMode>::type*>(
+ modes.data()));
+ if (error != HWC2_ERROR_NONE) {
+ count = 0;
+ }
+ modes.resize(count);
+
+ hidl_vec<ColorMode> modes_reply;
+ modes_reply.setToExternal(modes.data(), modes.size());
+ hidl_cb(static_cast<Error>(error), modes_reply);
+
+ return Void();
+}
+
+Return<void> HwcHal::getDisplayAttribute(Display display,
+ Config config, Attribute attribute,
+ getDisplayAttribute_cb hidl_cb)
+{
+ int32_t value;
+ auto error = mDispatch.getDisplayAttribute(mDevice, display, config,
+ static_cast<int32_t>(attribute), &value);
+
+ hidl_cb(static_cast<Error>(error), value);
+
+ return Void();
+}
+
+Return<void> HwcHal::getDisplayConfigs(Display display,
+ getDisplayConfigs_cb hidl_cb)
+{
+ uint32_t count = 0;
+ auto error = mDispatch.getDisplayConfigs(mDevice, display,
+ &count, nullptr);
+ if (error != HWC2_ERROR_NONE) {
+ count = 0;
+ }
+
+ std::vector<hwc2_config_t> configs(count);
+ error = mDispatch.getDisplayConfigs(mDevice, display,
+ &count, configs.data());
+ if (error != HWC2_ERROR_NONE) {
+ count = 0;
+ }
+ configs.resize(count);
+
+ hidl_vec<Config> configs_reply;
+ configs_reply.setToExternal(configs.data(), configs.size());
+ hidl_cb(static_cast<Error>(error), configs_reply);
+
+ return Void();
+}
+
+Return<void> HwcHal::getDisplayName(Display display,
+ getDisplayName_cb hidl_cb)
+{
+ uint32_t count = 0;
+ auto error = mDispatch.getDisplayName(mDevice, display, &count, nullptr);
+ if (error != HWC2_ERROR_NONE) {
+ count = 0;
+ }
+
+ std::vector<char> name(count + 1);
+ error = mDispatch.getDisplayName(mDevice, display, &count, name.data());
+ if (error != HWC2_ERROR_NONE) {
+ count = 0;
+ }
+ name.resize(count + 1);
+ name[count] = '\0';
+
+ hidl_string name_reply;
+ name_reply.setToExternal(name.data(), count);
+ hidl_cb(static_cast<Error>(error), name_reply);
+
+ return Void();
+}
+
+Return<void> HwcHal::getDisplayRequests(Display display,
+ getDisplayRequests_cb hidl_cb)
+{
+ int32_t display_reqs;
+ uint32_t count = 0;
+ auto error = mDispatch.getDisplayRequests(mDevice, display,
+ &display_reqs, &count, nullptr, nullptr);
+ if (error != HWC2_ERROR_NONE) {
+ count = 0;
+ }
+
+ std::vector<hwc2_layer_t> layers(count);
+ std::vector<int32_t> layer_reqs(count);
+ error = mDispatch.getDisplayRequests(mDevice, display,
+ &display_reqs, &count, layers.data(), layer_reqs.data());
+ if (error != HWC2_ERROR_NONE) {
+ count = 0;
+ }
+ layers.resize(count);
+ layer_reqs.resize(count);
+
+ hidl_vec<Layer> layers_reply;
+ layers_reply.setToExternal(layers.data(), layers.size());
+
+ hidl_vec<uint32_t> layer_reqs_reply;
+ layer_reqs_reply.setToExternal(
+ reinterpret_cast<uint32_t*>(layer_reqs.data()),
+ layer_reqs.size());
+
+ hidl_cb(static_cast<Error>(error), display_reqs,
+ layers_reply, layer_reqs_reply);
+
+ return Void();
+}
+
+Return<void> HwcHal::getDisplayType(Display display,
+ getDisplayType_cb hidl_cb)
+{
+ int32_t type;
+ auto error = mDispatch.getDisplayType(mDevice, display, &type);
+
+ hidl_cb(static_cast<Error>(error), static_cast<DisplayType>(type));
+
+ return Void();
+}
+
+Return<void> HwcHal::getDozeSupport(Display display,
+ getDozeSupport_cb hidl_cb)
+{
+ int32_t support;
+ auto error = mDispatch.getDozeSupport(mDevice, display, &support);
+
+ hidl_cb(static_cast<Error>(error), support);
+
+ return Void();
+}
+
+Return<void> HwcHal::getHdrCapabilities(Display display,
+ getHdrCapabilities_cb hidl_cb)
+{
+ float max_lumi, max_avg_lumi, min_lumi;
+ uint32_t count = 0;
+ auto error = mDispatch.getHdrCapabilities(mDevice, display,
+ &count, nullptr, &max_lumi, &max_avg_lumi, &min_lumi);
+ if (error != HWC2_ERROR_NONE) {
+ count = 0;
+ }
+
+ std::vector<Hdr> types(count);
+ error = mDispatch.getHdrCapabilities(mDevice, display, &count,
+ reinterpret_cast<std::underlying_type<Hdr>::type*>(types.data()),
+ &max_lumi, &max_avg_lumi, &min_lumi);
+ if (error != HWC2_ERROR_NONE) {
+ count = 0;
+ }
+ types.resize(count);
+
+ hidl_vec<Hdr> types_reply;
+ types_reply.setToExternal(types.data(), types.size());
+ hidl_cb(static_cast<Error>(error), types_reply,
+ max_lumi, max_avg_lumi, min_lumi);
+
+ return Void();
+}
+
+Return<void> HwcHal::getReleaseFences(Display display,
+ getReleaseFences_cb hidl_cb)
+{
+ uint32_t count = 0;
+ auto error = mDispatch.getReleaseFences(mDevice, display,
+ &count, nullptr, nullptr);
+ if (error != HWC2_ERROR_NONE) {
+ count = 0;
+ }
+
+ std::vector<hwc2_layer_t> layers(count);
+ std::vector<int32_t> fences(count);
+ error = mDispatch.getReleaseFences(mDevice, display,
+ &count, layers.data(), fences.data());
+ if (error != HWC2_ERROR_NONE) {
+ count = 0;
+ }
+ layers.resize(count);
+ fences.resize(count);
+
+ // filter out layers with release fence -1
+ std::vector<hwc2_layer_t> filtered_layers;
+ std::vector<int> filtered_fences;
+ for (size_t i = 0; i < layers.size(); i++) {
+ if (fences[i] >= 0) {
+ filtered_layers.push_back(layers[i]);
+ filtered_fences.push_back(fences[i]);
+ }
+ }
+
+ hidl_vec<Layer> layers_reply;
+ native_handle_t* fences_reply =
+ native_handle_create(filtered_fences.size(), 0);
+ if (fences_reply) {
+ layers_reply.setToExternal(filtered_layers.data(),
+ filtered_layers.size());
+ memcpy(fences_reply->data, filtered_fences.data(),
+ sizeof(int) * filtered_fences.size());
+
+ hidl_cb(static_cast<Error>(error), layers_reply, fences_reply);
+
+ native_handle_close(fences_reply);
+ native_handle_delete(fences_reply);
+ } else {
+ NATIVE_HANDLE_DECLARE_STORAGE(fences_storage, 0, 0);
+ fences_reply = native_handle_init(fences_storage, 0, 0);
+
+ hidl_cb(Error::NO_RESOURCES, layers_reply, fences_reply);
+
+ for (auto fence : filtered_fences) {
+ close(fence);
+ }
+ }
+
+ return Void();
+}
+
+Return<void> HwcHal::presentDisplay(Display display,
+ presentDisplay_cb hidl_cb)
+{
+ int32_t fence = -1;
+ auto error = mDispatch.presentDisplay(mDevice, display, &fence);
+
+ NATIVE_HANDLE_DECLARE_STORAGE(fence_storage, 1, 0);
+ native_handle_t* fence_reply;
+ if (fence >= 0) {
+ fence_reply = native_handle_init(fence_storage, 1, 0);
+ fence_reply->data[0] = fence;
+ } else {
+ fence_reply = native_handle_init(fence_storage, 0, 0);
+ }
+
+ hidl_cb(static_cast<Error>(error), fence_reply);
+
+ if (fence >= 0) {
+ close(fence);
+ }
+
+ return Void();
+}
+
+Return<Error> HwcHal::setActiveConfig(Display display, Config config)
+{
+ auto error = mDispatch.setActiveConfig(mDevice, display, config);
+ return static_cast<Error>(error);
+}
+
+Return<Error> HwcHal::setClientTarget(Display display,
+ const native_handle_t* target,
+ const native_handle_t* acquireFence,
+ Dataspace dataspace, const hidl_vec<Rect>& damage)
+{
+ if (!sHandleImporter.importBuffer(target)) {
+ return Error::NO_RESOURCES;
+ }
+
+ int32_t fence;
+ if (!sHandleImporter.importFence(acquireFence, fence)) {
+ sHandleImporter.freeBuffer(target);
+ return Error::NO_RESOURCES;
+ }
+
+ hwc_region_t damage_region = { damage.size(),
+ reinterpret_cast<const hwc_rect_t*>(&damage[0]) };
+
+ int32_t error = mDispatch.setClientTarget(mDevice, display,
+ target, fence, static_cast<int32_t>(dataspace),
+ damage_region);
+ if (error == HWC2_ERROR_NONE) {
+ std::lock_guard<std::mutex> lock(mDisplayMutex);
+
+ auto dpy = mDisplays.find(display);
+ dpy->second.ClientTarget = target;
+ } else {
+ sHandleImporter.freeBuffer(target);
+ sHandleImporter.closeFence(fence);
+ }
+
+ return static_cast<Error>(error);
+}
+
+Return<Error> HwcHal::setColorMode(Display display, ColorMode mode)
+{
+ auto error = mDispatch.setColorMode(mDevice, display,
+ static_cast<int32_t>(mode));
+ return static_cast<Error>(error);
+}
+
+Return<Error> HwcHal::setColorTransform(Display display,
+ const hidl_vec<float>& matrix, ColorTransform hint)
+{
+ auto error = mDispatch.setColorTransform(mDevice, display,
+ &matrix[0], static_cast<int32_t>(hint));
+ return static_cast<Error>(error);
+}
+
+Return<Error> HwcHal::setOutputBuffer(Display display,
+ const native_handle_t* buffer,
+ const native_handle_t* releaseFence)
+{
+ if (!sHandleImporter.importBuffer(buffer)) {
+ return Error::NO_RESOURCES;
+ }
+
+ int32_t fence;
+ if (!sHandleImporter.importFence(releaseFence, fence)) {
+ sHandleImporter.freeBuffer(buffer);
+ return Error::NO_RESOURCES;
+ }
+
+ int32_t error = mDispatch.setOutputBuffer(mDevice,
+ display, buffer, fence);
+ if (error == HWC2_ERROR_NONE) {
+ std::lock_guard<std::mutex> lock(mDisplayMutex);
+
+ auto dpy = mDisplays.find(display);
+ dpy->second.OutputBuffer = buffer;
+ } else {
+ sHandleImporter.freeBuffer(buffer);
+ }
+
+ // unlike in setClientTarget, fence is owned by us and is always closed
+ sHandleImporter.closeFence(fence);
+
+ return static_cast<Error>(error);
+}
+
+Return<Error> HwcHal::setPowerMode(Display display, PowerMode mode)
+{
+ auto error = mDispatch.setPowerMode(mDevice, display,
+ static_cast<int32_t>(mode));
+ return static_cast<Error>(error);
+}
+
+Return<Error> HwcHal::setVsyncEnabled(Display display,
+ Vsync enabled)
+{
+ auto error = mDispatch.setVsyncEnabled(mDevice, display,
+ static_cast<int32_t>(enabled));
+ return static_cast<Error>(error);
+}
+
+Return<void> HwcHal::validateDisplay(Display display,
+ validateDisplay_cb hidl_cb)
+{
+ uint32_t types_count = 0;
+ uint32_t reqs_count = 0;
+ auto error = mDispatch.validateDisplay(mDevice, display,
+ &types_count, &reqs_count);
+
+ hidl_cb(static_cast<Error>(error), types_count, reqs_count);
+
+ return Void();
+}
+
+Return<Error> HwcHal::setCursorPosition(Display display,
+ Layer layer, int32_t x, int32_t y)
+{
+ auto error = mDispatch.setCursorPosition(mDevice, display, layer, x, y);
+ return static_cast<Error>(error);
+}
+
+Return<Error> HwcHal::setLayerBuffer(Display display,
+ Layer layer, const native_handle_t* buffer,
+ const native_handle_t* acquireFence)
+{
+ if (!sHandleImporter.importBuffer(buffer)) {
+ return Error::NO_RESOURCES;
+ }
+
+ int32_t fence;
+ if (!sHandleImporter.importFence(acquireFence, fence)) {
+ sHandleImporter.freeBuffer(buffer);
+ return Error::NO_RESOURCES;
+ }
+
+ int32_t error = mDispatch.setLayerBuffer(mDevice,
+ display, layer, buffer, fence);
+ if (error == HWC2_ERROR_NONE) {
+ std::lock_guard<std::mutex> lock(mDisplayMutex);
+
+ auto dpy = mDisplays.find(display);
+ dpy->second.LayerBuffers[layer] = buffer;
+ } else {
+ sHandleImporter.freeBuffer(buffer);
+ sHandleImporter.closeFence(fence);
+ }
+
+ return static_cast<Error>(error);
+}
+
+Return<Error> HwcHal::setLayerSurfaceDamage(Display display,
+ Layer layer, const hidl_vec<Rect>& damage)
+{
+ hwc_region_t damage_region = { damage.size(),
+ reinterpret_cast<const hwc_rect_t*>(&damage[0]) };
+
+ auto error = mDispatch.setLayerSurfaceDamage(mDevice, display, layer,
+ damage_region);
+ return static_cast<Error>(error);
+}
+
+Return<Error> HwcHal::setLayerBlendMode(Display display,
+ Layer layer, BlendMode mode)
+{
+ auto error = mDispatch.setLayerBlendMode(mDevice, display, layer,
+ static_cast<int32_t>(mode));
+ return static_cast<Error>(error);
+}
+
+Return<Error> HwcHal::setLayerColor(Display display,
+ Layer layer, const Color& color)
+{
+ hwc_color_t hwc_color{color.r, color.g, color.b, color.a};
+ auto error = mDispatch.setLayerColor(mDevice, display, layer, hwc_color);
+ return static_cast<Error>(error);
+}
+
+Return<Error> HwcHal::setLayerCompositionType(Display display,
+ Layer layer, Composition type)
+{
+ auto error = mDispatch.setLayerCompositionType(mDevice, display, layer,
+ static_cast<int32_t>(type));
+ return static_cast<Error>(error);
+}
+
+Return<Error> HwcHal::setLayerDataspace(Display display,
+ Layer layer, Dataspace dataspace)
+{
+ auto error = mDispatch.setLayerDataspace(mDevice, display, layer,
+ static_cast<int32_t>(dataspace));
+ return static_cast<Error>(error);
+}
+
+Return<Error> HwcHal::setLayerDisplayFrame(Display display,
+ Layer layer, const Rect& frame)
+{
+ hwc_rect_t hwc_frame{frame.left, frame.top, frame.right, frame.bottom};
+ auto error = mDispatch.setLayerDisplayFrame(mDevice, display, layer,
+ hwc_frame);
+ return static_cast<Error>(error);
+}
+
+Return<Error> HwcHal::setLayerPlaneAlpha(Display display,
+ Layer layer, float alpha)
+{
+ auto error = mDispatch.setLayerPlaneAlpha(mDevice, display, layer, alpha);
+ return static_cast<Error>(error);
+}
+
+Return<Error> HwcHal::setLayerSidebandStream(Display display,
+ Layer layer, const native_handle_t* stream)
+{
+ if (!sHandleImporter.importBuffer(stream)) {
+ return Error::NO_RESOURCES;
+ }
+
+ int32_t error = mDispatch.setLayerSidebandStream(mDevice,
+ display, layer, stream);
+ if (error == HWC2_ERROR_NONE) {
+ std::lock_guard<std::mutex> lock(mDisplayMutex);
+
+ auto dpy = mDisplays.find(display);
+ dpy->second.LayerSidebandStreams[layer] = stream;
+ } else {
+ sHandleImporter.freeBuffer(stream);
+ }
+
+ return static_cast<Error>(error);
+}
+
+Return<Error> HwcHal::setLayerSourceCrop(Display display,
+ Layer layer, const FRect& crop)
+{
+ hwc_frect_t hwc_crop{crop.left, crop.top, crop.right, crop.bottom};
+ auto error = mDispatch.setLayerSourceCrop(mDevice, display, layer,
+ hwc_crop);
+ return static_cast<Error>(error);
+}
+
+Return<Error> HwcHal::setLayerTransform(Display display,
+ Layer layer, Transform transform)
+{
+ auto error = mDispatch.setLayerTransform(mDevice, display, layer,
+ static_cast<int32_t>(transform));
+ return static_cast<Error>(error);
+}
+
+Return<Error> HwcHal::setLayerVisibleRegion(Display display,
+ Layer layer, const hidl_vec<Rect>& visible)
+{
+ hwc_region_t visible_region = { visible.size(),
+ reinterpret_cast<const hwc_rect_t*>(&visible[0]) };
+
+ auto error = mDispatch.setLayerVisibleRegion(mDevice, display, layer,
+ visible_region);
+ return static_cast<Error>(error);
+}
+
+Return<Error> HwcHal::setLayerZOrder(Display display,
+ Layer layer, uint32_t z)
+{
+ auto error = mDispatch.setLayerZOrder(mDevice, display, layer, z);
+ return static_cast<Error>(error);
+}
+
+IComposer* HIDL_FETCH_IComposer(const char*)
+{
+ const hw_module_t* module;
+ int err = hw_get_module(HWC_HARDWARE_MODULE_ID, &module);
+ if (err) {
+ ALOGE("failed to get hwcomposer module");
+ return nullptr;
+ }
+
+ return new HwcHal(module);
+}
+
+} // namespace implementation
+} // namespace V2_1
+} // namespace composer
+} // namespace graphics
+} // namespace hardware
+} // namespace android
diff --git a/graphics/composer/2.1/default/Hwc.h b/graphics/composer/2.1/default/Hwc.h
new file mode 100644
index 0000000..de69417
--- /dev/null
+++ b/graphics/composer/2.1/default/Hwc.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_HARDWARE_GRAPHICS_COMPOSER_V2_1_HWC_H
+#define ANDROID_HARDWARE_GRAPHICS_COMPOSER_V2_1_HWC_H
+
+#include <android/hardware/graphics/composer/2.1/IComposer.h>
+
+namespace android {
+namespace hardware {
+namespace graphics {
+namespace composer {
+namespace V2_1 {
+namespace implementation {
+
+extern "C" IComposer* HIDL_FETCH_IComposer(const char* name);
+
+} // namespace implementation
+} // namespace V2_1
+} // namespace composer
+} // namespace graphics
+} // namespace hardware
+} // namespace android
+
+#endif // ANDROID_HARDWARE_GRAPHICS_COMPOSER_V2_1_HWC_H
diff --git a/graphics/composer/2.1/types.hal b/graphics/composer/2.1/types.hal
new file mode 100644
index 0000000..3c591b3
--- /dev/null
+++ b/graphics/composer/2.1/types.hal
@@ -0,0 +1,163 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.hardware.graphics.composer@2.1;
+
+/* Return codes from all functions. */
+enum Error : int32_t {
+ NONE = 0, /* no error */
+ BAD_CONFIG = 1, /* invalid Config */
+ BAD_DISPLAY = 2, /* invalid Display */
+ BAD_LAYER = 3, /* invalid Layer */
+ BAD_PARAMETER = 4, /* invalid width, height, etc. */
+ HAS_CHANGES = 5,
+ NO_RESOURCES = 6, /* temporary failure due to resource contention */
+ NOT_VALIDATED = 7, /* validateDisplay has not been called */
+ UNSUPPORTED = 8, /* permanent failure */
+};
+
+typedef uint32_t Config;
+typedef uint64_t Display;
+typedef uint64_t Layer;
+
+/*
+ * Copied from android_transform_t
+ *
+ * TODO(olv) copy comments over and generate android_transform_t
+ */
+enum Transform : int32_t {
+ FLIP_H = 0x1,
+ FLIP_V = 0x2,
+ ROT_90 = 0x4,
+ ROT_180 = 0x3,
+ ROT_270 = 0x7,
+ RESERVED = 0x8,
+};
+
+/*
+ * Copied from android_color_mode_t
+ *
+ * TODO(olv) copy comments over and generate android_color_mode_t
+ */
+enum ColorMode : int32_t {
+ NATIVE = 0,
+ STANDARD_BT601_625 = 1,
+ STANDARD_BT601_625_UNADJUSTED = 2,
+ STANDARD_BT601_525 = 3,
+ STANDARD_BT601_525_UNADJUSTED = 4,
+ STANDARD_BT709 = 5,
+ DCI_P3 = 6,
+ SRGB = 7,
+ ADOBE_RGB = 8,
+};
+
+/*
+ * Copied from android_color_transform_t
+ *
+ * TODO(olv) copy comments over and generate android_color_transform_t
+ */
+enum ColorTransform : int32_t {
+ IDENTITY = 0,
+ ARBITRARY_MATRIX = 1,
+ VALUE_INVERSE = 2,
+ GRAYSCALE = 3,
+ CORRECT_PROTANOPIA = 4,
+ CORRECT_DEUTERANOPIA = 5,
+ CORRECT_TRITANOPIA = 6
+};
+
+/*
+ * Copied from android_dataspace_t
+ *
+ * TODO(olv) copy comments over and generate android_dataspace_t
+ */
+enum Dataspace : int32_t {
+ UNKNOWN = 0x0,
+ ARBITRARY = 0x1,
+
+ STANDARD_SHIFT = 16,
+ STANDARD_MASK = 63 << STANDARD_SHIFT,
+ STANDARD_UNSPECIFIED = 0 << STANDARD_SHIFT,
+ STANDARD_BT709 = 1 << STANDARD_SHIFT,
+ STANDARD_BT601_625 = 2 << STANDARD_SHIFT,
+ STANDARD_BT601_625_UNADJUSTED = 3 << STANDARD_SHIFT,
+ STANDARD_BT601_525 = 4 << STANDARD_SHIFT,
+ STANDARD_BT601_525_UNADJUSTED = 5 << STANDARD_SHIFT,
+ STANDARD_BT2020 = 6 << STANDARD_SHIFT,
+ STANDARD_BT2020_CONSTANT_LUMINANCE = 7 << STANDARD_SHIFT,
+ STANDARD_BT470M = 8 << STANDARD_SHIFT,
+ STANDARD_FILM = 9 << STANDARD_SHIFT,
+
+ TRANSFER_SHIFT = 22,
+ TRANSFER_MASK = 31 << TRANSFER_SHIFT,
+ TRANSFER_UNSPECIFIED = 0 << TRANSFER_SHIFT,
+ TRANSFER_LINEAR = 1 << TRANSFER_SHIFT,
+ TRANSFER_SRGB = 2 << TRANSFER_SHIFT,
+ TRANSFER_SMPTE_170M = 3 << TRANSFER_SHIFT,
+ TRANSFER_GAMMA2_2 = 4 << TRANSFER_SHIFT,
+ TRANSFER_GAMMA2_8 = 5 << TRANSFER_SHIFT,
+ TRANSFER_ST2084 = 6 << TRANSFER_SHIFT,
+ TRANSFER_HLG = 7 << TRANSFER_SHIFT,
+
+ RANGE_SHIFT = 27,
+ RANGE_MASK = 7 << RANGE_SHIFT,
+ RANGE_UNSPECIFIED = 0 << RANGE_SHIFT,
+ RANGE_FULL = 1 << RANGE_SHIFT,
+ RANGE_LIMITED = 2 << RANGE_SHIFT,
+
+ SRGB_LINEAR = 0x200,
+ V0_SRGB_LINEAR = STANDARD_BT709 |
+ TRANSFER_LINEAR |
+ RANGE_FULL,
+
+ SRGB = 0x201,
+ V0_SRGB = STANDARD_BT709 |
+ TRANSFER_SRGB |
+ RANGE_FULL,
+
+ JFIF = 0x101,
+ V0_JFIF = STANDARD_BT601_625 |
+ TRANSFER_SMPTE_170M |
+ RANGE_FULL,
+
+ BT601_625 = 0x102,
+ V0_BT601_625 = STANDARD_BT601_625 |
+ TRANSFER_SMPTE_170M |
+ RANGE_LIMITED,
+
+ BT601_525 = 0x103,
+ V0_BT601_525 = STANDARD_BT601_525 |
+ TRANSFER_SMPTE_170M |
+ RANGE_LIMITED,
+
+ BT709 = 0x104,
+ V0_BT709 = STANDARD_BT709 |
+ TRANSFER_SMPTE_170M |
+ RANGE_LIMITED,
+
+ DEPTH = 0x1000,
+};
+
+/*
+ * Copied from android_hdr_t
+ *
+ * TODO(olv) copy comments over and generate android_hdr_t
+ */
+enum Hdr : int32_t {
+ DOLBY_VISION = 1,
+ HDR10 = 2,
+ HLG = 3,
+};