# build surfaceflinger's executable
include $(CLEAR_VARS)
+LOCAL_CFLAGS:= -DLOG_TAG=\"SurfaceFlinger\"
+
LOCAL_SRC_FILES:= \
main_surfaceflinger.cpp
LOCAL_SHARED_LIBRARIES := \
libsurfaceflinger \
+ liblog \
libbinder \
libutils
#include <sys/types.h>
#include <binder/PermissionCache.h>
+#include <binder/IPCThreadState.h>
#include <private/android_filesystem_config.h>
#include <EGL/eglext.h>
#include <utils/Mutex.h>
+#include <utils/String8.h>
#include <utils/Timers.h>
#include <hardware/hwcomposer_defs.h>
#include <math.h>
#include <dlfcn.h>
+#if defined(HAVE_PTHREADS)
+#include <sys/resource.h>
+#endif
+
#include <EGL/egl.h>
#include <cutils/log.h>
#include "RenderEngine/RenderEngine.h"
-
#define DISPLAY_COUNT 1
/*
// ---------------------------------------------------------------------------
SurfaceFlinger::SurfaceFlinger()
- : BnSurfaceComposer(), Thread(false),
+ : BnSurfaceComposer(),
mTransactionFlags(0),
mTransactionPending(false),
mAnimTransactionPending(false),
void SurfaceFlinger::onFirstRef()
{
mEventQueue.init(this);
-
- run("SurfaceFlinger", PRIORITY_URGENT_DISPLAY);
-
- // Wait for the main thread to be done with its initialization
- mReadyToRunBarrier.wait();
}
-
SurfaceFlinger::~SurfaceFlinger()
{
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
return config;
}
+void SurfaceFlinger::init() {
-status_t SurfaceFlinger::readyToRun()
-{
ALOGI( "SurfaceFlinger's main thread ready to run. "
"Initializing graphics H/W...");
// initialize our drawing state
mDrawingState = mCurrentState;
- // We're now ready to accept clients...
- mReadyToRunBarrier.open();
-
// set initial conditions (e.g. unblank default device)
initializeDisplays();
// start boot animation
startBootAnim();
-
- return NO_ERROR;
}
int32_t SurfaceFlinger::allocateHwcDisplayId(DisplayDevice::DisplayType type) {
return res;
}
-bool SurfaceFlinger::threadLoop() {
- waitForEvent();
- return true;
+void SurfaceFlinger::run() {
+#if defined(HAVE_PTHREADS)
+ setpriority(PRIO_PROCESS, 0, PRIORITY_URGENT_DISPLAY);
+#endif
+ do {
+ waitForEvent();
+ } while (true);
}
void SurfaceFlinger::onVSyncReceived(int type, nsecs_t timestamp) {
#include <utils/SortedVector.h>
#include <utils/threads.h>
-#include <binder/BinderService.h>
#include <binder/IMemory.h>
#include <ui/PixelFormat.h>
eTransactionMask = 0x07
};
-class SurfaceFlinger : public BinderService<SurfaceFlinger>,
- public BnSurfaceComposer,
+class SurfaceFlinger : public BnSurfaceComposer,
private IBinder::DeathRecipient,
- private Thread,
private HWComposer::EventHandler
{
public:
SurfaceFlinger() ANDROID_API;
+ // must be called before clients can connect
+ void init() ANDROID_API;
+
+ // starts SurfaceFlinger main loop in the current thread
+ void run() ANDROID_API;
+
enum {
EVENT_VSYNC = HWC_EVENT_VSYNC
};
virtual void binderDied(const wp<IBinder>& who);
/* ------------------------------------------------------------------------
- * Thread interface
+ * RefBase interface
*/
- virtual bool threadLoop();
- virtual status_t readyToRun();
virtual void onFirstRef();
/* ------------------------------------------------------------------------
// these are thread safe
mutable MessageQueue mEventQueue;
- mutable Barrier mReadyToRunBarrier;
FrameTracker mAnimFrameTracker;
// protected by mDestroyedLayerLock;
* limitations under the License.
*/
-#include <binder/BinderService.h>
+#include <binder/IServiceManager.h>
+#include <binder/IPCThreadState.h>
+#include <binder/ProcessState.h>
+#include <binder/IServiceManager.h>
#include "SurfaceFlinger.h"
using namespace android;
// When SF is launched in its own process, limit the number of
// binder threads to 4.
ProcessState::self()->setThreadPoolMaxThreadCount(4);
- SurfaceFlinger::publishAndJoinThreadPool(true);
+
+ // instantiate surfaceflinger
+ sp<SurfaceFlinger> flinger = new SurfaceFlinger();
+
+ // initialize before clients can connect
+ flinger->init();
+
+ // start the thread pool
+ sp<ProcessState> ps(ProcessState::self());
+ ps->startThreadPool();
+
+ // publish surface flinger
+ sp<IServiceManager> sm(defaultServiceManager());
+ sm->addService(String16(SurfaceFlinger::getServiceName()), flinger, false);
+
+ // run in this thread
+ flinger->run();
+
return 0;
}