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
8#include "include/private/SkTo.h"
9#include "src/core/SkAntiRun.h"
10#include "src/core/SkUtils.h"
11
12void SkAlphaRuns::reset(int width) {
13 SkASSERT(width > 0);
14
15#ifdef SK_DEBUG
16 sk_memset16((uint16_t*)fRuns, (uint16_t)(-42), width);
17#endif
18 fRuns[0] = SkToS16(width);
19 fRuns[width] = 0;
20 fAlpha[0] = 0;
21
22 SkDEBUGCODE(fWidth = width;)
23 SkDEBUGCODE(this->validate();)
24}
25
26#ifdef SK_DEBUG
27 void SkAlphaRuns::assertValid(int y, int maxStep) const {
28 int max = (y + 1) * maxStep - (y == maxStep - 1);
29
30 const int16_t* runs = fRuns;
31 const uint8_t* alpha = fAlpha;
32
33 while (*runs) {
34 SkASSERT(*alpha <= max);
35 alpha += *runs;
36 runs += *runs;
37 }
38 }
39
40 void SkAlphaRuns::dump() const {
41 const int16_t* runs = fRuns;
42 const uint8_t* alpha = fAlpha;
43
44 SkDebugf("Runs");
45 while (*runs) {
46 int n = *runs;
47
48 SkDebugf(" %02x", *alpha);
49 if (n > 1) {
50 SkDebugf(",%d", n);
51 }
52 alpha += n;
53 runs += n;
54 }
55 SkDebugf("\n");
56 }
57
58 void SkAlphaRuns::validate() const {
59 SkASSERT(fWidth > 0);
60
61 int count = 0;
62 const int16_t* runs = fRuns;
63
64 while (*runs) {
65 SkASSERT(*runs > 0);
66 count += *runs;
67 SkASSERT(count <= fWidth);
68 runs += *runs;
69 }
70 SkASSERT(count == fWidth);
71 }
72#endif
73