Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cd8d7f08 authored by Chia-I Wu's avatar Chia-I Wu
Browse files

surfaceflinger: update for IComposer changes

The new IComposer introduces IComposerClient to manage resources and
replaces most state changing functions by a "command buffer" to batch
calls.

Test: builds and boots
Change-Id: Idd1060f83fab28330e7119ff0f5a5bda5429811a
parent 4ada6dc8
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ LOCAL_MODULE := libsurfaceflinger
LOCAL_C_INCLUDES := \
    frameworks/native/vulkan/include \
    external/vulkan-validation-layers/libs/vkjson \
    system/libhwbinder/fast_msgq/include \

LOCAL_CFLAGS := -DLOG_TAG=\"SurfaceFlinger\"
LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES
@@ -130,13 +131,14 @@ endif

LOCAL_CFLAGS += -fvisibility=hidden -Werror=format

LOCAL_STATIC_LIBRARIES := libtrace_proto libvkjson
LOCAL_STATIC_LIBRARIES := libhwcomposer-command-buffer libtrace_proto libvkjson
LOCAL_SHARED_LIBRARIES := \
    android.hardware.graphics.allocator@2.0 \
    android.hardware.graphics.composer@2.1 \
    libcutils \
    liblog \
    libdl \
    libfmq \
    libhardware \
    libhidlbase \
    libhidltransport \
@@ -150,6 +152,7 @@ LOCAL_SHARED_LIBRARIES := \
    libgui \
    libpowermanager \
    libvulkan \
    libsync \
    libprotobuf-cpp-lite \
    libbase \
    android.hardware.power@1.0
+529 −230

File changed.

Preview size limit exceeded, changes collapsed.

+142 −44
Original line number Diff line number Diff line
@@ -17,11 +17,16 @@
#ifndef ANDROID_SF_COMPOSER_HAL_H
#define ANDROID_SF_COMPOSER_HAL_H

#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

#include <android/hardware/graphics/composer/2.1/IComposer.h>
#include <utils/StrongPointer.h>
#include <IComposerCommandBuffer.h>
#include <MessageQueue.h>

namespace android {

@@ -36,102 +41,195 @@ using android::hardware::graphics::common::V1_0::Transform;

using android::hardware::graphics::composer::V2_1::IComposer;
using android::hardware::graphics::composer::V2_1::IComposerCallback;
using android::hardware::graphics::composer::V2_1::IComposerClient;
using android::hardware::graphics::composer::V2_1::Error;
using android::hardware::graphics::composer::V2_1::Display;
using android::hardware::graphics::composer::V2_1::Layer;
using android::hardware::graphics::composer::V2_1::Config;

using android::hardware::graphics::composer::V2_1::CommandWriter;
using android::hardware::graphics::composer::V2_1::CommandReaderBase;

using android::hardware::kSynchronizedReadWrite;
using android::hardware::MessageQueue;
using android::hardware::MQDescriptorSync;
using android::hardware::hidl_vec;
using android::hardware::hidl_handle;

class CommandReader : public CommandReaderBase {
public:
    ~CommandReader();

    // Parse and execute commands from the command queue.  The commands are
    // actually return values from the server and will be saved in ReturnData.
    Error parse();

    // Get and clear saved errors.
    struct CommandError {
        uint32_t location;
        Error error;
    };
    std::vector<CommandError> takeErrors();

    bool hasChanges(Display display, uint32_t& numChangedCompositionTypes,
            uint32_t& numLayerRequestMasks) const;

    // Get and clear saved changed composition types.
    void takeChangedCompositionTypes(Display display,
            std::vector<Layer>& layers,
            std::vector<IComposerClient::Composition>& types);

    // Get and clear saved display requests.
    void takeDisplayRequests(Display display,
        uint32_t& displayRequestMask, std::vector<Layer>& layers,
        std::vector<uint32_t>& layerRequestMasks);

    // Get and clear saved release fences.
    void takeReleaseFences(Display display, std::vector<Layer>& layers,
            std::vector<int>& releaseFences);

    // Get and clear saved present fence.
    void takePresentFence(Display display, int& presentFence);

private:
    void resetData();

    bool parseSelectDisplay(uint16_t length);
    bool parseSetError(uint16_t length);
    bool parseSetChangedCompositionTypes(uint16_t length);
    bool parseSetDisplayRequests(uint16_t length);
    bool parseSetPresentFence(uint16_t length);
    bool parseSetReleaseFences(uint16_t length);

    struct ReturnData {
        uint32_t displayRequests = 0;

        std::vector<Layer> changedLayers;
        std::vector<IComposerClient::Composition> compositionTypes;

        std::vector<Layer> requestedLayers;
        std::vector<uint32_t> requestMasks;

        int presentFence = -1;

        std::vector<Layer> releasedLayers;
        std::vector<int> releaseFences;
    };

    std::vector<CommandError> mErrors;
    std::unordered_map<Display, ReturnData> mReturnData;

    // When SELECT_DISPLAY is parsed, this is updated to point to the
    // display's return data in mReturnData.  We use it to avoid repeated
    // map lookups.
    ReturnData* mCurrentReturnData;
};

// Composer is a wrapper to IComposer, a proxy to server-side composer.
class Composer {
public:
    Composer();

    std::vector<IComposer::Capability> getCapabilities() const;
    std::string dumpDebugInfo() const;
    std::vector<IComposer::Capability> getCapabilities();
    std::string dumpDebugInfo();

    void registerCallback(const sp<IComposerCallback>& callback) const;
    void registerCallback(const sp<IComposerCallback>& callback);

    uint32_t getMaxVirtualDisplayCount() const;
    uint32_t getMaxVirtualDisplayCount();
    Error createVirtualDisplay(uint32_t width, uint32_t height,
            PixelFormat& format, Display& display) const;
    Error destroyVirtualDisplay(Display display) const;
            PixelFormat& format, Display& display);
    Error destroyVirtualDisplay(Display display);

    Error acceptDisplayChanges(Display display) const;
    Error acceptDisplayChanges(Display display);

    Error createLayer(Display display, Layer& layer) const;
    Error destroyLayer(Display display, Layer layer) const;
    Error createLayer(Display display, Layer& layer);
    Error destroyLayer(Display display, Layer layer);

    Error getActiveConfig(Display display, Config& config) const;
    Error getActiveConfig(Display display, Config& config);
    Error getChangedCompositionTypes(Display display,
            std::vector<Layer>& layers,
            std::vector<IComposer::Composition>& types) const;
    Error getColorModes(Display display, std::vector<ColorMode>& modes) const;
            std::vector<IComposerClient::Composition>& types);
    Error getColorModes(Display display, std::vector<ColorMode>& modes);
    Error getDisplayAttribute(Display display, Config config,
            IComposer::Attribute attribute, int32_t& value) const;
            IComposerClient::Attribute attribute, int32_t& value);
    Error getDisplayConfigs(Display display,
            std::vector<Config>& configs) const;
    Error getDisplayName(Display display, std::string& name) const;
            std::vector<Config>& configs);
    Error getDisplayName(Display display, std::string& name);

    Error getDisplayRequests(Display display, uint32_t& displayRequestMask,
            std::vector<Layer>& layers,
            std::vector<uint32_t>& layerRequestMasks) const;
            std::vector<uint32_t>& layerRequestMasks);

    Error getDisplayType(Display display, IComposer::DisplayType& type) const;
    Error getDozeSupport(Display display, bool& support) const;
    Error getDisplayType(Display display, IComposerClient::DisplayType& type);
    Error getDozeSupport(Display display, bool& support);
    Error getHdrCapabilities(Display display, std::vector<Hdr>& types,
            float& maxLuminance, float& maxAverageLuminance,
            float& minLuminance) const;
            float& minLuminance);

    Error getReleaseFences(Display display, std::vector<Layer>& layers,
            std::vector<int>& releaseFences) const;
            std::vector<int>& releaseFences);

    Error presentDisplay(Display display, int& presentFence) const;
    Error presentDisplay(Display display, int& presentFence);

    Error setActiveConfig(Display display, Config config) const;
    Error setActiveConfig(Display display, Config config);
    Error setClientTarget(Display display, const native_handle_t* target,
            int acquireFence, Dataspace dataspace,
            const std::vector<IComposer::Rect>& damage) const;
    Error setColorMode(Display display, ColorMode mode) const;
            const std::vector<IComposerClient::Rect>& damage);
    Error setColorMode(Display display, ColorMode mode);
    Error setColorTransform(Display display, const float* matrix,
            ColorTransform hint) const;
            ColorTransform hint);
    Error setOutputBuffer(Display display, const native_handle_t* buffer,
            int releaseFence) const;
    Error setPowerMode(Display display, IComposer::PowerMode mode) const;
    Error setVsyncEnabled(Display display, IComposer::Vsync enabled) const;
            int releaseFence);
    Error setPowerMode(Display display, IComposerClient::PowerMode mode);
    Error setVsyncEnabled(Display display, IComposerClient::Vsync enabled);

    Error setClientTargetSlotCount(Display display);

    Error validateDisplay(Display display, uint32_t& numTypes,
            uint32_t& numRequests) const;
            uint32_t& numRequests);

    Error setCursorPosition(Display display, Layer layer,
            int32_t x, int32_t y) const;
            int32_t x, int32_t y);
    Error setLayerBuffer(Display display, Layer layer,
            const native_handle_t* buffer, int acquireFence) const;
            const native_handle_t* buffer, int acquireFence);
    Error setLayerSurfaceDamage(Display display, Layer layer,
            const std::vector<IComposer::Rect>& damage) const;
            const std::vector<IComposerClient::Rect>& damage);
    Error setLayerBlendMode(Display display, Layer layer,
            IComposer::BlendMode mode) const;
            IComposerClient::BlendMode mode);
    Error setLayerColor(Display display, Layer layer,
            const IComposer::Color& color) const;
            const IComposerClient::Color& color);
    Error setLayerCompositionType(Display display, Layer layer,
            IComposer::Composition type) const;
            IComposerClient::Composition type);
    Error setLayerDataspace(Display display, Layer layer,
            Dataspace dataspace) const;
            Dataspace dataspace);
    Error setLayerDisplayFrame(Display display, Layer layer,
            const IComposer::Rect& frame) const;
            const IComposerClient::Rect& frame);
    Error setLayerPlaneAlpha(Display display, Layer layer,
            float alpha) const;
            float alpha);
    Error setLayerSidebandStream(Display display, Layer layer,
            const native_handle_t* stream) const;
            const native_handle_t* stream);
    Error setLayerSourceCrop(Display display, Layer layer,
            const IComposer::FRect& crop) const;
            const IComposerClient::FRect& crop);
    Error setLayerTransform(Display display, Layer layer,
            Transform transform) const;
            Transform transform);
    Error setLayerVisibleRegion(Display display, Layer layer,
            const std::vector<IComposer::Rect>& visible) const;
    Error setLayerZOrder(Display display, Layer layer, uint32_t z) const;
            const std::vector<IComposerClient::Rect>& visible);
    Error setLayerZOrder(Display display, Layer layer, uint32_t z);

private:
    sp<IComposer> mService;
    // Many public functions above simply write a command into the command
    // queue to batch the calls.  validateDisplay and presentDisplay will call
    // this function to execute the command queue.
    Error execute();

    sp<IComposer> mComposer;
    sp<IComposerClient> mClient;

    // 64KiB minus a small space for metadata such as read/write pointers
    static constexpr size_t kWriterInitialSize =
        64 * 1024 / sizeof(uint32_t) - 16;
    CommandWriter mWriter;
    CommandReader mReader;
};

} // namespace Hwc2
+18 −15
Original line number Diff line number Diff line
@@ -286,6 +286,9 @@ void Device::callHotplug(std::shared_ptr<Display> display, Connection connected)
{
    if (connected == Connection::Connected) {
        if (!display->isConnected()) {
#ifndef BYPASS_IHWC
            mComposer->setClientTargetSlotCount(display->getId());
#endif
            display->loadConfigs();
            display->setConnected(true);
        }
@@ -650,7 +653,7 @@ Error Display::getChangedCompositionTypes(
            &numElements, layerIds.data(), types.data());
#else
    std::vector<Hwc2::Layer> layerIds;
    std::vector<Hwc2::IComposer::Composition> types;
    std::vector<Hwc2::IComposerClient::Composition> types;
    auto intError = mDevice.mComposer->getChangedCompositionTypes(mId,
            layerIds, types);
    uint32_t numElements = layerIds.size();
@@ -805,8 +808,8 @@ Error Display::getType(DisplayType* outType) const
    int32_t intError = mDevice.mGetDisplayType(mDevice.mHwcDevice, mId,
            &intType);
#else
    Hwc2::IComposer::DisplayType intType =
        Hwc2::IComposer::DisplayType::INVALID;
    Hwc2::IComposerClient::DisplayType intType =
        Hwc2::IComposerClient::DisplayType::INVALID;
    auto intError = mDevice.mComposer->getDisplayType(mId, intType);
#endif
    auto error = static_cast<Error>(intError);
@@ -970,7 +973,7 @@ Error Display::setClientTarget(buffer_handle_t target,
#else
    auto intError = mDevice.mComposer->setClientTarget(mId, target, fenceFd,
            static_cast<Hwc2::Dataspace>(dataspace),
            std::vector<Hwc2::IComposer::Rect>());
            std::vector<Hwc2::IComposerClient::Rect>());
#endif
    return static_cast<Error>(intError);
}
@@ -1020,7 +1023,7 @@ Error Display::setPowerMode(PowerMode mode)
    auto intMode = static_cast<int32_t>(mode);
    int32_t intError = mDevice.mSetPowerMode(mDevice.mHwcDevice, mId, intMode);
#else
    auto intMode = static_cast<Hwc2::IComposer::PowerMode>(mode);
    auto intMode = static_cast<Hwc2::IComposerClient::PowerMode>(mode);
    auto intError = mDevice.mComposer->setPowerMode(mId, intMode);
#endif
    return static_cast<Error>(intError);
@@ -1033,7 +1036,7 @@ Error Display::setVsyncEnabled(Vsync enabled)
    int32_t intError = mDevice.mSetVsyncEnabled(mDevice.mHwcDevice, mId,
            intEnabled);
#else
    auto intEnabled = static_cast<Hwc2::IComposer::Vsync>(enabled);
    auto intEnabled = static_cast<Hwc2::IComposerClient::Vsync>(enabled);
    auto intError = mDevice.mComposer->setVsyncEnabled(mId, intEnabled);
#endif
    return static_cast<Error>(intError);
@@ -1070,7 +1073,7 @@ int32_t Display::getAttribute(hwc2_config_t configId, Attribute attribute)
            configId, static_cast<int32_t>(attribute), &value);
#else
    auto intError = mDevice.mComposer->getDisplayAttribute(mId,
            configId, static_cast<Hwc2::IComposer::Attribute>(attribute),
            configId, static_cast<Hwc2::IComposerClient::Attribute>(attribute),
            value);
#endif
    auto error = static_cast<Error>(intError);
@@ -1221,7 +1224,7 @@ Error Layer::setSurfaceDamage(const Region& damage)
                mDisplayId, mId, {0, nullptr});
#else
        intError = mDevice.mComposer->setLayerSurfaceDamage(mDisplayId,
                mId, std::vector<Hwc2::IComposer::Rect>());
                mId, std::vector<Hwc2::IComposerClient::Rect>());
#endif
    } else {
        size_t rectCount = 0;
@@ -1230,7 +1233,7 @@ Error Layer::setSurfaceDamage(const Region& damage)
#ifdef BYPASS_IHWC
        std::vector<hwc_rect_t> hwcRects;
#else
        std::vector<Hwc2::IComposer::Rect> hwcRects;
        std::vector<Hwc2::IComposerClient::Rect> hwcRects;
#endif
        for (size_t rect = 0; rect < rectCount; ++rect) {
            hwcRects.push_back({rectArray[rect].left, rectArray[rect].top,
@@ -1260,7 +1263,7 @@ Error Layer::setBlendMode(BlendMode mode)
    int32_t intError = mDevice.mSetLayerBlendMode(mDevice.mHwcDevice,
            mDisplayId, mId, intMode);
#else
    auto intMode = static_cast<Hwc2::IComposer::BlendMode>(mode);
    auto intMode = static_cast<Hwc2::IComposerClient::BlendMode>(mode);
    auto intError = mDevice.mComposer->setLayerBlendMode(mDisplayId,
            mId, intMode);
#endif
@@ -1273,7 +1276,7 @@ Error Layer::setColor(hwc_color_t color)
    int32_t intError = mDevice.mSetLayerColor(mDevice.mHwcDevice, mDisplayId,
            mId, color);
#else
    Hwc2::IComposer::Color hwcColor{color.r, color.g, color.b, color.a};
    Hwc2::IComposerClient::Color hwcColor{color.r, color.g, color.b, color.a};
    auto intError = mDevice.mComposer->setLayerColor(mDisplayId,
            mId, hwcColor);
#endif
@@ -1287,7 +1290,7 @@ Error Layer::setCompositionType(Composition type)
    int32_t intError = mDevice.mSetLayerCompositionType(mDevice.mHwcDevice,
            mDisplayId, mId, intType);
#else
    auto intType = static_cast<Hwc2::IComposer::Composition>(type);
    auto intType = static_cast<Hwc2::IComposerClient::Composition>(type);
    auto intError = mDevice.mComposer->setLayerCompositionType(mDisplayId,
            mId, intType);
#endif
@@ -1315,7 +1318,7 @@ Error Layer::setDisplayFrame(const Rect& frame)
    int32_t intError = mDevice.mSetLayerDisplayFrame(mDevice.mHwcDevice,
            mDisplayId, mId, hwcRect);
#else
    Hwc2::IComposer::Rect hwcRect{frame.left, frame.top,
    Hwc2::IComposerClient::Rect hwcRect{frame.left, frame.top,
        frame.right, frame.bottom};
    auto intError = mDevice.mComposer->setLayerDisplayFrame(mDisplayId,
            mId, hwcRect);
@@ -1359,7 +1362,7 @@ Error Layer::setSourceCrop(const FloatRect& crop)
    int32_t intError = mDevice.mSetLayerSourceCrop(mDevice.mHwcDevice,
            mDisplayId, mId, hwcRect);
#else
    Hwc2::IComposer::FRect hwcRect{
    Hwc2::IComposerClient::FRect hwcRect{
        crop.left, crop.top, crop.right, crop.bottom};
    auto intError = mDevice.mComposer->setLayerSourceCrop(mDisplayId,
            mId, hwcRect);
@@ -1389,7 +1392,7 @@ Error Layer::setVisibleRegion(const Region& region)
#ifdef BYPASS_IHWC
    std::vector<hwc_rect_t> hwcRects;
#else
    std::vector<Hwc2::IComposer::Rect> hwcRects;
    std::vector<Hwc2::IComposerClient::Rect> hwcRects;
#endif
    for (size_t rect = 0; rect < rectCount; ++rect) {
        hwcRects.push_back({rectArray[rect].left, rectArray[rect].top,