Revert "Revert "add explicit src and dst colorspaces to filterColor4f""
This reverts commit 355111bf7c
.
Change-Id: I0aa45bf92f437a0d680aa788ef4dc5c0299c6fe0
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/244882
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
Auto-Submit: Mike Reed <reed@google.com>
This commit is contained in:
parent
8ab1530cd3
commit
bd84330ba2
@ -3,6 +3,8 @@ Skia Graphics Release Notes
|
||||
This file includes a list of high level updates for each milestone release.
|
||||
|
||||
-----
|
||||
* Add explicit src and dst colorspace parameters to SkColorFilter::filterColor4f()
|
||||
|
||||
* Add SkSurface::MakeFromCAMetalLayer
|
||||
|
||||
* Remove isRectContour and ksNestedFillRects from public
|
||||
|
@ -67,7 +67,13 @@ public:
|
||||
virtual uint32_t getFlags() const { return 0; }
|
||||
|
||||
SkColor filterColor(SkColor) const;
|
||||
SkColor4f filterColor4f(const SkColor4f&, SkColorSpace*) const;
|
||||
|
||||
/**
|
||||
* Converts the src color (in src colorspace), into the dst colorspace,
|
||||
* then applies this filter to it, returning the filtered color in the dst colorspace.
|
||||
*/
|
||||
SkColor4f filterColor4f(const SkColor4f& srcColor, SkColorSpace* srcCS,
|
||||
SkColorSpace* dstCS) const;
|
||||
|
||||
/** Construct a colorfilter whose effect is to first apply the inner filter and then apply
|
||||
* this filter, applied to the output of the inner filter.
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "include/private/SkTo.h"
|
||||
#include "src/core/SkAntiRun.h"
|
||||
#include "src/core/SkArenaAlloc.h"
|
||||
#include "src/core/SkColorSpacePriv.h"
|
||||
#include "src/core/SkMask.h"
|
||||
#include "src/core/SkMaskFilterBase.h"
|
||||
#include "src/core/SkPaintPriv.h"
|
||||
@ -718,6 +719,17 @@ SkBlitter* SkBlitter::Choose(const SkPixmap& device,
|
||||
p->setColor(0x00000000);
|
||||
}
|
||||
|
||||
#ifndef SK_SUPPORT_LEGACY_COLORFILTER_NO_SHADER
|
||||
if (paint->getColorFilter() && !paint->getShader()) {
|
||||
// apply the filter to the paint's color, and then remove the filter
|
||||
auto dstCS = device.colorSpace();
|
||||
SkPaint* p = paint.writable();
|
||||
p->setColor(p->getColorFilter()->filterColor4f(p->getColor4f(), sk_srgb_singleton(), dstCS),
|
||||
dstCS);
|
||||
p->setColorFilter(nullptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (drawCoverage) {
|
||||
if (device.colorType() == kAlpha_8_SkColorType) {
|
||||
SkASSERT(!paint->getShader());
|
||||
|
@ -44,30 +44,39 @@ bool SkColorFilter::appendStages(const SkStageRec& rec, bool shaderIsOpaque) con
|
||||
}
|
||||
|
||||
SkColor SkColorFilter::filterColor(SkColor c) const {
|
||||
return this->filterColor4f(SkColor4f::FromColor(c), nullptr)
|
||||
.toSkColor();
|
||||
#ifdef SK_SUPPORT_LEGACY_COLORFILTER_NO_SHADER
|
||||
SkColorSpace* cs = nullptr;
|
||||
#else
|
||||
SkColorSpace* cs = sk_srgb_singleton();
|
||||
#endif
|
||||
return this->filterColor4f(SkColor4f::FromColor(c), cs, cs).toSkColor();
|
||||
}
|
||||
|
||||
#include "src/core/SkRasterPipeline.h"
|
||||
SkColor4f SkColorFilter::filterColor4f(const SkColor4f& c, SkColorSpace* colorSpace) const {
|
||||
SkPMColor4f dst, src = c.premul();
|
||||
SkColor4f SkColorFilter::filterColor4f(const SkColor4f& origSrcColor, SkColorSpace* srcCS,
|
||||
SkColorSpace* dstCS) const {
|
||||
#ifdef SK_SUPPORT_LEGACY_COLORFILTER_NO_SHADER
|
||||
SkPMColor4f src = origSrcColor.premul();
|
||||
SkColor4f color = *(SkColor4f*)&src;
|
||||
#else
|
||||
SkColor4f color = origSrcColor;
|
||||
SkColorSpaceXformSteps(srcCS, kUnpremul_SkAlphaType,
|
||||
dstCS, kPremul_SkAlphaType).apply(color.vec());
|
||||
#endif
|
||||
|
||||
// determined experimentally, seems to cover compose+colormatrix
|
||||
constexpr size_t kEnoughForCommonFilters = 512;
|
||||
constexpr size_t kEnoughForCommonFilters = 512; // big enough for compose+colormatrix
|
||||
SkSTArenaAlloc<kEnoughForCommonFilters> alloc;
|
||||
SkRasterPipeline pipeline(&alloc);
|
||||
|
||||
pipeline.append_constant_color(&alloc, src.vec());
|
||||
|
||||
pipeline.append_constant_color(&alloc, color.vec());
|
||||
SkPaint dummyPaint;
|
||||
SkStageRec rec = {
|
||||
&pipeline, &alloc, kRGBA_F32_SkColorType, colorSpace, dummyPaint, nullptr, SkMatrix::I()
|
||||
&pipeline, &alloc, kRGBA_F32_SkColorType, dstCS, dummyPaint, nullptr, SkMatrix::I()
|
||||
};
|
||||
this->onAppendStages(rec, c.fA == 1);
|
||||
this->onAppendStages(rec, color.fA == 1);
|
||||
|
||||
SkPMColor4f dst;
|
||||
SkRasterPipeline_MemoryCtx dstPtr = { &dst, 0 };
|
||||
pipeline.append(SkRasterPipeline::store_f32, &dstPtr);
|
||||
pipeline.run(0,0, 1,1);
|
||||
|
||||
return dst.unpremul();
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include "src/core/SkDistanceFieldGen.h"
|
||||
#include "src/core/SkDraw.h"
|
||||
#include "src/core/SkFontPriv.h"
|
||||
#include "src/core/SkPaintPriv.h"
|
||||
#include "src/core/SkRasterClip.h"
|
||||
#include "src/core/SkStrike.h"
|
||||
#include "src/core/SkStrikeCache.h"
|
||||
@ -589,6 +588,7 @@ SkPMColor4f generate_filtered_color(const SkPaint& paint, const GrColorSpaceInfo
|
||||
}
|
||||
if (paint.getColorFilter() != nullptr) {
|
||||
filteredColor = paint.getColorFilter()->filterColor4f(filteredColor,
|
||||
colorSpaceInfo.colorSpace(),
|
||||
colorSpaceInfo.colorSpace());
|
||||
}
|
||||
return filteredColor.premul();
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "include/private/SkTemplates.h"
|
||||
#include "src/core/SkAutoMalloc.h"
|
||||
#include "src/core/SkBlendModePriv.h"
|
||||
#include "src/core/SkColorSpacePriv.h"
|
||||
#include "src/core/SkImagePriv.h"
|
||||
#include "src/core/SkMaskFilterBase.h"
|
||||
#include "src/core/SkMessageBus.h"
|
||||
@ -427,8 +428,8 @@ static inline bool skpaint_to_grpaint_impl(GrRecordingContext* context,
|
||||
SkColorFilter* colorFilter = skPaint.getColorFilter();
|
||||
if (colorFilter) {
|
||||
if (applyColorFilterToPaintColor) {
|
||||
grPaint->setColor4f(
|
||||
colorFilter->filterColor4f(origColor, colorSpaceInfo.colorSpace()).premul());
|
||||
SkColorSpace* dstCS = colorSpaceInfo.colorSpace();
|
||||
grPaint->setColor4f(colorFilter->filterColor4f(origColor, dstCS, dstCS).premul());
|
||||
} else {
|
||||
auto cfFP = colorFilter->asFragmentProcessor(context, colorSpaceInfo);
|
||||
if (cfFP) {
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "src/core/SkAnnotationKeys.h"
|
||||
#include "src/core/SkBitmapDevice.h"
|
||||
#include "src/core/SkClipOpPriv.h"
|
||||
#include "src/core/SkColorSpacePriv.h"
|
||||
#include "src/core/SkDraw.h"
|
||||
#include "src/core/SkGlyphRun.h"
|
||||
#include "src/core/SkImageFilterCache.h"
|
||||
@ -163,7 +164,9 @@ static SkTCopyOnFirstWrite<SkPaint> clean_paint(const SkPaint& srcPaint) {
|
||||
if (SkShader* shader = paint->getShader()) {
|
||||
p->setShader(shader->makeWithColorFilter(paint->refColorFilter()));
|
||||
} else {
|
||||
p->setColor4f(cf->filterColor4f(paint->getColor4f(), nullptr), nullptr);
|
||||
SkColorSpace* dstCS = sk_srgb_singleton(); // don't know PDF's space, so use srgb
|
||||
SkColor4f newColor = cf->filterColor4f(p->getColor4f(), sk_srgb_singleton(), dstCS);
|
||||
p->setColor4f(newColor, dstCS);
|
||||
}
|
||||
p->setColorFilter(nullptr);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user