blob: 32c329d30b970c32cda0ea1774fb642542c23c32 [file] [log] [blame]
Herb Derby5d9d8372020-09-23 12:00:53 -04001/*
2 * Copyright 2020 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "include/core/SkCanvas.h"
9#include "include/core/SkSurface.h"
10#include "include/core/SkTextBlob.h"
11#include "src/core/SkSurfacePriv.h"
12#include "tests/Test.h"
13#include "tools/ToolUtils.h"
14
15SkBitmap rasterize_blob(SkTextBlob* blob,
16 const SkPaint& paint,
17 GrRecordingContext* rContext,
18 const SkMatrix& matrix) {
19 const SkImageInfo info =
20 SkImageInfo::Make(500, 500, kN32_SkColorType, kPremul_SkAlphaType);
21 auto surface = SkSurface::MakeRenderTarget(rContext, SkBudgeted::kNo, info);
22 auto canvas = surface->getCanvas();
23 canvas->drawColor(SK_ColorWHITE);
24 canvas->concat(matrix);
25 canvas->drawTextBlob(blob, 10, 250, paint);
26 SkBitmap bitmap;
27 bitmap.allocN32Pixels(500, 500);
28 surface->readPixels(bitmap, 0, 0);
29 return bitmap;
30}
31
32bool check_for_black(const SkBitmap& bm) {
33 for (int y = 0; y < bm.height(); y++) {
34 for (int x = 0; x < bm.width(); x++) {
35 if (bm.getColor(x, y) == SK_ColorBLACK) {
36 return true;
37 }
38 }
39 }
40 return false;
41}
42
43DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrTextBlobScaleAnimation, reporter, ctxInfo) {
44 auto tf = ToolUtils::create_portable_typeface("Mono", SkFontStyle());
45 SkFont font{tf};
46 font.setHinting(SkFontHinting::kNormal);
47 font.setSize(12);
48 font.setEdging(SkFont::Edging::kAntiAlias);
49 font.setSubpixel(true);
50
51 SkTextBlobBuilder builder;
52 const auto& runBuffer = builder.allocRunPosH(font, 30, 0, nullptr);
53
54 for (int i = 0; i < 30; i++) {
55 runBuffer.glyphs[i] = static_cast<SkGlyphID>(i);
56 runBuffer.pos[i] = SkIntToScalar(i);
57 }
58 auto blob = builder.make();
59
60 auto dContext = ctxInfo.directContext();
61 bool anyBlack = false;
62 for (int n = -13; n < 5; n++) {
63 SkMatrix m = SkMatrix::Scale(std::exp2(n), std::exp2(n));
64 auto bm = rasterize_blob(blob.get(), SkPaint(), dContext, m);
65 anyBlack |= check_for_black(bm);
66 }
67 REPORTER_ASSERT(reporter, anyBlack);
68}