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

Commit ea0a5fb7 authored by Lloyd Pique's avatar Lloyd Pique
Browse files

SF: Allow SurfaceFlinger creation to be altered

As a first step, we need to be able to build a version of the
/system/binsurfacefligner binary that can (eventually) invoke the
SurfaceFlinger constructor to pass a "factory" class to replace certain
key types.

The unittest will also be able to use it to construct mocks by default.

Bug: None
Test: marlin builds, cheets_x86_64 builds (and overrides default)

Change-Id: Id6d5cabf0dd54e85ac0e6706edf3cbe8a0288bc3
parent 04da9df3
Loading
Loading
Loading
Loading
+38 −32
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ cc_defaults {
        "-DLOG_TAG=\"SurfaceFlinger\"",
        "-Wall",
        "-Werror",
        "-Wformat",
        "-Wthread-safety",
        "-Wunused",
        "-Wunreachable-code",
@@ -18,6 +19,10 @@ cc_defaults {
        "-DGL_GLEXT_PROTOTYPES",
        "-DEGL_EGLEXT_PROTOTYPES",
    ],
    include_dirs: [
        "frameworks/native/vulkan/vkjson",
        "frameworks/native/vulkan/include",
    ],
    shared_libs: [
        "android.frameworks.vr.composer@1.0",
        "android.hardware.configstore-utils",
@@ -84,6 +89,18 @@ cc_defaults {
    ],
}

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

cc_library_headers {
    name: "libsurfaceflinger_headers",
    export_include_dirs: ["."],
@@ -137,33 +154,23 @@ filegroup {
}

cc_library_shared {
    // Please use libsurfaceflinger_defaults to configure how the sources are
    // built, so the same settings can be used elsewhere.
    name: "libsurfaceflinger",
    defaults: ["libsurfaceflinger_defaults"],
    cflags: [
        "-fvisibility=hidden",
        "-Werror=format",
    ],
    defaults: ["libsurfaceflinger_production_defaults"],
    srcs: [
        ":libsurfaceflinger_sources",

        // Note: SurfaceFlingerFactory is not in the default sources so that it
        // can be easily replaced.
        "SurfaceFlingerFactory.cpp",
    ],
    logtags: ["EventLog/EventLogTags.logtags"],
    include_dirs: [
        "frameworks/native/vulkan/vkjson",
        "frameworks/native/vulkan/include",
    ],
    cppflags: [
        "-fwhole-program-vtables", // requires ThinLTO
    ],
    lto: {
        thin: true,
    },
}

cc_binary {
    name: "surfaceflinger",
cc_defaults {
    name: "libsurfaceflinger_binary",
    defaults: ["surfaceflinger_defaults"],
    init_rc: ["surfaceflinger.rc"],
    srcs: ["main_surfaceflinger.cpp"],
    whole_static_libs: [
        "libsigchain",
    ],
@@ -180,7 +187,6 @@ cc_binary {
        "libhidltransport",
        "liblayers_proto",
        "liblog",
        "libsurfaceflinger",
        "libtimestats_proto",
        "libutils",
    ],
@@ -189,19 +195,19 @@ cc_binary {
        "libtrace_proto",
    ],
    ldflags: ["-Wl,--export-dynamic"],
}

    // TODO(b/71715793): These version-scripts are required due to the use of
    // whole_static_libs to pull in libsigchain. To work, the files had to be
    // locally duplicated from their original location
    // $ANDROID_ROOT/art/sigchainlib/
    multilib: {
        lib32: {
            version_script: "version-script32.txt",
        },
        lib64: {
            version_script: "version-script64.txt",
        },
    },
filegroup {
    name: "surfaceflinger_binary_sources",
    srcs: ["main_surfaceflinger.cpp"],
}

cc_binary {
    name: "surfaceflinger",
    defaults: ["libsurfaceflinger_binary"],
    init_rc: ["surfaceflinger.rc"],
    srcs: [":surfaceflinger_binary_sources"],
    shared_libs: ["libsurfaceflinger"],
}

cc_library_shared {
+26 −0
Original line number 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 "SurfaceFlingerFactory.h"
#include "SurfaceFlinger.h"

namespace android::surfaceflinger {

sp<SurfaceFlinger> createSurfaceFlinger() {
    return new SurfaceFlinger();
}

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

#pragma once

#include <cutils/compiler.h>
#include <utils/StrongPointer.h>

namespace android {

class SurfaceFlinger;

namespace surfaceflinger {

ANDROID_API sp<SurfaceFlinger> createSurfaceFlinger();

} // namespace surfaceflinger
} // namespace android
+5 −5
Original line number Diff line number Diff line
@@ -21,16 +21,16 @@
#include <android/frameworks/displayservice/1.0/IDisplayService.h>
#include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
#include <android/hardware/graphics/allocator/2.0/IAllocator.h>
#include <cutils/sched_policy.h>
#include <binder/IServiceManager.h>
#include <binder/IPCThreadState.h>
#include <binder/ProcessState.h>
#include <binder/IServiceManager.h>
#include <binder/ProcessState.h>
#include <configstore/Utils.h>
#include <cutils/sched_policy.h>
#include <displayservice/DisplayService.h>
#include <hidl/LegacySupport.h>
#include <configstore/Utils.h>
#include "GpuService.h"
#include "SurfaceFlinger.h"
#include "SurfaceFlingerFactory.h"

using namespace android;

@@ -85,7 +85,7 @@ int main(int, char**) {
    ps->startThreadPool();

    // instantiate surfaceflinger
    sp<SurfaceFlinger> flinger = new SurfaceFlinger();
    sp<SurfaceFlinger> flinger = surfaceflinger::createSurfaceFlinger();

    setpriority(PRIO_PROCESS, 0, PRIORITY_URGENT_DISPLAY);