Line data Source code
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 :
9 : #include "SkAntiRun.h"
10 : #include "SkUtils.h"
11 :
12 2422 : void SkAlphaRuns::reset(int width) {
13 2422 : 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 2422 : fRuns[0] = SkToS16(width);
21 2422 : fRuns[width] = 0;
22 2422 : fAlpha[0] = 0;
23 :
24 2422 : SkDEBUGCODE(fWidth = width;)
25 2422 : SkDEBUGCODE(this->validate();)
26 2422 : }
27 :
28 : #ifdef SK_DEBUG
29 2861 : 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 2861 : }
43 :
44 0 : void SkAlphaRuns::dump() const {
45 0 : const int16_t* runs = fRuns;
46 0 : const uint8_t* alpha = fAlpha;
47 :
48 0 : SkDebugf("Runs");
49 0 : while (*runs) {
50 0 : int n = *runs;
51 :
52 0 : SkDebugf(" %02x", *alpha);
53 0 : if (n > 1) {
54 0 : SkDebugf(",%d", n);
55 : }
56 0 : alpha += n;
57 0 : runs += n;
58 : }
59 0 : SkDebugf("\n");
60 0 : }
61 :
62 15022 : 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 15022 : }
78 : #endif
|