diff options
author | Brian Osman <brianosman@google.com> | 2017-01-17 16:10:07 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-01-17 21:53:57 +0000 |
commit | 0d4ff6c601f2ce404a97068718caad5a2bb3d594 (patch) | |
tree | be37c1e4b454893b7df99aa19585455b728560fc /samplecode | |
parent | 98420d0c9b5934d6b08ea994844476ddedd23de0 (diff) |
Fix code that relied on readPixels not doing color space conversion
SampleApp doesn't have (can't easily get) an image, so I couldn't use
the new helper function there. It's probably still worth having?
BUG=skia:
Change-Id: I60c208ff958076015a9539359921b9aff68f25c8
Reviewed-on: https://skia-review.googlesource.com/7129
Reviewed-by: Matt Sarett <msarett@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Diffstat (limited to 'samplecode')
-rw-r--r-- | samplecode/SampleApp.cpp | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp index 3919c244a2..bd298dfa11 100644 --- a/samplecode/SampleApp.cpp +++ b/samplecode/SampleApp.cpp @@ -326,23 +326,27 @@ public: if (!IsGpuDeviceType(dType) || kRGBA_F16_SkColorType == win->info().colorType() || fActualColorBits > 24) { - // We made/have an off-screen surface. Get the contents as an SkImage: - SkImageInfo offscreenInfo = win->info(); - if (kMonitor_OutputColorSpace == gConfig[win->getColorConfigIndex()].fColorSpace || - kNarrow_OutputColorSpace == gConfig[win->getColorConfigIndex()].fColorSpace) { - // This is a big hack. We want our final output to be color "correct". If we snap - // an image in the gamut of the monitor, and then render to FBO0 (which we've tagged - // as sRGB), then we end up doing round-trip gamut conversion, and still seeing the - // same colors on-screen as if we weren't color managed at all. - // Instead, we readPixels into a buffer that we claim is sRGB (readPixels doesn't - // do gamut conversion), so these pixels then get thrown directly at the monitor, - // giving us the expected results (the output is adapted to the monitor's gamut). - auto srgb = SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); - offscreenInfo = offscreenInfo.makeColorSpace(srgb); + // We made/have an off-screen surface. Extract the pixels exactly as we rendered them: + SkImageInfo info = win->info(); + size_t rowBytes = info.minRowBytes(); + size_t size = info.getSafeSize(rowBytes); + auto data = SkData::MakeUninitialized(size); + SkASSERT(data); + + if (!renderingCanvas->readPixels(info, data->writable_data(), rowBytes, 0, 0)) { + SkDEBUGFAIL("Failed to read canvas pixels"); + return; } - SkBitmap bm; - bm.allocPixels(offscreenInfo); - renderingCanvas->readPixels(&bm, 0, 0); + + // Now, re-interpret those pixels as sRGB, so they won't be color converted when we + // draw then to FBO0. This ensures that if we rendered in any strange gamut, we'll see + // the "correct" output (because we generated the pixel values we wanted in the + // offscreen canvas). + auto colorSpace = kRGBA_F16_SkColorType == info.colorType() + ? SkColorSpace::MakeNamed(SkColorSpace::kSRGBLinear_Named) + : SkColorSpace::MakeNamed(SkColorSpace::kSRGB_Named); + auto offscreenImage = SkImage::MakeRasterData(info.makeColorSpace(colorSpace), data, + rowBytes); SkCanvas* gpuCanvas = fGpuSurface->getCanvas(); @@ -357,7 +361,7 @@ public: gammaPaint.setColorFilter(SkGammaColorFilter::Make(1.0f / 2.2f)); } - gpuCanvas->drawBitmap(bm, 0, 0, &gammaPaint); + gpuCanvas->drawImage(offscreenImage, 0, 0, &gammaPaint); } fGpuSurface->prepareForExternalIO(); |