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

Commit 2da74657 authored by Peiyong Lin's avatar Peiyong Lin
Browse files

[GPU Service] Separate GPU Service out of SurfaceFlinger.

Historically GPU service lives in SurfaceFlinger because it's a convenient
hack. This patch separates GPU service out of SurfaceFlinger. The GPU service
is a service that accesses to GPU, queries GPU capabilities and reports back.

Minor: Replace Vector with std::vector.

BUG: 118347356
Test: Build, flash and boot, `adb shell cmd gpuservice vkjson` to verify
Change-Id: If8feedc0a58bcd3c2e4111f8997117a618f5a516
Merged-In: If8feedc0a58bcd3c2e4111f8997117a618f5a516
parent de6858ef
Loading
Loading
Loading
Loading
+74 −0
Original line number Original line Diff line number Diff line
filegroup {
    name: "gpuservice_sources",
    srcs: [
        "GpuService.cpp",
    ],
}

filegroup {
    name: "gpuservice_binary_sources",
    srcs: ["main_gpuservice.cpp"],
}

cc_defaults {
    name: "gpuservice_defaults",
    cflags: [
        "-DLOG_TAG=\"GpuService\"",
        "-Wall",
        "-Werror",
        "-Wformat",
        "-Wthread-safety",
        "-Wunused",
        "-Wunreachable-code",
    ],
    cppflags: ["-std=c++1z"],
    srcs: [
        ":gpuservice_sources",
    ],
    include_dirs: [
        "frameworks/native/vulkan/vkjson",
        "frameworks/native/vulkan/include",
    ],
    shared_libs: [
        "libbinder",
        "liblog",
        "libutils",
        "libvulkan",
    ],
    static_libs: [
        "libvkjson",
    ],
}

cc_defaults {
    name: "gpuservice_production_defaults",
    defaults: ["gpuservice_defaults"],
    cflags: [
        "-fvisibility=hidden",
        "-fwhole-program-vtables", // requires ThinLTO
    ],
    lto: {
        thin: true,
    },
}

cc_defaults {
    name: "gpuservice_binary",
    defaults: ["gpuservice_defaults"],
    whole_static_libs: [
        "libsigchain",
    ],
    shared_libs: [
        "libbinder",
        "liblog",
        "libutils",
    ],
    ldflags: ["-Wl,--export-dynamic"],
}

cc_binary {
    name: "gpuservice",
    defaults: ["gpuservice_binary"],
    init_rc: ["gpuservice.rc"],
    srcs: [":gpuservice_binary_sources"],
}
+7 −19
Original line number Original line Diff line number Diff line
@@ -23,10 +23,7 @@


namespace android {
namespace android {


// ----------------------------------------------------------------------------
class BpGpuService : public BpInterface<IGpuService> {

class BpGpuService : public BpInterface<IGpuService>
{
public:
public:
    explicit BpGpuService(const sp<IBinder>& impl) : BpInterface<IGpuService>(impl) {}
    explicit BpGpuService(const sp<IBinder>& impl) : BpInterface<IGpuService>(impl) {}
};
};
@@ -34,19 +31,15 @@ public:
IMPLEMENT_META_INTERFACE(GpuService, "android.ui.IGpuService");
IMPLEMENT_META_INTERFACE(GpuService, "android.ui.IGpuService");


status_t BnGpuService::onTransact(uint32_t code, const Parcel& data,
status_t BnGpuService::onTransact(uint32_t code, const Parcel& data,
        Parcel* reply, uint32_t flags)
        Parcel* reply, uint32_t flags) {
{
    status_t status;
    status_t status;
    switch (code) {
    switch (code) {
    case SHELL_COMMAND_TRANSACTION: {
    case SHELL_COMMAND_TRANSACTION: {
        int in = data.readFileDescriptor();
        int in = data.readFileDescriptor();
        int out = data.readFileDescriptor();
        int out = data.readFileDescriptor();
        int err = data.readFileDescriptor();
        int err = data.readFileDescriptor();
        int argc = data.readInt32();
        std::vector<String16> args;
        Vector<String16> args;
        data.readString16Vector(&args);
        for (int i = 0; i < argc && data.dataAvail() > 0; i++) {
           args.add(data.readString16());
        }
        sp<IBinder> unusedCallback;
        sp<IBinder> unusedCallback;
        sp<IResultReceiver> resultReceiver;
        sp<IResultReceiver> resultReceiver;
        if ((status = data.readNullableStrongBinder(&unusedCallback)) != OK)
        if ((status = data.readNullableStrongBinder(&unusedCallback)) != OK)
@@ -64,20 +57,17 @@ status_t BnGpuService::onTransact(uint32_t code, const Parcel& data,
    }
    }
}
}


// ----------------------------------------------------------------------------

namespace {
namespace {
    status_t cmd_help(int out);
    status_t cmd_help(int out);
    status_t cmd_vkjson(int out, int err);
    status_t cmd_vkjson(int out, int err);
}
}


const char* const GpuService::SERVICE_NAME = "gpu";
const char* const GpuService::SERVICE_NAME = "gpuservice";


GpuService::GpuService() {}
GpuService::GpuService() = default;


status_t GpuService::shellCommand(int /*in*/, int out, int err,
status_t GpuService::shellCommand(int /*in*/, int out, int err,
        Vector<String16>& args)
                                  std::vector<String16>& args) {
{
    ALOGV("GpuService::shellCommand");
    ALOGV("GpuService::shellCommand");
    for (size_t i = 0, n = args.size(); i < n; i++)
    for (size_t i = 0, n = args.size(); i < n; i++)
        ALOGV("  arg[%zu]: '%s'", i, String8(args[i]).string());
        ALOGV("  arg[%zu]: '%s'", i, String8(args[i]).string());
@@ -93,8 +83,6 @@ status_t GpuService::shellCommand(int /*in*/, int out, int err,
    return BAD_VALUE;
    return BAD_VALUE;
}
}


// ----------------------------------------------------------------------------

namespace {
namespace {


status_t cmd_help(int out) {
status_t cmd_help(int out) {
+7 −6
Original line number Original line Diff line number Diff line
@@ -17,6 +17,8 @@
#ifndef ANDROID_GPUSERVICE_H
#ifndef ANDROID_GPUSERVICE_H
#define ANDROID_GPUSERVICE_H
#define ANDROID_GPUSERVICE_H


#include <vector>

#include <binder/IInterface.h>
#include <binder/IInterface.h>
#include <cutils/compiler.h>
#include <cutils/compiler.h>


@@ -34,22 +36,21 @@ public:
class BnGpuService: public BnInterface<IGpuService> {
class BnGpuService: public BnInterface<IGpuService> {
protected:
protected:
    virtual status_t shellCommand(int in, int out, int err,
    virtual status_t shellCommand(int in, int out, int err,
        Vector<String16>& args) = 0;
                                  std::vector<String16>& args) = 0;


    virtual status_t onTransact(uint32_t code, const Parcel& data,
    status_t onTransact(uint32_t code, const Parcel& data,
            Parcel* reply, uint32_t flags = 0) override;
            Parcel* reply, uint32_t flags = 0) override;
};
};


class GpuService : public BnGpuService
class GpuService : public BnGpuService {
{
public:
public:
    static const char* const SERVICE_NAME ANDROID_API;
    static const char* const SERVICE_NAME ANDROID_API;


    GpuService() ANDROID_API;
    GpuService() ANDROID_API;


protected:
protected:
    virtual status_t shellCommand(int in, int out, int err,
    status_t shellCommand(int in, int out, int err,
        Vector<String16>& args) override;
                          std::vector<String16>& args) override;
};
};


} // namespace android
} // namespace android
+4 −0
Original line number Original line Diff line number Diff line
service gpuservice /system/bin/gpuservice
    class core
    user gpu_service
    group graphics
+43 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright 2018 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 <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>
#include <binder/ProcessState.h>
#include <sys/resource.h>
#include "GpuService.h"

using namespace android;

int main(int /* argc */, char** /* argv */) {
    signal(SIGPIPE, SIG_IGN);

    // publish GpuService
    sp<GpuService> gpuservice = new GpuService();
    sp<IServiceManager> sm(defaultServiceManager());
    sm->addService(String16(GpuService::SERVICE_NAME), gpuservice, false);

    // limit the number of binder threads to 4.
    ProcessState::self()->setThreadPoolMaxThreadCount(4);

    // start the thread pool
    sp<ProcessState> ps(ProcessState::self());
    ps->startThreadPool();
    ps->giveThreadPoolName();
    IPCThreadState::self()->joinThreadPool();

    return 0;
}
Loading