summaryrefslogtreecommitdiff
path: root/cmds/screencap/screencap.cpp
diff options
context:
space:
mode:
authorRomain Guy <romainguy@google.com>2017-04-17 09:39:51 -0700
committerRomain Guy <romainguy@google.com>2017-06-02 11:02:13 -0700
commit26a2b97dbe48ee45e9ae70110714048f2f360f97 (patch)
tree1e8e25d446c598d0b552708c90878246a370ba42 /cmds/screencap/screencap.cpp
parent3b3388ca64a818f2c036cf0dbf02a9e011ccc8de (diff)
Enable wide color gamut rendering
When wide color gamut rendering is requested, hwui will now use an rgba16f scRGB-nl surface for rendering. This change also fixes the way screenshots are handled in the platform to behave properly with wide gamut rendering. This change does not affect hardware layers. They also need to use rgba16f scRGB-nl; this will be addressed in another CL. Bug: 29940137 Test: CtsUiRenderingTestCases, CtsGraphicsTestCases Change-Id: I68fd96c451652136c566ec48fb0e97c2a7a257c5
Diffstat (limited to 'cmds/screencap/screencap.cpp')
-rw-r--r--cmds/screencap/screencap.cpp39
1 files changed, 38 insertions, 1 deletions
diff --git a/cmds/screencap/screencap.cpp b/cmds/screencap/screencap.cpp
index 5fedc9e74087..607e6e0186e7 100644
--- a/cmds/screencap/screencap.cpp
+++ b/cmds/screencap/screencap.cpp
@@ -33,17 +33,24 @@
#include <ui/DisplayInfo.h>
#include <ui/PixelFormat.h>
+#include <system/graphics.h>
+
// TODO: Fix Skia.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include <SkImageEncoder.h>
#include <SkData.h>
+#include <SkColorSpace.h>
#pragma GCC diagnostic pop
using namespace android;
static uint32_t DEFAULT_DISPLAY_ID = ISurfaceComposer::eDisplayIdMain;
+#define COLORSPACE_UNKNOWN 0
+#define COLORSPACE_SRGB 1
+#define COLORSPACE_DISPLAY_P3 2
+
static void usage(const char* pname)
{
fprintf(stderr,
@@ -67,6 +74,31 @@ static SkColorType flinger2skia(PixelFormat f)
}
}
+static sk_sp<SkColorSpace> dataSpaceToColorSpace(android_dataspace d)
+{
+ switch (d) {
+ case HAL_DATASPACE_V0_SRGB:
+ return SkColorSpace::MakeSRGB();
+ case HAL_DATASPACE_DISPLAY_P3:
+ return SkColorSpace::MakeRGB(
+ SkColorSpace::kSRGB_RenderTargetGamma, SkColorSpace::kDCIP3_D65_Gamut);
+ default:
+ return nullptr;
+ }
+}
+
+static uint32_t dataSpaceToInt(android_dataspace d)
+{
+ switch (d) {
+ case HAL_DATASPACE_V0_SRGB:
+ return COLORSPACE_SRGB;
+ case HAL_DATASPACE_DISPLAY_P3:
+ return COLORSPACE_DISPLAY_P3;
+ default:
+ return COLORSPACE_UNKNOWN;
+ }
+}
+
static status_t notifyMediaScanner(const char* fileName) {
String8 cmd("am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d file://");
String8 fileUrl("\"");
@@ -139,6 +171,7 @@ int main(int argc, char** argv)
void const* base = NULL;
uint32_t w, s, h, f;
+ android_dataspace d;
size_t size = 0;
// Maps orientations from DisplayInfo to ISurfaceComposer
@@ -177,13 +210,15 @@ int main(int argc, char** argv)
h = screenshot.getHeight();
s = screenshot.getStride();
f = screenshot.getFormat();
+ d = screenshot.getDataSpace();
size = screenshot.getSize();
}
if (base != NULL) {
if (png) {
const SkImageInfo info =
- SkImageInfo::Make(w, h, flinger2skia(f), kPremul_SkAlphaType);
+ SkImageInfo::Make(w, h, flinger2skia(f), kPremul_SkAlphaType,
+ dataSpaceToColorSpace(d));
SkPixmap pixmap(info, base, s * bytesPerPixel(f));
struct FDWStream final : public SkWStream {
size_t fBytesWritten = 0;
@@ -200,9 +235,11 @@ int main(int argc, char** argv)
notifyMediaScanner(fn);
}
} else {
+ uint32_t c = dataSpaceToInt(d);
write(fd, &w, 4);
write(fd, &h, 4);
write(fd, &f, 4);
+ write(fd, &c, 4);
size_t Bpp = bytesPerPixel(f);
for (size_t y=0 ; y<h ; y++) {
write(fd, base, w*Bpp);