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

Commit 96f866c2 authored by Manali Bhutiyani's avatar Manali Bhutiyani
Browse files

[hwc-batching] Surfaceflinger code for HWC batching support.

This CL adds the SurfaceFlinger side code for supporting the new
batched commands for createLayer/DestroyLayer.

Bug: 290685621
Test: atest VtsHalGraphicsComposer3_TargetTest
      atest PerInstance/GraphicsComposerAidlBatchedCommandTest
Change-Id: I1793bda0a1eac1c2cecd0c6ab00d5df9fd8d6d0a
parent 0cd7e5f6
Loading
Loading
Loading
Loading
+57 −14
Original line number Diff line number Diff line
@@ -271,7 +271,10 @@ AidlComposer::AidlComposer(const std::string& serviceName) {
            }
        }
    }

    if (getLayerLifecycleBatchCommand()) {
        mEnableLayerCommandBatchingFlag =
                FlagManager::getInstance().enable_layer_command_batching();
    }
    ALOGI("Loaded AIDL composer3 HAL service");
}

@@ -407,25 +410,58 @@ Error AidlComposer::acceptDisplayChanges(Display display) {

Error AidlComposer::createLayer(Display display, Layer* outLayer) {
    int64_t layer;
    Error error = Error::NONE;
    if (!mEnableLayerCommandBatchingFlag) {
        const auto status = mAidlComposerClient->createLayer(translate<int64_t>(display),
                                                             kMaxLayerBufferCount, &layer);
        if (!status.isOk()) {
            ALOGE("createLayer failed %s", status.getDescription().c_str());
            return static_cast<Error>(status.getServiceSpecificError());
        }

    } else {
        // generate a unique layerID. map in AidlComposer with <SF_layerID, HWC_layerID>
        // Add this as a new displayCommand in execute command.
        // return the SF generated layerID instead of calling HWC
        layer = mLayerID++;
        mMutex.lock_shared();
        if (auto writer = getWriter(display)) {
            writer->get().setLayerLifecycleBatchCommandType(translate<int64_t>(display),
                                                            translate<int64_t>(layer),
                                                            LayerLifecycleBatchCommandType::CREATE);
            writer->get().setNewBufferSlotCount(translate<int64_t>(display),
                                                translate<int64_t>(layer), kMaxLayerBufferCount);
        } else {
            error = Error::BAD_DISPLAY;
        }
        mMutex.unlock_shared();
    }
    *outLayer = translate<Layer>(layer);
    return Error::NONE;
    return error;
}

Error AidlComposer::destroyLayer(Display display, Layer layer) {
    Error error = Error::NONE;
    if (!mEnableLayerCommandBatchingFlag) {
        const auto status = mAidlComposerClient->destroyLayer(translate<int64_t>(display),
                                                              translate<int64_t>(layer));
        if (!status.isOk()) {
            ALOGE("destroyLayer failed %s", status.getDescription().c_str());
            return static_cast<Error>(status.getServiceSpecificError());
        }
    return Error::NONE;
    } else {
        mMutex.lock_shared();
        if (auto writer = getWriter(display)) {
            writer->get()
                    .setLayerLifecycleBatchCommandType(translate<int64_t>(display),
                                                       translate<int64_t>(layer),
                                                       LayerLifecycleBatchCommandType::DESTROY);
        } else {
            error = Error::BAD_DISPLAY;
        }
        mMutex.unlock_shared();
    }

    return error;
}

Error AidlComposer::getActiveConfig(Display display, Config* outConfig) {
@@ -591,6 +627,13 @@ Error AidlComposer::getHdrCapabilities(Display display, std::vector<Hdr>* outTyp
    return Error::NONE;
}

bool AidlComposer::getLayerLifecycleBatchCommand() {
    std::vector<Capability> capabilities = getCapabilities();
    bool hasCapability = std::find(capabilities.begin(), capabilities.end(),
                                   Capability::LAYER_LIFECYCLE_BATCH_COMMAND) != capabilities.end();
    return hasCapability;
}

Error AidlComposer::getOverlaySupport(AidlOverlayProperties* outProperties) {
    const auto status = mAidlComposerClient->getOverlaySupport(outProperties);
    if (!status.isOk()) {
+3 −1
Original line number Diff line number Diff line
@@ -262,7 +262,7 @@ private:
    void removeDisplay(Display) EXCLUDES(mMutex);
    void addReader(Display) REQUIRES(mMutex);
    void removeReader(Display) REQUIRES(mMutex);

    bool getLayerLifecycleBatchCommand();
    bool hasMultiThreadedPresentSupport(Display);

    // 64KiB minus a small space for metadata such as read/write pointers
@@ -293,6 +293,8 @@ private:
    ftl::SharedMutex mMutex;

    int32_t mComposerInterfaceVersion = 1;
    bool mEnableLayerCommandBatchingFlag = false;
    std::atomic<int64_t> mLayerID = 1;

    // Buffer slots for layers are cleared by setting the slot buffer to this buffer.
    sp<GraphicBuffer> mClearSlotBuffer;
+2 −1
Original line number Diff line number Diff line
@@ -127,7 +127,7 @@ void FlagManager::dump(std::string& result) const {
    DUMP_READ_ONLY_FLAG(display_protected);
    DUMP_READ_ONLY_FLAG(fp16_client_target);
    DUMP_READ_ONLY_FLAG(game_default_frame_rate);

    DUMP_READ_ONLY_FLAG(enable_layer_command_batching);
#undef DUMP_READ_ONLY_FLAG
#undef DUMP_SERVER_FLAG
#undef DUMP_FLAG_INTERVAL
@@ -201,6 +201,7 @@ FLAG_MANAGER_READ_ONLY_FLAG(enable_fro_dependent_features, "")
FLAG_MANAGER_READ_ONLY_FLAG(display_protected, "")
FLAG_MANAGER_READ_ONLY_FLAG(fp16_client_target, "debug.sf.fp16_client_target")
FLAG_MANAGER_READ_ONLY_FLAG(game_default_frame_rate, "")
FLAG_MANAGER_READ_ONLY_FLAG(enable_layer_command_batching, "")

/// Trunk stable server flags ///
FLAG_MANAGER_SERVER_FLAG(late_boot_misc2, "")
+1 −0
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ public:
    bool display_protected() const;
    bool fp16_client_target() const;
    bool game_default_frame_rate() const;
    bool enable_layer_command_batching() const;

protected:
    // overridden for unit tests
+8 −0
Original line number Diff line number Diff line
@@ -31,6 +31,14 @@ flag {
  is_fixed_read_only: true
}

flag {
  name: "enable_layer_command_batching"
  namespace: "core_graphics"
  description: "This flag controls batching on createLayer/destroyLayer command with executeCommand."
  bug: "290685621"
  is_fixed_read_only: true
}

flag {
  name: "dont_skip_on_early"
  namespace: "core_graphics"