Fix render_ahead properties

0 and -1 both meant default when 0 should mean
0 and -1 should mean default

Test: manual
Fixes: 179290765
Change-Id: Ia9aa5e3d83757282bfff776e083d6b3d7d29e9c0
diff --git a/libs/hwui/Properties.cpp b/libs/hwui/Properties.cpp
index 65f4e8c..e798f2a 100644
--- a/libs/hwui/Properties.cpp
+++ b/libs/hwui/Properties.cpp
@@ -129,8 +129,9 @@
 
     runningInEmulator = base::GetBoolProperty(PROPERTY_QEMU_KERNEL, false);
 
-    defaultRenderAhead = std::max(-1, std::min(2, base::GetIntProperty(PROPERTY_RENDERAHEAD,
-            render_ahead().value_or(0))));
+    defaultRenderAhead = std::max(
+            -1,
+            std::min(2, base::GetIntProperty(PROPERTY_RENDERAHEAD, render_ahead().value_or(-1))));
 
     return (prevDebugLayersUpdates != debugLayersUpdates) || (prevDebugOverdraw != debugOverdraw);
 }
diff --git a/libs/hwui/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp
index eacabfd..42e93b6 100644
--- a/libs/hwui/renderthread/CanvasContext.cpp
+++ b/libs/hwui/renderthread/CanvasContext.cpp
@@ -157,12 +157,14 @@
 void CanvasContext::setSurface(ANativeWindow* window, bool enableTimeout) {
     ATRACE_CALL();
 
-    if (mRenderAheadDepth == 0 && DeviceInfo::get()->getMaxRefreshRate() > 66.6f) {
-        mFixedRenderAhead = false;
-        mRenderAheadCapacity = 1;
-    } else {
-        mFixedRenderAhead = true;
+    if (mFixedRenderAhead) {
         mRenderAheadCapacity = mRenderAheadDepth;
+    } else {
+        if (DeviceInfo::get()->getMaxRefreshRate() > 66.6f) {
+            mRenderAheadCapacity = 1;
+        } else {
+            mRenderAheadCapacity = 0;
+        }
     }
 
     if (window) {
@@ -762,11 +764,16 @@
 }
 
 void CanvasContext::setRenderAheadDepth(int renderAhead) {
-    if (renderAhead > 2 || renderAhead < 0 || mNativeSurface) {
+    if (renderAhead > 2 || renderAhead < -1 || mNativeSurface) {
         return;
     }
-    mFixedRenderAhead = true;
-    mRenderAheadDepth = static_cast<uint32_t>(renderAhead);
+    if (renderAhead == -1) {
+        mFixedRenderAhead = false;
+        mRenderAheadDepth = 0;
+    } else {
+        mFixedRenderAhead = true;
+        mRenderAheadDepth = static_cast<uint32_t>(renderAhead);
+    }
 }
 
 SkRect CanvasContext::computeDirtyRect(const Frame& frame, SkRect* dirty) {