summaryrefslogtreecommitdiff
path: root/libs/gui
diff options
context:
space:
mode:
author Alec Mouri <alecmouri@google.com> 2024-07-15 22:46:58 +0000
committer Alec Mouri <alecmouri@google.com> 2024-08-28 21:10:28 +0000
commit1b1853f92528a2214f0337decf4685250334a43c (patch)
tree1e9bd7edf505a1bdfb2da77e3b8252391f801d32 /libs/gui
parent2b96d359af29f34d5bf8ec631f1ea56104f0901e (diff)
Support capturing a gainmapped screenshot
This uses the gainmap concept from UltraHDR and ISO 21496-1 to produce screenshots that (a) can be rendered in HDR and (b) that are perfectly backwards-compatible on SDR displays are scenes where displaying SDR is preferable. The technical details of the screenshot process at a high level are: * A client requests that they want a gainmap attached to the screenshot result * SurfaceFlinger asks RenderEngine to perform three render passes * First, render the SDR base image, tonemapping using MouriMap * Second, render an HDR rendition. This is *also* tonemapped using MouriMap to the current display conditions. For HDR UI, this is effectively a no-op. For PQ and HLG content, this allows for approximating what is on-screen as closely as possible. Note that to preserve precision as much as possible, we require an FP16 framebuffer. * Finally, combine the SDR and HDR renditions into a gainmap * The client now receives the base image with the gainmap, as well as an HDR/SDR ratio. The client can use this information to generate gainmap metadata for encoding or round-tripping to the display. This MVP is sufficient for generating screenshots through adb screencap. Eventually, this can be used to integrate with the applications that want HDR screenshots, or to remove hacks that disable tonemapping during certain system animations. Bug: 329470026 Flag: com.android.graphics.surfaceflinger.flags.true_hdr_screenshots Test: builds Test: adb screencap Change-Id: I0434059d957bb6cc38d019743619d72dda72a269
Diffstat (limited to 'libs/gui')
-rw-r--r--libs/gui/ScreenCaptureResults.cpp15
-rw-r--r--libs/gui/aidl/android/gui/CaptureArgs.aidl5
-rw-r--r--libs/gui/aidl/android/gui/ScreenCaptureResults.aidl2
-rw-r--r--libs/gui/include/gui/ScreenCaptureResults.h5
4 files changed, 26 insertions, 1 deletions
diff --git a/libs/gui/ScreenCaptureResults.cpp b/libs/gui/ScreenCaptureResults.cpp
index 601a5f9b33..2de023e5b2 100644
--- a/libs/gui/ScreenCaptureResults.cpp
+++ b/libs/gui/ScreenCaptureResults.cpp
@@ -40,6 +40,13 @@ status_t ScreenCaptureResults::writeToParcel(android::Parcel* parcel) const {
SAFE_PARCEL(parcel->writeBool, capturedSecureLayers);
SAFE_PARCEL(parcel->writeBool, capturedHdrLayers);
SAFE_PARCEL(parcel->writeUint32, static_cast<uint32_t>(capturedDataspace));
+ if (optionalGainMap != nullptr) {
+ SAFE_PARCEL(parcel->writeBool, true);
+ SAFE_PARCEL(parcel->write, *optionalGainMap);
+ } else {
+ SAFE_PARCEL(parcel->writeBool, false);
+ }
+ SAFE_PARCEL(parcel->writeFloat, hdrSdrRatio);
return NO_ERROR;
}
@@ -68,6 +75,14 @@ status_t ScreenCaptureResults::readFromParcel(const android::Parcel* parcel) {
uint32_t dataspace = 0;
SAFE_PARCEL(parcel->readUint32, &dataspace);
capturedDataspace = static_cast<ui::Dataspace>(dataspace);
+
+ bool hasGainmap;
+ SAFE_PARCEL(parcel->readBool, &hasGainmap);
+ if (hasGainmap) {
+ optionalGainMap = new GraphicBuffer();
+ SAFE_PARCEL(parcel->read, *optionalGainMap);
+ }
+ SAFE_PARCEL(parcel->readFloat, &hdrSdrRatio);
return NO_ERROR;
}
diff --git a/libs/gui/aidl/android/gui/CaptureArgs.aidl b/libs/gui/aidl/android/gui/CaptureArgs.aidl
index 2bbed2b9d6..4920344e0e 100644
--- a/libs/gui/aidl/android/gui/CaptureArgs.aidl
+++ b/libs/gui/aidl/android/gui/CaptureArgs.aidl
@@ -69,5 +69,10 @@ parcelable CaptureArgs {
// exact colorspace is not an appropriate intermediate result.
// Note that if the caller is requesting a specific dataspace, this hint does nothing.
boolean hintForSeamlessTransition = false;
+
+ // Allows the screenshot to attach a gainmap, which allows for a per-pixel
+ // transformation of the screenshot to another luminance range, typically
+ // mapping an SDR base image into HDR.
+ boolean attachGainmap = false;
}
diff --git a/libs/gui/aidl/android/gui/ScreenCaptureResults.aidl b/libs/gui/aidl/android/gui/ScreenCaptureResults.aidl
index 97a903515b..f4ef16dc71 100644
--- a/libs/gui/aidl/android/gui/ScreenCaptureResults.aidl
+++ b/libs/gui/aidl/android/gui/ScreenCaptureResults.aidl
@@ -16,4 +16,4 @@
package android.gui;
-parcelable ScreenCaptureResults cpp_header "gui/ScreenCaptureResults.h" rust_type "gui_aidl_types_rs::ScreenCaptureResults"; \ No newline at end of file
+parcelable ScreenCaptureResults cpp_header "gui/ScreenCaptureResults.h" rust_type "gui_aidl_types_rs::ScreenCaptureResults";
diff --git a/libs/gui/include/gui/ScreenCaptureResults.h b/libs/gui/include/gui/ScreenCaptureResults.h
index 6e17791a29..f176f48fb4 100644
--- a/libs/gui/include/gui/ScreenCaptureResults.h
+++ b/libs/gui/include/gui/ScreenCaptureResults.h
@@ -36,6 +36,11 @@ public:
bool capturedSecureLayers{false};
bool capturedHdrLayers{false};
ui::Dataspace capturedDataspace{ui::Dataspace::V0_SRGB};
+ // A gainmap that can be used to "lift" the screenshot into HDR
+ sp<GraphicBuffer> optionalGainMap;
+ // HDR/SDR ratio value that fully applies the gainmap.
+ // Note that we use 1/64 epsilon offsets to eliminate precision issues
+ float hdrSdrRatio{1.0f};
};
} // namespace android::gui