summaryrefslogtreecommitdiff
path: root/libs/renderengine/RenderEngine.cpp
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/renderengine/RenderEngine.cpp
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/renderengine/RenderEngine.cpp')
-rw-r--r--libs/renderengine/RenderEngine.cpp28
1 files changed, 23 insertions, 5 deletions
diff --git a/libs/renderengine/RenderEngine.cpp b/libs/renderengine/RenderEngine.cpp
index bc3976d9f1..907590a236 100644
--- a/libs/renderengine/RenderEngine.cpp
+++ b/libs/renderengine/RenderEngine.cpp
@@ -21,6 +21,7 @@
#include "skia/GraphiteVkRenderEngine.h"
#include "skia/SkiaGLRenderEngine.h"
#include "threaded/RenderEngineThreaded.h"
+#include "ui/GraphicTypes.h"
#include <com_android_graphics_surfaceflinger_flags.h>
#include <cutils/properties.h>
@@ -101,17 +102,34 @@ ftl::Future<FenceResult> RenderEngine::drawLayers(const DisplaySettings& display
base::unique_fd&& bufferFence) {
const auto resultPromise = std::make_shared<std::promise<FenceResult>>();
std::future<FenceResult> resultFuture = resultPromise->get_future();
- updateProtectedContext(layers, buffer);
+ updateProtectedContext(layers, {buffer.get()});
drawLayersInternal(std::move(resultPromise), display, layers, buffer, std::move(bufferFence));
return resultFuture;
}
+ftl::Future<FenceResult> RenderEngine::drawGainmap(
+ const std::shared_ptr<ExternalTexture>& sdr, base::borrowed_fd&& sdrFence,
+ const std::shared_ptr<ExternalTexture>& hdr, base::borrowed_fd&& hdrFence,
+ float hdrSdrRatio, ui::Dataspace dataspace,
+ const std::shared_ptr<ExternalTexture>& gainmap) {
+ const auto resultPromise = std::make_shared<std::promise<FenceResult>>();
+ std::future<FenceResult> resultFuture = resultPromise->get_future();
+ updateProtectedContext({}, {sdr.get(), hdr.get(), gainmap.get()});
+ drawGainmapInternal(std::move(resultPromise), sdr, std::move(sdrFence), hdr,
+ std::move(hdrFence), hdrSdrRatio, dataspace, gainmap);
+ return resultFuture;
+}
+
void RenderEngine::updateProtectedContext(const std::vector<LayerSettings>& layers,
- const std::shared_ptr<ExternalTexture>& buffer) {
+ vector<const ExternalTexture*> buffers) {
const bool needsProtectedContext =
- (buffer && (buffer->getUsage() & GRALLOC_USAGE_PROTECTED)) ||
- std::any_of(layers.begin(), layers.end(), [](const LayerSettings& layer) {
- const std::shared_ptr<ExternalTexture>& buffer = layer.source.buffer.buffer;
+ std::any_of(layers.begin(), layers.end(),
+ [](const LayerSettings& layer) {
+ const std::shared_ptr<ExternalTexture>& buffer =
+ layer.source.buffer.buffer;
+ return buffer && (buffer->getUsage() & GRALLOC_USAGE_PROTECTED);
+ }) ||
+ std::any_of(buffers.begin(), buffers.end(), [](const ExternalTexture* buffer) {
return buffer && (buffer->getUsage() & GRALLOC_USAGE_PROTECTED);
});
useProtectedContext(needsProtectedContext);