2008-12-17 15:59:43 +00:00
|
|
|
/* libs/graphics/sgl/SkScan_AntiPath.cpp
|
|
|
|
**
|
|
|
|
** Copyright 2006, The Android Open Source Project
|
|
|
|
**
|
2011-03-02 15:58:18 +00:00
|
|
|
** Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
** you may not use this file except in compliance with the License.
|
|
|
|
** You may obtain a copy of the License at
|
2008-12-17 15:59:43 +00:00
|
|
|
**
|
2011-03-02 15:58:18 +00:00
|
|
|
** http://www.apache.org/licenses/LICENSE-2.0
|
2008-12-17 15:59:43 +00:00
|
|
|
**
|
2011-03-02 15:58:18 +00:00
|
|
|
** Unless required by applicable law or agreed to in writing, software
|
|
|
|
** distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
** See the License for the specific language governing permissions and
|
2008-12-17 15:59:43 +00:00
|
|
|
** limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SkScanPriv.h"
|
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkMatrix.h"
|
|
|
|
#include "SkBlitter.h"
|
|
|
|
#include "SkRegion.h"
|
|
|
|
#include "SkAntiRun.h"
|
|
|
|
|
|
|
|
#define SHIFT 2
|
|
|
|
#define SCALE (1 << SHIFT)
|
|
|
|
#define MASK (SCALE - 1)
|
|
|
|
|
2011-06-09 15:54:38 +00:00
|
|
|
/*
|
|
|
|
We have two techniques for capturing the output of the supersampler:
|
|
|
|
- SUPERMASK, which records a large mask-bitmap
|
|
|
|
this is often faster for small, complex objects
|
|
|
|
- RLE, which records a rle-encoded scanline
|
|
|
|
this is often faster for large objects with big spans
|
|
|
|
|
|
|
|
NEW_AA is a set of code-changes to try to make both paths produce identical
|
|
|
|
results. Its not quite there yet, though the remaining differences may be
|
|
|
|
in the subsequent blits, and not in the different masks/runs...
|
|
|
|
*/
|
2011-04-11 19:43:58 +00:00
|
|
|
//#define FORCE_SUPERMASK
|
|
|
|
//#define FORCE_RLE
|
2011-06-09 15:54:38 +00:00
|
|
|
//#define SK_SUPPORT_NEW_AA
|
2011-04-11 19:43:58 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
class BaseSuperBlitter : public SkBlitter {
|
|
|
|
public:
|
|
|
|
BaseSuperBlitter(SkBlitter* realBlitter, const SkIRect& ir,
|
|
|
|
const SkRegion& clip);
|
|
|
|
|
|
|
|
virtual void blitAntiH(int x, int y, const SkAlpha antialias[],
|
|
|
|
const int16_t runs[]) {
|
|
|
|
SkASSERT(!"How did I get here?");
|
|
|
|
}
|
|
|
|
virtual void blitV(int x, int y, int height, SkAlpha alpha) {
|
|
|
|
SkASSERT(!"How did I get here?");
|
|
|
|
}
|
|
|
|
virtual void blitRect(int x, int y, int width, int height) {
|
|
|
|
SkASSERT(!"How did I get here?");
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkBlitter* fRealBlitter;
|
|
|
|
int fCurrIY;
|
|
|
|
int fWidth, fLeft, fSuperLeft;
|
|
|
|
|
|
|
|
SkDEBUGCODE(int fCurrX;)
|
2011-05-31 19:18:02 +00:00
|
|
|
int fCurrY;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
BaseSuperBlitter::BaseSuperBlitter(SkBlitter* realBlitter, const SkIRect& ir,
|
|
|
|
const SkRegion& clip) {
|
|
|
|
fRealBlitter = realBlitter;
|
2011-03-02 15:58:18 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
// take the union of the ir bounds and clip, since we may be called with an
|
|
|
|
// inverse filltype
|
|
|
|
const int left = SkMin32(ir.fLeft, clip.getBounds().fLeft);
|
|
|
|
const int right = SkMax32(ir.fRight, clip.getBounds().fRight);
|
2011-03-02 15:58:18 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
fLeft = left;
|
|
|
|
fSuperLeft = left << SHIFT;
|
|
|
|
fWidth = right - left;
|
|
|
|
fCurrIY = -1;
|
2011-06-01 17:32:11 +00:00
|
|
|
fCurrY = -1;
|
|
|
|
SkDEBUGCODE(fCurrX = -1;)
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class SuperBlitter : public BaseSuperBlitter {
|
|
|
|
public:
|
|
|
|
SuperBlitter(SkBlitter* realBlitter, const SkIRect& ir,
|
|
|
|
const SkRegion& clip);
|
|
|
|
|
|
|
|
virtual ~SuperBlitter() {
|
|
|
|
this->flush();
|
|
|
|
sk_free(fRuns.fRuns);
|
|
|
|
}
|
|
|
|
|
|
|
|
void flush();
|
|
|
|
|
|
|
|
virtual void blitH(int x, int y, int width);
|
2010-12-06 18:52:40 +00:00
|
|
|
virtual void blitRect(int x, int y, int width, int height);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
SkAlphaRuns fRuns;
|
2011-05-31 19:18:02 +00:00
|
|
|
int fOffsetX;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
SuperBlitter::SuperBlitter(SkBlitter* realBlitter, const SkIRect& ir,
|
|
|
|
const SkRegion& clip)
|
|
|
|
: BaseSuperBlitter(realBlitter, ir, clip) {
|
|
|
|
const int width = fWidth;
|
|
|
|
|
|
|
|
// extra one to store the zero at the end
|
|
|
|
fRuns.fRuns = (int16_t*)sk_malloc_throw((width + 1 + (width + 2)/2) * sizeof(int16_t));
|
|
|
|
fRuns.fAlpha = (uint8_t*)(fRuns.fRuns + width + 1);
|
|
|
|
fRuns.reset(width);
|
2011-05-31 19:18:02 +00:00
|
|
|
|
|
|
|
fOffsetX = 0;
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
2011-04-11 19:43:58 +00:00
|
|
|
void SuperBlitter::flush() {
|
|
|
|
if (fCurrIY >= 0) {
|
|
|
|
if (!fRuns.empty()) {
|
2008-12-17 15:59:43 +00:00
|
|
|
// SkDEBUGCODE(fRuns.dump();)
|
|
|
|
fRealBlitter->blitAntiH(fLeft, fCurrIY, fRuns.fAlpha, fRuns.fRuns);
|
|
|
|
fRuns.reset(fWidth);
|
2011-05-31 19:18:02 +00:00
|
|
|
fOffsetX = 0;
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
fCurrIY = -1;
|
|
|
|
SkDEBUGCODE(fCurrX = -1;)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-11 19:43:58 +00:00
|
|
|
static inline int coverage_to_alpha(int aa) {
|
2008-12-17 15:59:43 +00:00
|
|
|
aa <<= 8 - 2*SHIFT;
|
|
|
|
aa -= aa >> (8 - SHIFT - 1);
|
|
|
|
return aa;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SUPER_Mask ((1 << SHIFT) - 1)
|
|
|
|
|
2011-04-11 19:43:58 +00:00
|
|
|
void SuperBlitter::blitH(int x, int y, int width) {
|
2008-12-17 15:59:43 +00:00
|
|
|
int iy = y >> SHIFT;
|
|
|
|
SkASSERT(iy >= fCurrIY);
|
|
|
|
|
|
|
|
x -= fSuperLeft;
|
|
|
|
// hack, until I figure out why my cubics (I think) go beyond the bounds
|
2011-04-11 19:43:58 +00:00
|
|
|
if (x < 0) {
|
2008-12-17 15:59:43 +00:00
|
|
|
width += x;
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SK_DEBUG
|
|
|
|
SkASSERT(y != fCurrY || x >= fCurrX);
|
|
|
|
#endif
|
2011-05-31 19:18:02 +00:00
|
|
|
SkASSERT(y >= fCurrY);
|
|
|
|
if (fCurrY != y) {
|
|
|
|
fOffsetX = 0;
|
|
|
|
fCurrY = y;
|
|
|
|
}
|
|
|
|
|
2011-04-11 19:43:58 +00:00
|
|
|
if (iy != fCurrIY) { // new scanline
|
2008-12-17 15:59:43 +00:00
|
|
|
this->flush();
|
|
|
|
fCurrIY = iy;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we sub 1 from maxValue 1 time for each block, so that we don't
|
|
|
|
// hit 256 as a summed max, but 255.
|
|
|
|
// int maxValue = (1 << (8 - SHIFT)) - (((y & MASK) + 1) >> SHIFT);
|
|
|
|
|
2011-05-31 14:36:21 +00:00
|
|
|
int start = x;
|
|
|
|
int stop = x + width;
|
|
|
|
|
|
|
|
SkASSERT(start >= 0 && stop > start);
|
|
|
|
int fb = start & SUPER_Mask;
|
|
|
|
int fe = stop & SUPER_Mask;
|
|
|
|
int n = (stop >> SHIFT) - (start >> SHIFT) - 1;
|
|
|
|
|
|
|
|
if (n < 0) {
|
|
|
|
fb = fe - fb;
|
|
|
|
n = 0;
|
|
|
|
fe = 0;
|
|
|
|
} else {
|
|
|
|
if (fb == 0) {
|
|
|
|
n += 1;
|
2011-04-11 19:43:58 +00:00
|
|
|
} else {
|
2011-05-31 14:36:21 +00:00
|
|
|
fb = (1 << SHIFT) - fb;
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
}
|
2011-05-31 19:18:02 +00:00
|
|
|
|
|
|
|
fOffsetX = fRuns.add(x >> SHIFT, coverage_to_alpha(fb), n, coverage_to_alpha(fe),
|
|
|
|
(1 << (8 - SHIFT)) - (((y & MASK) + 1) >> SHIFT),
|
|
|
|
fOffsetX);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
#ifdef SK_DEBUG
|
|
|
|
fRuns.assertValid(y & MASK, (1 << (8 - SHIFT)));
|
|
|
|
fCurrX = x + width;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-04-11 19:43:58 +00:00
|
|
|
void SuperBlitter::blitRect(int x, int y, int width, int height) {
|
2010-12-06 18:52:40 +00:00
|
|
|
for (int i = 0; i < height; ++i) {
|
|
|
|
blitH(x, y + i, width);
|
|
|
|
}
|
|
|
|
|
|
|
|
flush();
|
|
|
|
}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class MaskSuperBlitter : public BaseSuperBlitter {
|
|
|
|
public:
|
|
|
|
MaskSuperBlitter(SkBlitter* realBlitter, const SkIRect& ir,
|
|
|
|
const SkRegion& clip);
|
|
|
|
virtual ~MaskSuperBlitter() {
|
|
|
|
fRealBlitter->blitMask(fMask, fClipRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void blitH(int x, int y, int width);
|
|
|
|
|
2011-04-11 19:43:58 +00:00
|
|
|
static bool CanHandleRect(const SkIRect& bounds) {
|
|
|
|
#ifdef FORCE_RLE
|
|
|
|
return false;
|
|
|
|
#endif
|
2008-12-17 15:59:43 +00:00
|
|
|
int width = bounds.width();
|
|
|
|
int rb = SkAlign4(width);
|
2011-03-02 15:58:18 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
return (width <= MaskSuperBlitter::kMAX_WIDTH) &&
|
|
|
|
(rb * bounds.height() <= MaskSuperBlitter::kMAX_STORAGE);
|
|
|
|
}
|
2011-03-02 15:58:18 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
private:
|
|
|
|
enum {
|
2011-04-11 19:43:58 +00:00
|
|
|
#ifdef FORCE_SUPERMASK
|
|
|
|
kMAX_WIDTH = 2048,
|
|
|
|
kMAX_STORAGE = 1024 * 1024 * 2
|
|
|
|
#else
|
2008-12-17 15:59:43 +00:00
|
|
|
kMAX_WIDTH = 32, // so we don't try to do very wide things, where the RLE blitter would be faster
|
|
|
|
kMAX_STORAGE = 1024
|
2011-04-11 19:43:58 +00:00
|
|
|
#endif
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
SkMask fMask;
|
|
|
|
SkIRect fClipRect;
|
|
|
|
// we add 1 because add_aa_span can write (unchanged) 1 extra byte at the end, rather than
|
|
|
|
// perform a test to see if stopAlpha != 0
|
|
|
|
uint32_t fStorage[(kMAX_STORAGE >> 2) + 1];
|
|
|
|
};
|
|
|
|
|
|
|
|
MaskSuperBlitter::MaskSuperBlitter(SkBlitter* realBlitter, const SkIRect& ir,
|
|
|
|
const SkRegion& clip)
|
|
|
|
: BaseSuperBlitter(realBlitter, ir, clip) {
|
|
|
|
SkASSERT(CanHandleRect(ir));
|
|
|
|
|
|
|
|
fMask.fImage = (uint8_t*)fStorage;
|
|
|
|
fMask.fBounds = ir;
|
|
|
|
fMask.fRowBytes = ir.width();
|
|
|
|
fMask.fFormat = SkMask::kA8_Format;
|
2011-03-02 15:58:18 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
fClipRect = ir;
|
|
|
|
fClipRect.intersect(clip.getBounds());
|
2011-03-02 15:58:18 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
// For valgrind, write 1 extra byte at the end so we don't read
|
|
|
|
// uninitialized memory. See comment in add_aa_span and fStorage[].
|
|
|
|
memset(fStorage, 0, fMask.fBounds.height() * fMask.fRowBytes + 1);
|
|
|
|
}
|
|
|
|
|
2011-04-11 19:43:58 +00:00
|
|
|
static void add_aa_span(uint8_t* alpha, U8CPU startAlpha) {
|
2008-12-17 15:59:43 +00:00
|
|
|
/* I should be able to just add alpha[x] + startAlpha.
|
|
|
|
However, if the trailing edge of the previous span and the leading
|
|
|
|
edge of the current span round to the same super-sampled x value,
|
|
|
|
I might overflow to 256 with this add, hence the funny subtract.
|
|
|
|
*/
|
|
|
|
unsigned tmp = *alpha + startAlpha;
|
|
|
|
SkASSERT(tmp <= 256);
|
|
|
|
*alpha = SkToU8(tmp - (tmp >> 8));
|
|
|
|
}
|
|
|
|
|
2011-04-11 19:43:58 +00:00
|
|
|
static inline uint32_t quadplicate_byte(U8CPU value) {
|
|
|
|
uint32_t pair = (value << 8) | value;
|
|
|
|
return (pair << 16) | pair;
|
|
|
|
}
|
|
|
|
|
|
|
|
// minimum count before we want to setup an inner loop, adding 4-at-a-time
|
|
|
|
#define MIN_COUNT_FOR_QUAD_LOOP 16
|
|
|
|
|
|
|
|
static void add_aa_span(uint8_t* alpha, U8CPU startAlpha, int middleCount,
|
|
|
|
U8CPU stopAlpha, U8CPU maxValue) {
|
2008-12-17 15:59:43 +00:00
|
|
|
SkASSERT(middleCount >= 0);
|
|
|
|
|
|
|
|
/* I should be able to just add alpha[x] + startAlpha.
|
|
|
|
However, if the trailing edge of the previous span and the leading
|
|
|
|
edge of the current span round to the same super-sampled x value,
|
|
|
|
I might overflow to 256 with this add, hence the funny subtract.
|
|
|
|
*/
|
2011-06-09 15:54:38 +00:00
|
|
|
#ifdef SK_SUPPORT_NEW_AA
|
|
|
|
if (startAlpha) {
|
|
|
|
unsigned tmp = *alpha + startAlpha;
|
|
|
|
SkASSERT(tmp <= 256);
|
|
|
|
*alpha++ = SkToU8(tmp - (tmp >> 8));
|
|
|
|
}
|
|
|
|
#else
|
2008-12-17 15:59:43 +00:00
|
|
|
unsigned tmp = *alpha + startAlpha;
|
|
|
|
SkASSERT(tmp <= 256);
|
|
|
|
*alpha++ = SkToU8(tmp - (tmp >> 8));
|
2011-06-09 15:54:38 +00:00
|
|
|
#endif
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2011-04-11 19:43:58 +00:00
|
|
|
if (middleCount >= MIN_COUNT_FOR_QUAD_LOOP) {
|
|
|
|
// loop until we're quad-byte aligned
|
|
|
|
while (SkTCast<intptr_t>(alpha) & 0x3) {
|
|
|
|
alpha[0] = SkToU8(alpha[0] + maxValue);
|
|
|
|
alpha += 1;
|
|
|
|
middleCount -= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int bigCount = middleCount >> 2;
|
|
|
|
uint32_t* qptr = reinterpret_cast<uint32_t*>(alpha);
|
|
|
|
uint32_t qval = quadplicate_byte(maxValue);
|
|
|
|
do {
|
|
|
|
*qptr++ += qval;
|
|
|
|
} while (--bigCount > 0);
|
|
|
|
|
|
|
|
middleCount &= 3;
|
|
|
|
alpha = reinterpret_cast<uint8_t*> (qptr);
|
|
|
|
// fall through to the following while-loop
|
|
|
|
}
|
|
|
|
|
|
|
|
while (--middleCount >= 0) {
|
2008-12-17 15:59:43 +00:00
|
|
|
alpha[0] = SkToU8(alpha[0] + maxValue);
|
|
|
|
alpha += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// potentially this can be off the end of our "legal" alpha values, but that
|
|
|
|
// only happens if stopAlpha is also 0. Rather than test for stopAlpha != 0
|
|
|
|
// every time (slow), we just do it, and ensure that we've allocated extra space
|
|
|
|
// (see the + 1 comment in fStorage[]
|
|
|
|
*alpha = SkToU8(*alpha + stopAlpha);
|
|
|
|
}
|
|
|
|
|
2011-04-11 19:43:58 +00:00
|
|
|
void MaskSuperBlitter::blitH(int x, int y, int width) {
|
2008-12-17 15:59:43 +00:00
|
|
|
int iy = (y >> SHIFT);
|
2011-03-02 15:58:18 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
SkASSERT(iy >= fMask.fBounds.fTop && iy < fMask.fBounds.fBottom);
|
|
|
|
iy -= fMask.fBounds.fTop; // make it relative to 0
|
|
|
|
|
2009-08-21 22:00:12 +00:00
|
|
|
// This should never happen, but it does. Until the true cause is
|
|
|
|
// discovered, let's skip this span instead of crashing.
|
|
|
|
// See http://crbug.com/17569.
|
|
|
|
if (iy < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#ifdef SK_DEBUG
|
|
|
|
{
|
|
|
|
int ix = x >> SHIFT;
|
|
|
|
SkASSERT(ix >= fMask.fBounds.fLeft && ix < fMask.fBounds.fRight);
|
|
|
|
}
|
|
|
|
#endif
|
2011-03-02 15:58:18 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
x -= (fMask.fBounds.fLeft << SHIFT);
|
|
|
|
|
|
|
|
// hack, until I figure out why my cubics (I think) go beyond the bounds
|
2011-04-11 19:43:58 +00:00
|
|
|
if (x < 0) {
|
2008-12-17 15:59:43 +00:00
|
|
|
width += x;
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we sub 1 from maxValue 1 time for each block, so that we don't
|
|
|
|
// hit 256 as a summed max, but 255.
|
|
|
|
// int maxValue = (1 << (8 - SHIFT)) - (((y & MASK) + 1) >> SHIFT);
|
|
|
|
|
|
|
|
uint8_t* row = fMask.fImage + iy * fMask.fRowBytes + (x >> SHIFT);
|
|
|
|
|
|
|
|
int start = x;
|
|
|
|
int stop = x + width;
|
|
|
|
|
|
|
|
SkASSERT(start >= 0 && stop > start);
|
|
|
|
int fb = start & SUPER_Mask;
|
|
|
|
int fe = stop & SUPER_Mask;
|
|
|
|
int n = (stop >> SHIFT) - (start >> SHIFT) - 1;
|
|
|
|
|
|
|
|
|
2011-04-11 19:43:58 +00:00
|
|
|
if (n < 0) {
|
2009-08-12 20:21:49 +00:00
|
|
|
SkASSERT(row >= fMask.fImage);
|
|
|
|
SkASSERT(row < fMask.fImage + kMAX_STORAGE + 1);
|
2008-12-17 15:59:43 +00:00
|
|
|
add_aa_span(row, coverage_to_alpha(fe - fb));
|
2011-04-11 19:43:58 +00:00
|
|
|
} else {
|
2011-06-09 15:54:38 +00:00
|
|
|
#ifdef SK_SUPPORT_NEW_AA
|
|
|
|
if (0 == fb) {
|
|
|
|
n += 1;
|
|
|
|
} else {
|
|
|
|
fb = (1 << SHIFT) - fb;
|
|
|
|
}
|
|
|
|
#else
|
2008-12-17 15:59:43 +00:00
|
|
|
fb = (1 << SHIFT) - fb;
|
2011-06-09 15:54:38 +00:00
|
|
|
#endif
|
2009-08-12 20:21:49 +00:00
|
|
|
SkASSERT(row >= fMask.fImage);
|
|
|
|
SkASSERT(row + n + 1 < fMask.fImage + kMAX_STORAGE + 1);
|
2008-12-17 15:59:43 +00:00
|
|
|
add_aa_span(row, coverage_to_alpha(fb), n, coverage_to_alpha(fe),
|
|
|
|
(1 << (8 - SHIFT)) - (((y & MASK) + 1) >> SHIFT));
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SK_DEBUG
|
|
|
|
fCurrX = x + width;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-03-16 18:46:55 +00:00
|
|
|
/* Returns non-zero if (value << shift) overflows a short, which would mean
|
|
|
|
we could not shift it up and then convert to SkFixed.
|
|
|
|
i.e. is x expressible as signed (16-shift) bits?
|
|
|
|
*/
|
|
|
|
static int overflows_short_shift(int value, int shift) {
|
|
|
|
const int s = 16 + shift;
|
|
|
|
return (value << s >> s) - value;
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SkScan::AntiFillPath(const SkPath& path, const SkRegion& clip,
|
|
|
|
SkBlitter* blitter) {
|
|
|
|
if (clip.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-04-01 18:31:44 +00:00
|
|
|
SkIRect ir;
|
|
|
|
path.getBounds().roundOut(&ir);
|
2008-12-17 15:59:43 +00:00
|
|
|
if (ir.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-03-16 18:46:55 +00:00
|
|
|
// use bit-or since we expect all to pass, so no need to go slower with
|
|
|
|
// a short-circuiting logical-or
|
|
|
|
if (overflows_short_shift(ir.fLeft, SHIFT) |
|
|
|
|
overflows_short_shift(ir.fRight, SHIFT) |
|
|
|
|
overflows_short_shift(ir.fTop, SHIFT) |
|
|
|
|
overflows_short_shift(ir.fBottom, SHIFT)) {
|
|
|
|
// can't supersample, so draw w/o antialiasing
|
2008-12-17 15:59:43 +00:00
|
|
|
SkScan::FillPath(path, clip, blitter);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkScanClipper clipper(blitter, &clip, ir);
|
|
|
|
const SkIRect* clipRect = clipper.getClipRect();
|
|
|
|
|
|
|
|
if (clipper.getBlitter() == NULL) { // clipped out
|
|
|
|
if (path.isInverseFillType()) {
|
|
|
|
blitter->blitRegion(clip);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2011-03-02 15:58:18 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
// now use the (possibly wrapped) blitter
|
|
|
|
blitter = clipper.getBlitter();
|
|
|
|
|
|
|
|
if (path.isInverseFillType()) {
|
2011-03-02 15:58:18 +00:00
|
|
|
sk_blit_above(blitter, ir, clip);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkIRect superRect, *superClipRect = NULL;
|
|
|
|
|
2011-04-11 19:43:58 +00:00
|
|
|
if (clipRect) {
|
2008-12-17 15:59:43 +00:00
|
|
|
superRect.set( clipRect->fLeft << SHIFT, clipRect->fTop << SHIFT,
|
|
|
|
clipRect->fRight << SHIFT, clipRect->fBottom << SHIFT);
|
|
|
|
superClipRect = &superRect;
|
|
|
|
}
|
|
|
|
|
2009-08-21 22:00:12 +00:00
|
|
|
SkASSERT(SkIntToScalar(ir.fTop) <= path.getBounds().fTop);
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
// MaskSuperBlitter can't handle drawing outside of ir, so we can't use it
|
|
|
|
// if we're an inverse filltype
|
2011-04-11 19:43:58 +00:00
|
|
|
if (!path.isInverseFillType() && MaskSuperBlitter::CanHandleRect(ir)) {
|
2008-12-17 15:59:43 +00:00
|
|
|
MaskSuperBlitter superBlit(blitter, ir, clip);
|
2009-08-21 22:00:12 +00:00
|
|
|
SkASSERT(SkIntToScalar(ir.fTop) <= path.getBounds().fTop);
|
2010-02-22 16:05:48 +00:00
|
|
|
sk_fill_path(path, superClipRect, &superBlit, ir.fTop, ir.fBottom, SHIFT, clip);
|
2011-04-11 19:43:58 +00:00
|
|
|
} else {
|
2008-12-17 15:59:43 +00:00
|
|
|
SuperBlitter superBlit(blitter, ir, clip);
|
2010-02-22 16:05:48 +00:00
|
|
|
sk_fill_path(path, superClipRect, &superBlit, ir.fTop, ir.fBottom, SHIFT, clip);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2011-03-02 15:58:18 +00:00
|
|
|
|
|
|
|
if (path.isInverseFillType()) {
|
|
|
|
sk_blit_below(blitter, ir, clip);
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|