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" |
11 #include "SkGradientShader.h" | 11 #include "SkGradientShader.h" |
12 #include "SkPM4fPriv.h" | 12 #include "SkPM4fPriv.h" |
13 | 13 |
14 DEF_SIMPLE_GM(gamma, canvas, 560, 200) { | 14 DEF_SIMPLE_GM(gamma, canvas, 650, 200) { |
15 SkPaint p; | 15 SkPaint p; |
16 const SkScalar sz = 50.0f; | 16 const SkScalar sz = 50.0f; |
17 const int szInt = SkScalarTruncToInt(sz); | 17 const int szInt = SkScalarTruncToInt(sz); |
18 const SkScalar tx = sz + 5.0f; | 18 const SkScalar tx = sz + 15.0f; |
19 const SkRect r = SkRect::MakeXYWH(0, 0, sz, sz); | 19 const SkRect r = SkRect::MakeXYWH(0, 0, sz, sz); |
20 SkShader::TileMode rpt = SkShader::kRepeat_TileMode; | 20 SkShader::TileMode rpt = SkShader::kRepeat_TileMode; |
21 auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); | 21 auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); |
22 | 22 |
23 SkBitmap ditherBmp; | 23 SkBitmap ditherBmp; |
24 ditherBmp.allocN32Pixels(2, 2); | 24 ditherBmp.allocN32Pixels(2, 2); |
25 SkPMColor* pixels = reinterpret_cast<SkPMColor*>(ditherBmp.getPixels()); | 25 SkPMColor* pixels = reinterpret_cast<SkPMColor*>(ditherBmp.getPixels()); |
26 pixels[0] = pixels[3] = SkPackARGB32(0xFF, 0xFF, 0xFF, 0xFF); | 26 pixels[0] = pixels[3] = SkPackARGB32(0xFF, 0xFF, 0xFF, 0xFF); |
27 pixels[1] = pixels[2] = SkPackARGB32(0xFF, 0, 0, 0); | 27 pixels[1] = pixels[2] = SkPackARGB32(0xFF, 0, 0, 0); |
28 | 28 |
(...skipping 13 matching lines...) Expand all Loading... |
42 SkImageInfo mipmapInfo = SkImageInfo::Make(2, 2, kN32_SkColorType, kOpaque_S
kAlphaType, | 42 SkImageInfo mipmapInfo = SkImageInfo::Make(2, 2, kN32_SkColorType, kOpaque_S
kAlphaType, |
43 srgbColorSpace); | 43 srgbColorSpace); |
44 mipmapBmp.allocPixels(mipmapInfo); | 44 mipmapBmp.allocPixels(mipmapInfo); |
45 SkPMColor* mipmapPixels = reinterpret_cast<SkPMColor*>(mipmapBmp.getPixels()
); | 45 SkPMColor* mipmapPixels = reinterpret_cast<SkPMColor*>(mipmapBmp.getPixels()
); |
46 unsigned s25 = 0x89; // 255 * linear_to_srgb(0.25f) | 46 unsigned s25 = 0x89; // 255 * linear_to_srgb(0.25f) |
47 unsigned s75 = 0xE1; // 255 * linear_to_srgb(0.75f) | 47 unsigned s75 = 0xE1; // 255 * linear_to_srgb(0.75f) |
48 mipmapPixels[0] = mipmapPixels[3] = SkPackARGB32(0xFF, s25, s25, s25); | 48 mipmapPixels[0] = mipmapPixels[3] = SkPackARGB32(0xFF, s25, s25, s25); |
49 mipmapPixels[1] = mipmapPixels[2] = SkPackARGB32(0xFF, s75, s75, s75); | 49 mipmapPixels[1] = mipmapPixels[2] = SkPackARGB32(0xFF, s75, s75, s75); |
50 | 50 |
51 SkPaint textPaint; | 51 SkPaint textPaint; |
| 52 textPaint.setAntiAlias(true); |
52 textPaint.setColor(SK_ColorWHITE); | 53 textPaint.setColor(SK_ColorWHITE); |
| 54 sk_tool_utils::set_portable_typeface(&textPaint); |
53 | 55 |
54 // Helpers: | 56 // Helpers: |
55 auto advance = [&]() { | 57 auto advance = [&]() { |
56 canvas->translate(tx, 0); | 58 canvas->translate(tx, 0); |
57 p.reset(); | 59 p.reset(); |
58 }; | 60 }; |
59 | 61 |
60 auto nextRect = [&](const char* label, const char* label2) { | 62 auto nextRect = [&](const char* label, const char* label2) { |
61 canvas->drawRect(r, p); | 63 canvas->drawRect(r, p); |
62 canvas->drawText(label, strlen(label), 0, sz + textPaint.getFontSpacing(
), textPaint); | 64 canvas->drawText(label, strlen(label), 0, sz + textPaint.getFontSpacing(
), textPaint); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 p.setShader(SkShader::MakeBitmapShader(ditherBmp, rpt, rpt, &scaleMatrix)); | 120 p.setShader(SkShader::MakeBitmapShader(ditherBmp, rpt, rpt, &scaleMatrix)); |
119 p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality); | 121 p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality); |
120 nextRect("Dither", "Scale"); | 122 nextRect("Dither", "Scale"); |
121 | 123 |
122 // 25%/75% dither, scaled down by 2x. Tests ALL aspects of minification. Spe
cifically, are | 124 // 25%/75% dither, scaled down by 2x. Tests ALL aspects of minification. Spe
cifically, are |
123 // sRGB sources decoded to linear before computing mipmaps? | 125 // sRGB sources decoded to linear before computing mipmaps? |
124 p.setShader(SkShader::MakeBitmapShader(mipmapBmp, rpt, rpt, &scaleMatrix)); | 126 p.setShader(SkShader::MakeBitmapShader(mipmapBmp, rpt, rpt, &scaleMatrix)); |
125 p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality); | 127 p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality); |
126 nextRect("MipMaps", 0); | 128 nextRect("MipMaps", 0); |
127 | 129 |
128 // 50% grey via paint color. | 130 // 50% grey via paint color. Paint color (SkColor) is specified to be sRGB! |
129 p.setColor(0xff7f7f7f); | 131 p.setColor(0xffbcbcbc); |
130 nextRect("Color", 0); | 132 nextRect("Color", 0); |
131 | 133 |
132 // Black -> White gradient, scaled to sample just the middle. | 134 // Black -> White gradient, scaled to sample just the middle. |
133 // Tests gradient interpolation. | 135 // Tests gradient interpolation. |
134 SkPoint points[2] = { | 136 SkPoint points[2] = { |
135 SkPoint::Make(0 - (sz * 10), 0), | 137 SkPoint::Make(0 - (sz * 10), 0), |
136 SkPoint::Make(sz + (sz * 10), 0) | 138 SkPoint::Make(sz + (sz * 10), 0) |
137 }; | 139 }; |
138 SkColor colors[2] = { SK_ColorBLACK, SK_ColorWHITE }; | 140 SkColor colors[2] = { SK_ColorBLACK, SK_ColorWHITE }; |
139 p.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 2, | 141 p.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 2, |
(...skipping 13 matching lines...) Expand all Loading... |
153 | 155 |
154 // Bitmap wrapped in a shader (sRGB): | 156 // Bitmap wrapped in a shader (sRGB): |
155 p.setShader(SkShader::MakeBitmapShader(srgbGreyBmp, rpt, rpt)); | 157 p.setShader(SkShader::MakeBitmapShader(srgbGreyBmp, rpt, rpt)); |
156 p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality); | 158 p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality); |
157 nextRect("sRGB BMP", "Shader"); | 159 nextRect("sRGB BMP", "Shader"); |
158 | 160 |
159 // Carriage return. | 161 // Carriage return. |
160 canvas->restore(); | 162 canvas->restore(); |
161 canvas->translate(0, 2 * sz); | 163 canvas->translate(0, 2 * sz); |
162 | 164 |
163 const U8CPU sqrtHalf = 0xB4; | |
164 const SkColor sqrtHalfAlpha = SkColorSetARGB(sqrtHalf, 0, 0, 0); | |
165 const SkColor sqrtHalfWhite = SkColorSetARGB(0xFF, sqrtHalf, sqrtHalf, sqrtH
alf); | |
166 | |
167 // Xfermode tests, all done off-screen so certain modes work... | 165 // Xfermode tests, all done off-screen so certain modes work... |
168 | 166 |
169 canvas->saveLayer(nullptr, nullptr); | 167 canvas->saveLayer(nullptr, nullptr); |
170 | 168 |
171 nextXferRect(0x7fffffff, SkXfermode::kSrcOver_Mode, SK_ColorBLACK); | 169 nextXferRect(0x7fffffff, SkXfermode::kSrcOver_Mode, SK_ColorBLACK); |
172 nextXferRect(0x7f000000, SkXfermode::kSrcOver_Mode, SK_ColorWHITE); | 170 nextXferRect(0x7f000000, SkXfermode::kSrcOver_Mode, SK_ColorWHITE); |
173 | 171 |
174 nextXferRect(SK_ColorBLACK, SkXfermode::kDstOver_Mode, 0x7fffffff); | 172 nextXferRect(SK_ColorBLACK, SkXfermode::kDstOver_Mode, 0x7fffffff); |
175 nextXferRect(SK_ColorWHITE, SkXfermode::kSrcIn_Mode, 0x7fff00ff); | 173 nextXferRect(SK_ColorWHITE, SkXfermode::kSrcIn_Mode, 0x7fff00ff); |
176 nextXferRect(0x7fff00ff, SkXfermode::kDstIn_Mode, SK_ColorWHITE); | 174 nextXferRect(0x7fff00ff, SkXfermode::kDstIn_Mode, SK_ColorWHITE); |
177 nextXferRect(sqrtHalfWhite, SkXfermode::kSrcIn_Mode, sqrtHalfAlpha); | |
178 nextXferRect(sqrtHalfAlpha, SkXfermode::kDstIn_Mode, sqrtHalfWhite); | |
179 | 175 |
180 nextXferRect(0xff3f3f3f, SkXfermode::kPlus_Mode, 0xff3f3f3f); | 176 // 0x89 = 255 * linear_to_srgb(0.25) |
181 nextXferRect(sqrtHalfWhite, SkXfermode::kModulate_Mode, sqrtHalfWhite); | 177 nextXferRect(0xff898989, SkXfermode::kPlus_Mode, 0xff898989); |
| 178 |
| 179 // 0xDB = 255 * linear_to_srgb(sqrt(0.5)) |
| 180 nextXferRect(0xffdbdbdb, SkXfermode::kModulate_Mode, 0xffdbdbdb); |
182 | 181 |
183 canvas->restore(); | 182 canvas->restore(); |
184 } | 183 } |
OLD | NEW |