OLD | NEW |
---|---|
(Empty) | |
1 /* | |
robertphillips
2016/02/24 13:03:14
2016 ?
| |
2 * Copyright 2015 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 | |
robertphillips
2016/02/24 13:03:14
Do we need Resources.h & SkTypeface.h ?
| |
10 #include "Resources.h" | |
11 #include "SkCanvas.h" | |
12 #include "SkTextBlob.h" | |
13 #include "SkTypeface.h" | |
14 | |
15 namespace skiagm { | |
16 class TextBlobBlockReordering : public GM { | |
17 public: | |
18 // This gm tests that textblobs translate properly when their draw order is different from their | |
19 // flush order | |
20 TextBlobBlockReordering() { } | |
21 | |
22 protected: | |
23 void onOnceBeforeDraw() override { | |
24 SkTextBlobBuilder builder; | |
25 | |
26 // make textblob | |
27 // Large text is used to trigger atlas eviction | |
28 SkPaint paint; | |
29 paint.setTextSize(56); | |
30 const char* text = "AB"; | |
31 sk_tool_utils::set_portable_typeface(&paint); | |
32 | |
33 SkRect bounds; | |
34 paint.measureText(text, strlen(text), &bounds); | |
35 | |
36 SkScalar yOffset = bounds.height(); | |
37 sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, yOffset - 30); | |
38 | |
39 // build | |
40 fBlob.reset(builder.build()); | |
41 } | |
42 | |
43 SkString onShortName() override { | |
44 return SkString("textblobblockreordering"); | |
45 } | |
46 | |
47 SkISize onISize() override { | |
48 return SkISize::Make(kWidth, kHeight); | |
49 } | |
50 | |
robertphillips
2016/02/24 13:03:14
// This draws the same text blob 3 times. The seco
| |
51 void onDraw(SkCanvas* canvas) override { | |
52 canvas->drawColor(sk_tool_utils::color_to_565(SK_ColorGRAY)); | |
53 | |
54 SkPaint paint; | |
55 canvas->translate(10, 40); | |
56 | |
57 SkRect bounds = fBlob->bounds(); | |
58 const int yDelta = SkScalarFloorToInt(bounds.height()) + 20; | |
59 const int xDelta = SkScalarFloorToInt(bounds.width()); | |
60 | |
61 canvas->drawTextBlob(fBlob, 0, 0, paint); | |
62 | |
63 canvas->translate(SkIntToScalar(xDelta), SkIntToScalar(yDelta)); | |
64 | |
65 // draw a rect where the text should be, and then twiddle the xfermode | |
66 // so we don't batch | |
67 SkPaint redPaint; | |
68 redPaint.setColor(SK_ColorRED); | |
69 canvas->drawRect(bounds, redPaint); | |
70 SkPaint srcInPaint(paint); | |
71 srcInPaint.setXfermodeMode(SkXfermode::kSrcIn_Mode); | |
72 canvas->drawTextBlob(fBlob, 0, 0, srcInPaint); | |
73 | |
74 canvas->translate(SkIntToScalar(xDelta), SkIntToScalar(yDelta)); | |
75 canvas->drawTextBlob(fBlob, 0, 0, paint); | |
76 } | |
77 | |
78 private: | |
79 SkAutoTUnref<const SkTextBlob> fBlob; | |
80 | |
81 static const int kWidth = 675; | |
82 static const int kHeight = 1600; | |
83 | |
84 typedef GM INHERITED; | |
85 }; | |
86 | |
87 ////////////////////////////////////////////////////////////////////////////// | |
88 | |
89 DEF_GM(return new TextBlobBlockReordering;) | |
90 } | |
OLD | NEW |