Tonemap in RecordingCanvas

Intecepts bitmap calls to tonemap whenever the source is HDR (PQ/HLG)
and the destination is SDR.

Also, fix the following bugs discovered as part of testing:
1. Don't implicitly cast to booleans when extracting transfer functions
   from a dataspace in hwui's tonemapper.
2. Fix some typos in defining the HLG/PQ transfer functions.

Bug: 261088450
Test: New ColorBitmapActivity in HwAccelerationTest
Change-Id: I9d9d68fc4f57b999b3c6d4156bef281b4409f37e
diff --git a/libs/hwui/Tonemapper.cpp b/libs/hwui/Tonemapper.cpp
index a7e76b6..0d39f0e 100644
--- a/libs/hwui/Tonemapper.cpp
+++ b/libs/hwui/Tonemapper.cpp
@@ -18,7 +18,10 @@
 
 #include <SkRuntimeEffect.h>
 #include <log/log.h>
+// libshaders only exists on Android devices
+#ifdef __ANDROID__
 #include <shaders/shaders.h>
+#endif
 
 #include "utils/Color.h"
 
@@ -26,6 +29,8 @@
 
 namespace {
 
+// custom tonemapping only exists on Android devices
+#ifdef __ANDROID__
 class ColorFilterRuntimeEffectBuilder : public SkRuntimeEffectBuilder {
 public:
     explicit ColorFilterRuntimeEffectBuilder(sk_sp<SkRuntimeEffect> effect)
@@ -59,20 +64,21 @@
     return effectBuilder.makeColorFilter();
 }
 
-static bool extractTransfer(ui::Dataspace dataspace) {
-    return dataspace & HAL_DATASPACE_TRANSFER_MASK;
+static ui::Dataspace extractTransfer(ui::Dataspace dataspace) {
+    return static_cast<ui::Dataspace>(dataspace & HAL_DATASPACE_TRANSFER_MASK);
 }
 
 static bool isHdrDataspace(ui::Dataspace dataspace) {
     const auto transfer = extractTransfer(dataspace);
 
-    return transfer == HAL_DATASPACE_TRANSFER_ST2084 || transfer == HAL_DATASPACE_TRANSFER_HLG;
+    return transfer == ui::Dataspace::TRANSFER_ST2084 || transfer == ui::Dataspace::TRANSFER_HLG;
 }
 
 static ui::Dataspace getDataspace(const SkImageInfo& image) {
     return static_cast<ui::Dataspace>(
             ColorSpaceToADataSpace(image.colorSpace(), image.colorType()));
 }
+#endif
 
 }  // namespace
 
@@ -80,6 +86,8 @@
 // shader and tag it on the supplied paint.
 void tonemapPaint(const SkImageInfo& source, const SkImageInfo& destination, float maxLuminanceNits,
                   SkPaint& paint) {
+// custom tonemapping only exists on Android devices
+#ifdef __ANDROID__
     const auto sourceDataspace = getDataspace(source);
     const auto destinationDataspace = getDataspace(destination);
 
@@ -102,6 +110,9 @@
             paint.setColorFilter(colorFilter);
         }
     }
+#else
+    return;
+#endif
 }
 
 }  // namespace android::uirenderer