add savelayer flag to promote the later to half-float

Bug: skia:9256
Change-Id: Ifd7846349f83854e860306bd475cfba0adeddcb5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/227066
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
This commit is contained in:
Mike Reed 2019-07-12 12:53:11 -04:00 committed by Skia Commit-Bot
parent 57b0b09dfd
commit 1f3548cb05
3 changed files with 34 additions and 1 deletions

View File

@ -440,3 +440,32 @@ DEF_SIMPLE_GM(save_behind, canvas, 830, 670) {
canvas->translate(430, 0);
}
}
#include "include/effects/SkGradientShader.h"
DEF_SIMPLE_GM(savelayer_f16, canvas, 900, 300) {
int n = 15;
SkRect r{0, 0, 300, 300};
SkPaint paint;
const SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorRED };
paint.setShader(SkGradientShader::MakeSweep(r.centerX(), r.centerY(),
colors, nullptr, SK_ARRAY_COUNT(colors)));
canvas->drawOval(r, paint);
paint.setAlphaf(1.0f/n);
paint.setBlendMode(SkBlendMode::kPlus);
for (auto flags : {0, (int)SkCanvas::kF16ColorType}) {
canvas->translate(r.width(), 0);
SkCanvas::SaveLayerRec rec;
rec.fSaveLayerFlags = flags;
canvas->saveLayer(rec);
for (int i = 0; i < n; ++i) {
canvas->drawOval(r, paint);
}
canvas->restore();
}
}

View File

@ -578,7 +578,8 @@ public:
kInitWithPrevious_SaveLayerFlag = 1 << 2, //!< initializes with previous contents
kMaskAgainstCoverage_EXPERIMENTAL_DONT_USE_SaveLayerFlag =
1 << 3, //!< experimental: do not use
// instead of matching previous layer's colortype, use F16
kF16ColorType = 1 << 4,
#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
kDontClipToLayer_Legacy_SaveLayerFlag =
kDontClipToLayer_PrivateSaveLayerFlag, //!< deprecated

View File

@ -1079,6 +1079,9 @@ void SkCanvas::internalSaveLayer(const SaveLayerRec& rec, SaveLayerStrategy stra
}
SkImageInfo info = make_layer_info(priorDevice->imageInfo(), ir.width(), ir.height(), paint);
if (rec.fSaveLayerFlags & kF16ColorType) {
info = info.makeColorType(kRGBA_F16_SkColorType);
}
sk_sp<SkBaseDevice> newDevice;
{