Fix potential thread violation in applying gainmaps

When deciding whether or not to apply the gainmap & if so by how much
only use the CanvasContext ratio if we are on RenderThread.

Bug: 293927383
Test: Good guess
Change-Id: Ie49ae2718df09ab14019b354197d99538e8c6b04
diff --git a/libs/hwui/effects/GainmapRenderer.cpp b/libs/hwui/effects/GainmapRenderer.cpp
index db58b2b..3ebf7d1 100644
--- a/libs/hwui/effects/GainmapRenderer.cpp
+++ b/libs/hwui/effects/GainmapRenderer.cpp
@@ -54,14 +54,13 @@
         return maxPQLux / GenericSdrWhiteNits;
     } else if (skcms_TransferFunction_isHLGish(&destTF)) {
         return maxHLGLux / GenericSdrWhiteNits;
-    } else {
 #ifdef __ANDROID__
+    } else if (RenderThread::isCurrent()) {
         CanvasContext* context = CanvasContext::getActiveContext();
         return context ? context->targetSdrHdrRatio() : 1.f;
-#else
-        return 1.f;
 #endif
     }
+    return 1.f;
 }
 
 void DrawGainmapBitmap(SkCanvas* c, const sk_sp<const SkImage>& image, const SkRect& src,