Added display initialization method

The primary display device was being configured to "blank" by
default, which prevented the boot animation from appearing
(unless you got lucky with the hardware composer state).

Bug 6975688

Change-Id: I0fa52e9e719c6e997c5725a7baf15d9718461b78
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 7b070ba..1406deb 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -137,15 +137,8 @@
 {
     // the window manager died on us. prepare its eulogy.
 
-    // reset screen orientation
-    Vector<ComposerState> state;
-    Vector<DisplayState> displays;
-    DisplayState d;
-    d.what = DisplayState::eOrientationChanged;
-    d.token = mDefaultDisplays[DisplayDevice::DISPLAY_ID_MAIN];
-    d.orientation = DisplayState::eOrientationDefault;
-    displays.add(d);
-    setTransactionState(state, displays, 0);
+    // restore initial conditions (default device unblank, etc)
+    initializeDisplays();
 
     // restart the boot-animation
     startBootAnim();
@@ -451,6 +444,9 @@
     // We're now ready to accept clients...
     mReadyToRunBarrier.open();
 
+    // set initial conditions (e.g. unblank default device)
+    initializeDisplays();
+
     // start boot animation
     startBootAnim();
 
@@ -1729,6 +1725,36 @@
 
 // ---------------------------------------------------------------------------
 
+void SurfaceFlinger::onInitializeDisplays() {
+    // reset screen orientation
+    Vector<ComposerState> state;
+    Vector<DisplayState> displays;
+    DisplayState d;
+    d.what = DisplayState::eOrientationChanged;
+    d.token = mDefaultDisplays[DisplayDevice::DISPLAY_ID_MAIN];
+    d.orientation = DisplayState::eOrientationDefault;
+    displays.add(d);
+    setTransactionState(state, displays, 0);
+
+    // XXX: this should init default device to "unblank" and all other devices to "blank"
+    onScreenAcquired();
+}
+
+void SurfaceFlinger::initializeDisplays() {
+    class MessageScreenInitialized : public MessageBase {
+        SurfaceFlinger* flinger;
+    public:
+        MessageScreenInitialized(SurfaceFlinger* flinger) : flinger(flinger) { }
+        virtual bool handler() {
+            flinger->onInitializeDisplays();
+            return true;
+        }
+    };
+    sp<MessageBase> msg = new MessageScreenInitialized(this);
+    postMessageAsync(msg);  // we may be called from main thread, use async message
+}
+
+
 void SurfaceFlinger::onScreenAcquired() {
     ALOGD("Screen about to return, flinger = %p", this);
     sp<const DisplayDevice> hw(getDefaultDisplayDevice()); // XXX: this should be per DisplayDevice