Allow HW accleration to be activated on demand.

This CL adds a debugging preference that allows developers to
enable/disable Open GL rendering on demand. The setting change
does not take effect until the browser is restarted.

bug: 3185844
Change-Id: Ifcf5a7b7d4ddbf02a649a28c4f462e2da3f34bb6
diff --git a/res/values/strings.xml b/res/values/strings.xml
index a6ad15e..d724085 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -520,6 +520,8 @@
     <!-- Do not tranlsate.  Development option -->
     <string name="pref_development_nav_dump" translatable="false">Enable nav cache dump</string>
     <!-- Do not tranlsate.  Development option -->
+    <string name="pref_development_hardware_accel" translatable="false">Enable OpenGL Rendering</string>
+    <!-- Do not tranlsate.  Development option -->
     <string name="js_engine_flags" translatable="false">Set JS flags</string>
     <!-- Do not tranlsate.  Development option -->
     <string name="pref_development_uastring" translatable="false">UAString</string>
diff --git a/res/xml/debug_preferences.xml b/res/xml/debug_preferences.xml
index 54b2bd5..2ff4e79 100644
--- a/res/xml/debug_preferences.xml
+++ b/res/xml/debug_preferences.xml
@@ -54,6 +54,11 @@
         android:defaultValue="false"
         android:title="@string/pref_development_nav_dump" />
 
+    <CheckBoxPreference
+        android:key="enable_hardware_accel"
+        android:defaultValue="false"
+        android:title="@string/pref_development_hardware_accel" />
+
     <EditTextPreference
         android:key="js_engine_flags"
         android:title="@string/js_engine_flags"
diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java
index b882338..ef26145 100644
--- a/src/com/android/browser/BrowserActivity.java
+++ b/src/com/android/browser/BrowserActivity.java
@@ -24,7 +24,6 @@
 import android.app.ActionBar;
 import android.app.Activity;
 import android.app.AlertDialog;
-import android.app.Dialog;
 import android.app.DownloadManager;
 import android.app.ProgressDialog;
 import android.app.SearchManager;
@@ -43,7 +42,6 @@
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
 import android.content.res.Configuration;
-import android.content.res.Resources;
 import android.database.Cursor;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
@@ -71,7 +69,6 @@
 import android.provider.BrowserContract.Images;
 import android.provider.ContactsContract;
 import android.provider.ContactsContract.Intents.Insert;
-import android.provider.Downloads;
 import android.provider.MediaStore;
 import android.speech.RecognizerResultsIntent;
 import android.text.TextUtils;
@@ -105,7 +102,6 @@
 import android.webkit.WebIconDatabase;
 import android.webkit.WebSettings;
 import android.webkit.WebView;
-import android.widget.EditText;
 import android.widget.FrameLayout;
 import android.widget.LinearLayout;
 import android.widget.TextView;
@@ -172,8 +168,19 @@
             Log.v(LOGTAG, this + " onStart");
         }
         super.onCreate(icicle);
-        // test the browser in OpenGL
-        // requestWindowFeature(Window.FEATURE_OPENGL);
+
+        // Keep a settings instance handy.
+        mSettings = BrowserSettings.getInstance();
+
+        // render the browser in OpenGL
+        if (mSettings.isHardwareAccelerated()) {
+            // Set the flag in the activity's window
+            this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
+                    WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
+        } else {
+            // Clear the flag in the activity's window
+            this.getWindow().setFlags(0, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
+        }
 
         // enable this to test the browser in 32bit
         if (false) {
@@ -189,9 +196,6 @@
 
         mResolver = getContentResolver();
 
-        // Keep a settings instance handy.
-        mSettings = BrowserSettings.getInstance();
-
         // If this was a web search request, pass it on to the default web
         // search provider and finish this activity.
         if (handleWebSearchIntent(getIntent())) {
diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java
index 99de9dc..44842be 100644
--- a/src/com/android/browser/BrowserSettings.java
+++ b/src/com/android/browser/BrowserSettings.java
@@ -115,6 +115,7 @@
     private boolean tracing = false;
     private boolean lightTouch = false;
     private boolean navDump = false;
+    private boolean hardwareAccelerated = false;
 
     // By default the error console is shown once the user navigates to about:debug.
     // The setting can be then toggled from the settings menu.
@@ -446,6 +447,12 @@
             navDump = p.getBoolean("enable_nav_dump", navDump);
             userAgent = Integer.parseInt(p.getString("user_agent", "0"));
         }
+
+        // This setting can only be modified when the debug settings have been
+        // enabled but it is read and used by the browser at startup so we must
+        // initialize it regardless of the status of the debug settings.
+        hardwareAccelerated = p.getBoolean("enable_hardware_accel", hardwareAccelerated);
+
         // JS flags is loaded from DB even if showDebugSettings is false,
         // so that it can be set once and be effective all the time.
         jsFlags = p.getString("js_engine_flags", "");
@@ -519,6 +526,10 @@
         return navDump;
     }
 
+    public boolean isHardwareAccelerated() {
+        return hardwareAccelerated;
+    }
+
     public boolean showDebugSettings() {
         return showDebugSettings;
     }