epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2007 The Android Open Source Project |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 9 | |
| 10 | #ifndef SkBitmapProcState_DEFINED |
| 11 | #define SkBitmapProcState_DEFINED |
| 12 | |
| 13 | #include "SkBitmap.h" |
| 14 | #include "SkMatrix.h" |
| 15 | |
reed@google.com | 4bc0a9d | 2012-03-07 21:47:41 +0000 | [diff] [blame^] | 16 | #define FractionalInt_IS_64BIT |
| 17 | |
| 18 | #ifdef FractionalInt_IS_64BIT |
| 19 | typedef SkFixed48 SkFractionalInt; |
| 20 | #define SkScalarToFractionalInt(x) SkScalarToFixed48(x) |
| 21 | #define SkFractionalIntToFixed(x) SkFixed48ToFixed(x) |
| 22 | #define SkFractionalIntToInt(x) SkFixed48ToInt(x) |
| 23 | #else |
| 24 | typedef SkFixed SkFractionalInt; |
| 25 | #define SkScalarToFractionalInt(x) SkScalarToFixed(x) |
| 26 | #define SkFractionalIntToFixed(x) (x) |
| 27 | #define SkFractionalIntToInt(x) ((x) >> 16) |
| 28 | #endif |
| 29 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 30 | class SkPaint; |
| 31 | |
| 32 | struct SkBitmapProcState { |
| 33 | |
reed@android.com | 7a99eb1 | 2009-07-16 01:13:14 +0000 | [diff] [blame] | 34 | typedef void (*ShaderProc32)(const SkBitmapProcState&, int x, int y, |
| 35 | SkPMColor[], int count); |
| 36 | |
| 37 | typedef void (*ShaderProc16)(const SkBitmapProcState&, int x, int y, |
| 38 | uint16_t[], int count); |
| 39 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 40 | typedef void (*MatrixProc)(const SkBitmapProcState&, |
| 41 | uint32_t bitmapXY[], |
| 42 | int count, |
| 43 | int x, int y); |
| 44 | |
| 45 | typedef void (*SampleProc32)(const SkBitmapProcState&, |
| 46 | const uint32_t[], |
| 47 | int count, |
| 48 | SkPMColor colors[]); |
| 49 | |
| 50 | typedef void (*SampleProc16)(const SkBitmapProcState&, |
| 51 | const uint32_t[], |
| 52 | int count, |
| 53 | uint16_t colors[]); |
| 54 | |
| 55 | typedef U16CPU (*FixedTileProc)(SkFixed); // returns 0..0xFFFF |
reed@android.com | 07d1f00 | 2009-08-13 19:35:48 +0000 | [diff] [blame] | 56 | typedef U16CPU (*IntTileProc)(int value, int count); // returns 0..count-1 |
reed@android.com | 7a99eb1 | 2009-07-16 01:13:14 +0000 | [diff] [blame] | 57 | |
| 58 | // If a shader proc is present, then the corresponding matrix/sample procs |
| 59 | // are ignored |
| 60 | ShaderProc32 fShaderProc32; // chooseProcs |
| 61 | ShaderProc16 fShaderProc16; // chooseProcs |
| 62 | // These are used if the shaderproc is NULL |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 63 | MatrixProc fMatrixProc; // chooseProcs |
| 64 | SampleProc32 fSampleProc32; // chooseProcs |
| 65 | SampleProc16 fSampleProc16; // chooseProcs |
| 66 | |
reed@android.com | eef375b | 2009-08-03 14:45:45 +0000 | [diff] [blame] | 67 | const SkBitmap* fBitmap; // chooseProcs - orig or mip |
| 68 | const SkMatrix* fInvMatrix; // chooseProcs |
| 69 | SkMatrix::MapXYProc fInvProc; // chooseProcs |
| 70 | |
reed@google.com | 4bc0a9d | 2012-03-07 21:47:41 +0000 | [diff] [blame^] | 71 | SkFractionalInt fInvSxFractionalInt; |
| 72 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 73 | FixedTileProc fTileProcX; // chooseProcs |
| 74 | FixedTileProc fTileProcY; // chooseProcs |
reed@android.com | 07d1f00 | 2009-08-13 19:35:48 +0000 | [diff] [blame] | 75 | IntTileProc fIntTileProcY; // chooseProcs |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 76 | SkFixed fFilterOneX; |
| 77 | SkFixed fFilterOneY; |
| 78 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 79 | SkPMColor fPaintPMColor; // chooseProcs - A8 config |
reed@android.com | eef375b | 2009-08-03 14:45:45 +0000 | [diff] [blame] | 80 | SkFixed fInvSx; // chooseProcs |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 81 | SkFixed fInvKy; // chooseProcs |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 82 | uint16_t fAlphaScale; // chooseProcs |
| 83 | uint8_t fInvType; // chooseProcs |
| 84 | uint8_t fTileModeX; // CONSTRUCTOR |
| 85 | uint8_t fTileModeY; // CONSTRUCTOR |
| 86 | SkBool8 fDoFilter; // chooseProcs |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 87 | |
reed@android.com | c9a1d4b | 2009-08-03 15:05:55 +0000 | [diff] [blame] | 88 | /** Platforms implement this, and can optionally overwrite only the |
| 89 | following fields: |
| 90 | |
| 91 | fShaderProc32 |
| 92 | fShaderProc16 |
| 93 | fMatrixProc |
| 94 | fSampleProc32 |
| 95 | fSampleProc32 |
| 96 | |
| 97 | They will already have valid function pointers, so a platform that does |
| 98 | not have an accelerated version can just leave that field as is. A valid |
| 99 | implementation can do nothing (see SkBitmapProcState_opts_none.cpp) |
| 100 | */ |
| 101 | void platformProcs(); |
| 102 | |
reed@android.com | 258cb22 | 2010-04-14 13:36:33 +0000 | [diff] [blame] | 103 | /** Given the byte size of the index buffer to be passed to the matrix proc, |
| 104 | return the maximum number of resulting pixels that can be computed |
| 105 | (i.e. the number of SkPMColor values to be written by the sample proc). |
| 106 | This routine takes into account that filtering and scale-vs-affine |
| 107 | affect the amount of buffer space needed. |
reed@android.com | 4c128c4 | 2009-08-14 13:54:37 +0000 | [diff] [blame] | 108 | |
| 109 | Only valid to call after chooseProcs (setContext) has been called. It is |
| 110 | safe to call this inside the shader's shadeSpan() method. |
| 111 | */ |
| 112 | int maxCountForBufferSize(size_t bufferSize) const; |
| 113 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 114 | private: |
reed@android.com | eef375b | 2009-08-03 14:45:45 +0000 | [diff] [blame] | 115 | friend class SkBitmapProcShader; |
| 116 | |
| 117 | SkMatrix fUnitInvMatrix; // chooseProcs |
| 118 | SkBitmap fOrigBitmap; // CONSTRUCTOR |
| 119 | SkBitmap fMipBitmap; |
| 120 | |
reed@android.com | 07d1f00 | 2009-08-13 19:35:48 +0000 | [diff] [blame] | 121 | MatrixProc chooseMatrixProc(bool trivial_matrix); |
reed@android.com | eef375b | 2009-08-03 14:45:45 +0000 | [diff] [blame] | 122 | bool chooseProcs(const SkMatrix& inv, const SkPaint&); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 123 | }; |
| 124 | |
reed@android.com | 07d1f00 | 2009-08-13 19:35:48 +0000 | [diff] [blame] | 125 | /* Macros for packing and unpacking pairs of 16bit values in a 32bit uint. |
| 126 | Used to allow access to a stream of uint16_t either one at a time, or |
| 127 | 2 at a time by unpacking a uint32_t |
| 128 | */ |
| 129 | #ifdef SK_CPU_BENDIAN |
| 130 | #define PACK_TWO_SHORTS(pri, sec) ((pri) << 16 | (sec)) |
| 131 | #define UNPACK_PRIMARY_SHORT(packed) ((uint32_t)(packed) >> 16) |
| 132 | #define UNPACK_SECONDARY_SHORT(packed) ((packed) & 0xFFFF) |
| 133 | #else |
| 134 | #define PACK_TWO_SHORTS(pri, sec) ((pri) | ((sec) << 16)) |
| 135 | #define UNPACK_PRIMARY_SHORT(packed) ((packed) & 0xFFFF) |
| 136 | #define UNPACK_SECONDARY_SHORT(packed) ((uint32_t)(packed) >> 16) |
| 137 | #endif |
| 138 | |
| 139 | #ifdef SK_DEBUG |
| 140 | static inline uint32_t pack_two_shorts(U16CPU pri, U16CPU sec) { |
| 141 | SkASSERT((uint16_t)pri == pri); |
| 142 | SkASSERT((uint16_t)sec == sec); |
| 143 | return PACK_TWO_SHORTS(pri, sec); |
| 144 | } |
| 145 | #else |
| 146 | #define pack_two_shorts(pri, sec) PACK_TWO_SHORTS(pri, sec) |
| 147 | #endif |
| 148 | |
senorblanco@chromium.org | dc7de74 | 2009-11-30 20:00:29 +0000 | [diff] [blame] | 149 | // These functions are generated via macros, but are exposed here so that |
| 150 | // platformProcs may test for them by name. |
| 151 | void S32_opaque_D32_filter_DX(const SkBitmapProcState& s, const uint32_t xy[], |
| 152 | int count, SkPMColor colors[]); |
senorblanco@chromium.org | f3f0bd7 | 2009-12-10 22:46:31 +0000 | [diff] [blame] | 153 | void S32_alpha_D32_filter_DX(const SkBitmapProcState& s, const uint32_t xy[], |
| 154 | int count, SkPMColor colors[]); |
tomhudson@google.com | ae29b88 | 2012-03-06 14:59:04 +0000 | [diff] [blame] | 155 | void S32_opaque_D32_filter_DXDY(const SkBitmapProcState& s, |
| 156 | const uint32_t xy[], int count, SkPMColor colors[]); |
| 157 | void S32_alpha_D32_filter_DXDY(const SkBitmapProcState& s, |
| 158 | const uint32_t xy[], int count, SkPMColor colors[]); |
tomhudson@google.com | 06a7313 | 2012-02-22 18:30:43 +0000 | [diff] [blame] | 159 | void ClampX_ClampY_filter_scale(const SkBitmapProcState& s, uint32_t xy[], |
| 160 | int count, int x, int y); |
| 161 | void ClampX_ClampY_nofilter_scale(const SkBitmapProcState& s, uint32_t xy[], |
| 162 | int count, int x, int y); |
tomhudson@google.com | 5efaf26 | 2012-02-28 15:41:49 +0000 | [diff] [blame] | 163 | void ClampX_ClampY_filter_affine(const SkBitmapProcState& s, |
| 164 | uint32_t xy[], int count, int x, int y); |
| 165 | void ClampX_ClampY_nofilter_affine(const SkBitmapProcState& s, |
| 166 | uint32_t xy[], int count, int x, int y); |
senorblanco@chromium.org | dc7de74 | 2009-11-30 20:00:29 +0000 | [diff] [blame] | 167 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 168 | #endif |