OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 | 9 |
10 #include "Resources.h" | 10 #include "Resources.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 protected: | 25 protected: |
26 void onOnceBeforeDraw() override { | 26 void onOnceBeforeDraw() override { |
27 SkTextBlobBuilder builder; | 27 SkTextBlobBuilder builder; |
28 | 28 |
29 // make textblob | 29 // make textblob |
30 // Large text is used to trigger atlas eviction | 30 // Large text is used to trigger atlas eviction |
31 SkPaint paint; | 31 SkPaint paint; |
32 paint.setTextSize(256); | 32 paint.setTextSize(256); |
33 const char* text = "AB"; | 33 const char* text = "AB"; |
34 sk_tool_utils::set_portable_typeface(&paint); | 34 sk_tool_utils::set_portable_typeface_always(&paint); |
35 | 35 |
36 SkRect bounds; | 36 SkRect bounds; |
37 paint.measureText(text, strlen(text), &bounds); | 37 paint.measureText(text, strlen(text), &bounds); |
38 | 38 |
39 SkScalar yOffset = bounds.height(); | 39 SkScalar yOffset = bounds.height(); |
40 sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, yOffset - 30); | 40 sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, yOffset - 30); |
41 | 41 |
42 // A8 | 42 // A8 |
43 paint.setTextSize(28); | 43 paint.setTextSize(28); |
44 text = "The quick brown fox jumps over the lazy dog."; | 44 text = "The quick brown fox jumps over the lazy dog."; |
45 paint.setSubpixelText(false); | 45 paint.setSubpixelText(false); |
46 paint.setLCDRenderText(false); | 46 paint.setLCDRenderText(false); |
47 paint.measureText(text, strlen(text), &bounds); | 47 paint.measureText(text, strlen(text), &bounds); |
48 sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, yOffset - 8); | 48 sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, yOffset - 8); |
49 | 49 |
50 // build | 50 // build |
51 fBlob.reset(builder.build()); | 51 fBlob.reset(builder.build()); |
52 } | 52 } |
53 | 53 |
54 SkString onShortName() override { | 54 SkString onShortName() override { |
55 return SkString("textblobcolortrans"); | 55 return SkString("textblobcolortrans"); |
56 } | 56 } |
57 | 57 |
58 SkISize onISize() override { | 58 SkISize onISize() override { |
59 return SkISize::Make(kWidth, kHeight); | 59 return SkISize::Make(kWidth, kHeight); |
60 } | 60 } |
61 | 61 |
62 void onDraw(SkCanvas* canvas) override { | 62 void onDraw(SkCanvas* canvas) override { |
63 | 63 |
64 canvas->drawColor(SK_ColorGRAY); | 64 canvas->drawColor(sk_tool_utils::color_to_565(SK_ColorGRAY)); |
65 | 65 |
66 SkPaint paint; | 66 SkPaint paint; |
67 canvas->translate(10, 40); | 67 canvas->translate(10, 40); |
68 | 68 |
69 SkRect bounds = fBlob->bounds(); | 69 SkRect bounds = fBlob->bounds(); |
70 | 70 |
71 // Colors were chosen to map to pairs of canonical colors. The GPU Back
end will cache A8 | 71 // Colors were chosen to map to pairs of canonical colors. The GPU Back
end will cache A8 |
72 // Texture Blobs based on the canonical color they map to. Canonical co
lors are used to | 72 // Texture Blobs based on the canonical color they map to. Canonical co
lors are used to |
73 // create masks. For A8 there are 8 of them. | 73 // create masks. For A8 there are 8 of them. |
74 SkColor colors[] = {SK_ColorCYAN, SK_ColorLTGRAY, SK_ColorYELLOW, SK_Col
orWHITE}; | 74 SkColor colors[] = {SK_ColorCYAN, sk_tool_utils::color_to_565(SK_ColorLT
GRAY), |
| 75 SK_ColorYELLOW, SK_ColorWHITE}; |
75 | 76 |
76 size_t count = SK_ARRAY_COUNT(colors); | 77 size_t count = SK_ARRAY_COUNT(colors); |
77 size_t colorIndex = 0; | 78 size_t colorIndex = 0; |
78 for (int y = 0; y + SkScalarFloorToInt(bounds.height()) < kHeight; | 79 for (int y = 0; y + SkScalarFloorToInt(bounds.height()) < kHeight; |
79 y += SkScalarFloorToInt(bounds.height())) { | 80 y += SkScalarFloorToInt(bounds.height())) { |
80 paint.setColor(colors[colorIndex++ % count]); | 81 paint.setColor(colors[colorIndex++ % count]); |
81 canvas->save(); | 82 canvas->save(); |
82 canvas->translate(0, SkIntToScalar(y)); | 83 canvas->translate(0, SkIntToScalar(y)); |
83 canvas->drawTextBlob(fBlob, 0, 0, paint); | 84 canvas->drawTextBlob(fBlob, 0, 0, paint); |
84 canvas->restore(); | 85 canvas->restore(); |
85 } | 86 } |
86 } | 87 } |
87 | 88 |
88 private: | 89 private: |
89 SkAutoTUnref<const SkTextBlob> fBlob; | 90 SkAutoTUnref<const SkTextBlob> fBlob; |
90 | 91 |
91 static const int kWidth = 675; | 92 static const int kWidth = 675; |
92 static const int kHeight = 1600; | 93 static const int kHeight = 1600; |
93 | 94 |
94 typedef GM INHERITED; | 95 typedef GM INHERITED; |
95 }; | 96 }; |
96 | 97 |
97 ////////////////////////////////////////////////////////////////////////////// | 98 ////////////////////////////////////////////////////////////////////////////// |
98 | 99 |
99 DEF_GM( return SkNEW(TextBlobColorTrans); ) | 100 DEF_GM( return SkNEW(TextBlobColorTrans); ) |
100 } | 101 } |
OLD | NEW |