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