Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / gm / textblobgeometrychange.cpp
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"
9 #include "include/core/SkCanvas.h"
10 #include "include/core/SkFont.h"
11 #include "include/core/SkImageInfo.h"
12 #include "include/core/SkPaint.h"
13 #include "include/core/SkRect.h"
14 #include "include/core/SkRefCnt.h"
15 #include "include/core/SkScalar.h"
16 #include "include/core/SkSize.h"
17 #include "include/core/SkString.h"
18 #include "include/core/SkSurface.h"
19 #include "include/core/SkSurfaceProps.h"
20 #include "include/core/SkTextBlob.h"
21 #include "include/core/SkTypeface.h"
22 #include "tools/ToolUtils.h"
23
24 // This tests that we don't try to reuse textblobs from the GPU textblob cache across pixel geometry
25 // changes when we have LCD.  crbug/486744
26 namespace skiagm {
27 class TextBlobGeometryChange : public GM {
28 public:
29     TextBlobGeometryChange() { }
30
31 protected:
32     SkString onShortName() override {
33         return SkString("textblobgeometrychange");
34     }
35
36     SkISize onISize() override {
37         return SkISize::Make(kWidth, kHeight);
38     }
39
40     void onDraw(SkCanvas* canvas) override {
41         const char text[] = "Hamburgefons";
42
43         SkFont font(ToolUtils::create_portable_typeface(), 20);
44         font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
45
46         SkTextBlobBuilder builder;
47
48         ToolUtils::add_to_text_blob(&builder, text, font, 10, 10);
49
50         sk_sp<SkTextBlob> blob(builder.make());
51
52         SkImageInfo info = SkImageInfo::MakeN32Premul(200, 200);
53         SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
54         auto           surface = ToolUtils::makeSurface(canvas, info, &props);
55         SkCanvas* c = surface->getCanvas();
56
57         // LCD text on white background
58         SkRect rect = SkRect::MakeLTRB(0.f, 0.f, SkIntToScalar(kWidth), kHeight / 2.f);
59         SkPaint rectPaint;
60         rectPaint.setColor(0xffffffff);
61         canvas->drawRect(rect, rectPaint);
62         canvas->drawTextBlob(blob, 10, 50, SkPaint());
63
64         // This should not look garbled since we should disable LCD text in this case
65         // (i.e., unknown pixel geometry)
66         c->clear(0x00ffffff);
67         c->drawTextBlob(blob, 10, 150, SkPaint());
68         surface->draw(canvas, 0, 0);
69     }
70
71 private:
72     inline static constexpr int kWidth = 200;
73     inline static constexpr int kHeight = 200;
74
75     using INHERITED = GM;
76 };
77
78 //////////////////////////////////////////////////////////////////////////////
79
80 DEF_GM(return new TextBlobGeometryChange;)
81 }  // namespace skiagm