зеркало из https://github.com/mozilla/moz-skia.git
coding style
git-svn-id: http://skia.googlecode.com/svn/trunk@1092 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
Родитель
eadc8072aa
Коммит
d11f0e0173
|
@ -17,8 +17,7 @@
|
|||
|
||||
#include "SkAntiRun.h"
|
||||
|
||||
void SkAlphaRuns::reset(int width)
|
||||
{
|
||||
void SkAlphaRuns::reset(int width) {
|
||||
SkASSERT(width > 0);
|
||||
|
||||
fRuns[0] = SkToS16(width);
|
||||
|
@ -29,8 +28,7 @@ void SkAlphaRuns::reset(int width)
|
|||
SkDEBUGCODE(this->validate();)
|
||||
}
|
||||
|
||||
void SkAlphaRuns::Break(int16_t runs[], uint8_t alpha[], int x, int count)
|
||||
{
|
||||
void SkAlphaRuns::Break(int16_t runs[], uint8_t alpha[], int x, int count) {
|
||||
SkASSERT(count > 0 && x >= 0);
|
||||
|
||||
// SkAlphaRuns::BreakAt(runs, alpha, x);
|
||||
|
@ -39,13 +37,11 @@ void SkAlphaRuns::Break(int16_t runs[], uint8_t alpha[], int x, int count)
|
|||
int16_t* next_runs = runs + x;
|
||||
uint8_t* next_alpha = alpha + x;
|
||||
|
||||
while (x > 0)
|
||||
{
|
||||
while (x > 0) {
|
||||
int n = runs[0];
|
||||
SkASSERT(n > 0);
|
||||
|
||||
if (x < n)
|
||||
{
|
||||
if (x < n) {
|
||||
alpha[x] = alpha[0];
|
||||
runs[0] = SkToS16(x);
|
||||
runs[x] = SkToS16(n - x);
|
||||
|
@ -60,37 +56,34 @@ void SkAlphaRuns::Break(int16_t runs[], uint8_t alpha[], int x, int count)
|
|||
alpha = next_alpha;
|
||||
x = count;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
for (;;) {
|
||||
int n = runs[0];
|
||||
SkASSERT(n > 0);
|
||||
|
||||
if (x < n)
|
||||
{
|
||||
if (x < n) {
|
||||
alpha[x] = alpha[0];
|
||||
runs[0] = SkToS16(x);
|
||||
runs[x] = SkToS16(n - x);
|
||||
break;
|
||||
}
|
||||
x -= n;
|
||||
if (x <= 0)
|
||||
if (x <= 0) {
|
||||
break;
|
||||
|
||||
}
|
||||
runs += n;
|
||||
alpha += n;
|
||||
}
|
||||
}
|
||||
|
||||
void SkAlphaRuns::add(int x, U8CPU startAlpha, int middleCount, U8CPU stopAlpha, U8CPU maxValue)
|
||||
{
|
||||
void SkAlphaRuns::add(int x, U8CPU startAlpha, int middleCount, U8CPU stopAlpha,
|
||||
U8CPU maxValue) {
|
||||
SkASSERT(middleCount >= 0);
|
||||
SkASSERT(x >= 0 && x + (startAlpha != 0) + middleCount + (stopAlpha != 0) <= fWidth);
|
||||
|
||||
int16_t* runs = fRuns;
|
||||
uint8_t* alpha = fAlpha;
|
||||
|
||||
if (startAlpha)
|
||||
{
|
||||
if (startAlpha) {
|
||||
SkAlphaRuns::Break(runs, alpha, x, 1);
|
||||
/* I should be able to just add alpha[x] + startAlpha.
|
||||
However, if the trailing edge of the previous span and the leading
|
||||
|
@ -106,8 +99,8 @@ void SkAlphaRuns::add(int x, U8CPU startAlpha, int middleCount, U8CPU stopAlpha,
|
|||
x = 0;
|
||||
SkDEBUGCODE(this->validate();)
|
||||
}
|
||||
if (middleCount)
|
||||
{
|
||||
|
||||
if (middleCount) {
|
||||
SkAlphaRuns::Break(runs, alpha, x, middleCount);
|
||||
alpha += x;
|
||||
runs += x;
|
||||
|
@ -122,8 +115,8 @@ void SkAlphaRuns::add(int x, U8CPU startAlpha, int middleCount, U8CPU stopAlpha,
|
|||
} while (middleCount > 0);
|
||||
SkDEBUGCODE(this->validate();)
|
||||
}
|
||||
if (stopAlpha)
|
||||
{
|
||||
|
||||
if (stopAlpha) {
|
||||
SkAlphaRuns::Break(runs, alpha, x, 1);
|
||||
alpha[x] = SkToU8(alpha[x] + stopAlpha);
|
||||
SkDEBUGCODE(this->validate();)
|
||||
|
@ -131,49 +124,44 @@ void SkAlphaRuns::add(int x, U8CPU startAlpha, int middleCount, U8CPU stopAlpha,
|
|||
}
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
void SkAlphaRuns::assertValid(int y, int maxStep) const
|
||||
{
|
||||
void SkAlphaRuns::assertValid(int y, int maxStep) const {
|
||||
int max = (y + 1) * maxStep - (y == maxStep - 1);
|
||||
|
||||
const int16_t* runs = fRuns;
|
||||
const uint8_t* alpha = fAlpha;
|
||||
|
||||
while (*runs)
|
||||
{
|
||||
while (*runs) {
|
||||
SkASSERT(*alpha <= max);
|
||||
alpha += *runs;
|
||||
runs += *runs;
|
||||
}
|
||||
}
|
||||
|
||||
void SkAlphaRuns::dump() const
|
||||
{
|
||||
void SkAlphaRuns::dump() const {
|
||||
const int16_t* runs = fRuns;
|
||||
const uint8_t* alpha = fAlpha;
|
||||
|
||||
SkDebugf("Runs");
|
||||
while (*runs)
|
||||
{
|
||||
while (*runs) {
|
||||
int n = *runs;
|
||||
|
||||
SkDebugf(" %02x", *alpha);
|
||||
if (n > 1)
|
||||
if (n > 1) {
|
||||
SkDebugf(",%d", n);
|
||||
}
|
||||
alpha += n;
|
||||
runs += n;
|
||||
}
|
||||
SkDebugf("\n");
|
||||
}
|
||||
|
||||
void SkAlphaRuns::validate() const
|
||||
{
|
||||
void SkAlphaRuns::validate() const {
|
||||
SkASSERT(fWidth > 0);
|
||||
|
||||
int count = 0;
|
||||
const int16_t* runs = fRuns;
|
||||
|
||||
while (*runs)
|
||||
{
|
||||
while (*runs) {
|
||||
SkASSERT(*runs > 0);
|
||||
count += *runs;
|
||||
SkASSERT(count <= fWidth);
|
||||
|
|
|
@ -20,151 +20,29 @@
|
|||
|
||||
#include "SkBlitter.h"
|
||||
|
||||
inline int sk_make_nonzero_neg_one(int x)
|
||||
{
|
||||
return (x | -x) >> 31;
|
||||
}
|
||||
|
||||
#if 0
|
||||
template <int kShift> class SkAntiRun {
|
||||
static uint8_t coverage_to_alpha(int aa)
|
||||
{
|
||||
aa <<= 8 - 2*kShift;
|
||||
aa -= aa >> (8 - kShift - 1);
|
||||
return SkToU8(aa);
|
||||
}
|
||||
public:
|
||||
void set(int start, int stop)
|
||||
{
|
||||
SkASSERT(start >= 0 && stop > start);
|
||||
|
||||
#if 1
|
||||
int fb = start & kMask;
|
||||
int fe = stop & kMask;
|
||||
int n = (stop >> kShift) - (start >> kShift) - 1;
|
||||
|
||||
if (n < 0)
|
||||
{
|
||||
fb = fe - fb;
|
||||
n = 0;
|
||||
fe = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fb == 0)
|
||||
n += 1;
|
||||
else
|
||||
fb = (1 << kShift) - fb;
|
||||
}
|
||||
|
||||
fStartAlpha = coverage_to_alpha(fb);
|
||||
fMiddleCount = n;
|
||||
fStopAlpha = coverage_to_alpha(fe);
|
||||
#else
|
||||
int x0 = start >> kShift;
|
||||
int x1 = (stop - 1) >> kShift;
|
||||
int middle = x1 - x0;
|
||||
int aa;
|
||||
|
||||
if (middle == 0)
|
||||
{
|
||||
aa = stop - start;
|
||||
aa <<= 8 - 2*kShift;
|
||||
aa -= aa >> (8 - kShift - 1);
|
||||
SkASSERT(aa > 0 && aa < kMax);
|
||||
fStartAlpha = SkToU8(aa);
|
||||
fMiddleCount = 0;
|
||||
fStopAlpha = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
int aa = start & kMask;
|
||||
aa <<= 8 - 2*kShift;
|
||||
aa -= aa >> (8 - kShift - 1);
|
||||
SkASSERT(aa >= 0 && aa < kMax);
|
||||
if (aa)
|
||||
fStartAlpha = SkToU8(kMax - aa);
|
||||
else
|
||||
{
|
||||
fStartAlpha = 0;
|
||||
middle += 1;
|
||||
}
|
||||
aa = stop & kMask;
|
||||
aa <<= 8 - 2*kShift;
|
||||
aa -= aa >> (8 - kShift - 1);
|
||||
SkASSERT(aa >= 0 && aa < kMax);
|
||||
middle += sk_make_nonzero_neg_one(aa);
|
||||
|
||||
fStopAlpha = SkToU8(aa);
|
||||
fMiddleCount = middle;
|
||||
}
|
||||
SkASSERT(fStartAlpha < kMax);
|
||||
SkASSERT(fStopAlpha < kMax);
|
||||
#endif
|
||||
}
|
||||
|
||||
void blit(int x, int y, SkBlitter* blitter)
|
||||
{
|
||||
int16_t runs[2];
|
||||
runs[0] = 1;
|
||||
runs[1] = 0;
|
||||
|
||||
if (fStartAlpha)
|
||||
{
|
||||
blitter->blitAntiH(x, y, &fStartAlpha, runs);
|
||||
x += 1;
|
||||
}
|
||||
if (fMiddleCount)
|
||||
{
|
||||
blitter->blitH(x, y, fMiddleCount);
|
||||
x += fMiddleCount;
|
||||
}
|
||||
if (fStopAlpha)
|
||||
blitter->blitAntiH(x, y, &fStopAlpha, runs);
|
||||
}
|
||||
|
||||
uint8_t getStartAlpha() const { return fStartAlpha; }
|
||||
int getMiddleCount() const { return fMiddleCount; }
|
||||
uint8_t getStopAlpha() const { return fStopAlpha; }
|
||||
|
||||
private:
|
||||
uint8_t fStartAlpha, fStopAlpha;
|
||||
int fMiddleCount;
|
||||
|
||||
enum {
|
||||
kMask = (1 << kShift) - 1,
|
||||
kMax = (1 << (8 - kShift)) - 1
|
||||
};
|
||||
};
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class SkAlphaRuns {
|
||||
public:
|
||||
int16_t* fRuns;
|
||||
uint8_t* fAlpha;
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
bool empty() const {
|
||||
SkASSERT(fRuns[0] > 0);
|
||||
return fAlpha[0] == 0 && fRuns[fRuns[0]] == 0;
|
||||
}
|
||||
|
||||
void reset(int width);
|
||||
void add(int x, U8CPU startAlpha, int middleCount, U8CPU stopAlpha, U8CPU maxValue);
|
||||
SkDEBUGCODE(void assertValid(int y, int maxStep) const;)
|
||||
SkDEBUGCODE(void dump() const;)
|
||||
|
||||
static void Break(int16_t runs[], uint8_t alpha[], int x, int count);
|
||||
static void BreakAt(int16_t runs[], uint8_t alpha[], int x)
|
||||
{
|
||||
while (x > 0)
|
||||
{
|
||||
|
||||
static void BreakAt(int16_t runs[], uint8_t alpha[], int x) {
|
||||
while (x > 0) {
|
||||
int n = runs[0];
|
||||
SkASSERT(n > 0);
|
||||
|
||||
if (x < n)
|
||||
{
|
||||
if (x < n) {
|
||||
alpha[x] = alpha[0];
|
||||
runs[0] = SkToS16(x);
|
||||
runs[x] = SkToS16(n - x);
|
||||
|
|
|
@ -280,30 +280,27 @@ private:
|
|||
class SkAutoGlyphCache {
|
||||
public:
|
||||
SkAutoGlyphCache(SkGlyphCache* cache) : fCache(cache) {}
|
||||
SkAutoGlyphCache(const SkDescriptor* desc)
|
||||
{
|
||||
SkAutoGlyphCache(const SkDescriptor* desc) {
|
||||
fCache = SkGlyphCache::DetachCache(desc);
|
||||
}
|
||||
SkAutoGlyphCache(const SkPaint& paint, const SkMatrix* matrix)
|
||||
{
|
||||
SkAutoGlyphCache(const SkPaint& paint, const SkMatrix* matrix) {
|
||||
fCache = paint.detachCache(matrix);
|
||||
}
|
||||
~SkAutoGlyphCache()
|
||||
{
|
||||
if (fCache)
|
||||
~SkAutoGlyphCache() {
|
||||
if (fCache) {
|
||||
SkGlyphCache::AttachCache(fCache);
|
||||
}
|
||||
}
|
||||
|
||||
SkGlyphCache* getCache() const { return fCache; }
|
||||
SkGlyphCache* getCache() const { return fCache; }
|
||||
|
||||
void release()
|
||||
{
|
||||
if (fCache)
|
||||
{
|
||||
void release() {
|
||||
if (fCache) {
|
||||
SkGlyphCache::AttachCache(fCache);
|
||||
fCache = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
SkGlyphCache* fCache;
|
||||
|
||||
|
|
|
@ -45,16 +45,14 @@ size_t SkMask::computeTotalImageSize() const {
|
|||
/** We explicitly use this allocator for SkBimap pixels, so that we can
|
||||
freely assign memory allocated by one class to the other.
|
||||
*/
|
||||
uint8_t* SkMask::AllocImage(size_t size)
|
||||
{
|
||||
uint8_t* SkMask::AllocImage(size_t size) {
|
||||
return (uint8_t*)sk_malloc_throw(SkAlign4(size));
|
||||
}
|
||||
|
||||
/** We explicitly use this allocator for SkBimap pixels, so that we can
|
||||
freely assign memory allocated by one class to the other.
|
||||
*/
|
||||
void SkMask::FreeImage(void* image)
|
||||
{
|
||||
void SkMask::FreeImage(void* image) {
|
||||
sk_free(image);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче