paint is losing its text-related fields

Bug: skia:
Change-Id: I187c290f30259564e8ff396b54070ca305da3954
Reviewed-on: https://skia-review.googlesource.com/c/181400
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
Auto-Submit: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2019-01-04 15:57:33 -05:00 committed by Skia Commit-Bot
parent 8061ba8570
commit d5cdc2cd4d
6 changed files with 22 additions and 26 deletions

View File

@ -106,12 +106,13 @@ int find(T* array, int N, T item) {
static void draw(SkCanvas* canvas,
const SkPaint& p,
const SkFont& font,
const SkBitmap& src,
SkColorType colorType,
const char text[]) {
SkASSERT(src.colorType() == colorType);
canvas->drawBitmap(src, 0.0f, 0.0f);
canvas->drawString(text, 0.0f, 12.0f, p);
canvas->drawSimpleText(text, strlen(text), kUTF8_SkTextEncoding, 0.0f, 12.0f, font, p);
}
DEF_SIMPLE_GM(all_bitmap_configs, canvas, SCALE, 6 * SCALE) {
@ -119,28 +120,29 @@ DEF_SIMPLE_GM(all_bitmap_configs, canvas, SCALE, 6 * SCALE) {
SkPaint p;
p.setColor(SK_ColorBLACK);
p.setAntiAlias(true);
sk_tool_utils::set_portable_typeface(&p, nullptr);
SkFont font(sk_tool_utils::create_portable_typeface());
sk_tool_utils::draw_checkerboard(canvas, SK_ColorLTGRAY, SK_ColorWHITE, 8);
SkBitmap bitmap;
if (GetResourceAsBitmap("images/color_wheel.png", &bitmap)) {
bitmap.setImmutable();
draw(canvas, p, bitmap, kN32_SkColorType, "Native 32");
draw(canvas, p, font, bitmap, kN32_SkColorType, "Native 32");
canvas->translate(0.0f, SkIntToScalar(SCALE));
SkBitmap copy565 = copy_bitmap(bitmap, kRGB_565_SkColorType);
p.setColor(SK_ColorRED);
draw(canvas, p, copy565, kRGB_565_SkColorType, "RGB 565");
draw(canvas, p, font, copy565, kRGB_565_SkColorType, "RGB 565");
p.setColor(SK_ColorBLACK);
canvas->translate(0.0f, SkIntToScalar(SCALE));
SkBitmap copy4444 = copy_bitmap(bitmap, kARGB_4444_SkColorType);
draw(canvas, p, copy4444, kARGB_4444_SkColorType, "ARGB 4444");
draw(canvas, p, font, copy4444, kARGB_4444_SkColorType, "ARGB 4444");
canvas->translate(0.0f, SkIntToScalar(SCALE));
SkBitmap copyF16 = copy_bitmap(bitmap, kRGBA_F16_SkColorType);
draw(canvas, p, copyF16, kRGBA_F16_SkColorType, "RGBA F16");
draw(canvas, p, font, copyF16, kRGBA_F16_SkColorType, "RGBA F16");
} else {
canvas->translate(0.0f, SkIntToScalar(3 * SCALE));
@ -148,12 +150,12 @@ DEF_SIMPLE_GM(all_bitmap_configs, canvas, SCALE, 6 * SCALE) {
canvas->translate(0.0f, SkIntToScalar(SCALE));
SkBitmap bitmapA8 = make_bitmap(kAlpha_8_SkColorType);
draw(canvas, p, bitmapA8, kAlpha_8_SkColorType, "Alpha 8");
draw(canvas, p, font, bitmapA8, kAlpha_8_SkColorType, "Alpha 8");
p.setColor(SK_ColorRED);
canvas->translate(0.0f, SkIntToScalar(SCALE));
SkBitmap bitmapG8 = make_bitmap(kGray_8_SkColorType);
draw(canvas, p, bitmapG8, kGray_8_SkColorType, "Gray 8");
draw(canvas, p, font, bitmapG8, kGray_8_SkColorType, "Gray 8");
}
sk_sp<SkImage> make_not_native32_color_wheel() {

View File

@ -26,13 +26,14 @@ public:
*/
enum Bits {
kStyle_Bit = 1 << 0, //!< use this layer's Style/stroke settings
kTextSkewX_Bit = 1 << 1, //!< use this layer's textskewx
kPathEffect_Bit = 1 << 2, //!< use this layer's patheffect
kMaskFilter_Bit = 1 << 3, //!< use this layer's maskfilter
kShader_Bit = 1 << 4, //!< use this layer's shader
kColorFilter_Bit = 1 << 5, //!< use this layer's colorfilter
kXfermode_Bit = 1 << 6, //!< use this layer's xfermode
// unsupported kTextSkewX_Bit = 1 << 1,
/**
* Use the layer's paint entirely, with these exceptions:
* - We never override the draw's paint's text_encoding, since that is

View File

@ -79,6 +79,10 @@ public:
return paint.getTypeface() ? paint.refTypeface() : SkTypeface::MakeDefault();
}
static SkTextEncoding GetEncoding(const SkPaint& paint) {
return paint.getTextEncoding();
}
/** Serializes SkPaint into a buffer. A companion unflatten() call
can reconstitute the paint at a later time.

View File

@ -78,7 +78,7 @@ public:
fCount = 0;
} else {
fCount = SkPaintPriv::ValidCountText(fText, fByteLength,
paint->getTextEncoding());
SkPaintPriv::GetEncoding(*paint));
reader->validate(fCount > 0);
}
}
@ -461,7 +461,7 @@ void SkPicturePlayback::handleOp(SkReadBuffer* reader,
if (paint && text.text()) {
SkFont font = SkFont::LEGACY_ExtractFromPaint(*paint);
auto blob = SkTextBlob::MakeFromPosText(text.text(), text.length(), pos, font,
paint->getTextEncoding());
SkPaintPriv::GetEncoding(*paint));
canvas->drawTextBlob(blob, 0, 0, *paint);
}
} break;
@ -479,7 +479,7 @@ void SkPicturePlayback::handleOp(SkReadBuffer* reader,
if (top < clip.fBottom && bottom > clip.fTop && paint && text.text()) {
SkFont font = SkFont::LEGACY_ExtractFromPaint(*paint);
auto blob = SkTextBlob::MakeFromPosText(text.text(), text.length(), pos, font,
paint->getTextEncoding());
SkPaintPriv::GetEncoding(*paint));
canvas->drawTextBlob(blob, 0, 0, *paint);
}
} break;
@ -495,7 +495,7 @@ void SkPicturePlayback::handleOp(SkReadBuffer* reader,
if (paint && text.text()) {
SkFont font = SkFont::LEGACY_ExtractFromPaint(*paint);
auto blob = SkTextBlob::MakeFromPosTextH(text.text(), text.length(), xpos, constY,
font, paint->getTextEncoding());
font, SkPaintPriv::GetEncoding(*paint));
canvas->drawTextBlob(blob, 0, 0, *paint);
}
} break;
@ -515,7 +515,7 @@ void SkPicturePlayback::handleOp(SkReadBuffer* reader,
if (top < clip.fBottom && bottom > clip.fTop && paint && text.text()) {
SkFont font = SkFont::LEGACY_ExtractFromPaint(*paint);
auto blob = SkTextBlob::MakeFromPosTextH(text.text(), text.length(), xpos, constY,
font, paint->getTextEncoding());
font, SkPaintPriv::GetEncoding(*paint));
canvas->drawTextBlob(blob, 0, 0, *paint);
}
} break;
@ -634,7 +634,7 @@ void SkPicturePlayback::handleOp(SkReadBuffer* reader,
if (text.text()) {
SkFont font = SkFont::LEGACY_ExtractFromPaint(*paint);
auto blob = SkTextBlob::MakeFromRSXform(text.text(), text.length(), xform, font,
paint->getTextEncoding());
SkPaintPriv::GetEncoding(*paint));
canvas->drawTextBlob(blob, 0, 0, *paint);
}
} break;

View File

@ -79,7 +79,6 @@ void SkLayerDrawLooper::LayerDrawLooperContext::ApplyInfo(
sk_srgb_singleton());
BitFlags bits = info.fPaintBits;
SkTextEncoding encoding = dst->getTextEncoding();
if (0 == bits) {
return;
@ -91,7 +90,6 @@ void SkLayerDrawLooper::LayerDrawLooperContext::ApplyInfo(
*dst = src;
dst->setFlags(f);
dst->setColor4f(c, sk_srgb_singleton());
dst->setTextEncoding(encoding);
return;
}
@ -103,10 +101,6 @@ void SkLayerDrawLooper::LayerDrawLooperContext::ApplyInfo(
dst->setStrokeJoin(src.getStrokeJoin());
}
if (bits & kTextSkewX_Bit) {
dst->setTextSkewX(src.getTextSkewX());
}
if (bits & kPathEffect_Bit) {
dst->setPathEffect(src.refPathEffect());
}

View File

@ -46,11 +46,6 @@ static void test_font(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, font.getTypeface() == newFont.getTypeface());
REPORTER_ASSERT(reporter, 36 == newFont.getSize()); // double check we haven't changed
REPORTER_ASSERT(reporter, 24 == font.getSize()); // double check we haven't changed
SkPaint paint;
paint.setTextSize(18);
font = SkFont::LEGACY_ExtractFromPaint(paint);
REPORTER_ASSERT(reporter, font.getSize() == paint.getTextSize());
}
/*