skia2/tests/GrSlugTest.cpp
Herb Derby 22960eb7b2 don't produce empty slugs!
The current system short circuits out when an SkTextBlob will draw
anything based on its bounds, the bounds of the clip, and the state
of the paint.

A similar thing needs to happen, but the clip needs to be ignored.
Return the nullptr if the SkTextBlob would never draw to signal that
the Slug can be ignored.

Bug: chromium:1277583

Change-Id: I2d6641e03c88ae5f160c479c9e715ad8dc9f65b3
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/481592
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Herb Derby <herb@google.com>
2021-12-08 20:34:41 +00:00

47 lines
1.5 KiB
C++

/*
* Copyright 2021 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "include/core/SkTextBlob.h"
#include "include/private/chromium/GrSlug.h"
#include "src/gpu/GrDirectContextPriv.h"
#include "tests/Test.h"
#include "tools/ToolUtils.h"
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrSlug_empty, reporter, ctxInfo) {
auto dContext = ctxInfo.directContext();
SkImageInfo info = SkImageInfo::MakeN32Premul(256, 256);
auto surface(SkSurface::MakeRenderTarget(dContext, SkBudgeted::kNo, info));
auto canvas = surface->getCanvas();
static const char* kText = " ";
auto typeface = ToolUtils::create_portable_typeface("serif", SkFontStyle());
SkFont font(typeface);
size_t txtLen = strlen(kText);
int glyphCount = font.countText(kText, txtLen, SkTextEncoding::kUTF8);
SkTDArray<uint16_t> glyphs;
glyphs.append(glyphCount);
font.textToGlyphs(kText, txtLen, SkTextEncoding::kUTF8, glyphs.begin(), glyphCount);
SkTextBlobBuilder builder;
font.setSubpixel(true);
font.setEdging(SkFont::Edging::kAntiAlias);
font.setTypeface(typeface);
font.setSize(16);
const SkTextBlobBuilder::RunBuffer& buf = builder.allocRun(font, glyphs.count(), 0, 0);
memcpy(buf.glyphs, glyphs.begin(), glyphs.count() * sizeof(uint16_t));
auto blob = builder.make();
SkPaint p;
p.setAntiAlias(true);
sk_sp<GrSlug> slug = GrSlug::ConvertBlob(canvas, *blob, {10, 10}, p);
REPORTER_ASSERT(reporter, slug == nullptr);
}