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