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