Flutter Engine
The Flutter Engine
textblobgeometrychange.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm/gm.h"
10#include "include/core/SkFont.h"
13#include "include/core/SkRect.h"
16#include "include/core/SkSize.h"
22#include "tools/ToolUtils.h"
24
25// This tests that we don't try to reuse textblobs from the GPU textblob cache across pixel geometry
26// changes when we have LCD. crbug/486744
27namespace skiagm {
28class TextBlobGeometryChange : public GM {
29public:
31
32protected:
33 SkString getName() const override { return SkString("textblobgeometrychange"); }
34
35 SkISize getISize() override { return SkISize::Make(kWidth, kHeight); }
36
37 void onDraw(SkCanvas* canvas) override {
38 const char text[] = "Hamburgefons";
39
42
44
46
47 sk_sp<SkTextBlob> blob(builder.make());
48
51 auto surface = ToolUtils::makeSurface(canvas, info, &props);
52 SkCanvas* c = surface->getCanvas();
53
54 // LCD text on white background
55 SkRect rect = SkRect::MakeLTRB(0.f, 0.f, SkIntToScalar(kWidth), kHeight / 2.f);
56 SkPaint rectPaint;
57 rectPaint.setColor(0xffffffff);
58 canvas->drawRect(rect, rectPaint);
59 canvas->drawTextBlob(blob, 10, 50, SkPaint());
60
61 // This should not look garbled since we should disable LCD text in this case
62 // (i.e., unknown pixel geometry)
63 c->clear(0x00ffffff);
64 c->drawTextBlob(blob, 10, 150, SkPaint());
65 surface->draw(canvas, 0, 0);
66 }
67
68private:
69 inline static constexpr int kWidth = 200;
70 inline static constexpr int kHeight = 200;
71
72 using INHERITED = GM;
73};
74
75//////////////////////////////////////////////////////////////////////////////
76
77DEF_GM(return new TextBlobGeometryChange;)
78} // namespace skiagm
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
#define SkIntToScalar(x)
Definition: SkScalar.h:57
@ kUnknown_SkPixelGeometry
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void clear(SkColor color)
Definition: SkCanvas.h:1199
void drawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
Definition: SkCanvas.cpp:2484
Definition: SkFont.h:35
@ kSubpixelAntiAlias
glyph positioned in pixel using transparency
void setColor(SkColor color)
Definition: SkPaint.cpp:119
Definition: gm.h:110
GM(SkColor backgroundColor=SK_ColorWHITE)
Definition: gm.cpp:81
void onDraw(SkCanvas *canvas) override
VkSurfaceKHR surface
Definition: main.cc:49
std::u16string text
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
sk_sp< SkTypeface > DefaultPortableTypeface()
sk_sp< SkSurface > makeSurface(SkCanvas *canvas, const SkImageInfo &info, const SkSurfaceProps *props)
Definition: ToolUtils.cpp:512
void add_to_text_blob(SkTextBlobBuilder *builder, const char *text, const SkFont &font, SkScalar x, SkScalar y)
Definition: ToolUtils.cpp:228
font
Font Metadata and Metrics.
DEF_GM(return F(C(clipbox), 0.0f, 0.0f, {})) DEF_GM(return F(C(clipbox)
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static SkImageInfo MakeN32Premul(int width, int height)
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646