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
diff --git a/services/surfaceflinger/DisplayHardware/DisplayHardware.cpp b/services/surfaceflinger/DisplayHardware/DisplayHardware.cpp
index 7bf3e0a..f4be168 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 @@
const sp<SurfaceFlinger>& flinger,
uint32_t dpy)
: DisplayHardwareBase(flinger, dpy),
- mFlags(0), mHwc(0)
+ mFlinger(flinger), mFlags(0), mHwc(0)
{
init(dpy);
}
@@ -310,7 +311,7 @@
// 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 cdf89fd..40a6f1e 100644
--- a/services/surfaceflinger/DisplayHardware/DisplayHardware.h
+++ b/services/surfaceflinger/DisplayHardware/DisplayHardware.h
@@ -95,6 +95,7 @@
void init(uint32_t displayIndex) __attribute__((noinline));
void fini() __attribute__((noinline));
+ sp<SurfaceFlinger> mFlinger;
EGLDisplay mDisplay;
EGLSurface mSurface;
EGLContext mContext;
diff --git a/services/surfaceflinger/DisplayHardware/DisplayHardwareBase.h b/services/surfaceflinger/DisplayHardware/DisplayHardwareBase.h
index 30eb258..3ebc7b6 100644
--- a/services/surfaceflinger/DisplayHardware/DisplayHardwareBase.h
+++ b/services/surfaceflinger/DisplayHardware/DisplayHardwareBase.h
@@ -37,7 +37,7 @@
~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 4a3b20d..7d1bdf0 100644
--- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp
+++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp
@@ -30,12 +30,14 @@
#include <EGL/egl.h>
#include "HWComposer.h"
+#include "SurfaceFlinger.h"
namespace android {
// ---------------------------------------------------------------------------
-HWComposer::HWComposer()
- : mModule(0), mHwc(0), mList(0), mCapacity(0),
+HWComposer::HWComposer(const sp<SurfaceFlinger>& 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 @@
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 @@
return mHwc ? NO_ERROR : NO_INIT;
}
+void HWComposer::hook_invalidate(struct hwc_procs* procs) {
+ reinterpret_cast<cb_context *>(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 5a9e9eb..983898a 100644
--- a/services/surfaceflinger/DisplayHardware/HWComposer.h
+++ b/services/surfaceflinger/DisplayHardware/HWComposer.h
@@ -24,16 +24,19 @@
#include <hardware/hwcomposer.h>
+#include <utils/StrongPointer.h>
+
namespace android {
// ---------------------------------------------------------------------------
class String8;
+class SurfaceFlinger;
class HWComposer
{
public:
- HWComposer();
+ HWComposer(const sp<SurfaceFlinger>& flinger);
~HWComposer();
status_t initCheck() const;
@@ -60,12 +63,21 @@
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<SurfaceFlinger> 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;
};