Add fixes & test for isConfigTexturable and isConfigRenderable
[platform/upstream/libSkiaSharp.git] / gm / clip_error.cpp
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.h"
9 #include "sk_tool_utils.h"
10 #include "SkBlurMask.h"
11 #include "SkBlurMaskFilter.h"
12 #include "SkCanvas.h"
13 #include "SkTextBlob.h"
14
15 #define WIDTH 800
16 #define HEIGHT 800
17
18 static void draw_text(SkCanvas* canvas, sk_sp<SkTextBlob> blob,
19                       const SkPaint& paint, const SkPaint& blurPaint,
20                       const SkPaint& clearPaint) {
21     canvas->save();
22     canvas->clipRect(SkRect::MakeLTRB(0, 0, 1081, 665));
23     canvas->drawRect(SkRect::MakeLTRB(0, 0, 1081, 665), clearPaint);
24     // draw as blurred to push glyph to be too large for atlas
25     canvas->drawTextBlob(blob, 0, 256, blurPaint);
26     canvas->drawTextBlob(blob, 0, 477, paint);
27     canvas->restore();
28 }
29
30 // This test ensures that glyphs that are too large for the atlas
31 // are both translated and clipped correctly.
32 class ClipErrorGM : public skiagm::GM {
33 public:
34     ClipErrorGM() {}
35
36 protected:
37     SkString onShortName() override { return SkString("cliperror"); }
38
39     SkISize onISize() override { return SkISize::Make(WIDTH, HEIGHT); }
40
41     void onDraw(SkCanvas* canvas) override {
42         SkPaint paint;
43         paint.setAntiAlias(true);
44         paint.setStyle(SkPaint::kFill_Style);
45
46         const char text[] = "hambur";
47
48         sk_tool_utils::set_portable_typeface(&paint);
49         paint.setTextSize(256);
50         paint.setAntiAlias(true);
51
52         // setup up maskfilter
53         const SkScalar kSigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(50));
54
55         SkPaint blurPaint(paint);
56         blurPaint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, kSigma));
57
58         SkTextBlobBuilder builder;
59
60         sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, 0);
61
62         sk_sp<SkTextBlob> blob(builder.make());
63
64         SkPaint clearPaint(paint);
65         clearPaint.setColor(SK_ColorWHITE);
66
67         canvas->save();
68         canvas->translate(0, 0);
69         canvas->clipRect(SkRect::MakeLTRB(0, 0, WIDTH, 256));
70         draw_text(canvas, blob, paint, blurPaint, clearPaint);
71         canvas->restore();
72
73         canvas->save();
74         canvas->translate(0, 256);
75         canvas->clipRect(SkRect::MakeLTRB(0, 256, WIDTH, 510));
76         draw_text(canvas, blob, paint, blurPaint, clearPaint);
77         canvas->restore();
78     }
79
80 private:
81     typedef skiagm::GM INHERITED;
82 };
83
84 DEF_GM(return new ClipErrorGM;)