2015-07-17 19:47:39 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/ToolUtils.h"
|
2015-08-21 18:08:00 +00:00
|
|
|
|
2019-09-12 14:58:26 +00:00
|
|
|
#include <string>
|
|
|
|
|
2020-12-23 15:11:33 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkFontMgr.h"
|
|
|
|
#include "include/core/SkGraphics.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPoint.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
|
|
|
#include "include/core/SkTextBlob.h"
|
|
|
|
#include "include/core/SkTypeface.h"
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkGlyphRun.h"
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/fonts/RandomScalerContext.h"
|
2015-07-17 19:47:39 +00:00
|
|
|
|
|
|
|
#ifdef SK_BUILD_FOR_WIN
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/ports/SkTypeface_win.h"
|
2015-07-17 19:47:39 +00:00
|
|
|
#endif
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/Test.h"
|
2015-07-17 19:47:39 +00:00
|
|
|
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
2020-04-06 17:57:30 +00:00
|
|
|
#include "src/gpu/text/GrAtlasManager.h"
|
2020-06-26 16:50:38 +00:00
|
|
|
#include "src/gpu/text/GrTextBlobCache.h"
|
2015-07-17 19:47:39 +00:00
|
|
|
|
2016-09-13 17:00:23 +00:00
|
|
|
static void draw(SkCanvas* canvas, int redraw, const SkTArray<sk_sp<SkTextBlob>>& blobs) {
|
2015-07-22 18:00:32 +00:00
|
|
|
int yOffset = 0;
|
2015-07-17 19:47:39 +00:00
|
|
|
for (int r = 0; r < redraw; r++) {
|
|
|
|
for (int i = 0; i < blobs.count(); i++) {
|
2016-09-13 17:00:23 +00:00
|
|
|
const auto& blob = blobs[i];
|
2015-07-22 18:00:32 +00:00
|
|
|
const SkRect& bounds = blob->bounds();
|
|
|
|
yOffset += SkScalarCeilToInt(bounds.height());
|
2015-07-17 19:47:39 +00:00
|
|
|
SkPaint paint;
|
2015-07-22 18:00:32 +00:00
|
|
|
canvas->drawTextBlob(blob, 0, SkIntToScalar(yOffset), paint);
|
2015-07-17 19:47:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-23 15:30:25 +00:00
|
|
|
static const int kWidth = 1024;
|
|
|
|
static const int kHeight = 768;
|
2015-07-17 19:47:39 +00:00
|
|
|
|
2020-07-17 19:40:13 +00:00
|
|
|
static void setup_always_evict_atlas(GrDirectContext* dContext) {
|
|
|
|
dContext->priv().getAtlasManager()->setAtlasDimensionsToMinimum_ForTesting();
|
2018-09-04 17:27:00 +00:00
|
|
|
}
|
|
|
|
|
2020-06-26 16:50:38 +00:00
|
|
|
class GrTextBlobTestingPeer {
|
|
|
|
public:
|
|
|
|
static void SetBudget(GrTextBlobCache* cache, size_t budget) {
|
2020-07-23 17:24:53 +00:00
|
|
|
SkAutoSpinlock lock{cache->fSpinLock};
|
2020-06-26 16:50:38 +00:00
|
|
|
cache->fSizeBudget = budget;
|
|
|
|
cache->internalCheckPurge();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-07-17 19:47:39 +00:00
|
|
|
// This test hammers the GPU textblobcache and font atlas
|
2020-07-17 19:40:13 +00:00
|
|
|
static void text_blob_cache_inner(skiatest::Reporter* reporter, GrDirectContext* dContext,
|
2015-08-21 18:08:00 +00:00
|
|
|
int maxTotalText, int maxGlyphID, int maxFamilies, bool normal,
|
|
|
|
bool stressTest) {
|
2015-07-17 19:47:39 +00:00
|
|
|
// setup surface
|
|
|
|
uint32_t flags = 0;
|
2020-09-24 18:49:00 +00:00
|
|
|
SkSurfaceProps props(flags, kRGB_H_SkPixelGeometry);
|
2015-07-17 19:47:39 +00:00
|
|
|
|
2015-08-21 18:08:00 +00:00
|
|
|
// configure our context for maximum stressing of cache and atlas
|
|
|
|
if (stressTest) {
|
2020-07-17 19:40:13 +00:00
|
|
|
setup_always_evict_atlas(dContext);
|
|
|
|
GrTextBlobTestingPeer::SetBudget(dContext->priv().getTextBlobCache(), 0);
|
2015-08-21 18:08:00 +00:00
|
|
|
}
|
|
|
|
|
2019-03-26 15:10:11 +00:00
|
|
|
SkImageInfo info = SkImageInfo::Make(kWidth, kHeight, kRGBA_8888_SkColorType,
|
|
|
|
kPremul_SkAlphaType);
|
2020-07-17 19:40:13 +00:00
|
|
|
auto surface(SkSurface::MakeRenderTarget(dContext, SkBudgeted::kNo, info, 0, &props));
|
2015-07-17 19:47:39 +00:00
|
|
|
REPORTER_ASSERT(reporter, surface);
|
|
|
|
if (!surface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkCanvas* canvas = surface->getCanvas();
|
|
|
|
|
2016-11-04 15:49:42 +00:00
|
|
|
sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault());
|
2015-07-17 19:47:39 +00:00
|
|
|
|
2020-02-06 16:25:43 +00:00
|
|
|
int count = std::min(fm->countFamilies(), maxFamilies);
|
2015-07-17 19:47:39 +00:00
|
|
|
|
|
|
|
// make a ton of text
|
2015-07-31 18:45:22 +00:00
|
|
|
SkAutoTArray<uint16_t> text(maxTotalText);
|
|
|
|
for (int i = 0; i < maxTotalText; i++) {
|
|
|
|
text[i] = i % maxGlyphID;
|
2015-07-17 19:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// generate textblobs
|
2016-09-13 17:00:23 +00:00
|
|
|
SkTArray<sk_sp<SkTextBlob>> blobs;
|
2015-07-17 19:47:39 +00:00
|
|
|
for (int i = 0; i < count; i++) {
|
2018-11-23 18:08:33 +00:00
|
|
|
SkFont font;
|
|
|
|
font.setSize(48); // draw big glyphs to really stress the atlas
|
2015-07-17 19:47:39 +00:00
|
|
|
|
|
|
|
SkString familyName;
|
|
|
|
fm->getFamilyName(i, &familyName);
|
2016-11-04 15:49:42 +00:00
|
|
|
sk_sp<SkFontStyleSet> set(fm->createStyleSet(i));
|
2015-07-17 19:47:39 +00:00
|
|
|
for (int j = 0; j < set->count(); ++j) {
|
|
|
|
SkFontStyle fs;
|
2015-08-27 14:41:13 +00:00
|
|
|
set->getStyle(j, &fs, nullptr);
|
2015-07-17 19:47:39 +00:00
|
|
|
|
2015-07-31 18:45:22 +00:00
|
|
|
// We use a typeface which randomy returns unexpected mask formats to fuzz
|
2016-05-12 17:09:30 +00:00
|
|
|
sk_sp<SkTypeface> orig(set->createTypeface(j));
|
2015-07-31 18:45:22 +00:00
|
|
|
if (normal) {
|
2018-11-23 18:08:33 +00:00
|
|
|
font.setTypeface(orig);
|
2015-07-31 18:45:22 +00:00
|
|
|
} else {
|
2018-11-23 18:08:33 +00:00
|
|
|
font.setTypeface(sk_make_sp<SkRandomTypeface>(orig, SkPaint(), true));
|
2015-07-31 18:45:22 +00:00
|
|
|
}
|
2015-07-17 19:47:39 +00:00
|
|
|
|
|
|
|
SkTextBlobBuilder builder;
|
|
|
|
for (int aa = 0; aa < 2; aa++) {
|
|
|
|
for (int subpixel = 0; subpixel < 2; subpixel++) {
|
|
|
|
for (int lcd = 0; lcd < 2; lcd++) {
|
2018-11-23 18:08:33 +00:00
|
|
|
font.setEdging(SkFont::Edging::kAlias);
|
|
|
|
if (aa) {
|
|
|
|
font.setEdging(SkFont::Edging::kAntiAlias);
|
|
|
|
if (lcd) {
|
|
|
|
font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
font.setSubpixel(SkToBool(subpixel));
|
2015-07-31 18:45:22 +00:00
|
|
|
if (!SkToBool(lcd)) {
|
2018-11-23 18:08:33 +00:00
|
|
|
font.setSize(160);
|
2015-07-31 18:45:22 +00:00
|
|
|
}
|
2018-11-23 18:08:33 +00:00
|
|
|
const SkTextBlobBuilder::RunBuffer& run = builder.allocRun(font,
|
2015-07-31 18:45:22 +00:00
|
|
|
maxTotalText,
|
2015-07-17 19:47:39 +00:00
|
|
|
0, 0,
|
2015-08-27 14:41:13 +00:00
|
|
|
nullptr);
|
2015-07-31 18:45:22 +00:00
|
|
|
memcpy(run.glyphs, text.get(), maxTotalText * sizeof(uint16_t));
|
2015-07-17 19:47:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-13 17:00:23 +00:00
|
|
|
blobs.emplace_back(builder.make());
|
2015-07-17 19:47:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-23 15:30:25 +00:00
|
|
|
// create surface where LCD is impossible
|
2019-03-26 15:10:11 +00:00
|
|
|
info = SkImageInfo::Make(kWidth, kHeight, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
2015-07-23 15:30:25 +00:00
|
|
|
SkSurfaceProps propsNoLCD(0, kUnknown_SkPixelGeometry);
|
2016-03-24 01:59:25 +00:00
|
|
|
auto surfaceNoLCD(canvas->makeSurface(info, &propsNoLCD));
|
2015-07-23 15:30:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, surface);
|
|
|
|
if (!surface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkCanvas* canvasNoLCD = surfaceNoLCD->getCanvas();
|
|
|
|
|
2015-07-17 19:47:39 +00:00
|
|
|
// test redraw
|
|
|
|
draw(canvas, 2, blobs);
|
2015-07-23 15:30:25 +00:00
|
|
|
draw(canvasNoLCD, 2, blobs);
|
2015-07-17 19:47:39 +00:00
|
|
|
|
|
|
|
// test draw after free
|
2020-07-17 19:40:13 +00:00
|
|
|
dContext->freeGpuResources();
|
2015-07-17 19:47:39 +00:00
|
|
|
draw(canvas, 1, blobs);
|
|
|
|
|
2020-07-17 19:40:13 +00:00
|
|
|
dContext->freeGpuResources();
|
2015-07-23 15:30:25 +00:00
|
|
|
draw(canvasNoLCD, 1, blobs);
|
|
|
|
|
2015-07-17 19:47:39 +00:00
|
|
|
// test draw after abandon
|
2020-07-17 19:40:13 +00:00
|
|
|
dContext->abandonContext();
|
2015-07-17 19:47:39 +00:00
|
|
|
draw(canvas, 1, blobs);
|
|
|
|
}
|
2015-07-31 18:45:22 +00:00
|
|
|
|
2019-03-26 15:10:11 +00:00
|
|
|
DEF_GPUTEST_FOR_MOCK_CONTEXT(TextBlobCache, reporter, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
text_blob_cache_inner(reporter, ctxInfo.directContext(), 1024, 256, 30, true, false);
|
2015-08-21 18:08:00 +00:00
|
|
|
}
|
|
|
|
|
2019-03-26 15:10:11 +00:00
|
|
|
DEF_GPUTEST_FOR_MOCK_CONTEXT(TextBlobStressCache, reporter, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
text_blob_cache_inner(reporter, ctxInfo.directContext(), 256, 256, 10, true, true);
|
2015-07-31 18:45:22 +00:00
|
|
|
}
|
|
|
|
|
2019-03-26 15:10:11 +00:00
|
|
|
DEF_GPUTEST_FOR_MOCK_CONTEXT(TextBlobAbnormal, reporter, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
text_blob_cache_inner(reporter, ctxInfo.directContext(), 256, 256, 10, false, false);
|
2015-08-21 18:08:00 +00:00
|
|
|
}
|
|
|
|
|
2019-03-26 15:10:11 +00:00
|
|
|
DEF_GPUTEST_FOR_MOCK_CONTEXT(TextBlobStressAbnormal, reporter, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
text_blob_cache_inner(reporter, ctxInfo.directContext(), 256, 256, 10, false, true);
|
2015-07-31 18:45:22 +00:00
|
|
|
}
|
2019-09-12 14:58:26 +00:00
|
|
|
|
|
|
|
static const int kScreenDim = 160;
|
|
|
|
|
|
|
|
static SkBitmap draw_blob(SkTextBlob* blob, SkSurface* surface, SkPoint offset) {
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
|
|
|
|
SkCanvas* canvas = surface->getCanvas();
|
|
|
|
canvas->save();
|
|
|
|
canvas->drawColor(SK_ColorWHITE, SkBlendMode::kSrc);
|
|
|
|
canvas->translate(offset.fX, offset.fY);
|
|
|
|
canvas->drawTextBlob(blob, 0, 0, paint);
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.allocN32Pixels(kScreenDim, kScreenDim);
|
|
|
|
surface->readPixels(bitmap, 0, 0);
|
|
|
|
canvas->restore();
|
|
|
|
return bitmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool compare_bitmaps(const SkBitmap& expected, const SkBitmap& actual) {
|
|
|
|
SkASSERT(expected.width() == actual.width());
|
|
|
|
SkASSERT(expected.height() == actual.height());
|
|
|
|
for (int i = 0; i < expected.width(); ++i) {
|
|
|
|
for (int j = 0; j < expected.height(); ++j) {
|
|
|
|
SkColor expectedColor = expected.getColor(i, j);
|
|
|
|
SkColor actualColor = actual.getColor(i, j);
|
|
|
|
if (expectedColor != actualColor) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static sk_sp<SkTextBlob> make_blob() {
|
|
|
|
auto tf = SkTypeface::MakeFromName("Roboto2-Regular", SkFontStyle());
|
|
|
|
SkFont font;
|
|
|
|
font.setTypeface(tf);
|
|
|
|
font.setSubpixel(false);
|
|
|
|
font.setEdging(SkFont::Edging::kAlias);
|
|
|
|
font.setSize(24);
|
|
|
|
|
|
|
|
static char text[] = "HekpqB";
|
|
|
|
static const int maxGlyphLen = sizeof(text) * 4;
|
|
|
|
SkGlyphID glyphs[maxGlyphLen];
|
|
|
|
int glyphCount =
|
|
|
|
font.textToGlyphs(text, sizeof(text), SkTextEncoding::kUTF8, glyphs, maxGlyphLen);
|
|
|
|
|
|
|
|
SkTextBlobBuilder builder;
|
|
|
|
const auto& runBuffer = builder.allocRun(font, glyphCount, 0, 0);
|
|
|
|
for (int i = 0; i < glyphCount; i++) {
|
|
|
|
runBuffer.glyphs[i] = glyphs[i];
|
|
|
|
}
|
|
|
|
return builder.make();
|
|
|
|
}
|
|
|
|
|
2020-05-22 15:35:02 +00:00
|
|
|
// Turned off to pass on android and ios devices, which were running out of memory..
|
|
|
|
#if 0
|
2020-05-21 18:46:06 +00:00
|
|
|
static sk_sp<SkTextBlob> make_large_blob() {
|
|
|
|
auto tf = SkTypeface::MakeFromName("Roboto2-Regular", SkFontStyle());
|
|
|
|
SkFont font;
|
|
|
|
font.setTypeface(tf);
|
|
|
|
font.setSubpixel(false);
|
|
|
|
font.setEdging(SkFont::Edging::kAlias);
|
|
|
|
font.setSize(24);
|
|
|
|
|
|
|
|
const int mallocSize = 0x3c3c3bd; // x86 size
|
|
|
|
std::unique_ptr<char[]> text{new char[mallocSize + 1]};
|
|
|
|
if (text == nullptr) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < mallocSize; i++) {
|
|
|
|
text[i] = 'x';
|
|
|
|
}
|
|
|
|
text[mallocSize] = 0;
|
|
|
|
|
|
|
|
static const int maxGlyphLen = mallocSize;
|
|
|
|
std::unique_ptr<SkGlyphID[]> glyphs{new SkGlyphID[maxGlyphLen]};
|
|
|
|
int glyphCount =
|
|
|
|
font.textToGlyphs(
|
|
|
|
text.get(), mallocSize, SkTextEncoding::kUTF8, glyphs.get(), maxGlyphLen);
|
|
|
|
SkTextBlobBuilder builder;
|
|
|
|
const auto& runBuffer = builder.allocRun(font, glyphCount, 0, 0);
|
|
|
|
for (int i = 0; i < glyphCount; i++) {
|
|
|
|
runBuffer.glyphs[i] = glyphs[i];
|
|
|
|
}
|
|
|
|
return builder.make();
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextBlobIntegerOverflowTest, reporter, ctxInfo) {
|
2020-07-17 19:40:13 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
2020-05-21 18:46:06 +00:00
|
|
|
const SkImageInfo info =
|
|
|
|
SkImageInfo::Make(kScreenDim, kScreenDim, kN32_SkColorType, kPremul_SkAlphaType);
|
2020-07-17 19:40:13 +00:00
|
|
|
auto surface = SkSurface::MakeRenderTarget(dContext, SkBudgeted::kNo, info);
|
2020-05-21 18:46:06 +00:00
|
|
|
|
|
|
|
auto blob = make_large_blob();
|
|
|
|
int y = 40;
|
|
|
|
SkBitmap base = draw_blob(blob.get(), surface.get(), {40, y + 0.0f});
|
|
|
|
}
|
2020-05-22 15:35:02 +00:00
|
|
|
#endif
|
2020-05-21 18:46:06 +00:00
|
|
|
|
2019-09-12 14:58:26 +00:00
|
|
|
static const bool kDumpPngs = true;
|
|
|
|
// dump pngs needs a "good" and a "bad" directory to put the results in. This allows the use of the
|
|
|
|
// skdiff tool to visualize the differences.
|
|
|
|
|
|
|
|
void write_png(const std::string& filename, const SkBitmap& bitmap) {
|
|
|
|
auto data = SkEncodeBitmap(bitmap, SkEncodedImageFormat::kPNG, 0);
|
|
|
|
SkFILEWStream w{filename.c_str()};
|
|
|
|
w.write(data->data(), data->size());
|
|
|
|
w.fsync();
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextBlobJaggedGlyph, reporter, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto direct = ctxInfo.directContext();
|
2019-09-12 14:58:26 +00:00
|
|
|
const SkImageInfo info =
|
|
|
|
SkImageInfo::Make(kScreenDim, kScreenDim, kN32_SkColorType, kPremul_SkAlphaType);
|
2020-07-06 14:56:46 +00:00
|
|
|
auto surface = SkSurface::MakeRenderTarget(direct, SkBudgeted::kNo, info);
|
2019-09-12 14:58:26 +00:00
|
|
|
|
|
|
|
auto blob = make_blob();
|
|
|
|
|
|
|
|
for (int y = 40; y < kScreenDim - 40; y++) {
|
|
|
|
SkBitmap base = draw_blob(blob.get(), surface.get(), {40, y + 0.0f});
|
|
|
|
SkBitmap half = draw_blob(blob.get(), surface.get(), {40, y + 0.5f});
|
|
|
|
SkBitmap unit = draw_blob(blob.get(), surface.get(), {40, y + 1.0f});
|
|
|
|
bool isOk = compare_bitmaps(base, half) || compare_bitmaps(unit, half);
|
|
|
|
REPORTER_ASSERT(reporter, isOk);
|
|
|
|
if (!isOk) {
|
|
|
|
if (kDumpPngs) {
|
|
|
|
{
|
|
|
|
std::string filename = "bad/half-y" + std::to_string(y) + ".png";
|
|
|
|
write_png(filename, half);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
std::string filename = "good/half-y" + std::to_string(y) + ".png";
|
|
|
|
write_png(filename, base);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Testing the x direction across all platforms does not workout, because letter spacing can
|
|
|
|
// change based on non-integer advance widths, but this has been useful for diagnosing problems.
|
|
|
|
#if 0
|
|
|
|
blob = make_blob();
|
|
|
|
for (int x = 40; x < kScreenDim - 40; x++) {
|
|
|
|
SkBitmap base = draw_blob(blob.get(), surface.get(), {x + 0.0f, 40});
|
|
|
|
SkBitmap half = draw_blob(blob.get(), surface.get(), {x + 0.5f, 40});
|
|
|
|
SkBitmap unit = draw_blob(blob.get(), surface.get(), {x + 1.0f, 40});
|
|
|
|
bool isOk = compare_bitmaps(base, half) || compare_bitmaps(unit, half);
|
|
|
|
REPORTER_ASSERT(reporter, isOk);
|
|
|
|
if (!isOk) {
|
|
|
|
if (kDumpPngs) {
|
|
|
|
{
|
|
|
|
std::string filename = "bad/half-x" + std::to_string(x) + ".png";
|
|
|
|
write_png(filename, half);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
std::string filename = "good/half-x" + std::to_string(x) + ".png";
|
|
|
|
write_png(filename, base);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextBlobSmoothScroll, reporter, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto direct = ctxInfo.directContext();
|
2019-09-12 14:58:26 +00:00
|
|
|
const SkImageInfo info =
|
|
|
|
SkImageInfo::Make(kScreenDim, kScreenDim, kN32_SkColorType, kPremul_SkAlphaType);
|
2020-07-06 14:56:46 +00:00
|
|
|
auto surface = SkSurface::MakeRenderTarget(direct, SkBudgeted::kNo, info);
|
2019-09-12 14:58:26 +00:00
|
|
|
|
|
|
|
auto movingBlob = make_blob();
|
|
|
|
|
|
|
|
for (SkScalar y = 40; y < 50; y += 1.0/8.0) {
|
|
|
|
auto expectedBlob = make_blob();
|
|
|
|
auto expectedBitMap = draw_blob(expectedBlob.get(), surface.get(), {40, y});
|
|
|
|
auto movingBitmap = draw_blob(movingBlob.get(), surface.get(), {40, y});
|
|
|
|
bool isOk = compare_bitmaps(expectedBitMap, movingBitmap);
|
|
|
|
REPORTER_ASSERT(reporter, isOk);
|
|
|
|
if (!isOk) {
|
|
|
|
if (kDumpPngs) {
|
|
|
|
{
|
|
|
|
std::string filename = "bad/scroll-y" + std::to_string(y) + ".png";
|
|
|
|
write_png(filename, movingBitmap);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
std::string filename = "good/scroll-y" + std::to_string(y) + ".png";
|
|
|
|
write_png(filename, expectedBitMap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|