Revert of expand unitests for color4f (patchset #1 id:1 of https://codereview.chromium.org/1622893002/ )
Reason for revert:
leaking shadercontext in test
Original issue's description:
> expand unitests for color4f
>
> BUG=skia:
> GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1622893002
>
> TBR=
>
> Committed: https://skia.googlesource.com/skia/+/fac684502b6047ffc7dc2e59bd7e5a7cbfa5bf78
TBR=
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:
Review URL: https://codereview.chromium.org/1622923002
diff --git a/include/core/SkColor.h b/include/core/SkColor.h
index 3ebd18b..f18fb7e 100644
--- a/include/core/SkColor.h
+++ b/include/core/SkColor.h
@@ -169,8 +169,6 @@
float fVec[4];
float a() const { return fVec[SK_A32_SHIFT/8]; }
-
- static SkPM4f FromPMColor(SkPMColor);
};
/*
diff --git a/include/core/SkColorFilter.h b/include/core/SkColorFilter.h
index aece22e..211aae6 100644
--- a/include/core/SkColorFilter.h
+++ b/include/core/SkColorFilter.h
@@ -81,10 +81,6 @@
*/
virtual uint32_t getFlags() const { return 0; }
- bool supports4f() const {
- return SkToBool(this->getFlags() & kSupports4f_Flag);
- }
-
/**
* 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
diff --git a/include/core/SkShader.h b/include/core/SkShader.h
index 297091d..bf6d6dd 100644
--- a/include/core/SkShader.h
+++ b/include/core/SkShader.h
@@ -121,10 +121,6 @@
*/
virtual uint32_t getFlags() const { return 0; }
- bool supports4f() const {
- return SkToBool(this->getFlags() & kSupports4f_Flag);
- }
-
/**
* Called for each span of the object being drawn. Your subclass should
* set the appropriate colors (with premultiplied alpha) that correspond
diff --git a/src/core/SkColor.cpp b/src/core/SkColor.cpp
index 1794cd7..c9f4a14 100644
--- a/src/core/SkColor.cpp
+++ b/src/core/SkColor.cpp
@@ -104,10 +104,9 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
#include "SkNx.h"
-SkPM4f SkPM4f::FromPMColor(SkPMColor c) {
- Sk4f value = SkNx_cast<float>(Sk4b::Load((const uint8_t*)&c));
- SkPM4f c4;
- (value * Sk4f(1.0f / 255)).store(c4.fVec);
+SkColor4f SkColor4f::Pin(float a, float r, float g, float b) {
+ SkColor4f c4;
+ Sk4f::Min(Sk4f::Max(Sk4f(a, r, g, b), Sk4f(0)), Sk4f(1)).store(c4.vec());
return c4;
}
@@ -118,12 +117,6 @@
return c4;
}
-SkColor4f SkColor4f::Pin(float a, float r, float g, float b) {
- SkColor4f c4;
- Sk4f::Min(Sk4f::Max(Sk4f(a, r, g, b), Sk4f(0)), Sk4f(1)).store(c4.vec());
- return c4;
-}
-
SkPM4f SkColor4f::premul() const {
auto src = Sk4f::Load(this->pin().vec());
float srcAlpha = src.kth<0>(); // need the pinned version of our alpha
diff --git a/tests/SkColor4fTest.cpp b/tests/SkColor4fTest.cpp
index 6069246..b09b0c4 100644
--- a/tests/SkColor4fTest.cpp
+++ b/tests/SkColor4fTest.cpp
@@ -6,30 +6,11 @@
*/
#include "SkColor.h"
-#include "SkColorMatrixFilter.h"
-#include "SkGradientShader.h"
-#include "SkImage.h"
#include "SkShader.h"
-
+#include "SkColorMatrixFilter.h"
#include "Test.h"
#include "SkRandom.h"
-const float kTolerance = 1.0f / (1 << 20);
-
-static bool nearly_equal(float a, float b, float tol = kTolerance) {
- SkASSERT(tol >= 0);
- return fabsf(a - b) <= tol;
-}
-
-static bool nearly_equal(const SkPM4f a, const SkPM4f& b, float tol = kTolerance) {
- for (int i = 0; i < 4; ++i) {
- if (!nearly_equal(a.fVec[i], b.fVec[i], tol)) {
- return false;
- }
- }
- return true;
-}
-
DEF_TEST(SkColor4f_FromColor, reporter) {
const struct {
SkColor fC;
@@ -50,7 +31,12 @@
}
}
-DEF_TEST(Color4f_premul, reporter) {
+static bool nearly_equal(float a, float b) {
+ const float kTolerance = 1.0f / (1 << 20);
+ return fabsf(a - b) < kTolerance;
+}
+
+DEF_TEST(SkColor4f_premul, reporter) {
SkRandom rand;
for (int i = 0; i < 1000000; ++i) {
@@ -74,119 +60,3 @@
REPORTER_ASSERT(reporter, nearly_equal(pm4.fVec[SK_B_INDEX], c4.fA * c4.fB));
}
}
-
-//////////////////////////////////////////////////////////////////////////////////////////////////
-
-static SkShader* make_color() { return SkShader::CreateColorShader(0xFFBB8855); }
-
-static SkShader* make_image() {
- const SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2);
- const SkPMColor pixels[] {
- SkPackARGB32(0xFF, 0xBB, 0x88, 0x55),
- SkPackARGB32(0xFF, 0xBB, 0x88, 0x55),
- SkPackARGB32(0xFF, 0xBB, 0x88, 0x55),
- SkPackARGB32(0xFF, 0xBB, 0x88, 0x55),
- };
- SkAutoTUnref<SkImage> image(SkImage::NewRasterCopy(info, pixels, sizeof(SkPMColor) * 2));
- return image->newShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
-}
-
-static SkShader* make_grad() {
- const SkPoint pts[] {{ 0, 0 }, { 100, 100 }};
- const SkColor colors[] { SK_ColorRED, SK_ColorBLUE };
- return SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kClamp_TileMode);
-}
-
-static void compare_spans(const SkPM4f span4f[], const SkPMColor span4b[], int count,
- skiatest::Reporter* reporter) {
- for (int i = 0; i < count; ++i) {
- SkPM4f c0 = SkPM4f::FromPMColor(span4b[i]);
- SkPM4f c1 = span4f[i];
- REPORTER_ASSERT(reporter, nearly_equal(c0, c1, 1.0f/255));
- }
-}
-
-DEF_TEST(Color4f_shader, reporter) {
- struct {
- SkShader* (*fFact)();
- bool fSupports4f;
- } recs[] = {
- { make_color, true },
- { make_grad, false },
- { make_image, false },
- };
-
- SkPaint paint;
- for (const auto& rec : recs) {
- uint32_t storage[200];
- paint.setShader(rec.fFact())->unref();
- SkASSERT(paint.getShader()->contextSize() <= sizeof(storage));
- SkShader::Context* ctx = paint.getShader()->createContext({paint, SkMatrix::I(), nullptr},
- storage);
- REPORTER_ASSERT(reporter, ctx->supports4f() == rec.fSupports4f);
- if (ctx->supports4f()) {
- const int N = 100;
- SkPM4f buffer4f[N];
- ctx->shadeSpan4f(0, 0, buffer4f, N);
- SkPMColor buffer4b[N];
- ctx->shadeSpan(0, 0, buffer4b, N);
- compare_spans(buffer4f, buffer4b, N, reporter);
- }
- ctx->SkShader::Context::~Context();
- }
-}
-
-static SkColorFilter* make_mode_cf() {
- return SkColorFilter::CreateModeFilter(0xFFBB8855, SkXfermode::kPlus_Mode);
-}
-
-static SkColorFilter* make_mx_cf() {
- const float mx[] = {
- 0.5f, 0, 0, 0, 0.1f,
- 0, 0.5f, 0, 0, 0.2f,
- 0, 0, 1, 0, -0.1f,
- 0, 0, 0, 1, 0,
- };
- return SkColorMatrixFilter::Create(mx);
-}
-
-static SkColorFilter* make_compose_cf() {
- SkAutoTUnref<SkColorFilter> cf0(make_mode_cf());
- SkAutoTUnref<SkColorFilter> cf1(make_mx_cf());
- return SkColorFilter::CreateComposeFilter(cf0, cf1);
-}
-
-DEF_TEST(Color4f_colorfilter, reporter) {
- struct {
- SkColorFilter* (*fFact)();
- bool fSupports4f;
- } recs[] = {
- { make_mode_cf, false },
- { make_mx_cf, true },
- { make_compose_cf, false },
- };
-
- // prepare the src
- const int N = 100;
- SkPMColor src4b[N];
- SkPM4f src4f[N];
- SkRandom rand;
- for (int i = 0; i < N; ++i) {
- src4b[i] = SkPreMultiplyColor(rand.nextU());
- src4f[i] = SkPM4f::FromPMColor(src4b[i]);
- }
- // confirm that our srcs are (nearly) equal
- compare_spans(src4f, src4b, N, reporter);
-
- for (const auto& rec : recs) {
- SkAutoTUnref<SkColorFilter> filter(rec.fFact());
- REPORTER_ASSERT(reporter, filter->supports4f() == rec.fSupports4f);
- if (filter->supports4f()) {
- SkPMColor dst4b[N];
- filter->filterSpan(src4b, N, dst4b);
- SkPM4f dst4f[N];
- filter->filterSpan4f(src4f, N, dst4f);
- compare_spans(dst4f, dst4b, N, reporter);
- }
- }
-}