672062da97
The direct mask sub runs were only shifting the device bounds, and never really transforming them. This adds code to do the full bounds transform when the positionMatrix does not represent an integer offset. Add a meaningful clip to the slug GM to demonstrate change. With the old code, the slugs did not respect the clip. Now they do. Bug: chromium:1254726 Change-Id: I1f3ce2b5068ec5824e814ca9ac67c9aeae307187 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/479397 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Herb Derby <herb@google.com>
109 lines
3.2 KiB
C++
109 lines
3.2 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 "gm/gm.h"
|
|
#include "include/core/SkCanvas.h"
|
|
#include "include/core/SkColor.h"
|
|
#include "include/core/SkFont.h"
|
|
#include "include/core/SkFontStyle.h"
|
|
#include "include/core/SkFontTypes.h"
|
|
#include "include/core/SkPaint.h"
|
|
#include "include/core/SkPoint.h"
|
|
#include "include/core/SkRect.h"
|
|
#include "include/core/SkRefCnt.h"
|
|
#include "include/core/SkScalar.h"
|
|
#include "include/core/SkSize.h"
|
|
#include "include/core/SkString.h"
|
|
#include "include/core/SkTextBlob.h"
|
|
#include "include/core/SkTypeface.h"
|
|
#include "include/core/SkTypes.h"
|
|
#include "include/private/SkTDArray.h"
|
|
#include "include/private/chromium/GrSlug.h"
|
|
#include "tools/ToolUtils.h"
|
|
|
|
#if SK_SUPPORT_GPU && defined(SK_EXPERIMENTAL_ADD_ATLAS_PADDING)
|
|
class SlugGM : public skiagm::GM {
|
|
public:
|
|
SlugGM(const char* txt)
|
|
: fText(txt) {
|
|
}
|
|
|
|
protected:
|
|
void onOnceBeforeDraw() override {
|
|
fTypeface = ToolUtils::create_portable_typeface("serif", SkFontStyle());
|
|
SkFont font(fTypeface);
|
|
size_t txtLen = strlen(fText);
|
|
int glyphCount = font.countText(fText, txtLen, SkTextEncoding::kUTF8);
|
|
|
|
fGlyphs.append(glyphCount);
|
|
font.textToGlyphs(fText, txtLen, SkTextEncoding::kUTF8, fGlyphs.begin(), glyphCount);
|
|
}
|
|
|
|
SkString onShortName() override {
|
|
return SkString("slug");
|
|
}
|
|
|
|
SkISize onISize() override {
|
|
return SkISize::Make(1000, 480);
|
|
}
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
|
sk_sp<SkTextBlob> blob(this->makeBlob());
|
|
SkPaint p;
|
|
p.setAntiAlias(true);
|
|
canvas->clipIRect(SkIRect::MakeSize(this->getISize()).makeInset(40, 50));
|
|
canvas->scale(1.3f, 1.3f);
|
|
sk_sp<GrSlug> slug = GrSlug::ConvertBlob(canvas, *blob, {10, 10}, p);
|
|
if (slug == nullptr) {
|
|
return;
|
|
}
|
|
canvas->translate(0.5, 0.5);
|
|
canvas->translate(30, 30);
|
|
canvas->drawTextBlob(blob, 10, 10, p);
|
|
canvas->translate(370, 0);
|
|
slug->draw(canvas);
|
|
for (float scale = 1.5; scale < 4; scale += 0.5) {
|
|
canvas->translate(-370, 20 * scale);
|
|
canvas->save();
|
|
canvas->scale(scale, scale);
|
|
canvas->rotate(5);
|
|
canvas->drawTextBlob(blob, 10, 10, p);
|
|
canvas->restore();
|
|
canvas->translate(370, 0);
|
|
canvas->save();
|
|
canvas->scale(scale, scale);
|
|
canvas->rotate(5);
|
|
|
|
slug->draw(canvas);
|
|
canvas->restore();
|
|
}
|
|
}
|
|
|
|
private:
|
|
sk_sp<SkTextBlob> makeBlob() {
|
|
SkTextBlobBuilder builder;
|
|
|
|
SkFont font;
|
|
font.setSubpixel(true);
|
|
font.setEdging(SkFont::Edging::kAntiAlias);
|
|
font.setTypeface(fTypeface);
|
|
font.setSize(16);
|
|
|
|
const SkTextBlobBuilder::RunBuffer& buf = builder.allocRun(font, fGlyphs.count(), 0, 0);
|
|
memcpy(buf.glyphs, fGlyphs.begin(), fGlyphs.count() * sizeof(uint16_t));
|
|
return builder.make();
|
|
}
|
|
|
|
SkTDArray<uint16_t> fGlyphs;
|
|
sk_sp<SkTypeface> fTypeface;
|
|
const char* fText;
|
|
using INHERITED = skiagm::GM;
|
|
};
|
|
|
|
DEF_GM(return new SlugGM("hamburgefons");)
|
|
#endif
|