Only enable GL rendering on the main thread.

Change-Id: I41950f4c0a5063ee5d6950cf137eb60a1c7a72fe
diff --git a/core/java/android/view/ViewRoot.java b/core/java/android/view/ViewRoot.java
index 7c55f7b..d480bbc 100644
--- a/core/java/android/view/ViewRoot.java
+++ b/core/java/android/view/ViewRoot.java
@@ -485,7 +485,14 @@
     private void enableHardwareAcceleration(WindowManager.LayoutParams attrs) {
         mAttachInfo.mHardwareAccelerated = false;
         mAttachInfo.mHardwareAccelerationRequested = false;
-        
+
+        // Don't enable hardware acceleration when we're not on the main thread
+        if (Looper.getMainLooper() != Looper.myLooper()) {
+            Log.w(HardwareRenderer.LOG_TAG, "Attempting to initialize hardware acceleration " 
+                    + "outside of the main thread, aborting");
+            return;
+        }
+
         // Try to enable hardware acceleration if requested
         if (attrs != null &&
                 (attrs.flags & WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) != 0) {