aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrian Osman <brianosman@google.com>2018-09-04 09:31:50 -0400
committerSkia Commit-Bot <skia-commit-bot@chromium.org>2018-09-04 13:55:46 +0000
commitee87c8629cba96c2426ebbc1905c241af52f9ef0 (patch)
tree397dbdc4ca3ca69e072e87a615c2a3f8edb0593d /src
parent78aceb2f87ff9e35d30de11af814fa45817beb2e (diff)
downloadskqp-ee87c8629cba96c2426ebbc1905c241af52f9ef0.tar.gz
Switch SkPaint's color to SkColor4f
Change-Id: Ic2b83a05739720013a7c30ec014df0747b3f99a5 Reviewed-on: https://skia-review.googlesource.com/149229 Commit-Queue: Brian Osman <brianosman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/atlastext/SkAtlasTextTarget.cpp2
-rw-r--r--src/core/SkGlyphRunPainter.cpp2
-rw-r--r--src/core/SkPaint.cpp42
-rw-r--r--src/core/SkReadBuffer.h1
-rw-r--r--src/gpu/SkGpuDevice_drawTexture.cpp2
-rw-r--r--src/gpu/SkGr.cpp16
-rw-r--r--src/gpu/SkGr.h13
7 files changed, 44 insertions, 34 deletions
diff --git a/src/atlastext/SkAtlasTextTarget.cpp b/src/atlastext/SkAtlasTextTarget.cpp
index 848106a23e..c85e8d0e9e 100644
--- a/src/atlastext/SkAtlasTextTarget.cpp
+++ b/src/atlastext/SkAtlasTextTarget.cpp
@@ -105,7 +105,7 @@ public:
void makeGrPaint(GrMaskFormat, const SkPaint& skPaint, const SkMatrix&,
GrPaint* grPaint) override {
- grPaint->setColor4f(SkColorToPremulGrColor4fLegacy(skPaint.getColor()));
+ grPaint->setColor4f(SkColor4fToPremulGrColor4fLegacy(skPaint.getColor4f()));
}
GrContext* getContext() override {
diff --git a/src/core/SkGlyphRunPainter.cpp b/src/core/SkGlyphRunPainter.cpp
index 13c1e06968..ee002e1717 100644
--- a/src/core/SkGlyphRunPainter.cpp
+++ b/src/core/SkGlyphRunPainter.cpp
@@ -290,7 +290,7 @@ void SkGlyphRunListPainter::drawGlyphRunAsSDFWithFallback(
// -- GrTextContext --------------------------------------------------------------------------------
GrColor generate_filtered_color(const SkPaint& paint, const GrColorSpaceInfo& colorSpaceInfo) {
- GrColor4f filteredColor = SkColorToUnpremulGrColor4f(paint.getColor(), colorSpaceInfo);
+ GrColor4f filteredColor = SkColor4fToUnpremulGrColor4f(paint.getColor4f(), colorSpaceInfo);
if (paint.getColorFilter() != nullptr) {
filteredColor = GrColor4f::FromSkColor4f(
paint.getColorFilter()->filterColor4f(filteredColor.toSkColor4f(),
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp
index 15aa44eebc..43c568ba0b 100644
--- a/src/core/SkPaint.cpp
+++ b/src/core/SkPaint.cpp
@@ -8,6 +8,8 @@
#include "SkPaint.h"
#include "SkColorFilter.h"
+#include "SkColorSpacePriv.h"
+#include "SkColorSpaceXformSteps.h"
#include "SkData.h"
#include "SkDraw.h"
#include "SkFontDescriptor.h"
@@ -52,7 +54,7 @@ SkPaint::SkPaint() {
fTextSize = SkPaintDefaults_TextSize;
fTextScaleX = SK_Scalar1;
fTextSkewX = 0;
- fColor = SK_ColorBLACK;
+ fColor4f = { 0, 0, 0, 1 }; // opaque black
fWidth = 0;
fMiterLimit = SkPaintDefaults_MiterLimit;
fBlendMode = (unsigned)SkBlendMode::kSrcOver;
@@ -80,7 +82,7 @@ SkPaint::SkPaint(const SkPaint& src)
, COPY(fTextSize)
, COPY(fTextScaleX)
, COPY(fTextSkewX)
- , COPY(fColor)
+ , COPY(fColor4f)
, COPY(fWidth)
, COPY(fMiterLimit)
, COPY(fBlendMode)
@@ -100,7 +102,7 @@ SkPaint::SkPaint(SkPaint&& src) {
MOVE(fTextSize);
MOVE(fTextScaleX);
MOVE(fTextSkewX);
- MOVE(fColor);
+ MOVE(fColor4f);
MOVE(fWidth);
MOVE(fMiterLimit);
MOVE(fBlendMode);
@@ -126,7 +128,7 @@ SkPaint& SkPaint::operator=(const SkPaint& src) {
ASSIGN(fTextSize);
ASSIGN(fTextScaleX);
ASSIGN(fTextSkewX);
- ASSIGN(fColor);
+ ASSIGN(fColor4f);
ASSIGN(fWidth);
ASSIGN(fMiterLimit);
ASSIGN(fBlendMode);
@@ -152,7 +154,7 @@ SkPaint& SkPaint::operator=(SkPaint&& src) {
MOVE(fTextSize);
MOVE(fTextScaleX);
MOVE(fTextSkewX);
- MOVE(fColor);
+ MOVE(fColor4f);
MOVE(fWidth);
MOVE(fMiterLimit);
MOVE(fBlendMode);
@@ -174,7 +176,7 @@ bool operator==(const SkPaint& a, const SkPaint& b) {
&& EQUAL(fTextSize)
&& EQUAL(fTextScaleX)
&& EQUAL(fTextSkewX)
- && EQUAL(fColor)
+ && EQUAL(fColor4f)
&& EQUAL(fWidth)
&& EQUAL(fMiterLimit)
&& EQUAL(fBlendMode)
@@ -257,12 +259,18 @@ void SkPaint::setStyle(Style style) {
}
void SkPaint::setColor(SkColor color) {
- fColor = color;
+ fColor4f = SkColor4f::FromColor(color);
+}
+
+void SkPaint::setColor4f(const SkColor4f& color, SkColorSpace* colorSpace) {
+ SkColorSpaceXformSteps steps{colorSpace, kUnpremul_SkAlphaType,
+ sk_srgb_singleton(), kUnpremul_SkAlphaType};
+ fColor4f = color;
+ steps.apply(fColor4f.vec());
}
void SkPaint::setAlpha(U8CPU a) {
- this->setColor(SkColorSetARGB(a, SkColorGetR(fColor),
- SkColorGetG(fColor), SkColorGetB(fColor)));
+ fColor4f.fA = a * (1.0f / 255);
}
void SkPaint::setARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b) {
@@ -1196,7 +1204,7 @@ void SkPaintPriv::Flatten(const SkPaint& paint, SkWriteBuffer& buffer) {
buffer.writeScalar(paint.getTextSkewX());
buffer.writeScalar(paint.getStrokeWidth());
buffer.writeScalar(paint.getStrokeMiter());
- buffer.writeColor(paint.getColor());
+ buffer.writeColor4f(paint.getColor4f());
buffer.writeUInt(pack_paint_flags(paint.getFlags(), paint.getHinting(), paint.getTextAlign(),
paint.getFilterQuality(), flatFlags));
@@ -1225,7 +1233,13 @@ bool SkPaintPriv::Unflatten(SkPaint* paint, SkReadBuffer& buffer) {
paint->setTextSkewX(buffer.readScalar());
paint->setStrokeWidth(buffer.readScalar());
paint->setStrokeMiter(buffer.readScalar());
- paint->setColor(buffer.readColor());
+ if (buffer.isVersionLT(SkReadBuffer::kFloat4PaintColor_Version)) {
+ paint->setColor(buffer.readColor());
+ } else {
+ SkColor4f color;
+ buffer.readColor4f(&color);
+ paint->setColor4f(color, sk_srgb_singleton());
+ }
unsigned flatFlags = unpack_paint_flags(paint, buffer.readUInt());
@@ -1494,9 +1508,9 @@ bool SkPaint::nothingToDraw() const {
}
uint32_t SkPaint::getHash() const {
- // We're going to hash 7 pointers and 7 32-bit values, finishing up with fBitfields,
- // so fBitfields should be 7 pointers and 6 32-bit values from the start.
- static_assert(offsetof(SkPaint, fBitfields) == 7 * sizeof(void*) + 7 * sizeof(uint32_t),
+ // We're going to hash 7 pointers and 11 32-bit values, finishing up with fBitfields,
+ // so fBitfields should be 7 pointers and 10 32-bit values from the start.
+ static_assert(offsetof(SkPaint, fBitfields) == 7 * sizeof(void*) + 10 * sizeof(uint32_t),
"SkPaint_notPackedTightly");
return SkOpts::hash(reinterpret_cast<const uint32_t*>(this),
offsetof(SkPaint, fBitfields) + sizeof(fBitfields));
diff --git a/src/core/SkReadBuffer.h b/src/core/SkReadBuffer.h
index 4a0a2639ac..c539d16981 100644
--- a/src/core/SkReadBuffer.h
+++ b/src/core/SkReadBuffer.h
@@ -80,6 +80,7 @@ public:
kDontNegateImageSize_Version = 62,
kStoreImageBounds_Version = 63,
kRemoveOccluderFromBlurMaskFilter = 64,
+ kFloat4PaintColor_Version = 65,
};
/**
diff --git a/src/gpu/SkGpuDevice_drawTexture.cpp b/src/gpu/SkGpuDevice_drawTexture.cpp
index 47ee36a17a..a29e4ec684 100644
--- a/src/gpu/SkGpuDevice_drawTexture.cpp
+++ b/src/gpu/SkGpuDevice_drawTexture.cpp
@@ -134,7 +134,7 @@ static void draw_texture(const SkPaint& paint, const SkMatrix& ctm, const SkRect
color = paintColorXform ? SkColorToUnpremulGrColor(paint.getColor())
: SkColorToPremulGrColor(paint.getColor());
} else {
- color = SkColorAlphaToGrColor(paint.getColor());
+ color = GrColorPackA4(paint.getAlpha());
}
rtc->drawTexture(clip, std::move(proxy), filter, color, srcRect, dstRect, aa, constraint, ctm,
std::move(textureXform), std::move(paintColorXform));
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 0cc2f202dc..b79f01fa94 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -257,15 +257,15 @@ sk_sp<GrTextureProxy> GrMakeCachedImageProxy(GrProxyProvider* proxyProvider,
GrColor4f SkColorToPremulGrColor4f(SkColor c, const GrColorSpaceInfo& colorSpaceInfo) {
// We want to premultiply after color space conversion, so this is easy:
- return SkColorToUnpremulGrColor4f(c, colorSpaceInfo).premul();
+ return SkColor4fToUnpremulGrColor4f(SkColor4f::FromColor(c), colorSpaceInfo).premul();
}
-GrColor4f SkColorToPremulGrColor4fLegacy(SkColor c) {
- return GrColor4f::FromGrColor(SkColorToUnpremulGrColor(c)).premul();
+GrColor4f SkColor4fToPremulGrColor4fLegacy(SkColor4f c) {
+ return GrColor4f::FromSkColor4f(c).premul();
}
-GrColor4f SkColorToUnpremulGrColor4f(SkColor c, const GrColorSpaceInfo& colorSpaceInfo) {
- GrColor4f color = GrColor4f::FromGrColor(SkColorToUnpremulGrColor(c));
+GrColor4f SkColor4fToUnpremulGrColor4f(SkColor4f c, const GrColorSpaceInfo& colorSpaceInfo) {
+ GrColor4f color = GrColor4f::FromSkColor4f(c);
if (auto* xform = colorSpaceInfo.colorSpaceXformFromSRGB()) {
color = xform->apply(color);
}
@@ -367,7 +367,7 @@ static inline bool skpaint_to_grpaint_impl(GrContext* context,
SkBlendMode* primColorMode,
GrPaint* grPaint) {
// Convert SkPaint color to 4f format in the destination color space
- GrColor4f origColor = SkColorToUnpremulGrColor4f(skPaint.getColor(), colorSpaceInfo);
+ GrColor4f origColor = SkColor4fToUnpremulGrColor4f(skPaint.getColor4f(), colorSpaceInfo);
const GrFPArgs fpArgs(context, &viewM, skPaint.getFilterQuality(), &colorSpaceInfo);
@@ -409,7 +409,7 @@ static inline bool skpaint_to_grpaint_impl(GrContext* context,
}
// We can ignore origColor here - alpha is unchanged by gamma
- GrColor paintAlpha = SkColorAlphaToGrColor(skPaint.getColor());
+ GrColor paintAlpha = GrColorPackA4(skPaint.getAlpha());
if (GrColor_WHITE != paintAlpha) {
// No gamut conversion - paintAlpha is a (linear) alpha value, splatted to all
// color channels. It's value should be treated as the same in ANY color space.
@@ -437,7 +437,7 @@ static inline bool skpaint_to_grpaint_impl(GrContext* context,
grPaint->setColor4f(origColor.opaque());
// We can ignore origColor here - alpha is unchanged by gamma
- GrColor paintAlpha = SkColorAlphaToGrColor(skPaint.getColor());
+ GrColor paintAlpha = GrColorPackA4(skPaint.getAlpha());
if (GrColor_WHITE != paintAlpha) {
// No gamut conversion - paintAlpha is a (linear) alpha value, splatted to all
// color channels. It's value should be treated as the same in ANY color space.
diff --git a/src/gpu/SkGr.h b/src/gpu/SkGr.h
index ec9f30a3bf..1501f904db 100644
--- a/src/gpu/SkGr.h
+++ b/src/gpu/SkGr.h
@@ -58,16 +58,11 @@ static inline GrColor SkColorToUnpremulGrColor(SkColor c) {
return GrColorPackRGBA(r, g, b, a);
}
-/** Transform an SkColor (sRGB bytes) to GrColor4f for the specified color space info. */
+/** Transform an SkColor (sRGB bytes) or SkColor4f (sRGB floats) to GrColor4f
+ for the specified color space info. */
GrColor4f SkColorToPremulGrColor4f(SkColor, const GrColorSpaceInfo&);
-GrColor4f SkColorToPremulGrColor4fLegacy(SkColor);
-GrColor4f SkColorToUnpremulGrColor4f(SkColor, const GrColorSpaceInfo&);
-
-/** Replicates the SkColor's alpha to all four channels of the GrColor. */
-static inline GrColor SkColorAlphaToGrColor(SkColor c) {
- U8CPU a = SkColorGetA(c);
- return GrColorPackRGBA(a, a, a, a);
-}
+GrColor4f SkColor4fToPremulGrColor4fLegacy(SkColor4f);
+GrColor4f SkColor4fToUnpremulGrColor4f(SkColor4f, const GrColorSpaceInfo&);
//////////////////////////////////////////////////////////////////////////////