| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 // Necessary for certain Xfermode tests to work (ie some of them output whit
e @ 50% alpha): | 83 // Necessary for certain Xfermode tests to work (ie some of them output whit
e @ 50% alpha): |
| 84 canvas->clear(SK_ColorBLACK); | 84 canvas->clear(SK_ColorBLACK); |
| 85 | 85 |
| 86 // *Everything* should be perceptually 50% grey. Only the first rectangle | 86 // *Everything* should be perceptually 50% grey. Only the first rectangle |
| 87 // is guaranteed to draw that way, though. | 87 // is guaranteed to draw that way, though. |
| 88 canvas->save(); | 88 canvas->save(); |
| 89 | 89 |
| 90 // Black/white dither, pixel perfect. This is ground truth. | 90 // Black/white dither, pixel perfect. This is ground truth. |
| 91 p.setShader(SkShader::CreateBitmapShader( | 91 p.setShader(SkShader::MakeBitmapShader(ditherBmp, rpt, rpt)); |
| 92 ditherBmp, rpt, rpt))->unref(); | |
| 93 p.setFilterQuality(SkFilterQuality::kNone_SkFilterQuality); | 92 p.setFilterQuality(SkFilterQuality::kNone_SkFilterQuality); |
| 94 nextRect("Dither", "Reference"); | 93 nextRect("Dither", "Reference"); |
| 95 | 94 |
| 96 // Black/white dither, sampled at half-texel offset. Tests bilerp. | 95 // Black/white dither, sampled at half-texel offset. Tests bilerp. |
| 97 // NOTE: We need to apply a non-identity scale and/or rotation to trick | 96 // NOTE: We need to apply a non-identity scale and/or rotation to trick |
| 98 // the raster pipeline into *not* snapping to nearest. | 97 // the raster pipeline into *not* snapping to nearest. |
| 99 SkMatrix offsetMatrix = SkMatrix::Concat( | 98 SkMatrix offsetMatrix = SkMatrix::Concat( |
| 100 SkMatrix::MakeScale(-1.0f), SkMatrix::MakeTrans(0.5f, 0.0f)); | 99 SkMatrix::MakeScale(-1.0f), SkMatrix::MakeTrans(0.5f, 0.0f)); |
| 101 p.setShader(SkShader::CreateBitmapShader( | 100 p.setShader(SkShader::MakeBitmapShader(ditherBmp, rpt, rpt, &offsetMatrix)); |
| 102 ditherBmp, rpt, rpt, &offsetMatrix))->unref(); | |
| 103 p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality); | 101 p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality); |
| 104 nextRect("Dither", "Bilerp"); | 102 nextRect("Dither", "Bilerp"); |
| 105 | 103 |
| 106 // Black/white dither, scaled down by 2x. Tests minification. | 104 // Black/white dither, scaled down by 2x. Tests minification. |
| 107 SkMatrix scaleMatrix = SkMatrix::MakeScale(0.5f); | 105 SkMatrix scaleMatrix = SkMatrix::MakeScale(0.5f); |
| 108 p.setShader(SkShader::CreateBitmapShader( | 106 p.setShader(SkShader::MakeBitmapShader(ditherBmp, rpt, rpt, &scaleMatrix)); |
| 109 ditherBmp, rpt, rpt, &scaleMatrix))->unref(); | |
| 110 p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality); | 107 p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality); |
| 111 nextRect("Dither", "Scale"); | 108 nextRect("Dither", "Scale"); |
| 112 | 109 |
| 113 // 50% grey via paint color. | 110 // 50% grey via paint color. |
| 114 p.setColor(0xff7f7f7f); | 111 p.setColor(0xff7f7f7f); |
| 115 nextRect("Color", 0); | 112 nextRect("Color", 0); |
| 116 | 113 |
| 117 // Black -> White gradient, scaled to sample just the middle. | 114 // Black -> White gradient, scaled to sample just the middle. |
| 118 // Tests gradient interpolation. | 115 // Tests gradient interpolation. |
| 119 SkPoint points[2] = { | 116 SkPoint points[2] = { |
| 120 SkPoint::Make(0 - (sz * 10), 0), | 117 SkPoint::Make(0 - (sz * 10), 0), |
| 121 SkPoint::Make(sz + (sz * 10), 0) | 118 SkPoint::Make(sz + (sz * 10), 0) |
| 122 }; | 119 }; |
| 123 SkColor colors[2] = { SK_ColorBLACK, SK_ColorWHITE }; | 120 SkColor colors[2] = { SK_ColorBLACK, SK_ColorWHITE }; |
| 124 p.setShader(SkGradientShader::CreateLinear( | 121 p.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 2, |
| 125 points, colors, nullptr, 2, SkShader::kClamp_TileMode))->unref(); | 122 SkShader::kClamp_TileMode)); |
| 126 nextRect("Gradient", 0); | 123 nextRect("Gradient", 0); |
| 127 | 124 |
| 128 // 50% grey from linear bitmap, with drawBitmap | 125 // 50% grey from linear bitmap, with drawBitmap |
| 129 nextBitmap(linearGreyBmp, "Lnr BMP"); | 126 nextBitmap(linearGreyBmp, "Lnr BMP"); |
| 130 | 127 |
| 131 // 50% grey from sRGB bitmap, with drawBitmap | 128 // 50% grey from sRGB bitmap, with drawBitmap |
| 132 nextBitmap(srgbGreyBmp, "sRGB BMP"); | 129 nextBitmap(srgbGreyBmp, "sRGB BMP"); |
| 133 | 130 |
| 134 // Bitmap wrapped in a shader (linear): | 131 // Bitmap wrapped in a shader (linear): |
| 135 p.setShader(SkShader::CreateBitmapShader(linearGreyBmp, rpt, rpt))->unref(); | 132 p.setShader(SkShader::MakeBitmapShader(linearGreyBmp, rpt, rpt)); |
| 136 p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality); | 133 p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality); |
| 137 nextRect("Lnr BMP", "Shader"); | 134 nextRect("Lnr BMP", "Shader"); |
| 138 | 135 |
| 139 // Bitmap wrapped in a shader (sRGB): | 136 // Bitmap wrapped in a shader (sRGB): |
| 140 p.setShader(SkShader::CreateBitmapShader(srgbGreyBmp, rpt, rpt))->unref(); | 137 p.setShader(SkShader::MakeBitmapShader(srgbGreyBmp, rpt, rpt)); |
| 141 p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality); | 138 p.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality); |
| 142 nextRect("sRGB BMP", "Shader"); | 139 nextRect("sRGB BMP", "Shader"); |
| 143 | 140 |
| 144 // Carriage return. | 141 // Carriage return. |
| 145 canvas->restore(); | 142 canvas->restore(); |
| 146 canvas->translate(0, 2 * sz); | 143 canvas->translate(0, 2 * sz); |
| 147 | 144 |
| 148 const U8CPU sqrtHalf = 0xB4; | 145 const U8CPU sqrtHalf = 0xB4; |
| 149 const SkColor sqrtHalfAlpha = SkColorSetARGB(sqrtHalf, 0, 0, 0); | 146 const SkColor sqrtHalfAlpha = SkColorSetARGB(sqrtHalf, 0, 0, 0); |
| 150 const SkColor sqrtHalfWhite = SkColorSetARGB(0xFF, sqrtHalf, sqrtHalf, sqrtH
alf); | 147 const SkColor sqrtHalfWhite = SkColorSetARGB(0xFF, sqrtHalf, sqrtHalf, sqrtH
alf); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 162 nextXferRect(sqrtHalfWhite, SkXfermode::kSrcIn_Mode, sqrtHalfAlpha); | 159 nextXferRect(sqrtHalfWhite, SkXfermode::kSrcIn_Mode, sqrtHalfAlpha); |
| 163 nextXferRect(sqrtHalfAlpha, SkXfermode::kDstIn_Mode, sqrtHalfWhite); | 160 nextXferRect(sqrtHalfAlpha, SkXfermode::kDstIn_Mode, sqrtHalfWhite); |
| 164 | 161 |
| 165 nextXferRect(0xff3f3f3f, SkXfermode::kPlus_Mode, 0xff3f3f3f); | 162 nextXferRect(0xff3f3f3f, SkXfermode::kPlus_Mode, 0xff3f3f3f); |
| 166 nextXferRect(sqrtHalfWhite, SkXfermode::kModulate_Mode, sqrtHalfWhite); | 163 nextXferRect(sqrtHalfWhite, SkXfermode::kModulate_Mode, sqrtHalfWhite); |
| 167 | 164 |
| 168 canvas->restore(); | 165 canvas->restore(); |
| 169 | 166 |
| 170 canvas->restore(); | 167 canvas->restore(); |
| 171 } | 168 } |
| OLD | NEW |