Remove gradient SkFixed position records

At this point they are only used to build a cache key.  Replace with
float positions and delete the supporting code.

Change-Id: Ida12fd39ed3f612a807de4505c7398838e0693be
Reviewed-on: https://skia-review.googlesource.com/64940
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
This commit is contained in:
Florin Malita 2017-10-28 21:42:50 -04:00 committed by Skia Commit-Bot
parent e33f9ca61e
commit cad3b8c031
2 changed files with 5 additions and 52 deletions

View File

@ -8,6 +8,7 @@
#include <algorithm>
#include "Sk4fLinearGradient.h"
#include "SkColorSpace_XYZ.h"
#include "SkFloatBits.h"
#include "SkGradientBitmapCache.h"
#include "SkGradientShaderPriv.h"
#include "SkHalf.h"
@ -147,7 +148,7 @@ SkGradientShaderBase::SkGradientShaderBase(const Descriptor& desc, const SkMatri
}
if (fColorCount > kColorStorageCount) {
size_t size = sizeof(SkColor) + sizeof(SkColor4f) + sizeof(Rec);
size_t size = sizeof(SkColor) + sizeof(SkColor4f);
if (desc.fPos) {
size += sizeof(SkScalar);
}
@ -189,29 +190,15 @@ SkGradientShaderBase::SkGradientShaderBase(const Descriptor& desc, const SkMatri
if (desc.fPos && fColorCount) {
fOrigPos = (SkScalar*)(fOrigColors4f + fColorCount);
fRecs = (Rec*)(fOrigPos + fColorCount);
} else {
fOrigPos = nullptr;
fRecs = (Rec*)(fOrigColors4f + fColorCount);
}
if (fColorCount > 2) {
Rec* recs = fRecs;
recs->fPos = 0;
// recs->fScale = 0; // unused;
recs += 1;
if (desc.fPos) {
SkScalar* origPosPtr = fOrigPos;
*origPosPtr++ = 0;
/* We need to convert the user's array of relative positions into
fixed-point positions and scale factors. We need these results
to be strictly monotonic (no two values equal or out of order).
Hence this complex loop that just jams a zero for the scale
value if it sees a segment out of order, and it assures that
we start at 0 and end at 1.0
*/
SkScalar prev = 0;
int startIndex = dummyFirst ? 0 : 1;
int count = desc.fCount + dummyLast;
for (int i = startIndex; i < count; i++) {
@ -223,32 +210,7 @@ SkGradientShaderBase::SkGradientShaderBase(const Descriptor& desc, const SkMatri
curr = SkScalarPin(desc.fPos[i], 0, 1);
}
*origPosPtr++ = curr;
recs->fPos = SkScalarToFixed(curr);
SkFixed diff = SkScalarToFixed(curr - prev);
if (diff > 0) {
recs->fScale = (1 << 24) / diff;
} else {
recs->fScale = 0; // ignore this segment
}
// get ready for the next value
prev = curr;
recs += 1;
}
} else { // assume even distribution
fOrigPos = nullptr;
SkFixed dp = SK_Fixed1 / (desc.fCount - 1);
SkFixed p = dp;
SkFixed scale = (desc.fCount - 1) << 8; // (1 << 24) / dp
for (int i = 1; i < desc.fCount - 1; i++) {
recs->fPos = p;
recs->fScale = scale;
recs += 1;
p += dp;
}
recs->fPos = SK_Fixed1;
recs->fScale = scale;
}
} else if (desc.fPos) {
SkASSERT(2 == fColorCount);
@ -585,7 +547,7 @@ void SkGradientShaderBase::getGradientTableBitmap(SkBitmap* bitmap,
// build our key: [numColors + colors[] + {positions[]} + flags + colorType ]
int count = 1 + fColorCount + 1 + 1;
if (fColorCount > 2) {
count += fColorCount - 1; // fRecs[].fPos
count += fColorCount - 1;
}
SkAutoSTMalloc<16, int32_t> storage(count);
@ -596,7 +558,7 @@ void SkGradientShaderBase::getGradientTableBitmap(SkBitmap* bitmap,
buffer += fColorCount;
if (fColorCount > 2) {
for (int i = 1; i < fColorCount; i++) {
*buffer++ = fRecs[i].fPos;
*buffer++ = SkFloat2Bits(this->getPos(i));
}
}
*buffer++ = fGradFlags;

View File

@ -12,7 +12,6 @@
#include "SkArenaAlloc.h"
#include "SkAutoMalloc.h"
#include "SkFixed.h"
#include "SkMatrix.h"
#include "SkShaderBase.h"
#include "SkTDArray.h"
@ -80,11 +79,6 @@ public:
SkColor4f getXformedColor(size_t index, SkColorSpace*) const;
protected:
struct Rec {
SkFixed fPos; // 0...1
uint32_t fScale; // (1 << 24) / range
};
class GradientShaderBase4fContext;
SkGradientShaderBase(SkReadBuffer& );
@ -114,14 +108,12 @@ protected:
const SkMatrix fPtsToUnit;
TileMode fTileMode;
uint8_t fGradFlags;
Rec* fRecs;
private:
enum {
kColorStorageCount = 4, // more than this many colors, and we'll use sk_malloc for the space
kStorageSize = kColorStorageCount *
(sizeof(SkColor) + sizeof(SkScalar) + sizeof(Rec) + sizeof(SkColor4f))
kStorageSize = kColorStorageCount * (sizeof(SkColor) + sizeof(SkScalar) + sizeof(SkColor4f))
};
SkColor fStorage[(kStorageSize + 3) >> 2];
public:
@ -139,7 +131,6 @@ public:
bool colorsAreOpaque() const { return fColorsAreOpaque; }
TileMode getTileMode() const { return fTileMode; }
Rec* getRecs() const { return fRecs; }
private:
bool fColorsAreOpaque;