diff --git a/android/shared_compositor/surface_composer.cpp b/android/shared_compositor/surface_composer.cpp index f2d5c7345eec4b9474f93fa3f1efaffeab721151..d6ca98f07bfc0f5336c4c962770292426b261fd7 100644 --- a/android/shared_compositor/surface_composer.cpp +++ b/android/shared_compositor/surface_composer.cpp @@ -25,8 +25,12 @@ #include #include #include +#include #include +#include + +#include namespace { class DisplayDevice { @@ -68,6 +72,16 @@ private: sp const mChannel; }; +class Surface { +public: + Surface() { + BufferQueue::createBufferQueue(&producer, &consumer); + } + + sp producer; + sp consumer; +}; + class Client : public BnSurfaceComposerClient { public: Client() { } @@ -108,6 +122,19 @@ namespace anbox { namespace android { SurfaceComposer::SurfaceComposer() : mPrimaryDisplay(new BBinder) { + + hw_module_t const* module; + int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module); + if (err != 0) { + ALOGE("%s module not found", GRALLOC_HARDWARE_MODULE_ID); + return; + } + framebuffer_open(module, &mFbDev); +} + +SurfaceComposer::~SurfaceComposer() { + if (mFbDev) + framebuffer_close(mFbDev); } void SurfaceComposer::binderDied(const wp&) { @@ -158,6 +185,18 @@ void SurfaceComposer::setTransactionState(const Vector& state, void SurfaceComposer::bootFinished() { ALOGI("%s", __PRETTY_FUNCTION__); + + // wait patiently for the window manager death + const String16 name("window"); + sp window(defaultServiceManager()->getService(name)); + if (window != 0) { + window->linkToDeath(static_cast(this)); + } + + // stop boot animation + // formerly we would just kill the process, but we now ask it to exit so it + // can choose where to stop the animation. + property_set("service.bootanim.exit", "1"); } bool SurfaceComposer::authenticateSurfaceTexture(const sp& surface) const { @@ -174,12 +213,32 @@ status_t SurfaceComposer::getDisplayConfigs(const sp& display, Vectorclear(); + class Density { + static int getDensityFromProperty(char const* propName) { + char property[PROPERTY_VALUE_MAX]; + int density = 0; + if (property_get(propName, property, NULL) > 0) { + density = atoi(property); + } + return density; + } + public: + static int getBuildDensity() { + return getDensityFromProperty("ro.sf.lcd_density"); } + }; + + float density = Density::getBuildDensity() / 160.0f; + + // We will provide a single display configuration element here which is + // the framebuffer we're based on. No further display configurations + // are needed in our case. DisplayInfo info = DisplayInfo(); - info.w = 0; - info.h = 0; - info.xdpi = 0; - info.ydpi = 0; - info.fps = 60; + info.density = density; + info.w = mFbDev->width; + info.h = mFbDev->height; + info.xdpi = mFbDev->xdpi; + info.ydpi = mFbDev->ydpi; + info.fps = mFbDev->fps; info.secure = true; configs->push_back(info); @@ -188,11 +247,13 @@ status_t SurfaceComposer::getDisplayConfigs(const sp& display, Vector& display, DisplayStatInfo* stats) { ALOGI("%s", __PRETTY_FUNCTION__); - return OK; + return NO_ERROR; } int SurfaceComposer::getActiveConfig(const sp& display) { ALOGI("%s", __PRETTY_FUNCTION__); + + // We only provide one so it will be always our default return 0; } diff --git a/android/shared_compositor/surface_composer.h b/android/shared_compositor/surface_composer.h index 34190d1b8dd6d297114ca2246bbc3bd4b058b0ce..84c7239654d6105caff5dbd47cdbc78afd9484b9 100644 --- a/android/shared_compositor/surface_composer.h +++ b/android/shared_compositor/surface_composer.h @@ -18,14 +18,19 @@ #ifndef ANBOX_ANDROID_SURFACE_COMPOSER_H_ #define ANBOX_ANDROID_SURFACE_COMPOSER_H_ +#include +#include #include #include #include using namespace android; +struct framebuffer_device_t; + namespace anbox { namespace android { +class Framebuffer; class SurfaceComposer : public BinderService, public BnSurfaceComposer, public IBinder::DeathRecipient { @@ -33,6 +38,7 @@ public: static char const *getServiceName() { return "SurfaceFlinger"; } SurfaceComposer(); + virtual ~SurfaceComposer(); void binderDied(const wp& who) override; @@ -62,6 +68,7 @@ public: private: sp mPrimaryDisplay; + framebuffer_device_t *mFbDev; }; } // namespace android } // namespace anbox