SkAntiRun.h revision fa57ae7d1ec7404a654e0f32c09b698feec1b7fa
1/* libs/graphics/sgl/SkAntiRun.h
2**
3** Copyright 2006, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9**     http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#ifndef SkAntiRun_DEFINED
19#define SkAntiRun_DEFINED
20
21#include "SkBlitter.h"
22
23class SkAlphaRuns {
24public:
25    int16_t*    fRuns;
26    uint8_t*     fAlpha;
27
28    bool empty() const {
29        SkASSERT(fRuns[0] > 0);
30        return fAlpha[0] == 0 && fRuns[fRuns[0]] == 0;
31    }
32
33    void    reset(int width);
34
35    /**
36     *  Returns the offsetX value that should be passed on the next call,
37     *  assuming we're on the same scanline. If the caller is switching
38     *  scanlines, then offsetX should be 0 when this is called.
39     */
40    int add(int x, U8CPU startAlpha, int middleCount, U8CPU stopAlpha,
41            U8CPU maxValue, int offsetX);
42
43    SkDEBUGCODE(void assertValid(int y, int maxStep) const;)
44    SkDEBUGCODE(void dump() const;)
45
46    static void Break(int16_t runs[], uint8_t alpha[], int x, int count);
47
48    static void BreakAt(int16_t runs[], uint8_t alpha[], int x) {
49        while (x > 0) {
50            int n = runs[0];
51            SkASSERT(n > 0);
52
53            if (x < n) {
54                alpha[x] = alpha[0];
55                runs[0] = SkToS16(x);
56                runs[x] = SkToS16(n - x);
57                break;
58            }
59            runs += n;
60            alpha += n;
61            x -= n;
62        }
63    }
64
65private:
66    SkDEBUGCODE(int fWidth;)
67    SkDEBUGCODE(void validate() const;)
68};
69
70#endif
71
72