Flutter Engine
The Flutter Engine
clip_error.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 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 "gm/gm.h"
12#include "include/core/SkFont.h"
15#include "include/core/SkRect.h"
18#include "include/core/SkSize.h"
22#include "src/core/SkBlurMask.h"
23#include "tools/ToolUtils.h"
25
26#include <string.h>
27
28#define WIDTH 800
29#define HEIGHT 800
30
31static void draw_text(SkCanvas* canvas, sk_sp<SkTextBlob> blob,
32 const SkPaint& paint, const SkPaint& blurPaint,
33 const SkPaint& clearPaint) {
34 canvas->save();
35 canvas->clipRect(SkRect::MakeLTRB(0, 0, 1081, 665));
36 canvas->drawRect(SkRect::MakeLTRB(0, 0, 1081, 665), clearPaint);
37 // draw as blurred to push glyph to be too large for atlas
38 canvas->drawTextBlob(blob, 0, 256, blurPaint);
39 canvas->drawTextBlob(blob, 0, 477, paint);
40 canvas->restore();
41}
42
43// This test ensures that glyphs that are too large for the atlas
44// are both translated and clipped correctly.
45class ClipErrorGM : public skiagm::GM {
46public:
48
49protected:
50 SkString getName() const override { return SkString("cliperror"); }
51
52 SkISize getISize() override { return SkISize::Make(WIDTH, HEIGHT); }
53
54 void onDraw(SkCanvas* canvas) override {
56 paint.setAntiAlias(true);
57
59
60 // setup up maskfilter
62
63 SkPaint blurPaint(paint);
65
66 const char text[] = "hambur";
67 auto blob = SkTextBlob::MakeFromText(text, strlen(text), font);
68
69 SkPaint clearPaint(paint);
70 clearPaint.setColor(SK_ColorWHITE);
71
72 canvas->save();
73 canvas->translate(0, 0);
74 canvas->clipRect(SkRect::MakeLTRB(0, 0, WIDTH, 256));
75 draw_text(canvas, blob, paint, blurPaint, clearPaint);
76 canvas->restore();
77
78 canvas->save();
79 canvas->translate(0, 256);
80 canvas->clipRect(SkRect::MakeLTRB(0, 256, WIDTH, 510));
81 draw_text(canvas, blob, paint, blurPaint, clearPaint);
82 canvas->restore();
83 }
84
85private:
86 using INHERITED = skiagm::GM;
87};
88
89DEF_GM(return new ClipErrorGM;)
@ kNormal_SkBlurStyle
fuzzy inside and outside
Definition: SkBlurTypes.h:12
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
#define SkIntToScalar(x)
Definition: SkScalar.h:57
SkString getName() const override
Definition: clip_error.cpp:50
void onDraw(SkCanvas *canvas) override
Definition: clip_error.cpp:54
SkISize getISize() override
Definition: clip_error.cpp:52
static SkScalar SK_SPI ConvertRadiusToSigma(SkScalar radius)
Definition: SkBlurMask.cpp:39
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
int save()
Definition: SkCanvas.cpp:447
void drawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
Definition: SkCanvas.cpp:2484
Definition: SkFont.h:35
static sk_sp< SkMaskFilter > MakeBlur(SkBlurStyle style, SkScalar sigma, bool respectCTM=true)
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setMaskFilter(sk_sp< SkMaskFilter > maskFilter)
static sk_sp< SkTextBlob > MakeFromText(const void *text, size_t byteLength, const SkFont &font, SkTextEncoding encoding=SkTextEncoding::kUTF8)
Definition: SkTextBlob.cpp:788
Definition: gm.h:110
#define WIDTH
Definition: clip_error.cpp:28
static void draw_text(SkCanvas *canvas, sk_sp< SkTextBlob > blob, const SkPaint &paint, const SkPaint &blurPaint, const SkPaint &clearPaint)
Definition: clip_error.cpp:31
#define HEIGHT
Definition: clip_error.cpp:29
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
#define DEF_GM(CODE)
Definition: gm.h:40
std::u16string text
sk_sp< SkTypeface > DefaultPortableTypeface()
font
Font Metadata and Metrics.
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646