Apply color transform for Lattice fixed colors

This is fixing an issue with nine patch not drawing correctly
if there is a color transformaton.

Bug: b/69796044
Test: Ran lattice2 test for gbr-8888
Change-Id: Idadc2938222222750f0f8bfb12650569191b7ad9
Reviewed-on: https://skia-review.googlesource.com/83680
Commit-Queue: Stan Iliev <stani@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
This commit is contained in:
Stan Iliev 2017-12-18 14:46:30 -05:00 committed by Skia Commit-Bot
parent ff50008305
commit 45fd995b96
3 changed files with 27 additions and 4 deletions

View File

@ -164,8 +164,13 @@ public:
const Lattice& lattice, const SkRect& dst,
const SkPaint* paint) override {
if (!fTarget->quickReject(dst)) {
fTarget->drawImageLattice(prepareImage(img).get(), lattice, dst,
MaybePaint(paint, fXformer.get()));
SkSTArray<16, SkColor> colorBuffer;
int count = lattice.fRectTypes && lattice.fColors ?
(lattice.fXCount + 1) * (lattice.fYCount + 1) : 0;
colorBuffer.reset(count);
fTarget->drawImageLattice(prepareImage(img).get(),
fXformer->apply(lattice, colorBuffer.begin(), count),
dst, MaybePaint(paint, fXformer.get()));
}
}
void onDrawAtlas(const SkImage* atlas, const SkRSXform* xforms, const SkRect* tex,
@ -223,8 +228,12 @@ public:
MaybePaint(paint, fXformer.get()));
}
fTarget->drawImageLattice(fXformer->apply(bitmap).get(), lattice, dst,
SkSTArray<16, SkColor> colorBuffer;
int count = lattice.fRectTypes && lattice.fColors?
(lattice.fXCount + 1) * (lattice.fYCount + 1) : 0;
colorBuffer.reset(count);
fTarget->drawImageLattice(fXformer->apply(bitmap).get(),
fXformer->apply(lattice, colorBuffer.begin(), count), dst,
MaybePaint(paint, fXformer.get()));
}
void onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) override {

View File

@ -176,3 +176,14 @@ SkPaint SkColorSpaceXformer::apply(const SkPaint& src) {
return dst;
}
SkCanvas::Lattice SkColorSpaceXformer::apply(const SkCanvas::Lattice& lattice,
SkColor* colorBuffer, int count) {
if (count) {
this->apply(colorBuffer, lattice.fColors, count);
return {lattice.fXDivs, lattice.fYDivs, lattice.fRectTypes,
lattice.fXCount, lattice.fYCount, lattice.fBounds, colorBuffer};
}
return lattice;
}

View File

@ -8,6 +8,7 @@
#ifndef SkColorSpaceXformer_DEFINED
#define SkColorSpaceXformer_DEFINED
#include "SkCanvas.h"
#include "SkColor.h"
#include "SkRefCnt.h"
#include "SkTHash.h"
@ -38,6 +39,8 @@ public:
sk_sp<SkColorSpace> dst() const { return fDst; }
SkCanvas::Lattice apply(const SkCanvas::Lattice&, SkColor*, int);
private:
SkColorSpaceXformer(sk_sp<SkColorSpace> dst, std::unique_ptr<SkColorSpaceXform> fromSRGB);