Several fixes for fp 16 rendering:

With the GPU backend, allow F16 render targets to be created (along with
any other renderable format). We were previously just falling back to 8888.

In SampleApp, if the window configuration is F16, don't render directly
to the primary surface (which is actually sRGB 8888). Intead, make an
off-screen F16 surface, then blit it back to the framebuffer when we're done.

In DM, clamp values outside of [0,1]. These were wrapping, producing very
incorrect images. (Many filters can trigger out-of-range values due to
ringing).

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1890923003

Review URL: https://codereview.chromium.org/1890923003
This commit is contained in:
brianosman 2016-04-14 12:39:00 -07:00 committed by Commit bot
parent cbe3c1af98
commit 6b08652abf
3 changed files with 32 additions and 6 deletions

View File

@ -958,7 +958,12 @@ static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) {
return false;
}
for (int i = 0; i < w*h; i++) {
Sk4f fs = SkHalfToFloat_01(px[i]); // Convert up to linear floats.
// Convert up to linear floats.
Sk4f fs(SkHalfToFloat(static_cast<SkHalf>(px[i] >> (0 * 16))),
SkHalfToFloat(static_cast<SkHalf>(px[i] >> (1 * 16))),
SkHalfToFloat(static_cast<SkHalf>(px[i] >> (2 * 16))),
SkHalfToFloat(static_cast<SkHalf>(px[i] >> (3 * 16))));
fs = Sk4f::Max(0.0f, Sk4f::Min(fs, 1.0f)); // Clamp
float invA = 1.0f / fs[3];
fs = fs * Sk4f(invA, invA, invA, 1); // Unpremultiply.
rgba[i] = Sk4f_toS32(fs); // Pack down to sRGB bytes.

View File

@ -294,7 +294,14 @@ public:
#if SK_SUPPORT_GPU
if (IsGpuDeviceType(dType) && fCurContext) {
SkSurfaceProps props(win->getSurfaceProps());
return SkSurface::MakeRenderTargetDirect(fCurRenderTarget, &props).release();
if (kRGBA_F16_SkColorType == win->info().colorType()) {
// Need to make an off-screen F16 surface - the current render target is
// (probably) the wrong format.
return SkSurface::MakeRenderTarget(fCurContext, SkBudgeted::kNo, win->info(),
fMSAASampleCount, &props).release();
} else {
return SkSurface::MakeRenderTargetDirect(fCurRenderTarget, &props).release();
}
}
#endif
return nullptr;
@ -318,6 +325,16 @@ public:
bm.getPixels(),
bm.rowBytes(),
GrContext::kFlushWrites_PixelOp);
} else if (kRGBA_F16_SkColorType == win->info().colorType()) {
SkBitmap bm;
bm.allocPixels(win->info());
canvas->readPixels(&bm, 0, 0);
fCurRenderTarget->writePixels(0, 0, bm.width(), bm.height(),
SkImageInfo2GrPixelConfig(bm.info(),
*fCurContext->caps()),
bm.getPixels(),
bm.rowBytes(),
GrContext::kFlushWrites_PixelOp);
}
}
#endif

View File

@ -191,15 +191,19 @@ GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkBudgeted b
SkColorType ct = origInfo.colorType();
SkAlphaType at = origInfo.alphaType();
SkColorProfileType pt = origInfo.profileType();
if (kRGB_565_SkColorType == ct) {
if (kRGB_565_SkColorType == ct || kGray_8_SkColorType == ct) {
at = kOpaque_SkAlphaType; // force this setting
} else if (ct != kBGRA_8888_SkColorType && ct != kRGBA_8888_SkColorType) {
// Fall back from whatever ct was to default of kRGBA or kBGRA which is aliased as kN32
ct = kN32_SkColorType;
}
if (kOpaque_SkAlphaType != at) {
at = kPremul_SkAlphaType; // force this setting
}
GrPixelConfig origConfig = SkImageInfo2GrPixelConfig(ct, at, pt, *context->caps());
if (!context->caps()->isConfigRenderable(origConfig, sampleCount > 0)) {
// Fall back from whatever ct was to default of kRGBA or kBGRA which is aliased as kN32
ct = kN32_SkColorType;
}
const SkImageInfo info = SkImageInfo::Make(origInfo.width(), origInfo.height(), ct, at, pt);
GrSurfaceDesc desc;