Image filter DAG test for makeColorSpace()

Change-Id: I8aa3a8c701fdfe215cae639bc9c7082340c756d4
Reviewed-on: https://skia-review.googlesource.com/21721
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
This commit is contained in:
Florin Malita 2017-07-06 12:48:15 -04:00 committed by Skia Commit-Bot
parent 6d9f42984d
commit 08252eca36

View File

@ -10,6 +10,7 @@
#include "SkCanvas.h"
#include "SkColorFilterImageFilter.h"
#include "SkColorMatrixFilter.h"
#include "SkColorSpaceXformer.h"
#include "SkComposeImageFilter.h"
#include "SkDisplacementMapEffect.h"
#include "SkDropShadowImageFilter.h"
@ -1877,3 +1878,48 @@ DEF_TEST(ImageFilterComplexCTM, reporter) {
REPORTER_ASSERT(reporter, canHandle == rec.fExpectCanHandle);
}
}
// Test that transforming the filter DAG doesn't clone shared nodes multiple times.
DEF_TEST(ImageFilterColorSpaceDAG, reporter) {
// Helper for counting makeColorSpace() clones.
class TestFilter final : public SkImageFilter {
public:
TestFilter() : INHERITED(nullptr, 0, nullptr) {}
#ifndef SK_IGNORE_TO_STRING
void toString(SkString*) const override {}
#endif
Factory getFactory() const override { return nullptr; }
size_t cloneCount() const { return fCloneCount; }
protected:
sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* src, const Context&,
SkIPoint* offset) const override {
return nullptr;
}
sk_sp<SkImageFilter> onMakeColorSpace(SkColorSpaceXformer*) const override {
fCloneCount++;
return sk_ref_sp(const_cast<TestFilter*>(this));
}
private:
typedef SkImageFilter INHERITED;
mutable size_t fCloneCount = 0;
};
auto filter = sk_make_sp<TestFilter>();
REPORTER_ASSERT(reporter, filter->cloneCount() == 0u);
// Build a DAG referencing the filter twice.
auto complexFilter = SkMergeImageFilter::Make(filter, SkOffsetImageFilter::Make(1, 1, filter));
REPORTER_ASSERT(reporter, filter->cloneCount() == 0u);
auto xformer = SkColorSpaceXformer::Make(SkColorSpace::MakeSRGB());
auto xformedFilter = xformer->apply(complexFilter.get());
// FIXME: clone count should be 1 at this point.
REPORTER_ASSERT(reporter, filter->cloneCount() == 2u);
}