reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 | |
| 23 | class SkPaint; |
| 24 | |
| 25 | struct SkBitmapProcState { |
| 26 | |
reed@android.com | 7a99eb1 | 2009-07-16 01:13:14 +0000 | [diff] [blame] | 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 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 |
reed@android.com | 07d1f00 | 2009-08-13 19:35:48 +0000 | [diff] [blame] | 49 | typedef U16CPU (*IntTileProc)(int value, int count); // returns 0..count-1 |
reed@android.com | 7a99eb1 | 2009-07-16 01:13:14 +0000 | [diff] [blame] | 50 | |
| 51 | // If a shader proc is present, then the corresponding matrix/sample procs |
| 52 | // are ignored |
| 53 | ShaderProc32 fShaderProc32; // chooseProcs |
| 54 | ShaderProc16 fShaderProc16; // chooseProcs |
| 55 | // These are used if the shaderproc is NULL |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 56 | MatrixProc fMatrixProc; // chooseProcs |
| 57 | SampleProc32 fSampleProc32; // chooseProcs |
| 58 | SampleProc16 fSampleProc16; // chooseProcs |
| 59 | |
reed@android.com | eef375b | 2009-08-03 14:45:45 +0000 | [diff] [blame] | 60 | const SkBitmap* fBitmap; // chooseProcs - orig or mip |
| 61 | const SkMatrix* fInvMatrix; // chooseProcs |
| 62 | SkMatrix::MapXYProc fInvProc; // chooseProcs |
| 63 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 64 | FixedTileProc fTileProcX; // chooseProcs |
| 65 | FixedTileProc fTileProcY; // chooseProcs |
reed@android.com | 07d1f00 | 2009-08-13 19:35:48 +0000 | [diff] [blame] | 66 | IntTileProc fIntTileProcY; // chooseProcs |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 67 | SkFixed fFilterOneX; |
| 68 | SkFixed fFilterOneY; |
| 69 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 70 | SkPMColor fPaintPMColor; // chooseProcs - A8 config |
reed@android.com | eef375b | 2009-08-03 14:45:45 +0000 | [diff] [blame] | 71 | SkFixed fInvSx; // chooseProcs |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 72 | SkFixed fInvKy; // chooseProcs |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 73 | uint16_t fAlphaScale; // chooseProcs |
| 74 | uint8_t fInvType; // chooseProcs |
| 75 | uint8_t fTileModeX; // CONSTRUCTOR |
| 76 | uint8_t fTileModeY; // CONSTRUCTOR |
| 77 | SkBool8 fDoFilter; // chooseProcs |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 78 | |
reed@android.com | c9a1d4b | 2009-08-03 15:05:55 +0000 | [diff] [blame] | 79 | /** Platforms implement this, and can optionally overwrite only the |
| 80 | following fields: |
| 81 | |
| 82 | fShaderProc32 |
| 83 | fShaderProc16 |
| 84 | fMatrixProc |
| 85 | fSampleProc32 |
| 86 | fSampleProc32 |
| 87 | |
| 88 | They will already have valid function pointers, so a platform that does |
| 89 | not have an accelerated version can just leave that field as is. A valid |
| 90 | implementation can do nothing (see SkBitmapProcState_opts_none.cpp) |
| 91 | */ |
| 92 | void platformProcs(); |
| 93 | |
reed@android.com | 4c128c4 | 2009-08-14 13:54:37 +0000 | [diff] [blame] | 94 | /** Given the size of a buffer, to be used for calling the matrix and |
| 95 | sample procs, this return the maximum count that can be stored in the |
| 96 | buffer, taking into account that filtering and scale-vs-affine affect |
| 97 | this value. |
| 98 | |
| 99 | Only valid to call after chooseProcs (setContext) has been called. It is |
| 100 | safe to call this inside the shader's shadeSpan() method. |
| 101 | */ |
| 102 | int maxCountForBufferSize(size_t bufferSize) const; |
| 103 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 104 | private: |
reed@android.com | eef375b | 2009-08-03 14:45:45 +0000 | [diff] [blame] | 105 | friend class SkBitmapProcShader; |
| 106 | |
| 107 | SkMatrix fUnitInvMatrix; // chooseProcs |
| 108 | SkBitmap fOrigBitmap; // CONSTRUCTOR |
| 109 | SkBitmap fMipBitmap; |
| 110 | |
reed@android.com | 07d1f00 | 2009-08-13 19:35:48 +0000 | [diff] [blame] | 111 | MatrixProc chooseMatrixProc(bool trivial_matrix); |
reed@android.com | eef375b | 2009-08-03 14:45:45 +0000 | [diff] [blame] | 112 | bool chooseProcs(const SkMatrix& inv, const SkPaint&); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 113 | }; |
| 114 | |
reed@android.com | 07d1f00 | 2009-08-13 19:35:48 +0000 | [diff] [blame] | 115 | /* Macros for packing and unpacking pairs of 16bit values in a 32bit uint. |
| 116 | Used to allow access to a stream of uint16_t either one at a time, or |
| 117 | 2 at a time by unpacking a uint32_t |
| 118 | */ |
| 119 | #ifdef SK_CPU_BENDIAN |
| 120 | #define PACK_TWO_SHORTS(pri, sec) ((pri) << 16 | (sec)) |
| 121 | #define UNPACK_PRIMARY_SHORT(packed) ((uint32_t)(packed) >> 16) |
| 122 | #define UNPACK_SECONDARY_SHORT(packed) ((packed) & 0xFFFF) |
| 123 | #else |
| 124 | #define PACK_TWO_SHORTS(pri, sec) ((pri) | ((sec) << 16)) |
| 125 | #define UNPACK_PRIMARY_SHORT(packed) ((packed) & 0xFFFF) |
| 126 | #define UNPACK_SECONDARY_SHORT(packed) ((uint32_t)(packed) >> 16) |
| 127 | #endif |
| 128 | |
| 129 | #ifdef SK_DEBUG |
| 130 | static inline uint32_t pack_two_shorts(U16CPU pri, U16CPU sec) { |
| 131 | SkASSERT((uint16_t)pri == pri); |
| 132 | SkASSERT((uint16_t)sec == sec); |
| 133 | return PACK_TWO_SHORTS(pri, sec); |
| 134 | } |
| 135 | #else |
| 136 | #define pack_two_shorts(pri, sec) PACK_TWO_SHORTS(pri, sec) |
| 137 | #endif |
| 138 | |
senorblanco@chromium.org | dc7de74 | 2009-11-30 20:00:29 +0000 | [diff] [blame] | 139 | // These functions are generated via macros, but are exposed here so that |
| 140 | // platformProcs may test for them by name. |
| 141 | void S32_opaque_D32_filter_DX(const SkBitmapProcState& s, const uint32_t xy[], |
| 142 | int count, SkPMColor colors[]); |
senorblanco@chromium.org | f3f0bd7 | 2009-12-10 22:46:31 +0000 | [diff] [blame^] | 143 | void S32_alpha_D32_filter_DX(const SkBitmapProcState& s, const uint32_t xy[], |
| 144 | int count, SkPMColor colors[]); |
senorblanco@chromium.org | dc7de74 | 2009-11-30 20:00:29 +0000 | [diff] [blame] | 145 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 146 | #endif |