/*
 * Copyright (C) 2017 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.configstore@1.0;

interface ISurfaceFlingerConfigs {
    /**
     * The following two methods define (respectively):
     *
     * - The phase offset between hardware vsync and when apps are woken up by the
     *   Choreographer callback
     * - The phase offset between hardware vsync and when SurfaceFlinger wakes up
     *   to consume input
     *
     * Their values may be tuned to trade off between display pipeline latency (both
     * overall latency and the lengths of the app --> SF and SF --> display phases)
     * and frame delivery jitter (which typically manifests as "jank" or "jerkiness"
     * while interacting with the device). The default values must produce a
     * relatively low amount of jitter at the expense of roughly two frames of
     * app --> display latency, and unless significant testing is performed to avoid
     * increased display jitter (both manual investigation using systrace [1] and
     * automated testing using dumpsys gfxinfo [2] are recommended), they should not
     * be modified.
     *
     * [1] https://developer.android.com/studio/profile/systrace.html
     * [2] https://developer.android.com/training/testing/performance.html
     */
    vsyncEventPhaseOffsetNs() generates (OptionalInt64 value);
    vsyncSfEventPhaseOffsetNs() generates (OptionalInt64 value);

    /**
     * Instruct the Render Engine to use EGL_IMG_context_priority hint if
     * availabe.
     */
    useContextPriority() generates(OptionalBool value);

    /**
     * hasWideColorDisplay indicates that the device has
     * or can support a wide-color display, e.g. color space
     * greater than sRGB. Typical display may have same
     * color primaries as DCI-P3.
     * Indicate support for this feature by setting
     * TARGET_HAS_WIDE_COLOR_DISPLAY to true in BoardConfig.mk
     * This also means that the device is color managed.
     * A color managed device will use the appropriate
     * display mode depending on the content on the screen.
     * Default is sRGB.
     */
    hasWideColorDisplay() generates (OptionalBool value);

    /**
     * hwHDRDisplay indicates that the device has an High Dynamic Range display.
     * A display is considered High Dynamic Range if it
     *
     *     1. is a wide color gamut display, typically DCI-P3 or lager
     *     2. has high luminance capability, typically 540 nits or higher at 10% OPR
     *
     * Indicate support for this feature by setting
     * TARGET_HAS_HDR_DISPLAY to true in BoardConfig.mk
     * TARGET_HAS_WIDE_COLOR_DISPLAY must be set to true when
     * TARGET_HAS_HDR_DISPLAY is true.
     */
    hasHDRDisplay() generates (OptionalBool value);

    /**
     * Specify the offset in nanoseconds to add to vsync time when timestamping
     * present fences.
     */
    presentTimeOffsetFromVSyncNs() generates(OptionalInt64 value);

    /**
     * Some hardware can do RGB->YUV conversion more efficiently in hardware
     * controlled by HWC than in hardware controlled by the video encoder.
     * This instruct VirtualDisplaySurface to use HWC for such conversion on
     * GL composition.
     */
    useHwcForRGBtoYUV() generates(OptionalBool value);

    /**
     *  Maximum dimension supported by HWC for virtual display.
     *  Must be equals to min(max_width, max_height).
     */
    maxVirtualDisplaySize() generates (OptionalUInt64 value);

    /**
     * Indicates if Sync framework is available. Sync framework provides fence
     * mechanism which significantly reduces buffer processing latency.
     */
    hasSyncFramework() generates(OptionalBool value);

    /**
     * Return true if surface flinger should use vr flinger for compatible vr
     * apps, false otherwise. Devices that will never be running vr apps should
     * return false to avoid extra resource usage. Daydream ready devices must
     * return true for full vr support.
     */
    useVrFlinger() generates (OptionalBool value);

    /**
     * Controls the number of buffers SurfaceFlinger will allocate for use in
     * FramebufferSurface.
     */
    maxFrameBufferAcquiredBuffers() generates(OptionalInt64 value);

    /**
     * Returns true if surface flinger should start
     * hardware.graphics.allocator@2.0::IAllocator service.
     */
    startGraphicsAllocatorService() generates(OptionalBool value);
};
