Enable GPU pixel buffers on OpenGL ES 3.0 devices

Change-Id: I164d72ccd7a9bf6ae0e3f79dfef50083558937ba
diff --git a/libs/hwui/Caches.cpp b/libs/hwui/Caches.cpp
index f08b5ca..9d5a854 100644
--- a/libs/hwui/Caches.cpp
+++ b/libs/hwui/Caches.cpp
@@ -52,6 +52,7 @@
     initFont();
     initConstraints();
     initProperties();
+    initStaticProperties();
     initExtensions();
 
     mDebugLevel = readDebugLevel();
@@ -137,6 +138,18 @@
     glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
 }
 
+void Caches::initStaticProperties() {
+    gpuPixelBuffersEnabled = false;
+
+    // OpenGL ES 3.0+ specific features
+    if (mExtensions.getMajorGlVersion() >= 3) {
+        char property[PROPERTY_VALUE_MAX];
+        if (property_get(PROPERTY_ENABLE_GPU_PIXEL_BUFFERS, property, "true") > 0) {
+            gpuPixelBuffersEnabled = !strcmp(property, "true");
+        }
+    }
+}
+
 bool Caches::initProperties() {
     bool prevDebugLayersUpdates = debugLayersUpdates;
     bool prevDebugOverdraw = debugOverdraw;
diff --git a/libs/hwui/Caches.h b/libs/hwui/Caches.h
index 18aeeab..54e4138 100644
--- a/libs/hwui/Caches.h
+++ b/libs/hwui/Caches.h
@@ -302,6 +302,8 @@
 
     AssetAtlas assetAtlas;
 
+    bool gpuPixelBuffersEnabled;
+
     // Debug methods
     PFNGLINSERTEVENTMARKEREXTPROC eventMark;
     PFNGLPUSHGROUPMARKEREXTPROC startMark;
@@ -314,6 +316,7 @@
     void initFont();
     void initExtensions();
     void initConstraints();
+    void initStaticProperties();
 
     static void eventMarkNull(GLsizei length, const GLchar* marker) { }
     static void startMarkNull(GLsizei length, const GLchar* marker) { }
diff --git a/libs/hwui/PixelBuffer.cpp b/libs/hwui/PixelBuffer.cpp
index 8280370..29f8756 100644
--- a/libs/hwui/PixelBuffer.cpp
+++ b/libs/hwui/PixelBuffer.cpp
@@ -147,14 +147,8 @@
 ///////////////////////////////////////////////////////////////////////////////
 
 PixelBuffer* PixelBuffer::create(GLenum format, uint32_t width, uint32_t height, BufferType type) {
-    bool gpuBuffer = type == kBufferType_Auto && Extensions::getInstance().getMajorGlVersion() >= 3;
-    if (gpuBuffer) {
-        char property[PROPERTY_VALUE_MAX];
-        if (property_get(PROPERTY_ENABLE_GPU_PIXEL_BUFFERS, property, "false") > 0) {
-            if (!strcmp(property, "true")) {
-                return new GpuPixelBuffer(format, width, height);
-            }
-        }
+    if (type == kBufferType_Auto && Caches::getInstance().gpuPixelBuffersEnabled) {
+        return new GpuPixelBuffer(format, width, height);
     }
     return new CpuPixelBuffer(format, width, height);
 }
diff --git a/libs/hwui/Properties.h b/libs/hwui/Properties.h
index 7c68b5b..dbbb956 100644
--- a/libs/hwui/Properties.h
+++ b/libs/hwui/Properties.h
@@ -123,9 +123,9 @@
 
 /**
  * Indicates whether PBOs can be used to back pixel buffers.
- * Accepted values are "true" and "false".
+ * Accepted values are "true" and "false". Default is true.
  */
-#define PROPERTY_ENABLE_GPU_PIXEL_BUFFERS "hwui.use_gpu_pixel_buffers"
+#define PROPERTY_ENABLE_GPU_PIXEL_BUFFERS "ro.hwui.use_gpu_pixel_buffers"
 
 // These properties are defined in mega-bytes
 #define PROPERTY_TEXTURE_CACHE_SIZE "ro.hwui.texture_cache_size"