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

Commit e23e6bb2 authored by Vishnu Nair's avatar Vishnu Nair Committed by Android (Google) Code Review
Browse files

Merge "SF: Carve out LayerCreationArgs"

parents 32183f86 cb8be507
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -30,7 +30,8 @@ enum {
    METADATA_ACCESSIBILITY_ID = 5,
    METADATA_OWNER_PID = 6,
    METADATA_DEQUEUE_TIME = 7,
    METADATA_GAME_MODE = 8
    METADATA_GAME_MODE = 8,
    METADATA_CALLING_UID = 9,
};

struct LayerMetadata : public Parcelable {
+1 −0
Original line number Diff line number Diff line
@@ -155,6 +155,7 @@ filegroup {
        "DisplayRenderArea.cpp",
        "Effects/Daltonizer.cpp",
        "EventLog/EventLog.cpp",
        "FrontEnd/LayerCreationArgs.cpp",
        "FrontEnd/TransactionHandler.cpp",
        "FlagManager.cpp",
        "FpsReporter.cpp",
+3 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include <gui/AidlStatusUtil.h>

#include "Client.h"
#include "FrontEnd/LayerCreationArgs.h"
#include "Layer.h"
#include "SurfaceFlinger.h"

@@ -83,7 +84,8 @@ binder::Status Client::createSurface(const std::string& name, int32_t flags,
    sp<IBinder> handle;
    LayerCreationArgs args(mFlinger.get(), sp<Client>::fromExisting(this), name.c_str(),
                           static_cast<uint32_t>(flags), std::move(metadata));
    const status_t status = mFlinger->createLayer(args, parent, *outResult);
    args.parentHandle = parent;
    const status_t status = mFlinger->createLayer(args, *outResult);
    return binderStatusFromStatusT(status);
}

+62 −0
Original line number Diff line number Diff line
/*
 * Copyright 2022 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.
 */

#include "LayerCreationArgs.h"
#include <binder/IPCThreadState.h>
#include <private/android_filesystem_config.h>
#include "Client.h"
#include "gui/LayerMetadata.h"

namespace android::surfaceflinger {

std::atomic<uint32_t> LayerCreationArgs::sSequence{1};

LayerCreationArgs::LayerCreationArgs(SurfaceFlinger* flinger, sp<Client> client, std::string name,
                                     uint32_t flags, gui::LayerMetadata metadataArg,
                                     std::optional<uint32_t> id)
      : flinger(flinger),
        client(std::move(client)),
        name(std::move(name)),
        flags(flags),
        metadata(std::move(metadataArg)) {
    IPCThreadState* ipc = IPCThreadState::self();
    ownerPid = ipc->getCallingPid();
    uid_t callingUid = ipc->getCallingUid();
    metadata.setInt32(gui::METADATA_CALLING_UID, static_cast<int32_t>(callingUid));
    ownerUid = callingUid;
    if (ownerUid == AID_GRAPHICS || ownerUid == AID_SYSTEM) {
        // System can override the calling UID/PID since it can create layers on behalf of apps.
        ownerPid = metadata.getInt32(gui::METADATA_OWNER_PID, ownerPid);
        ownerUid = static_cast<uid_t>(
                metadata.getInt32(gui::METADATA_OWNER_UID, static_cast<int32_t>(ownerUid)));
    }

    if (id) {
        sequence = *id;
        sSequence = *id + 1;
    } else {
        sequence = sSequence++;
        if (sequence == UNASSIGNED_LAYER_ID) {
            ALOGW("Layer sequence id rolled over.");
            sequence = sSequence++;
        }
    }
}

LayerCreationArgs::LayerCreationArgs(const LayerCreationArgs& args)
      : LayerCreationArgs(args.flinger, args.client, args.name, args.flags, args.metadata) {}

} // namespace android::surfaceflinger
+56 −0
Original line number Diff line number Diff line
/*
 * Copyright 2022 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.
 */

#pragma once

#include <binder/Binder.h>
#include <gui/LayerMetadata.h>
#include <utils/StrongPointer.h>
#include <cstdint>
#include <limits>
#include <optional>
constexpr uint32_t UNASSIGNED_LAYER_ID = std::numeric_limits<uint32_t>::max();

namespace android {
class SurfaceFlinger;
class Client;
} // namespace android

namespace android::surfaceflinger {

struct LayerCreationArgs {
    static std::atomic<uint32_t> sSequence;

    LayerCreationArgs(android::SurfaceFlinger*, sp<android::Client>, std::string name,
                      uint32_t flags, gui::LayerMetadata,
                      std::optional<uint32_t> id = std::nullopt);
    LayerCreationArgs(const LayerCreationArgs&);

    android::SurfaceFlinger* flinger;
    sp<android::Client> client;
    std::string name;
    uint32_t flags; // ISurfaceComposerClient flags
    gui::LayerMetadata metadata;
    pid_t ownerPid;
    uid_t ownerUid;
    uint32_t textureName;
    uint32_t sequence;
    bool addToRoot = true;
    wp<IBinder> parentHandle = nullptr;
    wp<IBinder> mirrorLayerHandle = nullptr;
};

} // namespace android::surfaceflinger
Loading