SkBitmapProcState.h revision c9a1d4b519c2db8e43e54fef068c46462d2f8a4b
1/*
2** Copyright 2007, The Android Open Source Project
3**
4** Licensed under the Apache License, Version 2.0 (the "License");
5** you may not use this file except in compliance with the License.
6** You may obtain a copy of the License at
7**
8**     http://www.apache.org/licenses/LICENSE-2.0
9**
10** Unless required by applicable law or agreed to in writing, software
11** distributed under the License is distributed on an "AS IS" BASIS,
12** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13** See the License for the specific language governing permissions and
14** limitations under the License.
15*/
16
17#ifndef SkBitmapProcState_DEFINED
18#define SkBitmapProcState_DEFINED
19
20#include "SkBitmap.h"
21#include "SkMatrix.h"
22
23class SkPaint;
24
25struct SkBitmapProcState {
26
27    typedef void (*ShaderProc32)(const SkBitmapProcState&, int x, int y,
28                                 SkPMColor[], int count);
29
30    typedef void (*ShaderProc16)(const SkBitmapProcState&, int x, int y,
31                                 uint16_t[], int count);
32
33    typedef void (*MatrixProc)(const SkBitmapProcState&,
34                               uint32_t bitmapXY[],
35                               int count,
36                               int x, int y);
37
38    typedef void (*SampleProc32)(const SkBitmapProcState&,
39                                 const uint32_t[],
40                                 int count,
41                                 SkPMColor colors[]);
42
43    typedef void (*SampleProc16)(const SkBitmapProcState&,
44                                 const uint32_t[],
45                                 int count,
46                                 uint16_t colors[]);
47
48    typedef U16CPU (*FixedTileProc)(SkFixed);   // returns 0..0xFFFF
49
50    // If a shader proc is present, then the corresponding matrix/sample procs
51    // are ignored
52    ShaderProc32        fShaderProc32;      // chooseProcs
53    ShaderProc16        fShaderProc16;      // chooseProcs
54    // These are used if the shaderproc is NULL
55    MatrixProc          fMatrixProc;        // chooseProcs
56    SampleProc32        fSampleProc32;      // chooseProcs
57    SampleProc16        fSampleProc16;      // chooseProcs
58
59    const SkBitmap*     fBitmap;            // chooseProcs - orig or mip
60    const SkMatrix*     fInvMatrix;         // chooseProcs
61    SkMatrix::MapXYProc fInvProc;           // chooseProcs
62
63    FixedTileProc       fTileProcX;         // chooseProcs
64    FixedTileProc       fTileProcY;         // chooseProcs
65    SkFixed             fFilterOneX;
66    SkFixed             fFilterOneY;
67
68    SkPMColor           fPaintPMColor;      // chooseProcs - A8 config
69    SkFixed             fInvSx;             // chooseProcs
70    SkFixed             fInvKy;             // chooseProcs
71    uint16_t            fAlphaScale;        // chooseProcs
72    uint8_t             fInvType;           // chooseProcs
73    uint8_t             fTileModeX;         // CONSTRUCTOR
74    uint8_t             fTileModeY;         // CONSTRUCTOR
75    SkBool8             fDoFilter;          // chooseProcs
76
77    /** Platforms implement this, and can optionally overwrite only the
78        following fields:
79
80        fShaderProc32
81        fShaderProc16
82        fMatrixProc
83        fSampleProc32
84        fSampleProc32
85
86        They will already have valid function pointers, so a platform that does
87        not have an accelerated version can just leave that field as is. A valid
88        implementation can do nothing (see SkBitmapProcState_opts_none.cpp)
89     */
90    void platformProcs();
91
92private:
93    friend class SkBitmapProcShader;
94
95    SkMatrix            fUnitInvMatrix;     // chooseProcs
96    SkBitmap            fOrigBitmap;        // CONSTRUCTOR
97    SkBitmap            fMipBitmap;
98
99    MatrixProc chooseMatrixProc();
100    bool chooseProcs(const SkMatrix& inv, const SkPaint&);
101};
102
103#endif
104