Bug 887627 - Avoid /sys/power/wait_for_fb_* on jb-gonk. r=mwu

This commit is contained in:
Michael Vines 2013-07-01 16:03:17 -07:00
Родитель 0df298b75b
Коммит 3897f06ad4
6 изменённых файлов: 88 добавлений и 29 удалений

Просмотреть файл

@ -29,6 +29,10 @@ public:
virtual void SetEnabled(bool enabled) = 0;
typedef void (*OnEnabledCallbackType)(bool enabled);
virtual void OnEnabled(OnEnabledCallbackType callback) = 0;
virtual void* GetHWCDevice() = 0;
virtual bool SwapBuffers(EGLDisplay dpy, EGLSurface sur) = 0;

Просмотреть файл

@ -25,11 +25,53 @@
#include "mozilla/FileUtils.h"
#include "mozilla/NullPtr.h"
#include "mozilla/FileUtils.h"
#include "BootAnimation.h"
using namespace android;
namespace {
static const char* kSleepFile = "/sys/power/wait_for_fb_sleep";
static const char* kWakeFile = "/sys/power/wait_for_fb_wake";
static mozilla::GonkDisplay::OnEnabledCallbackType sEnabledCallback;
static pthread_t sFramebufferWatchThread;
static void *
frameBufferWatcher(void *)
{
int len = 0;
char buf;
while (true) {
// Cannot use epoll here because kSleepFile and kWakeFile are
// always ready to read and blocking.
{
mozilla::ScopedClose fd(open(kSleepFile, O_RDONLY, 0));
do {
len = read(fd.get(), &buf, 1);
} while (len < 0 && errno == EINTR);
NS_WARN_IF_FALSE(len >= 0, "WAIT_FOR_FB_SLEEP failed");
}
sEnabledCallback(false);
{
mozilla::ScopedClose fd(open(kWakeFile, O_RDONLY, 0));
do {
len = read(fd.get(), &buf, 1);
} while (len < 0 && errno == EINTR);
NS_WARN_IF_FALSE(len >= 0, "WAIT_FOR_FB_WAKE failed");
}
sEnabledCallback(true);
}
return nullptr;
}
} // anonymous namespace
namespace mozilla {
static GonkDisplayICS* sGonkDisplay = nullptr;
@ -97,6 +139,21 @@ GonkDisplayICS::SetEnabled(bool enabled)
set_screen_state(enabled);
}
void
GonkDisplayICS::OnEnabled(OnEnabledCallbackType callback)
{
if (sEnabledCallback)
return;
sEnabledCallback = callback;
// Watching screen on/off state by using a pthread
// which implicitly calls exit() when the main thread ends
if (pthread_create(&sFramebufferWatchThread, NULL, frameBufferWatcher, NULL)) {
NS_RUNTIMEABORT("Failed to create framebufferWatcherThread, aborting...");
}
}
void*
GonkDisplayICS::GetHWCDevice()
{

Просмотреть файл

@ -34,6 +34,8 @@ public:
virtual void SetEnabled(bool enabled);
virtual void OnEnabled(OnEnabledCallbackType callback);
virtual void* GetHWCDevice();
virtual bool SwapBuffers(EGLDisplay dpy, EGLSurface sur);

Просмотреть файл

@ -35,6 +35,7 @@ GonkDisplayJB::GonkDisplayJB()
, mFBModule(nullptr)
, mHwc(nullptr)
, mFBDevice(nullptr)
, mEnabledCallback(nullptr)
{
int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &mFBModule);
ALOGW_IF(err, "%s module not found", GRALLOC_HARDWARE_MODULE_ID);
@ -121,10 +122,19 @@ GonkDisplayJB::SetEnabled(bool enabled)
else if (mFBDevice->enableScreen)
mFBDevice->enableScreen(mFBDevice, enabled);
if (mEnabledCallback)
mEnabledCallback(enabled);
if (!enabled)
autosuspend_enable();
}
void
GonkDisplayJB::OnEnabled(OnEnabledCallbackType callback)
{
mEnabledCallback = callback;
}
void*
GonkDisplayJB::GetHWCDevice()
{

Просмотреть файл

@ -32,6 +32,8 @@ public:
virtual void SetEnabled(bool enabled);
virtual void OnEnabled(OnEnabledCallbackType callback);
virtual void* GetHWCDevice();
virtual bool SwapBuffers(EGLDisplay dpy, EGLSurface sur);
@ -54,6 +56,7 @@ private:
hwc_display_contents_1_t* mList;
uint32_t mWidth;
uint32_t mHeight;
OnEnabledCallbackType mEnabledCallback;
};
}

Просмотреть файл

@ -23,6 +23,7 @@
#include "mozilla/Hal.h"
#include "mozilla/Preferences.h"
#include "mozilla/FileUtils.h"
#include "mozilla/ClearOnShutdown.h"
#include "Framebuffer.h"
#include "gfxContext.h"
#include "gfxPlatform.h"
@ -74,7 +75,6 @@ static bool sUsingOMTC;
static bool sUsingHwc;
static bool sScreenInitialized;
static nsRefPtr<gfxASurface> sOMTCSurface;
static pthread_t sFramebufferWatchThread;
namespace {
@ -115,30 +115,13 @@ private:
bool mIsOn;
};
static const char* kSleepFile = "/sys/power/wait_for_fb_sleep";
static const char* kWakeFile = "/sys/power/wait_for_fb_wake";
static StaticRefPtr<ScreenOnOffEvent> sScreenOnEvent;
static StaticRefPtr<ScreenOnOffEvent> sScreenOffEvent;
static void *frameBufferWatcher(void *) {
char buf;
bool ret;
nsRefPtr<ScreenOnOffEvent> mScreenOnEvent = new ScreenOnOffEvent(true);
nsRefPtr<ScreenOnOffEvent> mScreenOffEvent = new ScreenOnOffEvent(false);
while (true) {
// Cannot use epoll here because kSleepFile and kWakeFile are
// always ready to read and blocking.
ret = ReadSysFile(kSleepFile, &buf, sizeof(buf));
NS_WARN_IF_FALSE(ret, "WAIT_FOR_FB_SLEEP failed");
NS_DispatchToMainThread(mScreenOffEvent);
ret = ReadSysFile(kWakeFile, &buf, sizeof(buf));
NS_WARN_IF_FALSE(ret, "WAIT_FOR_FB_WAKE failed");
NS_DispatchToMainThread(mScreenOnEvent);
}
return NULL;
static void
displayEnabledCallback(bool enabled)
{
NS_DispatchToMainThread(enabled ? sScreenOnEvent : sScreenOffEvent);
}
} // anonymous namespace
@ -146,11 +129,11 @@ static void *frameBufferWatcher(void *) {
nsWindow::nsWindow()
{
if (!sScreenInitialized) {
// Watching screen on/off state by using a pthread
// which implicitly calls exit() when the main thread ends
if (pthread_create(&sFramebufferWatchThread, NULL, frameBufferWatcher, NULL)) {
NS_RUNTIMEABORT("Failed to create framebufferWatcherThread, aborting...");
}
sScreenOnEvent = new ScreenOnOffEvent(true);
ClearOnShutdown(&sScreenOnEvent);
sScreenOffEvent = new ScreenOnOffEvent(false);
ClearOnShutdown(&sScreenOffEvent);
GetGonkDisplay()->OnEnabled(displayEnabledCallback);
nsIntSize screenSize;
bool gotFB = Framebuffer::GetSize(&screenSize);