summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathias Agopian <mathias@google.com>2012-04-10 22:09:54 -0700
committerMathias Agopian <mathias@google.com>2012-04-10 22:18:43 -0700
commitb60314a12f3336b27d73920805ab07cbc498d857 (patch)
treea921016f2448da9f274ff3c4abe59bac7b89746a
parente2c4f4ec23b735dd2a03f4ea8b08b288a1bb04e8 (diff)
downloadframeworks_native-b60314a12f3336b27d73920805ab07cbc498d857.zip
frameworks_native-b60314a12f3336b27d73920805ab07cbc498d857.tar.gz
frameworks_native-b60314a12f3336b27d73920805ab07cbc498d857.tar.bz2
rework screen on/off code
Change-Id: I13f71e850592a588bbd4805b1830c503bd4decb4
-rw-r--r--services/surfaceflinger/DisplayHardware/DisplayHardwareBase.cpp19
-rw-r--r--services/surfaceflinger/DisplayHardware/DisplayHardwareBase.h4
-rw-r--r--services/surfaceflinger/SurfaceFlinger.cpp85
-rw-r--r--services/surfaceflinger/SurfaceFlinger.h21
4 files changed, 63 insertions, 66 deletions
diff --git a/services/surfaceflinger/DisplayHardware/DisplayHardwareBase.cpp b/services/surfaceflinger/DisplayHardware/DisplayHardwareBase.cpp
index 69f1aca..d3a8bde 100644
--- a/services/surfaceflinger/DisplayHardware/DisplayHardwareBase.cpp
+++ b/services/surfaceflinger/DisplayHardware/DisplayHardwareBase.cpp
@@ -54,15 +54,12 @@ bool DisplayHardwareBase::DisplayEventThread::threadLoop() {
sp<SurfaceFlinger> flinger = mFlinger.promote();
ALOGD("About to give-up screen, flinger = %p", flinger.get());
if (flinger != 0) {
- mBarrier.close();
- flinger->screenReleased(0);
- mBarrier.wait();
+ flinger->screenReleased();
}
if (waitForFbWake() == NO_ERROR) {
- sp<SurfaceFlinger> flinger = mFlinger.promote();
ALOGD("Screen about to return, flinger = %p", flinger.get());
if (flinger != 0) {
- flinger->screenAcquired(0);
+ flinger->screenAcquired();
}
return true;
}
@@ -98,17 +95,12 @@ status_t DisplayHardwareBase::DisplayEventThread::waitForFbWake() {
return err < 0 ? -errno : int(NO_ERROR);
}
-status_t DisplayHardwareBase::DisplayEventThread::releaseScreen() const {
- mBarrier.open();
- return NO_ERROR;
-}
-
// ----------------------------------------------------------------------------
DisplayHardwareBase::DisplayHardwareBase(const sp<SurfaceFlinger>& flinger,
uint32_t displayIndex)
- : mScreenAcquired(true)
{
+ mScreenAcquired = true;
mDisplayEventThread = new DisplayEventThread(flinger);
}
@@ -130,10 +122,7 @@ bool DisplayHardwareBase::canDraw() const {
}
void DisplayHardwareBase::releaseScreen() const {
- status_t err = mDisplayEventThread->releaseScreen();
- if (err >= 0) {
- mScreenAcquired = false;
- }
+ mScreenAcquired = false;
}
void DisplayHardwareBase::acquireScreen() const {
diff --git a/services/surfaceflinger/DisplayHardware/DisplayHardwareBase.h b/services/surfaceflinger/DisplayHardware/DisplayHardwareBase.h
index fba211b..6857481 100644
--- a/services/surfaceflinger/DisplayHardware/DisplayHardwareBase.h
+++ b/services/surfaceflinger/DisplayHardware/DisplayHardwareBase.h
@@ -19,8 +19,8 @@
#include <stdint.h>
#include <utils/RefBase.h>
+#include <utils/StrongPointer.h>
#include <utils/threads.h>
-#include "Barrier.h"
namespace android {
@@ -48,14 +48,12 @@ public:
private:
class DisplayEventThread : public Thread {
wp<SurfaceFlinger> mFlinger;
- mutable Barrier mBarrier;
status_t waitForFbSleep();
status_t waitForFbWake();
public:
DisplayEventThread(const sp<SurfaceFlinger>& flinger);
virtual ~DisplayEventThread();
virtual bool threadLoop();
- status_t releaseScreen() const;
status_t initCheck() const;
};
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 7023e0f..f891b29 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -96,7 +96,6 @@ SurfaceFlinger::SurfaceFlinger()
mDebugInTransaction(0),
mLastTransactionTime(0),
mBootFinished(false),
- mConsoleSignals(0),
mSecureFrameBuffer(0)
{
init();
@@ -410,11 +409,6 @@ void SurfaceFlinger::onMessageReceived(int32_t what)
switch (what) {
case MessageQueue::REFRESH: {
// case MessageQueue::INVALIDATE: {
- // check for transactions
- if (CC_UNLIKELY(mConsoleSignals)) {
- handleConsoleEvents();
- }
-
// if we're in a global transaction, don't do anything.
const uint32_t mask = eTransactionNeeded | eTraversalNeeded;
uint32_t transactionFlags = peekTransactionFlags(mask);
@@ -482,28 +476,6 @@ void SurfaceFlinger::postFramebuffer()
mSwapRegion.clear();
}
-void SurfaceFlinger::handleConsoleEvents()
-{
- // something to do with the console
- const DisplayHardware& hw = graphicPlane(0).displayHardware();
-
- int what = android_atomic_and(0, &mConsoleSignals);
- if (what & eConsoleAcquired) {
- hw.acquireScreen();
- // this is a temporary work-around, eventually this should be called
- // by the power-manager
- SurfaceFlinger::turnElectronBeamOn(mElectronBeamAnimationMode);
- }
-
- if (what & eConsoleReleased) {
- if (hw.isScreenAcquired()) {
- hw.releaseScreen();
- }
- }
-
- mDirtyRegion.set(hw.bounds());
-}
-
void SurfaceFlinger::handleTransaction(uint32_t transactionFlags)
{
ATRACE_CALL();
@@ -1490,20 +1462,57 @@ uint32_t SurfaceFlinger::setClientStateLocked(
return flags;
}
-void SurfaceFlinger::screenReleased(int dpy)
-{
- // this may be called by a signal handler, we can't do too much in here
- android_atomic_or(eConsoleReleased, &mConsoleSignals);
- signalTransaction();
+// ---------------------------------------------------------------------------
+
+void SurfaceFlinger::onScreenAcquired() {
+ const DisplayHardware& hw(graphicPlane(0).displayHardware());
+ hw.acquireScreen();
+ // this is a temporary work-around, eventually this should be called
+ // by the power-manager
+ SurfaceFlinger::turnElectronBeamOn(mElectronBeamAnimationMode);
+ mDirtyRegion.set(hw.bounds());
+ // from this point on, SF will priocess updates again
}
-void SurfaceFlinger::screenAcquired(int dpy)
-{
- // this may be called by a signal handler, we can't do too much in here
- android_atomic_or(eConsoleAcquired, &mConsoleSignals);
- signalTransaction();
+void SurfaceFlinger::onScreenReleased() {
+ const DisplayHardware& hw(graphicPlane(0).displayHardware());
+ if (hw.isScreenAcquired()) {
+ mDirtyRegion.set(hw.bounds());
+ hw.releaseScreen();
+ // from this point on, SF will stop drawing
+ }
+}
+
+void SurfaceFlinger::screenAcquired() {
+ class MessageScreenAcquired : public MessageBase {
+ SurfaceFlinger* flinger;
+ public:
+ MessageScreenAcquired(SurfaceFlinger* flinger) : flinger(flinger) { }
+ virtual bool handler() {
+ flinger->onScreenAcquired();
+ return true;
+ }
+ };
+ sp<MessageBase> msg = new MessageScreenAcquired(this);
+ postMessageSync(msg);
}
+void SurfaceFlinger::screenReleased() {
+ class MessageScreenReleased : public MessageBase {
+ SurfaceFlinger* flinger;
+ public:
+ MessageScreenReleased(SurfaceFlinger* flinger) : flinger(flinger) { }
+ virtual bool handler() {
+ flinger->onScreenReleased();
+ return true;
+ }
+ };
+ sp<MessageBase> msg = new MessageScreenReleased(this);
+ postMessageSync(msg);
+}
+
+// ---------------------------------------------------------------------------
+
status_t SurfaceFlinger::dump(int fd, const Vector<String16>& args)
{
const size_t SIZE = 4096;
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 6fa81db..46bbab2 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -182,8 +182,17 @@ public:
virtual status_t turnElectronBeamOff(int32_t mode);
virtual status_t turnElectronBeamOn(int32_t mode);
- void screenReleased(DisplayID dpy);
- void screenAcquired(DisplayID dpy);
+
+ // called when screen needs to turn off
+ void screenReleased();
+ // called when screen is turning back on
+ void screenAcquired();
+
+ // called on the main thread in response to screenReleased()
+ void onScreenReleased();
+ // called on the main thread in response to screenAcquired()
+ void onScreenAcquired();
+
status_t renderScreenToTexture(DisplayID dpy,
GLuint* textureName, GLfloat* uOut, GLfloat* vOut);
@@ -294,7 +303,6 @@ public: // hack to work around gcc 4.0.3 bug
private:
void waitForEvent();
- void handleConsoleEvents();
void handleTransaction(uint32_t transactionFlags);
void handleTransactionLocked(uint32_t transactionFlags);
@@ -412,13 +420,6 @@ private:
mutable Mutex mDestroyedLayerLock;
Vector<LayerBase const *> mDestroyedLayers;
- // atomic variables
- enum {
- eConsoleReleased = 1,
- eConsoleAcquired = 2
- };
- volatile int32_t mConsoleSignals;
-
// only written in the main thread, only read in other threads
volatile int32_t mSecureFrameBuffer;
};