epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 8 | #ifndef SkCoreBlitters_DEFINED |
| 9 | #define SkCoreBlitters_DEFINED |
| 10 | |
commit-bot@chromium.org | a5572e5 | 2014-03-07 03:24:41 +0000 | [diff] [blame] | 11 | #include "SkBitmapProcShader.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 12 | #include "SkBlitter.h" |
| 13 | #include "SkBlitRow.h" |
commit-bot@chromium.org | a5572e5 | 2014-03-07 03:24:41 +0000 | [diff] [blame] | 14 | #include "SkShader.h" |
| 15 | #include "SkSmallAllocator.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 16 | |
| 17 | class SkRasterBlitter : public SkBlitter { |
| 18 | public: |
| 19 | SkRasterBlitter(const SkBitmap& device) : fDevice(device) {} |
| 20 | |
| 21 | protected: |
| 22 | const SkBitmap& fDevice; |
| 23 | |
| 24 | private: |
| 25 | typedef SkBlitter INHERITED; |
| 26 | }; |
| 27 | |
| 28 | class SkShaderBlitter : public SkRasterBlitter { |
| 29 | public: |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 30 | /** |
| 31 | * The storage for shaderContext is owned by the caller, but the object itself is not. |
| 32 | * The blitter only ensures that the storage always holds a live object, but it may |
| 33 | * exchange that object. |
| 34 | */ |
| 35 | SkShaderBlitter(const SkBitmap& device, const SkPaint& paint, |
| 36 | SkShader::Context* shaderContext); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 37 | virtual ~SkShaderBlitter(); |
| 38 | |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 39 | /** |
| 40 | * Create a new shader context and uses it instead of the old one if successful. |
| 41 | * Will create the context at the same location as the old one (this is safe |
| 42 | * because the shader itself is unchanged). |
| 43 | */ |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 44 | bool resetShaderContext(const SkShader::ContextRec&) override; |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 45 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 46 | SkShader::Context* getShaderContext() const override { return fShaderContext; } |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 47 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 48 | protected: |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 49 | uint32_t fShaderFlags; |
| 50 | const SkShader* fShader; |
| 51 | SkShader::Context* fShaderContext; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 52 | |
| 53 | private: |
| 54 | // illegal |
| 55 | SkShaderBlitter& operator=(const SkShaderBlitter&); |
| 56 | |
| 57 | typedef SkRasterBlitter INHERITED; |
| 58 | }; |
| 59 | |
| 60 | /////////////////////////////////////////////////////////////////////////////// |
| 61 | |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 62 | class SkA8_Coverage_Blitter : public SkRasterBlitter { |
| 63 | public: |
| 64 | SkA8_Coverage_Blitter(const SkBitmap& device, const SkPaint& paint); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 65 | void blitH(int x, int y, int width) override; |
| 66 | void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override; |
| 67 | void blitV(int x, int y, int height, SkAlpha alpha) override; |
| 68 | void blitRect(int x, int y, int width, int height) override; |
| 69 | void blitMask(const SkMask&, const SkIRect&) override; |
| 70 | const SkBitmap* justAnOpaqueColor(uint32_t*) override; |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 71 | }; |
| 72 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 73 | class SkA8_Blitter : public SkRasterBlitter { |
| 74 | public: |
| 75 | SkA8_Blitter(const SkBitmap& device, const SkPaint& paint); |
| 76 | virtual void blitH(int x, int y, int width); |
| 77 | virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]); |
| 78 | virtual void blitV(int x, int y, int height, SkAlpha alpha); |
| 79 | virtual void blitRect(int x, int y, int width, int height); |
| 80 | virtual void blitMask(const SkMask&, const SkIRect&); |
| 81 | virtual const SkBitmap* justAnOpaqueColor(uint32_t*); |
| 82 | |
| 83 | private: |
| 84 | unsigned fSrcA; |
| 85 | |
| 86 | // illegal |
| 87 | SkA8_Blitter& operator=(const SkA8_Blitter&); |
| 88 | |
| 89 | typedef SkRasterBlitter INHERITED; |
| 90 | }; |
| 91 | |
| 92 | class SkA8_Shader_Blitter : public SkShaderBlitter { |
| 93 | public: |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 94 | SkA8_Shader_Blitter(const SkBitmap& device, const SkPaint& paint, |
| 95 | SkShader::Context* shaderContext); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 96 | virtual ~SkA8_Shader_Blitter(); |
| 97 | virtual void blitH(int x, int y, int width); |
| 98 | virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]); |
| 99 | virtual void blitMask(const SkMask&, const SkIRect&); |
| 100 | |
| 101 | private: |
| 102 | SkXfermode* fXfermode; |
| 103 | SkPMColor* fBuffer; |
| 104 | uint8_t* fAAExpand; |
| 105 | |
| 106 | // illegal |
| 107 | SkA8_Shader_Blitter& operator=(const SkA8_Shader_Blitter&); |
| 108 | |
| 109 | typedef SkShaderBlitter INHERITED; |
| 110 | }; |
| 111 | |
| 112 | //////////////////////////////////////////////////////////////// |
| 113 | |
| 114 | class SkARGB32_Blitter : public SkRasterBlitter { |
| 115 | public: |
| 116 | SkARGB32_Blitter(const SkBitmap& device, const SkPaint& paint); |
| 117 | virtual void blitH(int x, int y, int width); |
| 118 | virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]); |
| 119 | virtual void blitV(int x, int y, int height, SkAlpha alpha); |
| 120 | virtual void blitRect(int x, int y, int width, int height); |
| 121 | virtual void blitMask(const SkMask&, const SkIRect&); |
| 122 | virtual const SkBitmap* justAnOpaqueColor(uint32_t*); |
reed | 6983f66 | 2015-04-15 18:23:03 -0700 | [diff] [blame^] | 123 | #ifndef SK_SUPPORT_LEGACY_BLITANTIH2V2 |
| 124 | void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override; |
| 125 | void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override; |
| 126 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 127 | |
| 128 | protected: |
reed@google.com | ee467ee | 2011-03-09 13:23:57 +0000 | [diff] [blame] | 129 | SkColor fColor; |
| 130 | SkPMColor fPMColor; |
senorblanco@chromium.org | 29e5054 | 2010-12-16 19:07:45 +0000 | [diff] [blame] | 131 | SkBlitRow::ColorProc fColor32Proc; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 132 | |
| 133 | private: |
| 134 | unsigned fSrcA, fSrcR, fSrcG, fSrcB; |
| 135 | |
| 136 | // illegal |
| 137 | SkARGB32_Blitter& operator=(const SkARGB32_Blitter&); |
| 138 | |
| 139 | typedef SkRasterBlitter INHERITED; |
| 140 | }; |
| 141 | |
reed@android.com | dafaf7a | 2009-07-10 03:05:59 +0000 | [diff] [blame] | 142 | class SkARGB32_Opaque_Blitter : public SkARGB32_Blitter { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 143 | public: |
reed@android.com | dafaf7a | 2009-07-10 03:05:59 +0000 | [diff] [blame] | 144 | SkARGB32_Opaque_Blitter(const SkBitmap& device, const SkPaint& paint) |
| 145 | : INHERITED(device, paint) { SkASSERT(paint.getAlpha() == 0xFF); } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 146 | virtual void blitMask(const SkMask&, const SkIRect&); |
reed | 6983f66 | 2015-04-15 18:23:03 -0700 | [diff] [blame^] | 147 | #ifndef SK_SUPPORT_LEGACY_BLITANTIH2V2 |
| 148 | void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override; |
| 149 | void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override; |
| 150 | #endif |
reed@android.com | dafaf7a | 2009-07-10 03:05:59 +0000 | [diff] [blame] | 151 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 152 | private: |
| 153 | typedef SkARGB32_Blitter INHERITED; |
| 154 | }; |
| 155 | |
reed@android.com | dafaf7a | 2009-07-10 03:05:59 +0000 | [diff] [blame] | 156 | class SkARGB32_Black_Blitter : public SkARGB32_Opaque_Blitter { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 157 | public: |
reed@android.com | dafaf7a | 2009-07-10 03:05:59 +0000 | [diff] [blame] | 158 | SkARGB32_Black_Blitter(const SkBitmap& device, const SkPaint& paint) |
| 159 | : INHERITED(device, paint) {} |
reed@android.com | dafaf7a | 2009-07-10 03:05:59 +0000 | [diff] [blame] | 160 | virtual void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]); |
reed | 6983f66 | 2015-04-15 18:23:03 -0700 | [diff] [blame^] | 161 | #ifndef SK_SUPPORT_LEGACY_BLITANTIH2V2 |
| 162 | void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override; |
| 163 | void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override; |
| 164 | #endif |
reed@android.com | b602b8e | 2009-07-10 15:58:53 +0000 | [diff] [blame] | 165 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 166 | private: |
reed@android.com | dafaf7a | 2009-07-10 03:05:59 +0000 | [diff] [blame] | 167 | typedef SkARGB32_Opaque_Blitter INHERITED; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 168 | }; |
| 169 | |
| 170 | class SkARGB32_Shader_Blitter : public SkShaderBlitter { |
| 171 | public: |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 172 | SkARGB32_Shader_Blitter(const SkBitmap& device, const SkPaint& paint, |
| 173 | SkShader::Context* shaderContext); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 174 | virtual ~SkARGB32_Shader_Blitter(); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 175 | void blitH(int x, int y, int width) override; |
| 176 | void blitV(int x, int y, int height, SkAlpha alpha) override; |
| 177 | void blitRect(int x, int y, int width, int height) override; |
| 178 | void blitAntiH(int x, int y, const SkAlpha[], const int16_t[]) override; |
| 179 | void blitMask(const SkMask&, const SkIRect&) override; |
skia.committer@gmail.com | f57c01b | 2012-10-13 02:01:56 +0000 | [diff] [blame] | 180 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 181 | private: |
reed@android.com | c4cae85 | 2009-09-23 15:06:10 +0000 | [diff] [blame] | 182 | SkXfermode* fXfermode; |
| 183 | SkPMColor* fBuffer; |
| 184 | SkBlitRow::Proc32 fProc32; |
| 185 | SkBlitRow::Proc32 fProc32Blend; |
reed@google.com | 13201e7 | 2012-11-16 13:20:41 +0000 | [diff] [blame] | 186 | bool fShadeDirectlyIntoDevice; |
| 187 | bool fConstInY; |
skia.committer@gmail.com | f57c01b | 2012-10-13 02:01:56 +0000 | [diff] [blame] | 188 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 189 | // illegal |
| 190 | SkARGB32_Shader_Blitter& operator=(const SkARGB32_Shader_Blitter&); |
skia.committer@gmail.com | f57c01b | 2012-10-13 02:01:56 +0000 | [diff] [blame] | 191 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 192 | typedef SkShaderBlitter INHERITED; |
| 193 | }; |
| 194 | |
reed@android.com | 1fc4c60 | 2009-10-02 16:34:57 +0000 | [diff] [blame] | 195 | /////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 196 | |
reed@android.com | 1fc4c60 | 2009-10-02 16:34:57 +0000 | [diff] [blame] | 197 | /* These return the correct subclass of blitter for their device config. |
| 198 | |
| 199 | Currently, they make the following assumptions about the state of the |
| 200 | paint: |
reed@google.com | 981d479 | 2011-03-09 12:55:47 +0000 | [diff] [blame] | 201 | |
reed@android.com | 1fc4c60 | 2009-10-02 16:34:57 +0000 | [diff] [blame] | 202 | 1. If there is an xfermode, there will also be a shader |
| 203 | 2. If there is a colorfilter, there will be a shader that itself handles |
| 204 | calling the filter, so the blitter can always ignore the colorfilter obj |
| 205 | |
| 206 | These pre-conditions must be handled by the caller, in our case |
| 207 | SkBlitter::Choose(...) |
| 208 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 209 | |
commit-bot@chromium.org | a5572e5 | 2014-03-07 03:24:41 +0000 | [diff] [blame] | 210 | SkBlitter* SkBlitter_ChooseD565(const SkBitmap& device, const SkPaint& paint, |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 211 | SkShader::Context* shaderContext, |
commit-bot@chromium.org | a5572e5 | 2014-03-07 03:24:41 +0000 | [diff] [blame] | 212 | SkTBlitterAllocator* allocator); |
reed@android.com | 1fc4c60 | 2009-10-02 16:34:57 +0000 | [diff] [blame] | 213 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 214 | #endif |