OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2007 The Android Open Source Project | 2 * Copyright 2007 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkBitmapProcState_DEFINED | 8 #ifndef SkBitmapProcState_DEFINED |
9 #define SkBitmapProcState_DEFINED | 9 #define SkBitmapProcState_DEFINED |
10 | 10 |
11 #include "SkBitmap.h" | 11 #include "SkBitmap.h" |
12 #include "SkBitmapController.h" | 12 #include "SkBitmapController.h" |
13 #include "SkBitmapFilter.h" | 13 #include "SkBitmapFilter.h" |
14 #include "SkBitmapProvider.h" | 14 #include "SkBitmapProvider.h" |
15 #include "SkFloatBits.h" | 15 #include "SkFloatBits.h" |
16 #include "SkMatrix.h" | 16 #include "SkMatrix.h" |
17 #include "SkMipMap.h" | 17 #include "SkMipMap.h" |
18 #include "SkPaint.h" | 18 #include "SkPaint.h" |
19 #include "SkShader.h" | 19 #include "SkShader.h" |
20 #include "SkTemplates.h" | 20 #include "SkTemplates.h" |
21 | 21 |
22 typedef SkFixed3232 SkFractionalInt; | 22 typedef SkFixed3232 SkFractionalInt; |
23 #define SkScalarToFractionalInt(x) SkScalarToFixed3232(x) | 23 #define SkScalarToFractionalInt(x) SkScalarToFixed3232(x) |
24 #define SkFractionalIntToFixed(x) SkFixed3232ToFixed(x) | 24 #define SkFractionalIntToFixed(x) SkFixed3232ToFixed(x) |
25 #define SkFixedToFractionalInt(x) SkFixedToFixed3232(x) | 25 #define SkFixedToFractionalInt(x) SkFixedToFixed3232(x) |
26 #define SkFractionalIntToInt(x) SkFixed3232ToInt(x) | 26 #define SkFractionalIntToInt(x) SkFixed3232ToInt(x) |
27 | 27 |
28 class SkPaint; | 28 class SkPaint; |
29 | 29 |
30 struct SkBitmapProcState { | 30 struct SkBitmapProcInfo { |
31 SkBitmapProcState(const SkBitmapProvider&, SkShader::TileMode tmx, SkShader: :TileMode tmy); | 31 SkBitmapProcInfo(const SkBitmapProvider&, SkShader::TileMode tmx, SkShader:: TileMode tmy); |
32 SkBitmapProcState(const SkBitmap&, SkShader::TileMode tmx, SkShader::TileMod e tmy); | 32 SkBitmapProcInfo(const SkBitmap&, SkShader::TileMode tmx, SkShader::TileMode tmy); |
33 ~SkBitmapProcState(); | 33 ~SkBitmapProcInfo(); |
34 | |
35 const SkBitmapProvider fProvider; | |
36 | |
37 SkPixmap fPixmap; | |
38 SkMatrix fInvMatrix; // copy of what is in fBMState, can we remove the dup? | |
39 uint8_t fInvType; | |
40 SkColor fPaintColor; | |
41 uint8_t fTileModeX; | |
herb_g
2016/03/02 16:00:18
Can we switch TileMode in SkShader to be.
enum Til
reed1
2016/03/02 16:28:28
Done.
| |
42 uint8_t fTileModeY; | |
43 uint8_t fFilterLevel; | |
44 | |
45 bool init(const SkMatrix& inverse, const SkPaint&); | |
46 | |
47 private: | |
48 enum { | |
49 kBMStateSize = 136 // found by inspection. if too small, we will call n ew/delete | |
50 }; | |
51 SkAlignedSStorage<kBMStateSize> fBMStateStorage; | |
52 SkBitmapController::State* fBMState; | |
53 }; | |
54 | |
55 struct SkBitmapProcState : public SkBitmapProcInfo { | |
56 SkBitmapProcState(const SkBitmapProvider& prov, SkShader::TileMode tmx, SkSh ader::TileMode tmy) | |
57 : SkBitmapProcInfo(prov, tmx, tmy) {} | |
58 SkBitmapProcState(const SkBitmap& bitmap, SkShader::TileMode tmx, SkShader:: TileMode tmy) | |
59 : SkBitmapProcInfo(bitmap, tmx, tmy) {} | |
60 | |
61 bool setup(const SkMatrix& inv, const SkPaint& paint) { | |
62 return this->init(inv, paint) && this->chooseProcs(); | |
63 } | |
34 | 64 |
35 typedef void (*ShaderProc32)(const void* ctx, int x, int y, SkPMColor[], int count); | 65 typedef void (*ShaderProc32)(const void* ctx, int x, int y, SkPMColor[], int count); |
36 | 66 |
37 typedef void (*ShaderProc16)(const void* ctx, int x, int y, uint16_t[], int count); | 67 typedef void (*ShaderProc16)(const void* ctx, int x, int y, uint16_t[], int count); |
38 | 68 |
39 typedef void (*MatrixProc)(const SkBitmapProcState&, | 69 typedef void (*MatrixProc)(const SkBitmapProcState&, |
40 uint32_t bitmapXY[], | 70 uint32_t bitmapXY[], |
41 int count, | 71 int count, |
42 int x, int y); | 72 int x, int y); |
43 | 73 |
44 typedef void (*SampleProc32)(const SkBitmapProcState&, | 74 typedef void (*SampleProc32)(const SkBitmapProcState&, |
45 const uint32_t[], | 75 const uint32_t[], |
46 int count, | 76 int count, |
47 SkPMColor colors[]); | 77 SkPMColor colors[]); |
48 | 78 |
49 typedef U16CPU (*FixedTileProc)(SkFixed); // returns 0..0xFFFF | 79 typedef U16CPU (*FixedTileProc)(SkFixed); // returns 0..0xFFFF |
50 typedef U16CPU (*FixedTileLowBitsProc)(SkFixed, int); // returns 0..0xF | 80 typedef U16CPU (*FixedTileLowBitsProc)(SkFixed, int); // returns 0..0xF |
51 typedef U16CPU (*IntTileProc)(int value, int count); // returns 0..count-1 | 81 typedef U16CPU (*IntTileProc)(int value, int count); // returns 0..count-1 |
52 | 82 |
53 SkPixmap fPixmap; | |
54 SkMatrix fInvMatrix; // copy of what is in fBMState, can we remove the dup? | |
55 | |
56 SkMatrix::MapXYProc fInvProc; // chooseProcs | 83 SkMatrix::MapXYProc fInvProc; // chooseProcs |
57 | |
58 SkFractionalInt fInvSxFractionalInt; | 84 SkFractionalInt fInvSxFractionalInt; |
59 SkFractionalInt fInvKyFractionalInt; | 85 SkFractionalInt fInvKyFractionalInt; |
60 | 86 |
61 FixedTileProc fTileProcX; // chooseProcs | 87 FixedTileProc fTileProcX; // chooseProcs |
62 FixedTileProc fTileProcY; // chooseProcs | 88 FixedTileProc fTileProcY; // chooseProcs |
63 FixedTileLowBitsProc fTileLowBitsProcX; // chooseProcs | 89 FixedTileLowBitsProc fTileLowBitsProcX; // chooseProcs |
64 FixedTileLowBitsProc fTileLowBitsProcY; // chooseProcs | 90 FixedTileLowBitsProc fTileLowBitsProcY; // chooseProcs |
65 IntTileProc fIntTileProcY; // chooseProcs | 91 IntTileProc fIntTileProcY; // chooseProcs |
66 SkFixed fFilterOneX; | 92 SkFixed fFilterOneX; |
67 SkFixed fFilterOneY; | 93 SkFixed fFilterOneY; |
68 | 94 |
69 SkPMColor fPaintPMColor; // chooseProcs - A8 config | |
70 SkFixed fInvSx; // chooseProcs | 95 SkFixed fInvSx; // chooseProcs |
71 SkFixed fInvKy; // chooseProcs | 96 SkFixed fInvKy; // chooseProcs |
97 SkPMColor fPaintPMColor; // chooseProcs - A8 config | |
72 uint16_t fAlphaScale; // chooseProcs | 98 uint16_t fAlphaScale; // chooseProcs |
73 uint8_t fInvType; // chooseProcs | |
74 uint8_t fTileModeX; // CONSTRUCTOR | |
75 uint8_t fTileModeY; // CONSTRUCTOR | |
76 uint8_t fFilterLevel; // chooseProcs | |
77 | 99 |
78 /** Platforms implement this, and can optionally overwrite only the | 100 /** Platforms implement this, and can optionally overwrite only the |
79 following fields: | 101 following fields: |
80 | 102 |
81 fShaderProc32 | 103 fShaderProc32 |
82 fShaderProc16 | 104 fShaderProc16 |
83 fMatrixProc | 105 fMatrixProc |
84 fSampleProc32 | 106 fSampleProc32 |
85 fSampleProc32 | 107 fSampleProc32 |
86 | 108 |
(...skipping 20 matching lines...) Expand all Loading... | |
107 ShaderProc16 getShaderProc16() const { return fShaderProc16; } | 129 ShaderProc16 getShaderProc16() const { return fShaderProc16; } |
108 | 130 |
109 #ifdef SK_DEBUG | 131 #ifdef SK_DEBUG |
110 MatrixProc getMatrixProc() const; | 132 MatrixProc getMatrixProc() const; |
111 #else | 133 #else |
112 MatrixProc getMatrixProc() const { return fMatrixProc; } | 134 MatrixProc getMatrixProc() const { return fMatrixProc; } |
113 #endif | 135 #endif |
114 SampleProc32 getSampleProc32() const { return fSampleProc32; } | 136 SampleProc32 getSampleProc32() const { return fSampleProc32; } |
115 | 137 |
116 private: | 138 private: |
117 friend class SkBitmapProcShader; | |
118 friend class SkLightingShaderImpl; | |
119 | |
120 ShaderProc32 fShaderProc32; // chooseProcs | 139 ShaderProc32 fShaderProc32; // chooseProcs |
121 ShaderProc16 fShaderProc16; // chooseProcs | 140 ShaderProc16 fShaderProc16; // chooseProcs |
122 // These are used if the shaderproc is nullptr | 141 // These are used if the shaderproc is nullptr |
123 MatrixProc fMatrixProc; // chooseProcs | 142 MatrixProc fMatrixProc; // chooseProcs |
124 SampleProc32 fSampleProc32; // chooseProcs | 143 SampleProc32 fSampleProc32; // chooseProcs |
125 | 144 |
126 const SkBitmapProvider fProvider; | |
127 | |
128 enum { | |
129 kBMStateSize = 136 // found by inspection. if too small, we will call n ew/delete | |
130 }; | |
131 SkAlignedSStorage<kBMStateSize> fBMStateStorage; | |
132 SkBitmapController::State* fBMState; | |
133 | |
134 MatrixProc chooseMatrixProc(bool trivial_matrix); | 145 MatrixProc chooseMatrixProc(bool trivial_matrix); |
135 bool chooseProcs(const SkMatrix& inv, const SkPaint&); | 146 bool chooseProcs(); // caller must have called init() first (on our base-cla ss) |
136 bool chooseScanlineProcs(bool trivialMatrix, bool clampClamp, const SkPaint& paint); | 147 bool chooseScanlineProcs(bool trivialMatrix, bool clampClamp); |
137 ShaderProc32 chooseShaderProc32(); | 148 ShaderProc32 chooseShaderProc32(); |
138 | 149 |
139 // Return false if we failed to setup for fast translate (e.g. overflow) | 150 // Return false if we failed to setup for fast translate (e.g. overflow) |
140 bool setupForTranslate(); | 151 bool setupForTranslate(); |
141 | 152 |
142 #ifdef SK_DEBUG | 153 #ifdef SK_DEBUG |
143 static void DebugMatrixProc(const SkBitmapProcState&, | 154 static void DebugMatrixProc(const SkBitmapProcState&, |
144 uint32_t[], int count, int x, int y); | 155 uint32_t[], int count, int x, int y); |
145 #endif | 156 #endif |
146 }; | 157 }; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 SkFixed fixedY() const { return SkFractionalIntToFixed(fY); } | 238 SkFixed fixedY() const { return SkFractionalIntToFixed(fY); } |
228 | 239 |
229 int intX() const { return SkFractionalIntToInt(fX); } | 240 int intX() const { return SkFractionalIntToInt(fX); } |
230 int intY() const { return SkFractionalIntToInt(fY); } | 241 int intY() const { return SkFractionalIntToInt(fY); } |
231 | 242 |
232 private: | 243 private: |
233 SkFractionalInt fX, fY; | 244 SkFractionalInt fX, fY; |
234 }; | 245 }; |
235 | 246 |
236 #endif | 247 #endif |
OLD | NEW |