From 19d7bd65045e88724ad59a8d7066a9092754c7e4 Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Mon, 19 Feb 2018 14:10:57 -0500 Subject: hide virtual and rename to onMakeComposed Bug: skia: Change-Id: Ic18ee2af3273f81ebec9c9031162e808186c0acd Reviewed-on: https://skia-review.googlesource.com/108300 Reviewed-by: Mike Reed Commit-Queue: Mike Reed --- fuzz/FuzzCanvas.cpp | 2 +- gm/color4f.cpp | 5 ++--- gm/srgb.cpp | 4 ++-- gm/tablecolorfilter.cpp | 2 +- include/core/SkColorFilter.h | 30 +++++++++++++++++------------ include/core/SkRefCnt.h | 4 ++++ src/core/SkCanvas.cpp | 2 +- src/core/SkColorFilter.cpp | 19 ++++++++---------- src/core/SkColorMatrixFilterRowMajor255.cpp | 2 +- src/core/SkColorMatrixFilterRowMajor255.h | 2 +- src/effects/SkColorFilterImageFilter.cpp | 3 +-- src/effects/SkTableColorFilter.cpp | 4 ++-- src/utils/SkShadowUtils.cpp | 20 ++++++++++--------- tests/ColorFilterTest.cpp | 2 +- tests/TableColorFilterTest.cpp | 2 +- 15 files changed, 55 insertions(+), 48 deletions(-) diff --git a/fuzz/FuzzCanvas.cpp b/fuzz/FuzzCanvas.cpp index ffc8781e6b..a14468f033 100644 --- a/fuzz/FuzzCanvas.cpp +++ b/fuzz/FuzzCanvas.cpp @@ -184,7 +184,7 @@ static sk_sp make_fuzz_colorfilter(Fuzz* fuzz, int depth) { case 2: { sk_sp outer = make_fuzz_colorfilter(fuzz, depth - 1); sk_sp inner = make_fuzz_colorfilter(fuzz, depth - 1); - return SkColorFilter::MakeComposeFilter(std::move(outer), std::move(inner)); + return outer->makeComposed(std::move(inner)); } case 3: { SkScalar array[20]; diff --git a/gm/color4f.cpp b/gm/color4f.cpp index b1ec0bf84b..792f7d58ee 100644 --- a/gm/color4f.cpp +++ b/gm/color4f.cpp @@ -35,14 +35,13 @@ static sk_sp make_cf0() { static sk_sp make_cf1() { SkColorMatrix cm; cm.setSaturation(0.75f); - auto a(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat)); + auto a = SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat); // CreateComposedFilter will try to concat these two matrices, resulting in a single // filter (which is good for speed). For this test, we want to force a real compose of // these two, so our inner filter has a scale-up, which disables the optimization of // combining the two matrices. cm.setScale(1.1f, 0.9f, 1); - auto b(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat)); - return SkColorFilter::MakeComposeFilter(a, b); + return a->makeComposed(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat)); } static sk_sp make_cf2() { diff --git a/gm/srgb.cpp b/gm/srgb.cpp index f0bff6922c..21571c5d8c 100644 --- a/gm/srgb.cpp +++ b/gm/srgb.cpp @@ -32,11 +32,11 @@ DEF_SIMPLE_GM(srgb_colorfilter, canvas, 512, 256*3) { p.setColorFilter(cf1); canvas->drawImage(img, 0, 256, &p); - p.setColorFilter(SkColorFilter::MakeComposeFilter(cf1, cf0)); + p.setColorFilter(cf1->makeComposed(cf0)); canvas->drawImage(img, 256, 256, &p); p.setColorFilter(cf2); canvas->drawImage(img, 0, 512, &p); - p.setColorFilter(SkColorFilter::MakeComposeFilter(cf2, cf0)); + p.setColorFilter(cf2->makeComposed(cf0)); canvas->drawImage(img, 256, 512, &p); } diff --git a/gm/tablecolorfilter.cpp b/gm/tablecolorfilter.cpp index df6f7d6564..8902d59a11 100644 --- a/gm/tablecolorfilter.cpp +++ b/gm/tablecolorfilter.cpp @@ -263,7 +263,7 @@ protected: for (int y = 0; y < MODES; ++y) { canvas->save(); for (int x = 0; x < MODES; ++x) { - paint.setColorFilter(SkColorFilter::MakeComposeFilter(filters[y], filters[x])); + paint.setColorFilter(filters[y]->makeComposed(filters[x])); canvas->drawRect(r, paint); canvas->translate(r.width() + spacer, 0); } diff --git a/include/core/SkColorFilter.h b/include/core/SkColorFilter.h index fde3d26345..1bf18429cd 100644 --- a/include/core/SkColorFilter.h +++ b/include/core/SkColorFilter.h @@ -76,15 +76,6 @@ public: */ virtual uint32_t getFlags() const { return 0; } - /** - * If this subclass can optimally createa composition with the inner filter, return it as - * a new filter (which the caller must unref() when it is done). If no such optimization - * is known, return NULL. - * - * e.g. result(color) == this_filter(inner(color)) - */ - virtual sk_sp makeComposed(sk_sp) const { return nullptr; } - SkColor filterColor(SkColor) const; SkColor4f filterColor4f(const SkColor4f&) const; @@ -100,14 +91,20 @@ public: static sk_sp MakeModeFilter(SkColor c, SkBlendMode mode); /** Construct a colorfilter whose effect is to first apply the inner filter and then apply - * the outer filter to the result of the inner's. - * The reference counts for outer and inner are incremented. + * this filter, applied to the output of the inner filter. + * + * result = this(inner(...)) * * Due to internal limits, it is possible that this will return NULL, so the caller must * always check. */ + sk_sp makeComposed(sk_sp inner) const; + + // DEPRECATED, call makeComposed instead static sk_sp MakeComposeFilter(sk_sp outer, - sk_sp inner); + sk_sp inner) { + return outer ? outer->makeComposed(inner) : inner; + } /** Construct a color filter that transforms a color by a 4x5 matrix. The matrix is in row- * major order and the translation column is specified in unnormalized, 0...255, space. @@ -155,6 +152,15 @@ protected: return sk_ref_sp(const_cast(this)); } + /** + * If this subclass can optimally createa composition with the inner filter, return it as + * a new filter (which the caller must unref() when it is done). If no such optimization + * is known, return NULL. + * + * e.g. result(color) == this_filter(inner(color)) + */ + virtual sk_sp onMakeComposed(sk_sp) const { return nullptr; } + private: /* * Returns 1 if this is a single filter (not a composition of other filters), otherwise it diff --git a/include/core/SkRefCnt.h b/include/core/SkRefCnt.h index 01580abe1a..5d070a2cc1 100644 --- a/include/core/SkRefCnt.h +++ b/include/core/SkRefCnt.h @@ -445,4 +445,8 @@ template sk_sp sk_ref_sp(T* obj) { return sk_sp(SkSafeRef(obj)); } +template sk_sp sk_ref_sp(const T* obj) { + return sk_sp(const_cast(SkSafeRef(obj))); +} + #endif diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 2667f8fed0..5795c0a82a 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -400,7 +400,7 @@ static sk_sp image_to_color_filter(const SkPaint& paint) { // The paint has both a colorfilter(paintCF) and an imagefilter-which-is-a-colorfilter(imgCF) // and we need to combine them into a single colorfilter. - return SkColorFilter::MakeComposeFilter(std::move(imgCF), sk_ref_sp(paintCF)); + return imgCF->makeComposed(sk_ref_sp(paintCF)); } /** diff --git a/src/core/SkColorFilter.cpp b/src/core/SkColorFilter.cpp index 3c6beea794..31e8b3250f 100644 --- a/src/core/SkColorFilter.cpp +++ b/src/core/SkColorFilter.cpp @@ -159,7 +159,7 @@ private: auto outer = xformer->apply(fOuter.get()); auto inner = xformer->apply(fInner.get()); if (outer != fOuter || inner != fInner) { - return SkColorFilter::MakeComposeFilter(outer, inner); + return outer->makeComposed(inner); } return this->INHERITED::onMakeColorSpace(xformer); } @@ -176,29 +176,26 @@ private: sk_sp SkComposeColorFilter::CreateProc(SkReadBuffer& buffer) { sk_sp outer(buffer.readColorFilter()); sk_sp inner(buffer.readColorFilter()); - return MakeComposeFilter(std::move(outer), std::move(inner)); + return outer->makeComposed(std::move(inner)); } -sk_sp SkColorFilter::MakeComposeFilter(sk_sp outer, - sk_sp inner) { - if (!outer) { - return inner; - } + +sk_sp SkColorFilter::makeComposed(sk_sp inner) const { if (!inner) { - return outer; + return sk_ref_sp(this); } // Give the subclass a shot at a more optimal composition... - auto composition = outer->makeComposed(inner); + auto composition = this->onMakeComposed(inner); if (composition) { return composition; } - int count = inner->privateComposedFilterCount() + outer->privateComposedFilterCount(); + int count = inner->privateComposedFilterCount() + this->privateComposedFilterCount(); if (count > SK_MAX_COMPOSE_COLORFILTER_COUNT) { return nullptr; } - return sk_sp(new SkComposeColorFilter(std::move(outer), std::move(inner),count)); + return sk_sp(new SkComposeColorFilter(sk_ref_sp(this), std::move(inner), count)); } /////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/core/SkColorMatrixFilterRowMajor255.cpp b/src/core/SkColorMatrixFilterRowMajor255.cpp index f7d0425dcb..c85ea3d8ec 100644 --- a/src/core/SkColorMatrixFilterRowMajor255.cpp +++ b/src/core/SkColorMatrixFilterRowMajor255.cpp @@ -164,7 +164,7 @@ void SkColorMatrixFilterRowMajor255::onAppendStages(SkRasterPipeline* p, } sk_sp -SkColorMatrixFilterRowMajor255::makeComposed(sk_sp innerFilter) const { +SkColorMatrixFilterRowMajor255::onMakeComposed(sk_sp innerFilter) const { SkScalar innerMatrix[20]; if (innerFilter->asColorMatrix(innerMatrix) && !needs_clamping(innerMatrix)) { SkScalar concat[20]; diff --git a/src/core/SkColorMatrixFilterRowMajor255.h b/src/core/SkColorMatrixFilterRowMajor255.h index 6e63b14b3e..41aec87c5d 100644 --- a/src/core/SkColorMatrixFilterRowMajor255.h +++ b/src/core/SkColorMatrixFilterRowMajor255.h @@ -20,7 +20,7 @@ public: uint32_t getFlags() const override; bool asColorMatrix(SkScalar matrix[20]) const override; - sk_sp makeComposed(sk_sp) const override; + sk_sp onMakeComposed(sk_sp) const override; #if SK_SUPPORT_GPU std::unique_ptr asFragmentProcessor( diff --git a/src/effects/SkColorFilterImageFilter.cpp b/src/effects/SkColorFilterImageFilter.cpp index 50861fe78b..a36cf5f2b5 100644 --- a/src/effects/SkColorFilterImageFilter.cpp +++ b/src/effects/SkColorFilterImageFilter.cpp @@ -27,8 +27,7 @@ sk_sp SkColorFilterImageFilter::Make(sk_sp cf, if (input && input->isColorFilterNode(&inputCF)) { // This is an optimization, as it collapses the hierarchy by just combining the two // colorfilters into a single one, which the new imagefilter will wrap. - sk_sp newCF(SkColorFilter::MakeComposeFilter(cf,// can't move bc of fallthru - sk_sp(inputCF))); + sk_sp newCF = cf->makeComposed(sk_sp(inputCF)); if (newCF) { return sk_sp(new SkColorFilterImageFilter(std::move(newCF), sk_ref_sp(input->getInput(0)), diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp index 45c70d6215..124e98f8ae 100644 --- a/src/effects/SkTableColorFilter.cpp +++ b/src/effects/SkTableColorFilter.cpp @@ -83,7 +83,7 @@ public: ~SkTable_ColorFilter() override { delete fBitmap; } bool asComponentTable(SkBitmap* table) const override; - sk_sp makeComposed(sk_sp inner) const override; + sk_sp onMakeComposed(sk_sp inner) const override; #if SK_SUPPORT_GPU std::unique_ptr asFragmentProcessor( @@ -270,7 +270,7 @@ static void combine_tables(uint8_t res[256], const uint8_t outer[256], const uin } } -sk_sp SkTable_ColorFilter::makeComposed(sk_sp innerFilter) const { +sk_sp SkTable_ColorFilter::onMakeComposed(sk_sp innerFilter) const { SkBitmap innerBM; if (!innerFilter->asComponentTable(&innerBM)) { return nullptr; diff --git a/src/utils/SkShadowUtils.cpp b/src/utils/SkShadowUtils.cpp index 12f95ee120..fcb3432450 100644 --- a/src/utils/SkShadowUtils.cpp +++ b/src/utils/SkShadowUtils.cpp @@ -438,9 +438,9 @@ template SkPaint paint; // Run the vertex color through a GaussianColorFilter and then modulate the grayscale result of // that against our 'color' param. - paint.setColorFilter(SkColorFilter::MakeComposeFilter( - SkColorFilter::MakeModeFilter(color, SkBlendMode::kModulate), - SkGaussianColorFilter::Make())); + paint.setColorFilter( + SkColorFilter::MakeModeFilter(color, SkBlendMode::kModulate)->makeComposed( + SkGaussianColorFilter::Make())); drawProc(vertices.get(), SkBlendMode::kModulate, paint, context.fTranslate.fX, context.fTranslate.fY); @@ -565,9 +565,10 @@ void SkBaseDevice::drawShadow(const SkPath& path, const SkDrawShadowRec& rec) { SkPaint paint; // Run the vertex color through a GaussianColorFilter and then modulate the // grayscale result of that against our 'color' param. - paint.setColorFilter(SkColorFilter::MakeComposeFilter( - SkColorFilter::MakeModeFilter(rec.fAmbientColor, SkBlendMode::kModulate), - SkGaussianColorFilter::Make())); + paint.setColorFilter( + SkColorFilter::MakeModeFilter(rec.fAmbientColor, + SkBlendMode::kModulate)->makeComposed( + SkGaussianColorFilter::Make())); this->drawVertices(vertices.get(), SkBlendMode::kModulate, paint); } } else { @@ -595,9 +596,10 @@ void SkBaseDevice::drawShadow(const SkPath& path, const SkDrawShadowRec& rec) { SkPaint paint; // Run the vertex color through a GaussianColorFilter and then modulate the // grayscale result of that against our 'color' param. - paint.setColorFilter(SkColorFilter::MakeComposeFilter( - SkColorFilter::MakeModeFilter(rec.fSpotColor, SkBlendMode::kModulate), - SkGaussianColorFilter::Make())); + paint.setColorFilter( + SkColorFilter::MakeModeFilter(rec.fSpotColor, + SkBlendMode::kModulate)->makeComposed( + SkGaussianColorFilter::Make())); this->drawVertices(vertices.get(), SkBlendMode::kModulate, paint); } } else { diff --git a/tests/ColorFilterTest.cpp b/tests/ColorFilterTest.cpp index c502a70a4f..dc4a3a0ea5 100644 --- a/tests/ColorFilterTest.cpp +++ b/tests/ColorFilterTest.cpp @@ -42,7 +42,7 @@ static void test_composecolorfilter_limit(skiatest::Reporter* reporter) { auto parent(make_filter()); for (int i = 2; i < way_too_many; ++i) { auto filter(make_filter()); - parent = SkColorFilter::MakeComposeFilter(parent, filter); + parent = parent->makeComposed(filter); if (nullptr == parent) { REPORTER_ASSERT(reporter, i > 2); // we need to have succeeded at least once! return; diff --git a/tests/TableColorFilterTest.cpp b/tests/TableColorFilterTest.cpp index baf6a47b14..857aa7ed69 100644 --- a/tests/TableColorFilterTest.cpp +++ b/tests/TableColorFilterTest.cpp @@ -30,7 +30,7 @@ DEF_TEST(TableColorFilter, r) { // The rec2020 primaries are not representable in sRGB, but will clamp to the sRGB primaries. SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE }; - sk_sp composed = SkColorFilter::MakeComposeFilter(table, to_srgb); + sk_sp composed = table->makeComposed(to_srgb); for (auto color : colors) { REPORTER_ASSERT(r, composed->filterColor(color) == color); } -- cgit v1.2.3