diff --git a/bench/ColorFilterBench.cpp b/bench/ColorFilterBench.cpp index cced1b23d0..fc09c371f4 100644 --- a/bench/ColorFilterBench.cpp +++ b/bench/ColorFilterBench.cpp @@ -16,23 +16,22 @@ #define FILTER_HEIGHT_LARGE SkIntToScalar(256) static sk_sp make_brightness(float amount, sk_sp input) { - SkScalar amount255 = amount * 255; - SkScalar matrix[20] = { 1, 0, 0, 0, amount255, - 0, 1, 0, 0, amount255, - 0, 0, 1, 0, amount255, - 0, 0, 0, 1, 0 }; - sk_sp filter(SkColorFilters::MatrixRowMajor255(matrix)); + float matrix[20] = { 1, 0, 0, 0, amount, + 0, 1, 0, 0, amount, + 0, 0, 1, 0, amount, + 0, 0, 0, 1, 0 }; + sk_sp filter(SkColorFilters::Matrix(matrix)); return SkColorFilterImageFilter::Make(std::move(filter), std::move(input)); } static sk_sp make_grayscale(sk_sp input) { - SkScalar matrix[20]; - memset(matrix, 0, 20 * sizeof(SkScalar)); + float matrix[20]; + memset(matrix, 0, 20 * sizeof(float)); matrix[0] = matrix[5] = matrix[10] = 0.2126f; matrix[1] = matrix[6] = matrix[11] = 0.7152f; matrix[2] = matrix[7] = matrix[12] = 0.0722f; matrix[18] = 1.0f; - sk_sp filter(SkColorFilters::MatrixRowMajor255(matrix)); + sk_sp filter(SkColorFilters::Matrix(matrix)); return SkColorFilterImageFilter::Make(std::move(filter), std::move(input)); } diff --git a/bench/ImageFilterCollapse.cpp b/bench/ImageFilterCollapse.cpp index 2e1c6d7187..4f827d3879 100644 --- a/bench/ImageFilterCollapse.cpp +++ b/bench/ImageFilterCollapse.cpp @@ -98,22 +98,21 @@ private: }; static sk_sp make_brightness(float amount) { - SkScalar amount255 = amount * 255; - SkScalar matrix[20] = { 1, 0, 0, 0, amount255, - 0, 1, 0, 0, amount255, - 0, 0, 1, 0, amount255, + SkScalar matrix[20] = { 1, 0, 0, 0, amount, + 0, 1, 0, 0, amount, + 0, 0, 1, 0, amount, 0, 0, 0, 1, 0 }; - return SkColorFilters::MatrixRowMajor255(matrix); + return SkColorFilters::Matrix(matrix); } static sk_sp make_grayscale() { - SkScalar matrix[20]; - memset(matrix, 0, 20 * sizeof(SkScalar)); + float matrix[20]; + memset(matrix, 0, 20 * sizeof(float)); matrix[0] = matrix[5] = matrix[10] = 0.2126f; matrix[1] = matrix[6] = matrix[11] = 0.7152f; matrix[2] = matrix[7] = matrix[12] = 0.0722f; matrix[18] = 1.0f; - return SkColorFilters::MatrixRowMajor255(matrix); + return SkColorFilters::Matrix(matrix); } class MatrixCollapseBench: public BaseImageFilterCollapseBench { diff --git a/fuzz/FuzzCanvas.cpp b/fuzz/FuzzCanvas.cpp index 67c13a3822..fcf043fc05 100644 --- a/fuzz/FuzzCanvas.cpp +++ b/fuzz/FuzzCanvas.cpp @@ -127,9 +127,9 @@ static sk_sp make_fuzz_colorfilter(Fuzz* fuzz, int depth) { return outer->makeComposed(std::move(inner)); } case 3: { - SkScalar array[20]; + float array[20]; fuzz->nextN(array, SK_ARRAY_COUNT(array)); - return SkColorFilters::MatrixRowMajor255(array); + return SkColorFilters::Matrix(array); } case 4: { SkColor mul, add; diff --git a/gm/alpha_image.cpp b/gm/alpha_image.cpp index e659c46113..5a7078c2b7 100644 --- a/gm/alpha_image.cpp +++ b/gm/alpha_image.cpp @@ -26,12 +26,12 @@ static SkBitmap make_alpha_image(int w, int h) { } static sk_sp make_color_filter() { - SkScalar colorMatrix[20] = { + float colorMatrix[20] = { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0.5, 0.5, 0, 0, 0, 0.5, 0.5, 0}; // mix G and A. - return SkColorFilters::MatrixRowMajor255(colorMatrix); + return SkColorFilters::Matrix(colorMatrix); } DEF_SIMPLE_GM(alpha_image, canvas, 256, 256) { diff --git a/gm/coloremoji.cpp b/gm/coloremoji.cpp index c02c9a64d6..b8e3f99b55 100644 --- a/gm/coloremoji.cpp +++ b/gm/coloremoji.cpp @@ -31,13 +31,13 @@ static sk_sp MakeLinear() { } static sk_sp make_grayscale(sk_sp input) { - SkScalar matrix[20]; - memset(matrix, 0, 20 * sizeof(SkScalar)); + float matrix[20]; + memset(matrix, 0, 20 * sizeof(float)); matrix[0] = matrix[5] = matrix[10] = 0.2126f; matrix[1] = matrix[6] = matrix[11] = 0.7152f; matrix[2] = matrix[7] = matrix[12] = 0.0722f; matrix[18] = 1.0f; - sk_sp filter(SkColorFilters::MatrixRowMajor255(matrix)); + sk_sp filter(SkColorFilters::Matrix(matrix)); return SkColorFilterImageFilter::Make(std::move(filter), std::move(input)); } diff --git a/gm/colorfilteralpha8.cpp b/gm/colorfilteralpha8.cpp index 4c116d5103..54bf9ff572 100644 --- a/gm/colorfilteralpha8.cpp +++ b/gm/colorfilteralpha8.cpp @@ -35,9 +35,9 @@ protected: 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 255.0f + 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; - paint.setColorFilter(SkColorFilters::MatrixRowMajor255(opaqueGrayMatrix)); + paint.setColorFilter(SkColorFilters::Matrix(opaqueGrayMatrix)); canvas->drawBitmap(bitmap, 100.0f, 100.0f, &paint); } diff --git a/gm/colorfilterimagefilter.cpp b/gm/colorfilterimagefilter.cpp index 38797a08c0..70f95ef5bd 100644 --- a/gm/colorfilterimagefilter.cpp +++ b/gm/colorfilterimagefilter.cpp @@ -20,23 +20,22 @@ #define MARGIN SkIntToScalar(10) static sk_sp cf_make_brightness(float brightness) { - SkScalar amount255 = brightness * 255; - SkScalar matrix[20] = { - 1, 0, 0, 0, amount255, - 0, 1, 0, 0, amount255, - 0, 0, 1, 0, amount255, + float matrix[20] = { + 1, 0, 0, 0, brightness, + 0, 1, 0, 0, brightness, + 0, 0, 1, 0, brightness, 0, 0, 0, 1, 0 }; - return SkColorFilters::MatrixRowMajor255(matrix); + return SkColorFilters::Matrix(matrix); } static sk_sp cf_make_grayscale() { - SkScalar matrix[20]; - memset(matrix, 0, 20 * sizeof(SkScalar)); + float matrix[20]; + memset(matrix, 0, 20 * sizeof(float)); matrix[0] = matrix[5] = matrix[10] = 0.2126f; matrix[1] = matrix[6] = matrix[11] = 0.7152f; matrix[2] = matrix[7] = matrix[12] = 0.0722f; matrix[18] = 1.0f; - return SkColorFilters::MatrixRowMajor255(matrix); + return SkColorFilters::Matrix(matrix); } static sk_sp cf_make_colorize(SkColor color) { diff --git a/gm/colormatrix.cpp b/gm/colormatrix.cpp index 21c14ca5ec..cf3facac99 100644 --- a/gm/colormatrix.cpp +++ b/gm/colormatrix.cpp @@ -17,8 +17,8 @@ static void set_color_matrix(SkPaint* paint, const SkColorMatrix& matrix) { paint->setColorFilter(SkColorFilters::Matrix(matrix)); } -static void set_array(SkPaint* paint, const SkScalar array[]) { - paint->setColorFilter(SkColorFilters::MatrixRowMajor255(array)); +static void set_array(SkPaint* paint, const float array[]) { + paint->setColorFilter(SkColorFilters::Matrix(array)); } class ColorMatrixGM : public skiagm::GM { @@ -121,14 +121,12 @@ protected: set_color_matrix(&paint, matrix); canvas->drawImage(bmps[i], 80, 160, &paint); - SkScalar s1 = SK_Scalar1; - SkScalar s255 = SkIntToScalar(255); // Move red into alpha, set color to white - SkScalar data[20] = { - 0, 0, 0, 0, s255, - 0, 0, 0, 0, s255, - 0, 0, 0, 0, s255, - s1, 0, 0, 0, 0, + float data[20] = { + 0, 0, 0, 0, 1, + 0, 0, 0, 0, 1, + 0, 0, 0, 0, 1, + 1, 0, 0, 0, 0, }; set_array(&paint, data); diff --git a/gm/fadefilter.cpp b/gm/fadefilter.cpp index fe31033b86..1240519346 100644 --- a/gm/fadefilter.cpp +++ b/gm/fadefilter.cpp @@ -11,11 +11,11 @@ // This GM renders correctly in 8888, but fails in PDF DEF_SIMPLE_GM(fadefilter, canvas, 256, 256) { - SkScalar matrix[20] = { 1, 0, 0, 0, 128.0f, - 0, 1, 0, 0, 128.0f, - 0, 0, 1, 0, 128.0f, - 0, 0, 0, 1, 0 }; - sk_sp colorFilter(SkColorFilters::MatrixRowMajor255(matrix)); + float matrix[20] = { 1, 0, 0, 0, 0.5f, + 0, 1, 0, 0, 0.5f, + 0, 0, 1, 0, 0.5f, + 0, 0, 0, 1, 0 }; + sk_sp colorFilter(SkColorFilters::Matrix(matrix)); SkPaint layerPaint; layerPaint.setImageFilter(SkColorFilterImageFilter::Make(std::move(colorFilter), nullptr)); canvas->drawRect(SkRect::MakeLTRB(64, 64, 192, 192), layerPaint); diff --git a/gm/imagefilterscropexpand.cpp b/gm/imagefilterscropexpand.cpp index 5274304a99..5f312b0f41 100644 --- a/gm/imagefilterscropexpand.cpp +++ b/gm/imagefilterscropexpand.cpp @@ -50,11 +50,11 @@ DEF_SIMPLE_GM(imagefilterscropexpand, canvas, 730, 650) { // This color matrix saturates the green component but only partly increases the opacity. // For the opaque checkerboard, the opacity boost doesn't matter but it does impact the // area outside the checkerboard. - SkScalar matrix[20] = { 1, 0, 0, 0, 0, - 0, 1, 0, 0, 255, - 0, 0, 1, 0, 0, - 0, 0, 0, 1, 32 }; - sk_sp cfAlphaTrans(SkColorFilters::MatrixRowMajor255(matrix)); + float matrix[20] = { 1, 0, 0, 0, 0, + 0, 1, 0, 0, 1, + 0, 0, 1, 0, 0, + 0, 0, 0, 1, 32.0f/255 }; + sk_sp cfAlphaTrans(SkColorFilters::Matrix(matrix)); SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); SkScalar MARGIN = SkIntToScalar(12); diff --git a/gm/imagefiltersgraph.cpp b/gm/imagefiltersgraph.cpp index f41be74473..c26f9bf701 100644 --- a/gm/imagefiltersgraph.cpp +++ b/gm/imagefiltersgraph.cpp @@ -62,12 +62,12 @@ protected: { sk_sp morph(SkDilateImageFilter::Make(5, 5, nullptr)); - SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, - 0, SK_Scalar1, 0, 0, 0, - 0, 0, SK_Scalar1, 0, 0, - 0, 0, 0, 0.5f, 0 }; + float matrix[20] = { 1, 0, 0, 0, 0, + 0, 1, 0, 0, 0, + 0, 0, 1, 0, 0, + 0, 0, 0, 0.5f, 0 }; - sk_sp matrixFilter(SkColorFilters::MatrixRowMajor255(matrix)); + sk_sp matrixFilter(SkColorFilters::Matrix(matrix)); sk_sp colorMorph(SkColorFilterImageFilter::Make(std::move(matrixFilter), std::move(morph))); SkPaint paint; @@ -78,11 +78,11 @@ protected: canvas->translate(SkIntToScalar(100), 0); } { - SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, - 0, SK_Scalar1, 0, 0, 0, - 0, 0, SK_Scalar1, 0, 0, - 0, 0, 0, 0.5f, 0 }; - sk_sp matrixCF(SkColorFilters::MatrixRowMajor255(matrix)); + float matrix[20] = { 1, 0, 0, 0, 0, + 0, 1, 0, 0, 0, + 0, 0, 1, 0, 0, + 0, 0, 0, 0.5f, 0 }; + sk_sp matrixCF(SkColorFilters::Matrix(matrix)); sk_sp matrixFilter(SkColorFilterImageFilter::Make(std::move(matrixCF), nullptr)); sk_sp offsetFilter(SkOffsetImageFilter::Make(10.0f, 10.f, diff --git a/gm/imagefromyuvtextures.cpp b/gm/imagefromyuvtextures.cpp index 72f4278142..b19b7e9878 100644 --- a/gm/imagefromyuvtextures.cpp +++ b/gm/imagefromyuvtextures.cpp @@ -20,13 +20,13 @@ static sk_sp yuv_to_rgb_colorfilter() { static const float kJPEGConversionMatrix[20] = { - 1.0f, 0.0f, 1.402f, 0.0f, -180.0f, - 1.0f, -0.344136f, -0.714136f, 0.0f, 136.0f, - 1.0f, 1.772f, 0.0f, 0.0f, -227.6f, + 1.0f, 0.0f, 1.402f, 0.0f, -180.0f/255, + 1.0f, -0.344136f, -0.714136f, 0.0f, 136.0f/255, + 1.0f, 1.772f, 0.0f, 0.0f, -227.6f/255, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f }; - return SkColorFilters::MatrixRowMajor255(kJPEGConversionMatrix); + return SkColorFilters::Matrix(kJPEGConversionMatrix); } namespace skiagm { diff --git a/gm/mixercolorfilter.cpp b/gm/mixercolorfilter.cpp index 603159a083..e73b540be1 100644 --- a/gm/mixercolorfilter.cpp +++ b/gm/mixercolorfilter.cpp @@ -39,14 +39,14 @@ static sk_sp MakeTintColorFilter(SkColor lo, SkColor hi) { // // The input luminance is stored in the alpha channel // (and RGB are cleared -- see SkLumaColorFilter). Thus: - const SkScalar tint_matrix[] = { - 0, 0, 0, (r_hi - r_lo) / 255.0f, SkIntToScalar(r_lo), - 0, 0, 0, (g_hi - g_lo) / 255.0f, SkIntToScalar(g_lo), - 0, 0, 0, (b_hi - b_lo) / 255.0f, SkIntToScalar(b_lo), - 0, 0, 0, (a_hi - a_lo) / 255.0f, SkIntToScalar(a_lo), + const float tint_matrix[] = { + 0, 0, 0, (r_hi - r_lo) / 255.0f, SkIntToScalar(r_lo) / 255.0f, + 0, 0, 0, (g_hi - g_lo) / 255.0f, SkIntToScalar(g_lo) / 255.0f, + 0, 0, 0, (b_hi - b_lo) / 255.0f, SkIntToScalar(b_lo) / 255.0f, + 0, 0, 0, (a_hi - a_lo) / 255.0f, SkIntToScalar(a_lo) / 255.0f, }; - return SkColorFilters::MatrixRowMajor255(tint_matrix) + return SkColorFilters::Matrix(tint_matrix) ->makeComposed(SkLumaColorFilter::Make()); } diff --git a/gm/srgb.cpp b/gm/srgb.cpp index 4968a675f2..358c1387e7 100644 --- a/gm/srgb.cpp +++ b/gm/srgb.cpp @@ -21,7 +21,7 @@ DEF_SIMPLE_GM(srgb_colorfilter, canvas, 512, 256*3) { 0, 0, 1, 0, 0, -1, 0, 0, 1, 0, }; - auto cf0 = SkColorFilters::MatrixRowMajor255(array); + auto cf0 = SkColorFilters::Matrix(array); auto cf1 = SkColorFilters::LinearToSRGBGamma(); auto cf2 = SkColorFilters::SRGBToLinearGamma(); diff --git a/gm/tileimagefilter.cpp b/gm/tileimagefilter.cpp index a3f4f1e871..b2c5b196e6 100644 --- a/gm/tileimagefilter.cpp +++ b/gm/tileimagefilter.cpp @@ -85,17 +85,17 @@ protected: } { - SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0, - 0, SK_Scalar1, 0, 0, 0, - 0, 0, SK_Scalar1, 0, 0, - 0, 0, 0, SK_Scalar1, 0 }; + float matrix[20] = { 1, 0, 0, 0, 0, + 0, 1, 0, 0, 0, + 0, 0, 1, 0, 0, + 0, 0, 0, 1, 0 }; SkRect srcRect = SkRect::MakeWH(SkIntToScalar(fBitmap->width()), SkIntToScalar(fBitmap->height())); SkRect dstRect = SkRect::MakeWH(SkIntToScalar(fBitmap->width() * 2), SkIntToScalar(fBitmap->height() * 2)); sk_sp tile(SkTileImageFilter::Make(srcRect, dstRect, nullptr)); - sk_sp cf(SkColorFilters::MatrixRowMajor255(matrix)); + sk_sp cf(SkColorFilters::Matrix(matrix)); SkPaint paint; paint.setImageFilter(SkColorFilterImageFilter::Make(std::move(cf), std::move(tile))); diff --git a/gm/wacky_yuv_formats.cpp b/gm/wacky_yuv_formats.cpp index 77a191990c..945b8a9e05 100644 --- a/gm/wacky_yuv_formats.cpp +++ b/gm/wacky_yuv_formats.cpp @@ -784,13 +784,13 @@ static GrBackendTexture create_yuva_texture(GrGpu* gpu, const SkBitmap& bm, static sk_sp yuv_to_rgb_colorfilter() { static const float kJPEGConversionMatrix[20] = { - 1.0f, 0.0f, 1.402f, 0.0f, -180.0f, - 1.0f, -0.344136f, -0.714136f, 0.0f, 136.0f, - 1.0f, 1.772f, 0.0f, 0.0f, -227.6f, + 1.0f, 0.0f, 1.402f, 0.0f, -180.0f/255, + 1.0f, -0.344136f, -0.714136f, 0.0f, 136.0f/255, + 1.0f, 1.772f, 0.0f, 0.0f, -227.6f/255, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f }; - return SkColorFilters::MatrixRowMajor255(kJPEGConversionMatrix); + return SkColorFilters::Matrix(kJPEGConversionMatrix); } namespace skiagm { diff --git a/modules/sksg/src/SkSGColorFilter.cpp b/modules/sksg/src/SkSGColorFilter.cpp index 939484dc01..b04df183d5 100644 --- a/modules/sksg/src/SkSGColorFilter.cpp +++ b/modules/sksg/src/SkSGColorFilter.cpp @@ -140,14 +140,14 @@ sk_sp Make2ColorGradient(const sk_sp& color0, const sk_sp< // // Composing these two, we get the total tint matrix: - const SkScalar tint_matrix[] = { - dR*SK_LUM_COEFF_R, dR*SK_LUM_COEFF_G, dR*SK_LUM_COEFF_B, 0, c0.fR * 255, - dG*SK_LUM_COEFF_R, dG*SK_LUM_COEFF_G, dG*SK_LUM_COEFF_B, 0, c0.fG * 255, - dB*SK_LUM_COEFF_R, dB*SK_LUM_COEFF_G, dB*SK_LUM_COEFF_B, 0, c0.fB * 255, - 0, 0, 0, 1, 0, + const float tint_matrix[] = { + dR*SK_LUM_COEFF_R, dR*SK_LUM_COEFF_G, dR*SK_LUM_COEFF_B, 0, c0.fR, + dG*SK_LUM_COEFF_R, dG*SK_LUM_COEFF_G, dG*SK_LUM_COEFF_B, 0, c0.fG, + dB*SK_LUM_COEFF_R, dB*SK_LUM_COEFF_G, dB*SK_LUM_COEFF_B, 0, c0.fB, + 0, 0, 0, 1, 0, }; - return SkColorFilters::MatrixRowMajor255(tint_matrix); + return SkColorFilters::Matrix(tint_matrix); } sk_sp MakeNColorGradient(const std::vector>& colors) { @@ -191,7 +191,7 @@ sk_sp MakeNColorGradient(const std::vector>& colors) } SkASSERT(span_start == 256); - const SkScalar luminance_matrix[] = { + const float luminance_matrix[] = { SK_LUM_COEFF_R, SK_LUM_COEFF_G, SK_LUM_COEFF_B, 0, 0, // r' = L SK_LUM_COEFF_R, SK_LUM_COEFF_G, SK_LUM_COEFF_B, 0, 0, // g' = L SK_LUM_COEFF_R, SK_LUM_COEFF_G, SK_LUM_COEFF_B, 0, 0, // b' = L @@ -199,7 +199,7 @@ sk_sp MakeNColorGradient(const std::vector>& colors) }; return SkTableColorFilter::MakeARGB(nullptr, rTable, gTable, bTable) - ->makeComposed(SkColorFilters::MatrixRowMajor255(luminance_matrix)); + ->makeComposed(SkColorFilters::Matrix(luminance_matrix)); } } // namespace diff --git a/samplecode/SampleMixer.cpp b/samplecode/SampleMixer.cpp index 75e308634f..61cf0a7fd0 100644 --- a/samplecode/SampleMixer.cpp +++ b/samplecode/SampleMixer.cpp @@ -16,7 +16,7 @@ #include "src/core/SkUtils.h" #include "tools/Resources.h" -const SkScalar gMat[] = { +const float gMat[] = { .3f, .6f, .1f, 0, 0, .3f, .6f, .1f, 0, 0, .3f, .6f, .1f, 0, 0, @@ -58,7 +58,7 @@ protected: void onDrawContent(SkCanvas* canvas) override { if (!fImg) { fImg = GetResourceAsImage("images/mandrill_256.png"); - fCF0 = SkColorFilters::MatrixRowMajor255(gMat); + fCF0 = SkColorFilters::Matrix(gMat); fCF1 = SkColorFilters::Blend(0xFF44CC88, SkBlendMode::kScreen); } diff --git a/samplecode/SampleThinAA.cpp b/samplecode/SampleThinAA.cpp index febb4c5e77..8cdd0f6a54 100644 --- a/samplecode/SampleThinAA.cpp +++ b/samplecode/SampleThinAA.cpp @@ -214,14 +214,14 @@ public: blit.setFilterQuality(scale > 1.f ? kNone_SkFilterQuality : kMedium_SkFilterQuality); if (debugMode) { // Makes anything that's > 1/255 alpha fully opaque and sets color to medium green. - static constexpr SkScalar kFilter[] = { - 0.f, 0.f, 0.f, 0.f, 16.f, - 0.f, 0.f, 0.f, 0.f, 200.f, - 0.f, 0.f, 0.f, 0.f, 16.f, + static constexpr float kFilter[] = { + 0.f, 0.f, 0.f, 0.f, 16.f/255, + 0.f, 0.f, 0.f, 0.f, 200.f/255, + 0.f, 0.f, 0.f, 0.f, 16.f/255, 0.f, 0.f, 0.f, 255.f, 0.f }; - blit.setColorFilter(SkColorFilters::MatrixRowMajor255(kFilter)); + blit.setColorFilter(SkColorFilters::Matrix(kFilter)); } canvas->scale(scale, scale); diff --git a/src/core/SkOverdrawCanvas.cpp b/src/core/SkOverdrawCanvas.cpp index 7d72bc8083..1a5e417fdd 100644 --- a/src/core/SkOverdrawCanvas.cpp +++ b/src/core/SkOverdrawCanvas.cpp @@ -34,12 +34,12 @@ SkOverdrawCanvas::SkOverdrawCanvas(SkCanvas* canvas) 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, + 0.0f, 0.0f, 0.0f, 0.0f, 1.0f/255, }; fPaint.setAntiAlias(false); fPaint.setBlendMode(SkBlendMode::kPlus); - fPaint.setColorFilter(SkColorFilters::MatrixRowMajor255(kIncrementAlpha)); + fPaint.setColorFilter(SkColorFilters::Matrix(kIncrementAlpha)); } namespace { diff --git a/tests/ColorMatrixTest.cpp b/tests/ColorMatrixTest.cpp index 52a19b0ea5..eddcb33fe0 100644 --- a/tests/ColorMatrixTest.cpp +++ b/tests/ColorMatrixTest.cpp @@ -42,12 +42,12 @@ static inline void test_colorMatrixCTS(skiatest::Reporter* reporter) { SkCanvas canvas(bitmap); SkPaint paint; - SkScalar blueToCyan[20] = { + float blueToCyan[20] = { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f }; - paint.setColorFilter(SkColorFilters::MatrixRowMajor255(blueToCyan)); + paint.setColorFilter(SkColorFilters::Matrix(blueToCyan)); paint.setColor(SK_ColorBLUE); canvas.drawPoint(0, 0, paint); @@ -66,13 +66,13 @@ static inline void test_colorMatrixCTS(skiatest::Reporter* reporter) { canvas.drawPoint(0, 0, paint); assert_color(reporter, SK_ColorWHITE, bitmap.getColor(0, 0)); - SkScalar transparentRedAddBlue[20] = { + float transparentRedAddBlue[20] = { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, 64.0f, + 0.0f, 0.0f, 1.0f, 0.0f, 64.0f/255, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f }; - paint.setColorFilter(SkColorFilters::MatrixRowMajor255(transparentRedAddBlue)); + paint.setColorFilter(SkColorFilters::Matrix(transparentRedAddBlue)); bitmap.eraseColor(SK_ColorTRANSPARENT); paint.setColor(SK_ColorRED); @@ -93,7 +93,7 @@ static inline void test_colorMatrixCTS(skiatest::Reporter* reporter) { assert_color(reporter, SK_ColorCYAN, bitmap.getColor(0, 0)); // create a new filter with the changed matrix - paint.setColorFilter(SkColorFilters::MatrixRowMajor255(transparentRedAddBlue)); + paint.setColorFilter(SkColorFilters::Matrix(transparentRedAddBlue)); canvas.drawPoint(0, 0, paint); assert_color(reporter, SK_ColorBLUE, bitmap.getColor(0, 0)); } @@ -107,13 +107,13 @@ DEF_TEST(ColorMatrix_clamp_while_unpremul, r) { // This matrix does green += 255/255 and alpha += 32/255. We want to test // that if we pass it opaque alpha and small red and blue values, red and // blue stay unchanged, not pumped up by that ~1.12 intermediate alpha. - SkScalar m[] = { + float m[] = { 1, 0, 0, 0, 0, - 0, 1, 0, 0, 255, + 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, - 0, 0, 0, 1, 32, + 0, 0, 0, 1, 32.0f/255, }; - auto filter = SkColorFilters::MatrixRowMajor255(m); + auto filter = SkColorFilters::Matrix(m); SkColor filtered = filter->filterColor(0xff0a0b0c); REPORTER_ASSERT(r, SkColorGetA(filtered) == 0xff); diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp index 95d07d6fc6..b9ef638e9e 100644 --- a/tests/ImageFilterTest.cpp +++ b/tests/ImageFilterTest.cpp @@ -339,24 +339,24 @@ static sk_sp make_small_image() { } static sk_sp make_scale(float amount, sk_sp input) { - SkScalar s = amount; - SkScalar matrix[20] = { s, 0, 0, 0, 0, - 0, s, 0, 0, 0, - 0, 0, s, 0, 0, - 0, 0, 0, s, 0 }; - sk_sp filter(SkColorFilters::MatrixRowMajor255(matrix)); + float s = amount; + float matrix[20] = { s, 0, 0, 0, 0, + 0, s, 0, 0, 0, + 0, 0, s, 0, 0, + 0, 0, 0, s, 0 }; + sk_sp filter(SkColorFilters::Matrix(matrix)); return SkColorFilterImageFilter::Make(std::move(filter), std::move(input)); } static sk_sp make_grayscale(sk_sp input, const SkImageFilter::CropRect* cropRect) { - SkScalar matrix[20]; - memset(matrix, 0, 20 * sizeof(SkScalar)); + float matrix[20]; + memset(matrix, 0, 20 * sizeof(float)); matrix[0] = matrix[5] = matrix[10] = 0.2126f; matrix[1] = matrix[6] = matrix[11] = 0.7152f; matrix[2] = matrix[7] = matrix[12] = 0.0722f; matrix[18] = 1.0f; - sk_sp filter(SkColorFilters::MatrixRowMajor255(matrix)); + sk_sp filter(SkColorFilters::Matrix(matrix)); return SkColorFilterImageFilter::Make(std::move(filter), std::move(input), cropRect); } @@ -454,14 +454,14 @@ DEF_TEST(ImageFilter, reporter) { { // Check that two non-commutative matrices are concatenated in // the correct order. - SkScalar blueToRedMatrix[20] = { 0 }; - blueToRedMatrix[2] = blueToRedMatrix[18] = SK_Scalar1; - SkScalar redToGreenMatrix[20] = { 0 }; - redToGreenMatrix[5] = redToGreenMatrix[18] = SK_Scalar1; - sk_sp blueToRed(SkColorFilters::MatrixRowMajor255(blueToRedMatrix)); + float blueToRedMatrix[20] = { 0 }; + blueToRedMatrix[2] = blueToRedMatrix[18] = 1; + float redToGreenMatrix[20] = { 0 }; + redToGreenMatrix[5] = redToGreenMatrix[18] = 1; + sk_sp blueToRed(SkColorFilters::Matrix(blueToRedMatrix)); sk_sp filter1(SkColorFilterImageFilter::Make(std::move(blueToRed), nullptr)); - sk_sp redToGreen(SkColorFilters::MatrixRowMajor255(redToGreenMatrix)); + sk_sp redToGreen(SkColorFilters::Matrix(redToGreenMatrix)); sk_sp filter2(SkColorFilterImageFilter::Make(std::move(redToGreen), std::move(filter1))); @@ -1557,11 +1557,12 @@ DEF_TEST(ImageFilterCanComputeFastBounds, reporter) { } { - SkScalar greenMatrix[20] = { 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1, - 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1 }; - sk_sp greenCF(SkColorFilters::MatrixRowMajor255(greenMatrix)); + float greenMatrix[20] = { 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1.0f/255, + 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1.0f/255 + }; + sk_sp greenCF(SkColorFilters::Matrix(greenMatrix)); sk_sp green(SkColorFilterImageFilter::Make(greenCF, nullptr)); REPORTER_ASSERT(reporter, greenCF->affectsTransparentBlack());