rework screen on/off code
Change-Id: I13f71e850592a588bbd4805b1830c503bd4decb4
This commit is contained in:
parent
e2c4f4ec23
commit
b60314a12f
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue