| 1 |
/* |
| 2 |
* Copyright 2006 The Android Open Source Project |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
#include "src/core/SkAlphaRuns.h" |
| 8 |
|
| 9 |
#include "src/core/SkMemset.h" |
| 10 |
|
| 11 |
void SkAlphaRuns::reset(int width) { |
| 12 |
SkASSERT(width > 0); |
| 13 |
|
| 14 |
#ifdef SK_DEBUG |
| 15 |
SkOpts::memset16((uint16_t*)fRuns, (uint16_t)(-42), width); |
| 16 |
#endif |
| 17 |
fRuns[0] = SkToS16(width); |
| 18 |
fRuns[width] = 0; |
| 19 |
fAlpha[0] = 0; |
| 20 |
|
| 21 |
SkDEBUGCODE(fWidth = width;) |
| 22 |
SkDEBUGCODE(this->validate();) |
| 23 |
} |
| 24 |
|
| 25 |
#ifdef SK_DEBUG |
| 26 |
void SkAlphaRuns::assertValid(int y, int maxStep) const { |
| 27 |
int max = (y + 1) * maxStep - (y == maxStep - 1); |
| 28 |
|
| 29 |
const int16_t* runs = fRuns; |
| 30 |
const uint8_t* alpha = fAlpha; |
| 31 |
|
| 32 |
while (*runs) { |
| 33 |
SkASSERT(*alpha <= max); |
| 34 |
alpha += *runs; |
| 35 |
runs += *runs; |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
void SkAlphaRuns::dump() const { |
| 40 |
const int16_t* runs = fRuns; |
| 41 |
const uint8_t* alpha = fAlpha; |
| 42 |
|
| 43 |
SkDebugf("Runs"); |
| 44 |
while (*runs) { |
| 45 |
int n = *runs; |
| 46 |
|
| 47 |
SkDebugf(" %02x", *alpha); |
| 48 |
if (n > 1) { |
| 49 |
SkDebugf(",%d", n); |
| 50 |
} |
| 51 |
alpha += n; |
| 52 |
runs += n; |
| 53 |
} |
| 54 |
SkDebugf("\n"); |
| 55 |
} |
| 56 |
|
| 57 |
void SkAlphaRuns::validate() const { |
| 58 |
SkASSERT(fWidth > 0); |
| 59 |
|
| 60 |
int count = 0; |
| 61 |
const int16_t* runs = fRuns; |
| 62 |
|
| 63 |
while (*runs) { |
| 64 |
SkASSERT(*runs > 0); |
| 65 |
count += *runs; |
| 66 |
SkASSERT(count <= fWidth); |
| 67 |
runs += *runs; |
| 68 |
} |
| 69 |
SkASSERT(count == fWidth); |
| 70 |
} |
| 71 |
#endif |