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" |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 14 | #include "SkShaderBase.h" |
Mike Reed | d470673 | 2016-11-15 16:44:34 -0500 | [diff] [blame] | 15 | #include "SkXfermodePriv.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 16 | |
| 17 | class SkRasterBlitter : public SkBlitter { |
| 18 | public: |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 19 | SkRasterBlitter(const SkPixmap& device) : fDevice(device) {} |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 20 | |
| 21 | protected: |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 22 | const SkPixmap fDevice; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 | */ |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 35 | SkShaderBlitter(const SkPixmap& device, const SkPaint& paint, |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 36 | SkShaderBase::Context* shaderContext); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 37 | virtual ~SkShaderBlitter(); |
| 38 | |
| 39 | protected: |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 40 | uint32_t fShaderFlags; |
| 41 | const SkShader* fShader; |
| 42 | SkShaderBase::Context* fShaderContext; |
| 43 | bool fConstInY; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 44 | |
| 45 | private: |
| 46 | // illegal |
| 47 | SkShaderBlitter& operator=(const SkShaderBlitter&); |
| 48 | |
| 49 | typedef SkRasterBlitter INHERITED; |
| 50 | }; |
| 51 | |
| 52 | /////////////////////////////////////////////////////////////////////////////// |
| 53 | |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 54 | class SkA8_Coverage_Blitter : public SkRasterBlitter { |
| 55 | public: |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 56 | SkA8_Coverage_Blitter(const SkPixmap& device, const SkPaint& paint); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 57 | void blitH(int x, int y, int width) override; |
| 58 | void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override; |
| 59 | void blitV(int x, int y, int height, SkAlpha alpha) override; |
| 60 | void blitRect(int x, int y, int width, int height) override; |
| 61 | void blitMask(const SkMask&, const SkIRect&) override; |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 62 | const SkPixmap* justAnOpaqueColor(uint32_t*) override; |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 65 | //////////////////////////////////////////////////////////////// |
| 66 | |
| 67 | class SkARGB32_Blitter : public SkRasterBlitter { |
| 68 | public: |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 69 | SkARGB32_Blitter(const SkPixmap& device, const SkPaint& paint); |
reed | 3dfd133 | 2015-06-25 14:26:11 -0700 | [diff] [blame] | 70 | void blitH(int x, int y, int width) override; |
| 71 | void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override; |
| 72 | void blitV(int x, int y, int height, SkAlpha alpha) override; |
| 73 | void blitRect(int x, int y, int width, int height) override; |
| 74 | void blitMask(const SkMask&, const SkIRect&) override; |
| 75 | const SkPixmap* justAnOpaqueColor(uint32_t*) override; |
reed | 6983f66 | 2015-04-15 18:23:03 -0700 | [diff] [blame] | 76 | void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override; |
| 77 | void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 78 | |
| 79 | protected: |
reed@google.com | ee467ee | 2011-03-09 13:23:57 +0000 | [diff] [blame] | 80 | SkColor fColor; |
| 81 | SkPMColor fPMColor; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 82 | |
| 83 | private: |
| 84 | unsigned fSrcA, fSrcR, fSrcG, fSrcB; |
| 85 | |
| 86 | // illegal |
| 87 | SkARGB32_Blitter& operator=(const SkARGB32_Blitter&); |
| 88 | |
| 89 | typedef SkRasterBlitter INHERITED; |
| 90 | }; |
| 91 | |
reed@android.com | dafaf7a | 2009-07-10 03:05:59 +0000 | [diff] [blame] | 92 | class SkARGB32_Opaque_Blitter : public SkARGB32_Blitter { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 93 | public: |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 94 | SkARGB32_Opaque_Blitter(const SkPixmap& device, const SkPaint& paint) |
reed@android.com | dafaf7a | 2009-07-10 03:05:59 +0000 | [diff] [blame] | 95 | : INHERITED(device, paint) { SkASSERT(paint.getAlpha() == 0xFF); } |
reed | 3dfd133 | 2015-06-25 14:26:11 -0700 | [diff] [blame] | 96 | void blitMask(const SkMask&, const SkIRect&) override; |
reed | 6983f66 | 2015-04-15 18:23:03 -0700 | [diff] [blame] | 97 | void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override; |
| 98 | void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override; |
reed@android.com | dafaf7a | 2009-07-10 03:05:59 +0000 | [diff] [blame] | 99 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 100 | private: |
| 101 | typedef SkARGB32_Blitter INHERITED; |
| 102 | }; |
| 103 | |
reed@android.com | dafaf7a | 2009-07-10 03:05:59 +0000 | [diff] [blame] | 104 | class SkARGB32_Black_Blitter : public SkARGB32_Opaque_Blitter { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 105 | public: |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 106 | SkARGB32_Black_Blitter(const SkPixmap& device, const SkPaint& paint) |
reed@android.com | dafaf7a | 2009-07-10 03:05:59 +0000 | [diff] [blame] | 107 | : INHERITED(device, paint) {} |
reed | 3dfd133 | 2015-06-25 14:26:11 -0700 | [diff] [blame] | 108 | void blitAntiH(int x, int y, const SkAlpha antialias[], const int16_t runs[]) override; |
reed | 6983f66 | 2015-04-15 18:23:03 -0700 | [diff] [blame] | 109 | void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) override; |
| 110 | void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) override; |
reed@android.com | b602b8e | 2009-07-10 15:58:53 +0000 | [diff] [blame] | 111 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 112 | private: |
reed@android.com | dafaf7a | 2009-07-10 03:05:59 +0000 | [diff] [blame] | 113 | typedef SkARGB32_Opaque_Blitter INHERITED; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | class SkARGB32_Shader_Blitter : public SkShaderBlitter { |
| 117 | public: |
reed | 41e010c | 2015-06-09 12:16:53 -0700 | [diff] [blame] | 118 | SkARGB32_Shader_Blitter(const SkPixmap& device, const SkPaint& paint, |
Florin Malita | 4aed138 | 2017-05-25 10:38:07 -0400 | [diff] [blame] | 119 | SkShaderBase::Context* shaderContext); |
Brian Salomon | d3b6597 | 2017-03-22 12:05:03 -0400 | [diff] [blame] | 120 | ~SkARGB32_Shader_Blitter() override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 121 | void blitH(int x, int y, int width) override; |
| 122 | void blitV(int x, int y, int height, SkAlpha alpha) override; |
| 123 | void blitRect(int x, int y, int width, int height) override; |
| 124 | void blitAntiH(int x, int y, const SkAlpha[], const int16_t[]) override; |
| 125 | void blitMask(const SkMask&, const SkIRect&) override; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 126 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 127 | private: |
reed@android.com | c4cae85 | 2009-09-23 15:06:10 +0000 | [diff] [blame] | 128 | SkXfermode* fXfermode; |
| 129 | SkPMColor* fBuffer; |
| 130 | SkBlitRow::Proc32 fProc32; |
| 131 | SkBlitRow::Proc32 fProc32Blend; |
reed@google.com | 13201e7 | 2012-11-16 13:20:41 +0000 | [diff] [blame] | 132 | bool fShadeDirectlyIntoDevice; |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 133 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 134 | // illegal |
| 135 | SkARGB32_Shader_Blitter& operator=(const SkARGB32_Shader_Blitter&); |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 136 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 137 | typedef SkShaderBlitter INHERITED; |
| 138 | }; |
| 139 | |
reed@android.com | 1fc4c60 | 2009-10-02 16:34:57 +0000 | [diff] [blame] | 140 | /////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 141 | |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 142 | // Neither of these ever returns nullptr, but this first factory may return a SkNullBlitter. |
Mike Klein | fb191da | 2016-11-15 13:20:33 -0500 | [diff] [blame] | 143 | SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap&, const SkPaint&, const SkMatrix& ctm, |
Matt Sarett | 25834ff | 2017-02-15 15:54:35 -0500 | [diff] [blame] | 144 | SkArenaAlloc*); |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 145 | // Use this if you've pre-baked a shader pipeline, including modulating with paint alpha. |
| 146 | // This factory never returns an SkNullBlitter. |
| 147 | SkBlitter* SkCreateRasterPipelineBlitter(const SkPixmap&, const SkPaint&, |
Mike Reed | 0264095 | 2017-05-19 15:32:13 -0400 | [diff] [blame] | 148 | const SkRasterPipeline& shaderPipeline, |
Mike Klein | b35cb31 | 2017-05-19 12:01:01 -0400 | [diff] [blame] | 149 | bool shader_is_opaque, |
Mike Reed | 0264095 | 2017-05-19 15:32:13 -0400 | [diff] [blame] | 150 | SkArenaAlloc*); |
mtklein | 9a5c47f | 2016-07-22 11:05:04 -0700 | [diff] [blame] | 151 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 152 | #endif |