From 4f7788e64bfe50b74c7e0a4070da6b8450bb5070 Mon Sep 17 00:00:00 2001 From: Simon Fels Date: Tue, 28 Jun 2016 19:47:00 +0200 Subject: [PATCH] Add first bits for a shared compositor implementation --- Android.mk | 4 + android/CMakeLists.txt | 7 + android/shared_compositor/Android.mk | 25 ++ android/shared_compositor/main.cpp | 49 ++++ .../shared_compositor/surface_composer.cpp | 224 ++++++++++++++++++ android/shared_compositor/surface_composer.h | 69 ++++++ 6 files changed, 378 insertions(+) create mode 100644 android/shared_compositor/Android.mk create mode 100644 android/shared_compositor/main.cpp create mode 100644 android/shared_compositor/surface_composer.cpp create mode 100644 android/shared_compositor/surface_composer.h diff --git a/Android.mk b/Android.mk index 6480c36..7e8332b 100644 --- a/Android.mk +++ b/Android.mk @@ -53,3 +53,7 @@ LOCAL_CFLAGS := \ -fexceptions \ -std=c++1y include $(BUILD_EXECUTABLE) + +# The compositor has its Android.mk in its subfolder as it should not +# depend on any other anbox sources. +include $(call all-makefiles-under, $(LOCAL_PATH)/android/shared_compositor) diff --git a/android/CMakeLists.txt b/android/CMakeLists.txt index 744b73f..186ac43 100644 --- a/android/CMakeLists.txt +++ b/android/CMakeLists.txt @@ -24,3 +24,10 @@ target_link_libraries(anboxd # for easy integration into used IDEs. set_target_properties(anboxd PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1) + +set(ANBOX_SHARED_COMPOSITOR + shared_compositor/main.cpp + shared_compositor/surface_composer.cpp) +add_executable(anbox_shared_compositor ${ANBOX_SHARED_COMPOSITOR}) +set_target_properties(anbox_shared_compositor + PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1) diff --git a/android/shared_compositor/Android.mk b/android/shared_compositor/Android.mk new file mode 100644 index 0000000..bf71b20 --- /dev/null +++ b/android/shared_compositor/Android.mk @@ -0,0 +1,25 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_CLASS := EXECUTABLES +LOCAL_MODULE := anbox_shared_compositor +LOCAL_SRC_FILES := \ + main.cpp \ + surface_composer.cpp +LOCAL_SHARED_LIBRARIES := \ + libcutils \ + liblog \ + libdl \ + libhardware \ + libutils \ + libEGL \ + libGLESv1_CM \ + libGLESv2 \ + libbinder \ + libui \ + libgui +LOCAL_CFLAGS := \ + -fexceptions \ + -std=c++1y +include $(BUILD_EXECUTABLE) diff --git a/android/shared_compositor/main.cpp b/android/shared_compositor/main.cpp new file mode 100644 index 0000000..b096216 --- /dev/null +++ b/android/shared_compositor/main.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2016 Simon Fels + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + */ + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "surface_composer.h" + +using namespace android; + +int main(int, char**) { + ProcessState::self()->setThreadPoolMaxThreadCount(4); + + sp ps(ProcessState::self()); + ps->startThreadPool(); + + setpriority(PRIO_PROCESS, 0, PRIORITY_URGENT_DISPLAY); + set_sched_policy(0, SP_FOREGROUND); + + anbox::android::SurfaceComposer::instantiate(); + + IPCThreadState::self()->joinThreadPool(); + + return EXIT_SUCCESS; +} diff --git a/android/shared_compositor/surface_composer.cpp b/android/shared_compositor/surface_composer.cpp new file mode 100644 index 0000000..f2d5c73 --- /dev/null +++ b/android/shared_compositor/surface_composer.cpp @@ -0,0 +1,224 @@ +/* + * Copyright (C) 2016 Simon Fels + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + */ + +#include "surface_composer.h" + +#define LOG_TAG "AnboxSurfaceComposer" +#include + +#include + +#include +#include +#include + +#include + +namespace { +class DisplayDevice { +public: + enum DisplayType { + DISPLAY_ID_INVALID = -1, + DISPLAY_PRIMARY = HWC_DISPLAY_PRIMARY, + DISPLAY_EXTERNAL = HWC_DISPLAY_EXTERNAL, + DISPLAY_VIRTUAL = HWC_DISPLAY_VIRTUAL, + NUM_BUILTIN_DISPLAY_TYPES = HWC_NUM_PHYSICAL_DISPLAY_TYPES, + }; +}; + +class DisplayEventConnection : public BnDisplayEventConnection { +public: + DisplayEventConnection() : + mChannel(new BitTube) { + } + + status_t postEvent(const DisplayEventReceiver::Event& event) { + return OK; + } + +private: + virtual void setVsyncRate(uint32_t count) { + } + + virtual void requestNextVsync() { + } + + virtual void onFirstRef() { + } + + virtual sp getDataChannel() const { + return mChannel; + } + +private: + sp const mChannel; +}; + +class Client : public BnSurfaceComposerClient { +public: + Client() { } + ~Client() { } + + status_t initCheck() const { + return OK; + } + +private: + virtual status_t createSurface( + const String8& name, + uint32_t w, uint32_t h,PixelFormat format, uint32_t flags, + sp* handle, + sp* gbp) { + return OK; + } + + virtual status_t destroySurface(const sp& handle) { + return OK; + } + + virtual status_t clearLayerFrameStats(const sp& handle) const { + return OK; + } + + virtual status_t getLayerFrameStats(const sp& handle, FrameStats* outStats) const { + return OK; + } + + virtual status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { + return OK; + } +}; +} + +namespace anbox { +namespace android { +SurfaceComposer::SurfaceComposer() : + mPrimaryDisplay(new BBinder) { +} + +void SurfaceComposer::binderDied(const wp&) { + ALOGI("%s", __PRETTY_FUNCTION__); +} + +sp SurfaceComposer::createConnection() { + ALOGI("%s", __PRETTY_FUNCTION__); + sp bclient; + sp client(new Client); + status_t err = client->initCheck(); + if (err == NO_ERROR) { + bclient = client; + } + return bclient; +} + +sp SurfaceComposer::createGraphicBufferAlloc() { + ALOGI("%s", __PRETTY_FUNCTION__); + return nullptr; +} + +sp SurfaceComposer::createDisplayEventConnection() { + ALOGI("%s", __PRETTY_FUNCTION__); + return new DisplayEventConnection; +} + +sp SurfaceComposer::createDisplay(const String8& displayName, bool secure) { + ALOGI("%s", __PRETTY_FUNCTION__); + return nullptr; +} + +void SurfaceComposer::destroyDisplay(const sp& display) { + ALOGI("%s", __PRETTY_FUNCTION__); +} + +sp SurfaceComposer::getBuiltInDisplay(int32_t id) { + if (id != DisplayDevice::DISPLAY_PRIMARY) + return nullptr; + + return mPrimaryDisplay; +} + +void SurfaceComposer::setTransactionState(const Vector& state, + const Vector& displays, uint32_t flags) { + ALOGI("%s", __PRETTY_FUNCTION__); +} + +void SurfaceComposer::bootFinished() { + ALOGI("%s", __PRETTY_FUNCTION__); +} + +bool SurfaceComposer::authenticateSurfaceTexture(const sp& surface) const { + ALOGI("%s", __PRETTY_FUNCTION__); + return true; +} + +void SurfaceComposer::setPowerMode(const sp& display, int mode) { + ALOGI("%s", __PRETTY_FUNCTION__); +} + +status_t SurfaceComposer::getDisplayConfigs(const sp& display, Vector* configs) { + ALOGI("%s", __PRETTY_FUNCTION__); + + configs->clear(); + + DisplayInfo info = DisplayInfo(); + info.w = 0; + info.h = 0; + info.xdpi = 0; + info.ydpi = 0; + info.fps = 60; + info.secure = true; + configs->push_back(info); + + return OK; +} + +status_t SurfaceComposer::getDisplayStats(const sp& display, DisplayStatInfo* stats) { + ALOGI("%s", __PRETTY_FUNCTION__); + return OK; +} + +int SurfaceComposer::getActiveConfig(const sp& display) { + ALOGI("%s", __PRETTY_FUNCTION__); + return 0; +} + +status_t SurfaceComposer::setActiveConfig(const sp& display, int id) { + ALOGI("%s", __PRETTY_FUNCTION__); + return OK; +} + +status_t SurfaceComposer::captureScreen(const sp& display, + const sp& producer, + Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight, + uint32_t minLayerZ, uint32_t maxLayerZ, + bool useIdentityTransform, + Rotation rotation) { + ALOGI("%s", __PRETTY_FUNCTION__); + return OK; +} + +status_t SurfaceComposer::clearAnimationFrameStats() { + ALOGI("%s", __PRETTY_FUNCTION__); + return OK; +} + +status_t SurfaceComposer::getAnimationFrameStats(FrameStats* outStats) const { + ALOGI("%s", __PRETTY_FUNCTION__); + return OK; +} +} // namespace android +} // namespace anbox diff --git a/android/shared_compositor/surface_composer.h b/android/shared_compositor/surface_composer.h new file mode 100644 index 0000000..34190d1 --- /dev/null +++ b/android/shared_compositor/surface_composer.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2016 Simon Fels + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + */ + +#ifndef ANBOX_ANDROID_SURFACE_COMPOSER_H_ +#define ANBOX_ANDROID_SURFACE_COMPOSER_H_ + +#include +#include +#include + +using namespace android; + +namespace anbox { +namespace android { +class SurfaceComposer : public BinderService, + public BnSurfaceComposer, + public IBinder::DeathRecipient { +public: + static char const *getServiceName() { return "SurfaceFlinger"; } + + SurfaceComposer(); + + void binderDied(const wp& who) override; + + sp createConnection(); + sp createGraphicBufferAlloc(); + sp createDisplayEventConnection(); + sp createDisplay(const String8& displayName, bool secure); + void destroyDisplay(const sp& display); + sp getBuiltInDisplay(int32_t id); + void setTransactionState(const Vector& state, + const Vector& displays, uint32_t flags); + void bootFinished(); + bool authenticateSurfaceTexture(const sp& surface) const; + void setPowerMode(const sp& display, int mode); + status_t getDisplayConfigs(const sp& display, Vector* configs); + status_t getDisplayStats(const sp& display, DisplayStatInfo* stats); + int getActiveConfig(const sp& display); + status_t setActiveConfig(const sp& display, int id); + status_t captureScreen(const sp& display, + const sp& producer, + Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight, + uint32_t minLayerZ, uint32_t maxLayerZ, + bool useIdentityTransform, + Rotation rotation = eRotateNone); + status_t clearAnimationFrameStats(); + status_t getAnimationFrameStats(FrameStats* outStats) const; + +private: + sp mPrimaryDisplay; +}; +} // namespace android +} // namespace anbox + +#endif