From c7d14e247117392fbd44aa454622778a25c076ae Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Mon, 1 Aug 2011 16:32:21 -0700 Subject: [PATCH] Add a h/w composer API to allow the HAL to trigger a redraw This is useful in various situations, for instance if the HAL wants to change its compositing strategy. Bug: 4488017 Change-Id: I5afc14e5917c6db7926d7417d48677d5aba50caa --- .../DisplayHardware/DisplayHardware.cpp | 5 +++-- .../DisplayHardware/DisplayHardware.h | 1 + .../DisplayHardware/DisplayHardwareBase.h | 2 +- .../DisplayHardware/HWComposer.cpp | 21 +++++++++++++++++-- .../DisplayHardware/HWComposer.h | 14 ++++++++++++- 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/services/surfaceflinger/DisplayHardware/DisplayHardware.cpp b/services/surfaceflinger/DisplayHardware/DisplayHardware.cpp index 7bf3e0ae0..f4be16838 100644 --- a/services/surfaceflinger/DisplayHardware/DisplayHardware.cpp +++ b/services/surfaceflinger/DisplayHardware/DisplayHardware.cpp @@ -40,6 +40,7 @@ #include "GLExtensions.h" #include "HWComposer.h" +#include "SurfaceFlinger.h" using namespace android; @@ -75,7 +76,7 @@ DisplayHardware::DisplayHardware( const sp& flinger, uint32_t dpy) : DisplayHardwareBase(flinger, dpy), - mFlags(0), mHwc(0) + mFlinger(flinger), mFlags(0), mHwc(0) { init(dpy); } @@ -310,7 +311,7 @@ void DisplayHardware::init(uint32_t dpy) // initialize the H/W composer - mHwc = new HWComposer(); + mHwc = new HWComposer(mFlinger); if (mHwc->initCheck() == NO_ERROR) { mHwc->setFrameBuffer(mDisplay, mSurface); } diff --git a/services/surfaceflinger/DisplayHardware/DisplayHardware.h b/services/surfaceflinger/DisplayHardware/DisplayHardware.h index cdf89fd0b..40a6f1e8c 100644 --- a/services/surfaceflinger/DisplayHardware/DisplayHardware.h +++ b/services/surfaceflinger/DisplayHardware/DisplayHardware.h @@ -95,6 +95,7 @@ private: void init(uint32_t displayIndex) __attribute__((noinline)); void fini() __attribute__((noinline)); + sp mFlinger; EGLDisplay mDisplay; EGLSurface mSurface; EGLContext mContext; diff --git a/services/surfaceflinger/DisplayHardware/DisplayHardwareBase.h b/services/surfaceflinger/DisplayHardware/DisplayHardwareBase.h index 30eb25877..3ebc7b6cc 100644 --- a/services/surfaceflinger/DisplayHardware/DisplayHardwareBase.h +++ b/services/surfaceflinger/DisplayHardware/DisplayHardwareBase.h @@ -37,7 +37,7 @@ public: ~DisplayHardwareBase(); - // console managment + // console management void releaseScreen() const; void acquireScreen() const; bool isScreenAcquired() const; diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp index 4a3b20ded..7d1bdf002 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp +++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp @@ -30,12 +30,14 @@ #include #include "HWComposer.h" +#include "SurfaceFlinger.h" namespace android { // --------------------------------------------------------------------------- -HWComposer::HWComposer() - : mModule(0), mHwc(0), mList(0), mCapacity(0), +HWComposer::HWComposer(const sp& flinger) + : mFlinger(flinger), + mModule(0), mHwc(0), mList(0), mCapacity(0), mDpy(EGL_NO_DISPLAY), mSur(EGL_NO_SURFACE) { int err = hw_get_module(HWC_HARDWARE_MODULE_ID, &mModule); @@ -44,6 +46,13 @@ HWComposer::HWComposer() err = hwc_open(mModule, &mHwc); LOGE_IF(err, "%s device failed to initialize (%s)", HWC_HARDWARE_COMPOSER, strerror(-err)); + if (err == 0) { + if (mHwc->registerProcs) { + mCBContext.hwc = this; + mCBContext.procs.invalidate = &hook_invalidate; + mHwc->registerProcs(mHwc, &mCBContext.procs); + } + } } } @@ -58,6 +67,14 @@ status_t HWComposer::initCheck() const { return mHwc ? NO_ERROR : NO_INIT; } +void HWComposer::hook_invalidate(struct hwc_procs* procs) { + reinterpret_cast(procs)->hwc->invalidate(); +} + +void HWComposer::invalidate() { + mFlinger->signalEvent(); +} + void HWComposer::setFrameBuffer(EGLDisplay dpy, EGLSurface sur) { mDpy = (hwc_display_t)dpy; mSur = (hwc_surface_t)sur; diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.h b/services/surfaceflinger/DisplayHardware/HWComposer.h index 5a9e9ebb1..983898a42 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.h +++ b/services/surfaceflinger/DisplayHardware/HWComposer.h @@ -24,16 +24,19 @@ #include +#include + namespace android { // --------------------------------------------------------------------------- class String8; +class SurfaceFlinger; class HWComposer { public: - HWComposer(); + HWComposer(const sp& flinger); ~HWComposer(); status_t initCheck() const; @@ -60,12 +63,21 @@ public: void dump(String8& out, char* scratch, size_t SIZE) const; private: + struct cb_context { + hwc_procs_t procs; + HWComposer* hwc; + }; + static void hook_invalidate(struct hwc_procs* procs); + void invalidate(); + + sp mFlinger; hw_module_t const* mModule; hwc_composer_device_t* mHwc; hwc_layer_list_t* mList; size_t mCapacity; hwc_display_t mDpy; hwc_surface_t mSur; + cb_context mCBContext; };