aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bench/PatchBench.cpp3
-rw-r--r--src/core/SkCanvas.cpp4
-rw-r--r--src/core/SkDevice.cpp5
-rw-r--r--src/core/SkDevice.h3
-rw-r--r--src/utils/SkPatchUtils.cpp57
-rw-r--r--src/utils/SkPatchUtils.h4
6 files changed, 32 insertions, 44 deletions
diff --git a/bench/PatchBench.cpp b/bench/PatchBench.cpp
index d88dd14a2b..375560e15d 100644
--- a/bench/PatchBench.cpp
+++ b/bench/PatchBench.cpp
@@ -351,8 +351,9 @@ public:
{ 0, 0 }, { 10, 0 }, { 10, 10 }, { 0, 10 },
};
+ auto cs = fLinearInterp ? SkColorSpace::MakeSRGBLinear() : nullptr;
for (int i = 0; i < 100*loops; ++i) {
- SkPatchUtils::MakeVertices(pts, colors, tex, 20, 20, fLinearInterp);
+ SkPatchUtils::MakeVertices(pts, colors, tex, 20, 20, cs.get());
}
}
};
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 45bbc64308..5b2a2cf3c2 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -2647,12 +2647,10 @@ void SkCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
return;
}
- const bool interpColorsLinearly = (this->imageInfo().colorSpace() != nullptr);
-
LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, nullptr)
while (iter.next()) {
- iter.fDevice->drawPatch(cubics, colors, texCoords, bmode, interpColorsLinearly, paint);
+ iter.fDevice->drawPatch(cubics, colors, texCoords, bmode, paint);
}
LOOPER_END
diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp
index 08fc3e2b0d..c1359e7075 100644
--- a/src/core/SkDevice.cpp
+++ b/src/core/SkDevice.cpp
@@ -131,11 +131,10 @@ void SkBaseDevice::drawDRRect(const SkRRect& outer,
}
void SkBaseDevice::drawPatch(const SkPoint cubics[12], const SkColor colors[4],
- const SkPoint texCoords[4], SkBlendMode bmode,
- bool interpColorsLinearly, const SkPaint& paint) {
+ const SkPoint texCoords[4], SkBlendMode bmode, const SkPaint& paint) {
SkISize lod = SkPatchUtils::GetLevelOfDetail(cubics, &this->ctm());
auto vertices = SkPatchUtils::MakeVertices(cubics, colors, texCoords, lod.width(), lod.height(),
- interpColorsLinearly);
+ this->imageInfo().colorSpace());
if (vertices) {
this->drawVertices(vertices.get(), nullptr, 0, bmode, paint);
}
diff --git a/src/core/SkDevice.h b/src/core/SkDevice.h
index 93ed3e184a..4959f1fec3 100644
--- a/src/core/SkDevice.h
+++ b/src/core/SkDevice.h
@@ -234,8 +234,7 @@ protected:
const SkPaint& paint, SkDrawFilter* drawFilter);
// default implementation calls drawVertices
virtual void drawPatch(const SkPoint cubics[12], const SkColor colors[4],
- const SkPoint texCoords[4], SkBlendMode, bool interpColorsLinearly,
- const SkPaint& paint);
+ const SkPoint texCoords[4], SkBlendMode, const SkPaint& paint);
// default implementation calls drawPath
virtual void drawAtlas(const SkImage* atlas, const SkRSXform[], const SkRect[],
diff --git a/src/utils/SkPatchUtils.cpp b/src/utils/SkPatchUtils.cpp
index a28abdf807..af91626b51 100644
--- a/src/utils/SkPatchUtils.cpp
+++ b/src/utils/SkPatchUtils.cpp
@@ -252,38 +252,23 @@ struct SkRGBAf {
}
};
-static void skcolor_to_linear(SkRGBAf dst[], const SkColor src[], int count, SkColorSpace* cs,
- bool doPremul) {
- if (cs) {
- auto srcCS = SkColorSpace::MakeSRGB();
- auto dstCS = cs->makeLinearGamma();
- auto op = doPremul ? SkColorSpaceXform::kPremul_AlphaOp
- : SkColorSpaceXform::kPreserve_AlphaOp;
- SkColorSpaceXform::Apply(dstCS.get(), SkColorSpaceXform::kRGBA_F32_ColorFormat, dst,
- srcCS.get(), SkColorSpaceXform::kBGRA_8888_ColorFormat, src,
- count, op);
- } else {
- for (int i = 0; i < count; ++i) {
- dst[i] = SkRGBAf::FromBGRA32(src[i]);
- if (doPremul) {
- dst[i] = dst[i].premul();
- }
- }
- }
+static void skcolor_to_float(SkRGBAf dst[], const SkColor src[], int count, SkColorSpace* dstCS,
+ bool doPremul) {
+ // Source is always sRGB SkColor (safe because sRGB is a global singleton)
+ auto srcCS = SkColorSpace::MakeSRGB().get();
+
+ auto op = doPremul ? SkColorSpaceXform::kPremul_AlphaOp : SkColorSpaceXform::kPreserve_AlphaOp;
+ SkAssertResult(SkColorSpaceXform::Apply(dstCS, SkColorSpaceXform::kRGBA_F32_ColorFormat, dst,
+ srcCS, SkColorSpaceXform::kBGRA_8888_ColorFormat, src,
+ count, op));
}
-static void linear_to_skcolor(SkColor dst[], const SkRGBAf src[], int count, SkColorSpace* cs) {
- if (cs) {
- auto srcCS = cs->makeLinearGamma();
- auto dstCS = SkColorSpace::MakeSRGB();
- SkColorSpaceXform::Apply(dstCS.get(), SkColorSpaceXform::kBGRA_8888_ColorFormat, dst,
- srcCS.get(), SkColorSpaceXform::kRGBA_F32_ColorFormat, src,
- count, SkColorSpaceXform::kPreserve_AlphaOp);
- } else {
- for (int i = 0; i < count; ++i) {
- dst[i] = src[i].toBGRA32();
- }
- }
+static void float_to_skcolor(SkColor dst[], const SkRGBAf src[], int count, SkColorSpace* srcCS) {
+ // Destination is always sRGB SkColor (safe because sRGB is a global singleton)
+ auto dstCS = SkColorSpace::MakeSRGB().get();
+ SkAssertResult(SkColorSpaceXform::Apply(dstCS, SkColorSpaceXform::kBGRA_8888_ColorFormat, dst,
+ srcCS, SkColorSpaceXform::kRGBA_F32_ColorFormat, src,
+ count, SkColorSpaceXform::kPreserve_AlphaOp));
}
static void unpremul(SkRGBAf array[], int count) {
@@ -294,7 +279,7 @@ static void unpremul(SkRGBAf array[], int count) {
sk_sp<SkVertices> SkPatchUtils::MakeVertices(const SkPoint cubics[12], const SkColor srcColors[4],
const SkPoint srcTexCoords[4], int lodX, int lodY,
- bool interpColorsLinearly) {
+ SkColorSpace* colorSpace) {
if (lodX < 1 || lodY < 1 || nullptr == cubics) {
return nullptr;
}
@@ -307,6 +292,11 @@ sk_sp<SkVertices> SkPatchUtils::MakeVertices(const SkPoint cubics[12], const SkC
return nullptr;
}
+ // Treat null interpolation space as sRGB (safe because sRGB is a global singleton)
+ if (!colorSpace) {
+ colorSpace = SkColorSpace::MakeSRGB().get();
+ }
+
int vertexCount = SkToS32(mult64);
// it is recommended to generate draw calls of no more than 65536 indices, so we never generate
// more than 60000 indices. To accomplish that we resize the LOD and vertex count
@@ -333,7 +323,6 @@ sk_sp<SkVertices> SkPatchUtils::MakeVertices(const SkPoint cubics[12], const SkC
SkSTArenaAlloc<2048> alloc;
SkRGBAf* cornerColors = srcColors ? alloc.makeArray<SkRGBAf>(4) : nullptr;
SkRGBAf* tmpColors = srcColors ? alloc.makeArray<SkRGBAf>(vertexCount) : nullptr;
- auto convertCS = interpColorsLinearly ? SkColorSpace::MakeSRGB() : nullptr;
SkVertices::Builder builder(SkVertices::kTriangles_VertexMode, vertexCount, indexCount, flags);
SkPoint* pos = builder.positions();
@@ -357,7 +346,7 @@ sk_sp<SkVertices> SkPatchUtils::MakeVertices(const SkPoint cubics[12], const SkC
doPremul = false; // no need
}
- skcolor_to_linear(cornerColors, srcColors, kNumCorners, convertCS.get(), doPremul);
+ skcolor_to_float(cornerColors, srcColors, kNumCorners, colorSpace, doPremul);
}
SkPoint pts[kNumPtsCubic];
@@ -440,7 +429,7 @@ sk_sp<SkVertices> SkPatchUtils::MakeVertices(const SkPoint cubics[12], const SkC
if (doPremul) {
unpremul(tmpColors, vertexCount);
}
- linear_to_skcolor(builder.colors(), tmpColors, vertexCount, convertCS.get());
+ float_to_skcolor(builder.colors(), tmpColors, vertexCount, colorSpace);
}
return builder.detach();
}
diff --git a/src/utils/SkPatchUtils.h b/src/utils/SkPatchUtils.h
index ee7a1f6dbc..0751f81f6f 100644
--- a/src/utils/SkPatchUtils.h
+++ b/src/utils/SkPatchUtils.h
@@ -12,6 +12,8 @@
#include "SkMatrix.h"
#include "SkVertices.h"
+class SkColorSpace;
+
class SK_API SkPatchUtils {
public:
@@ -49,7 +51,7 @@ public:
static sk_sp<SkVertices> MakeVertices(const SkPoint cubics[12], const SkColor colors[4],
const SkPoint texCoords[4], int lodX, int lodY,
- bool interpColorsLinearly = false);
+ SkColorSpace* colorSpace = nullptr);
};
#endif