OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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" |
11 #include "SkBlurImageFilter.h" | 11 #include "SkBlurImageFilter.h" |
12 #include "SkColorFilterImageFilter.h" | 12 #include "SkColorFilterImageFilter.h" |
13 #include "SkColorMatrixFilter.h" | 13 #include "SkColorMatrixFilter.h" |
14 #include "SkCanvas.h" | 14 #include "SkCanvas.h" |
15 #include "SkGradientShader.h" | 15 #include "SkGradientShader.h" |
16 #include "SkStream.h" | 16 #include "SkStream.h" |
17 #include "SkTypeface.h" | 17 #include "SkTypeface.h" |
18 | 18 |
19 /* | 19 /* |
20 * Spits out a dummy gradient to test blur with shader on paint | 20 * Spits out a dummy gradient to test blur with shader on paint |
21 */ | 21 */ |
22 static sk_sp<SkShader> MakeLinear() { | 22 static sk_sp<SkShader> MakeLinear() { |
23 static const SkPoint kPts[] = { { 0, 0 }, { 32, 32 } }; | 23 constexpr SkPoint kPts[] = { { 0, 0 }, { 32, 32 } }; |
24 static const SkScalar kPos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; | 24 constexpr SkScalar kPos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; |
25 static const SkColor kColors[] = {0x80F00080, 0xF0F08000, 0x800080F0 }; | 25 constexpr SkColor kColors[] = {0x80F00080, 0xF0F08000, 0x800080F0 }; |
26 return SkGradientShader::MakeLinear(kPts, kColors, kPos, SK_ARRAY_COUNT(kCol
ors), | 26 return SkGradientShader::MakeLinear(kPts, kColors, kPos, SK_ARRAY_COUNT(kCol
ors), |
27 SkShader::kClamp_TileMode); | 27 SkShader::kClamp_TileMode); |
28 } | 28 } |
29 | 29 |
30 static sk_sp<SkImageFilter> make_grayscale(sk_sp<SkImageFilter> input) { | 30 static sk_sp<SkImageFilter> make_grayscale(sk_sp<SkImageFilter> input) { |
31 SkScalar matrix[20]; | 31 SkScalar matrix[20]; |
32 memset(matrix, 0, 20 * sizeof(SkScalar)); | 32 memset(matrix, 0, 20 * sizeof(SkScalar)); |
33 matrix[0] = matrix[5] = matrix[10] = 0.2126f; | 33 matrix[0] = matrix[5] = matrix[10] = 0.2126f; |
34 matrix[1] = matrix[6] = matrix[11] = 0.7152f; | 34 matrix[1] = matrix[6] = matrix[11] = 0.7152f; |
35 matrix[2] = matrix[7] = matrix[12] = 0.0722f; | 35 matrix[2] = matrix[7] = matrix[12] = 0.0722f; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 void onDraw(SkCanvas* canvas) override { | 71 void onDraw(SkCanvas* canvas) override { |
72 | 72 |
73 canvas->drawColor(sk_tool_utils::color_to_565(SK_ColorGRAY)); | 73 canvas->drawColor(sk_tool_utils::color_to_565(SK_ColorGRAY)); |
74 | 74 |
75 SkPaint paint; | 75 SkPaint paint; |
76 paint.setTypeface(emojiFont.typeface); | 76 paint.setTypeface(emojiFont.typeface); |
77 const char* text = emojiFont.text; | 77 const char* text = emojiFont.text; |
78 | 78 |
79 // draw text at different point sizes | 79 // draw text at different point sizes |
80 static constexpr SkScalar textSizes[] = { 10, 30, 50, }; | 80 constexpr SkScalar textSizes[] = { 10, 30, 50, }; |
81 SkPaint::FontMetrics metrics; | 81 SkPaint::FontMetrics metrics; |
82 SkScalar y = 0; | 82 SkScalar y = 0; |
83 for (const SkScalar& textSize : textSizes) { | 83 for (const SkScalar& textSize : textSizes) { |
84 paint.setTextSize(textSize); | 84 paint.setTextSize(textSize); |
85 paint.getFontMetrics(&metrics); | 85 paint.getFontMetrics(&metrics); |
86 y += -metrics.fAscent; | 86 y += -metrics.fAscent; |
87 canvas->drawText(text, strlen(text), 10, y, paint); | 87 canvas->drawText(text, strlen(text), 10, y, paint); |
88 y += metrics.fDescent + metrics.fLeading; | 88 y += metrics.fDescent + metrics.fLeading; |
89 } | 89 } |
90 | 90 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 const SkScalar boundsQuarterWidth = boundsHalfWidth * SK_ScalarHalf; | 130 const SkScalar boundsQuarterWidth = boundsHalfWidth * SK_ScalarHalf; |
131 const SkScalar boundsQuarterHeight = boundsHalfHeight * SK_ScalarHalf; | 131 const SkScalar boundsQuarterHeight = boundsHalfHeight * SK_ScalarHalf; |
132 | 132 |
133 SkRect upperLeftClip = SkRect::MakeXYWH(bounds.left(), bounds.top(), | 133 SkRect upperLeftClip = SkRect::MakeXYWH(bounds.left(), bounds.top(), |
134 boundsHalfWidth, boundsHalfHeigh
t); | 134 boundsHalfWidth, boundsHalfHeigh
t); |
135 SkRect lowerRightClip = SkRect::MakeXYWH(bounds.centerX(), bounds.center
Y(), | 135 SkRect lowerRightClip = SkRect::MakeXYWH(bounds.centerX(), bounds.center
Y(), |
136 boundsHalfWidth, boundsHalfHeig
ht); | 136 boundsHalfWidth, boundsHalfHeig
ht); |
137 SkRect interiorClip = bounds; | 137 SkRect interiorClip = bounds; |
138 interiorClip.inset(boundsQuarterWidth, boundsQuarterHeight); | 138 interiorClip.inset(boundsQuarterWidth, boundsQuarterHeight); |
139 | 139 |
140 static const SkRect clipRects[] = { bounds, upperLeftClip, lowerRightCli
p, interiorClip }; | 140 const SkRect clipRects[] = { bounds, upperLeftClip, lowerRightClip, inte
riorClip }; |
141 | 141 |
142 SkPaint clipHairline; | 142 SkPaint clipHairline; |
143 clipHairline.setColor(SK_ColorWHITE); | 143 clipHairline.setColor(SK_ColorWHITE); |
144 clipHairline.setStyle(SkPaint::kStroke_Style); | 144 clipHairline.setStyle(SkPaint::kStroke_Style); |
145 | 145 |
146 for (const SkRect& clipRect : clipRects) { | 146 for (const SkRect& clipRect : clipRects) { |
147 canvas->translate(0, bounds.height()); | 147 canvas->translate(0, bounds.height()); |
148 canvas->save(); | 148 canvas->save(); |
149 canvas->drawRect(clipRect, clipHairline); | 149 canvas->drawRect(clipRect, clipHairline); |
150 paint.setAlpha(0x20); | 150 paint.setAlpha(0x20); |
151 canvas->drawText(text, strlen(text), 0, 0, paint); | 151 canvas->drawText(text, strlen(text), 0, 0, paint); |
152 canvas->clipRect(clipRect); | 152 canvas->clipRect(clipRect); |
153 paint.setAlpha(0xFF); | 153 paint.setAlpha(0xFF); |
154 canvas->drawText(text, strlen(text), 0, 0, paint); | 154 canvas->drawText(text, strlen(text), 0, 0, paint); |
155 canvas->restore(); | 155 canvas->restore(); |
156 canvas->translate(0, SkIntToScalar(25)); | 156 canvas->translate(0, SkIntToScalar(25)); |
157 } | 157 } |
158 } | 158 } |
159 | 159 |
160 typedef GM INHERITED; | 160 typedef GM INHERITED; |
161 }; | 161 }; |
162 | 162 |
163 ////////////////////////////////////////////////////////////////////////////// | 163 ////////////////////////////////////////////////////////////////////////////// |
164 | 164 |
165 DEF_GM(return new ColorEmojiGM;) | 165 DEF_GM(return new ColorEmojiGM;) |
166 | 166 |
167 } | 167 } |
OLD | NEW |