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

Commit c3d695db authored by Leon Scroggins III's avatar Leon Scroggins III
Browse files

ComposerClient[Writer/Reader]: enforce a specific display

Add a new parameter and member to ComposerClient[Writer/Reader]
representing the only display it should apply to. The caller is
responsible for ensuring that they only ever refer to that same display.
The display is recorded here for error checking. This isn't strictly
necessary, but crashing here verifies that we only use the proper
display.

This is helpful for use with DisplayCapability.MULTI_THREADED_PRESENT,
although it is fine to use a single display per writer/reader without
the capability.

For the Reader, make the display optional, so that a single reader can
continue to be used for multiple displays. This allows devices without
the new DisplayCapability to continue to work without changes.

Remove copy constructor and operator=. Add a move constructor. This
ensures it will be properly moved when used in containers.

Bug: 241285491
Test: make
Change-Id: Ic7116e64138280747a32500c67dedeeabd7c669b
parent b1bc6f43
Loading
Loading
Loading
Loading
+22 −1
Original line number Diff line number Diff line
@@ -19,8 +19,8 @@
#include <algorithm>
#include <limits>
#include <memory>
#include <optional>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <inttypes.h>
@@ -41,8 +41,15 @@ namespace aidl::android::hardware::graphics::composer3 {

class ComposerClientReader {
  public:
    explicit ComposerClientReader(std::optional<int64_t> display = {}) : mDisplay(display) {}

    ~ComposerClientReader() { resetData(); }

    ComposerClientReader(ComposerClientReader&&) = default;

    ComposerClientReader(const ComposerClientReader&) = delete;
    ComposerClientReader& operator=(const ComposerClientReader&) = delete;

    // Parse and execute commands from the command queue.  The commands are
    // actually return values from the server and will be saved in ReturnData.
    void parse(std::vector<CommandResultPayload>&& results) {
@@ -85,6 +92,7 @@ class ComposerClientReader {

    void hasChanges(int64_t display, uint32_t* outNumChangedCompositionTypes,
                    uint32_t* outNumLayerRequestMasks) const {
        LOG_ALWAYS_FATAL_IF(mDisplay && display != *mDisplay);
        auto found = mReturnData.find(display);
        if (found == mReturnData.end()) {
            *outNumChangedCompositionTypes = 0;
@@ -100,6 +108,7 @@ class ComposerClientReader {

    // Get and clear saved changed composition types.
    std::vector<ChangedCompositionLayer> takeChangedCompositionTypes(int64_t display) {
        LOG_ALWAYS_FATAL_IF(mDisplay && display != *mDisplay);
        auto found = mReturnData.find(display);
        if (found == mReturnData.end()) {
            return {};
@@ -111,6 +120,7 @@ class ComposerClientReader {

    // Get and clear saved display requests.
    DisplayRequest takeDisplayRequests(int64_t display) {
        LOG_ALWAYS_FATAL_IF(mDisplay && display != *mDisplay);
        auto found = mReturnData.find(display);
        if (found == mReturnData.end()) {
            return {};
@@ -122,6 +132,7 @@ class ComposerClientReader {

    // Get and clear saved release fences.
    std::vector<ReleaseFences::Layer> takeReleaseFences(int64_t display) {
        LOG_ALWAYS_FATAL_IF(mDisplay && display != *mDisplay);
        auto found = mReturnData.find(display);
        if (found == mReturnData.end()) {
            return {};
@@ -133,6 +144,7 @@ class ComposerClientReader {

    // Get and clear saved present fence.
    ndk::ScopedFileDescriptor takePresentFence(int64_t display) {
        LOG_ALWAYS_FATAL_IF(mDisplay && display != *mDisplay);
        auto found = mReturnData.find(display);
        if (found == mReturnData.end()) {
            return {};
@@ -144,6 +156,7 @@ class ComposerClientReader {

    // Get what stage succeeded during PresentOrValidate: Present or Validate
    std::optional<PresentOrValidate::Result> takePresentOrValidateStage(int64_t display) {
        LOG_ALWAYS_FATAL_IF(mDisplay && display != *mDisplay);
        auto found = mReturnData.find(display);
        if (found == mReturnData.end()) {
            return std::nullopt;
@@ -154,6 +167,7 @@ class ComposerClientReader {

    // Get the client target properties requested by hardware composer.
    ClientTargetPropertyWithBrightness takeClientTargetProperty(int64_t display) {
        LOG_ALWAYS_FATAL_IF(mDisplay && display != *mDisplay);
        auto found = mReturnData.find(display);

        // If not found, return the default values.
@@ -177,32 +191,38 @@ class ComposerClientReader {
    void parseSetError(CommandError&& error) { mErrors.emplace_back(error); }

    void parseSetChangedCompositionTypes(ChangedCompositionTypes&& changedCompositionTypes) {
        LOG_ALWAYS_FATAL_IF(mDisplay && changedCompositionTypes.display != *mDisplay);
        auto& data = mReturnData[changedCompositionTypes.display];
        data.changedLayers = std::move(changedCompositionTypes.layers);
    }

    void parseSetDisplayRequests(DisplayRequest&& displayRequest) {
        LOG_ALWAYS_FATAL_IF(mDisplay && displayRequest.display != *mDisplay);
        auto& data = mReturnData[displayRequest.display];
        data.displayRequests = std::move(displayRequest);
    }

    void parseSetPresentFence(PresentFence&& presentFence) {
        LOG_ALWAYS_FATAL_IF(mDisplay && presentFence.display != *mDisplay);
        auto& data = mReturnData[presentFence.display];
        data.presentFence = std::move(presentFence.fence);
    }

    void parseSetReleaseFences(ReleaseFences&& releaseFences) {
        LOG_ALWAYS_FATAL_IF(mDisplay && releaseFences.display != *mDisplay);
        auto& data = mReturnData[releaseFences.display];
        data.releasedLayers = std::move(releaseFences.layers);
    }

    void parseSetPresentOrValidateDisplayResult(const PresentOrValidate&& presentOrValidate) {
        LOG_ALWAYS_FATAL_IF(mDisplay && presentOrValidate.display != *mDisplay);
        auto& data = mReturnData[presentOrValidate.display];
        data.presentOrValidateState = std::move(presentOrValidate.result);
    }

    void parseSetClientTargetProperty(
            const ClientTargetPropertyWithBrightness&& clientTargetProperty) {
        LOG_ALWAYS_FATAL_IF(mDisplay && clientTargetProperty.display != *mDisplay);
        auto& data = mReturnData[clientTargetProperty.display];
        data.clientTargetProperty = std::move(clientTargetProperty);
    }
@@ -222,6 +242,7 @@ class ComposerClientReader {

    std::vector<CommandError> mErrors;
    std::unordered_map<int64_t, ReturnData> mReturnData;
    const std::optional<int64_t> mDisplay;
};

}  // namespace aidl::android::hardware::graphics::composer3
+8 −3
Original line number Diff line number Diff line
@@ -19,8 +19,6 @@
#include <algorithm>
#include <limits>
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <inttypes.h>
@@ -63,10 +61,15 @@ class ComposerClientWriter final {
  public:
    static constexpr std::optional<ClockMonotonicTimestamp> kNoTimestamp = std::nullopt;

    ComposerClientWriter() { reset(); }
    explicit ComposerClientWriter(int64_t display) : mDisplay(display) { reset(); }

    ~ComposerClientWriter() { reset(); }

    ComposerClientWriter(ComposerClientWriter&&) = default;

    ComposerClientWriter(const ComposerClientWriter&) = delete;
    ComposerClientWriter& operator=(const ComposerClientWriter&) = delete;

    void reset() {
        mDisplayCommand.reset();
        mLayerCommand.reset();
@@ -229,6 +232,7 @@ class ComposerClientWriter final {
    std::optional<DisplayCommand> mDisplayCommand;
    std::optional<LayerCommand> mLayerCommand;
    std::vector<DisplayCommand> mCommands;
    const int64_t mDisplay;

    Buffer getBuffer(uint32_t slot, const native_handle_t* bufferHandle, int fence) {
        Buffer bufferCommand;
@@ -254,6 +258,7 @@ class ComposerClientWriter final {

    DisplayCommand& getDisplayCommand(int64_t display) {
        if (!mDisplayCommand.has_value() || mDisplayCommand->display != display) {
            LOG_ALWAYS_FATAL_IF(display != mDisplay);
            flushLayerCommand();
            flushDisplayCommand();
            mDisplayCommand.emplace();
+1 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@
#include <string>
#include <thread>
#include <unordered_map>
#include <unordered_set>
#include "GraphicsComposerCallback.h"

using aidl::android::hardware::graphics::common::Dataspace;
+65 −64

File changed.

Preview size limit exceeded, changes collapsed.

+172 −124

File changed.

Preview size limit exceeded, changes collapsed.