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 | #include "SkDraw.h" |
| 9 | #include "SkBlitter.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 10 | #include "SkCanvas.h" |
| 11 | #include "SkColorPriv.h" |
| 12 | #include "SkDevice.h" |
reed@google.com | 1c028bd | 2013-08-28 15:23:19 +0000 | [diff] [blame] | 13 | #include "SkDeviceLooper.h" |
bungeman@google.com | 2211b62 | 2012-01-13 15:02:58 +0000 | [diff] [blame] | 14 | #include "SkFixed.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 15 | #include "SkMaskFilter.h" |
| 16 | #include "SkPaint.h" |
| 17 | #include "SkPathEffect.h" |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 18 | #include "SkRasterClip.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 19 | #include "SkRasterizer.h" |
scroggo@google.com | a8e33a9 | 2013-11-08 18:02:53 +0000 | [diff] [blame] | 20 | #include "SkRRect.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 21 | #include "SkScan.h" |
| 22 | #include "SkShader.h" |
commit-bot@chromium.org | a5572e5 | 2014-03-07 03:24:41 +0000 | [diff] [blame] | 23 | #include "SkSmallAllocator.h" |
robertphillips@google.com | 76f9e93 | 2013-01-15 20:17:47 +0000 | [diff] [blame] | 24 | #include "SkString.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 25 | #include "SkStroke.h" |
kkinnunen | cb9a2c8 | 2014-06-12 23:06:28 -0700 | [diff] [blame] | 26 | #include "SkTextMapStateProc.h" |
reed@google.com | 32e5d97 | 2011-07-27 18:25:57 +0000 | [diff] [blame] | 27 | #include "SkTLazy.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 28 | #include "SkUtils.h" |
commit-bot@chromium.org | 559a883 | 2014-05-30 10:08:22 +0000 | [diff] [blame] | 29 | #include "SkVertState.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 30 | |
| 31 | #include "SkAutoKern.h" |
| 32 | #include "SkBitmapProcShader.h" |
| 33 | #include "SkDrawProcs.h" |
reed@google.com | ae57358 | 2013-01-03 15:22:40 +0000 | [diff] [blame] | 34 | #include "SkMatrixUtils.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 35 | |
commit-bot@chromium.org | a5572e5 | 2014-03-07 03:24:41 +0000 | [diff] [blame] | 36 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 37 | //#define TRACE_BITMAP_DRAWS |
| 38 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 39 | |
reed@google.com | fd4236e | 2011-07-25 21:16:22 +0000 | [diff] [blame] | 40 | /** Helper for allocating small blitters on the stack. |
| 41 | */ |
reed@google.com | 40c2ba2 | 2011-07-25 19:41:22 +0000 | [diff] [blame] | 42 | class SkAutoBlitterChoose : SkNoncopyable { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 43 | public: |
reed@google.com | 1d6ee0b | 2011-07-05 17:44:56 +0000 | [diff] [blame] | 44 | SkAutoBlitterChoose() { |
| 45 | fBlitter = NULL; |
| 46 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 47 | SkAutoBlitterChoose(const SkBitmap& device, const SkMatrix& matrix, |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 48 | const SkPaint& paint, bool drawCoverage = false) { |
commit-bot@chromium.org | a5572e5 | 2014-03-07 03:24:41 +0000 | [diff] [blame] | 49 | fBlitter = SkBlitter::Choose(device, matrix, paint, &fAllocator, |
| 50 | drawCoverage); |
commit-bot@chromium.org | e61a86c | 2013-11-18 16:03:59 +0000 | [diff] [blame] | 51 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 52 | |
| 53 | SkBlitter* operator->() { return fBlitter; } |
| 54 | SkBlitter* get() const { return fBlitter; } |
| 55 | |
reed@google.com | 1d6ee0b | 2011-07-05 17:44:56 +0000 | [diff] [blame] | 56 | void choose(const SkBitmap& device, const SkMatrix& matrix, |
krajcevski | 53f0959 | 2014-08-06 11:12:14 -0700 | [diff] [blame] | 57 | const SkPaint& paint, bool drawCoverage = false) { |
reed@google.com | 1d6ee0b | 2011-07-05 17:44:56 +0000 | [diff] [blame] | 58 | SkASSERT(!fBlitter); |
krajcevski | 53f0959 | 2014-08-06 11:12:14 -0700 | [diff] [blame] | 59 | fBlitter = SkBlitter::Choose(device, matrix, paint, &fAllocator, |
| 60 | drawCoverage); |
reed@google.com | 1d6ee0b | 2011-07-05 17:44:56 +0000 | [diff] [blame] | 61 | } |
| 62 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 63 | private: |
commit-bot@chromium.org | a5572e5 | 2014-03-07 03:24:41 +0000 | [diff] [blame] | 64 | // Owned by fAllocator, which will handle the delete. |
| 65 | SkBlitter* fBlitter; |
| 66 | SkTBlitterAllocator fAllocator; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 67 | }; |
commit-bot@chromium.org | e61a86c | 2013-11-18 16:03:59 +0000 | [diff] [blame] | 68 | #define SkAutoBlitterChoose(...) SK_REQUIRE_LOCAL_VAR(SkAutoBlitterChoose) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 69 | |
reed@google.com | 40c2ba2 | 2011-07-25 19:41:22 +0000 | [diff] [blame] | 70 | /** |
| 71 | * Since we are providing the storage for the shader (to avoid the perf cost |
| 72 | * of calling new) we insist that in our destructor we can account for all |
| 73 | * owners of the shader. |
| 74 | */ |
| 75 | class SkAutoBitmapShaderInstall : SkNoncopyable { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 76 | public: |
commit-bot@chromium.org | 9c9005a | 2014-04-28 14:55:39 +0000 | [diff] [blame] | 77 | SkAutoBitmapShaderInstall(const SkBitmap& src, const SkPaint& paint, |
| 78 | const SkMatrix* localMatrix = NULL) |
reed@google.com | 40c2ba2 | 2011-07-25 19:41:22 +0000 | [diff] [blame] | 79 | : fPaint(paint) /* makes a copy of the paint */ { |
mtklein | 7ef849d | 2014-11-24 09:11:45 -0800 | [diff] [blame] | 80 | fPaint.setShader(SkCreateBitmapShader(src, SkShader::kClamp_TileMode, |
| 81 | SkShader::kClamp_TileMode, |
| 82 | localMatrix, &fAllocator)); |
reed@google.com | 40c2ba2 | 2011-07-25 19:41:22 +0000 | [diff] [blame] | 83 | // we deliberately left the shader with an owner-count of 2 |
| 84 | SkASSERT(2 == fPaint.getShader()->getRefCnt()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 85 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 86 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 87 | ~SkAutoBitmapShaderInstall() { |
commit-bot@chromium.org | a5572e5 | 2014-03-07 03:24:41 +0000 | [diff] [blame] | 88 | // since fAllocator will destroy shader, we insist that owners == 2 |
| 89 | SkASSERT(2 == fPaint.getShader()->getRefCnt()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 90 | |
reed@google.com | 40c2ba2 | 2011-07-25 19:41:22 +0000 | [diff] [blame] | 91 | fPaint.setShader(NULL); // unref the shader by 1 |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 92 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 93 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 94 | |
reed@google.com | 40c2ba2 | 2011-07-25 19:41:22 +0000 | [diff] [blame] | 95 | // return the new paint that has the shader applied |
| 96 | const SkPaint& paintWithShader() const { return fPaint; } |
| 97 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 98 | private: |
commit-bot@chromium.org | a5572e5 | 2014-03-07 03:24:41 +0000 | [diff] [blame] | 99 | // copy of caller's paint (which we then modify) |
| 100 | SkPaint fPaint; |
| 101 | // Stores the shader. |
| 102 | SkTBlitterAllocator fAllocator; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 103 | }; |
commit-bot@chromium.org | e61a86c | 2013-11-18 16:03:59 +0000 | [diff] [blame] | 104 | #define SkAutoBitmapShaderInstall(...) SK_REQUIRE_LOCAL_VAR(SkAutoBitmapShaderInstall) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 105 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 106 | /////////////////////////////////////////////////////////////////////////////// |
| 107 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 108 | SkDraw::SkDraw() { |
| 109 | sk_bzero(this, sizeof(*this)); |
| 110 | } |
| 111 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 112 | SkDraw::SkDraw(const SkDraw& src) { |
| 113 | memcpy(this, &src, sizeof(*this)); |
| 114 | } |
| 115 | |
reed@google.com | 4bbdeac | 2013-01-24 21:03:11 +0000 | [diff] [blame] | 116 | bool SkDraw::computeConservativeLocalClipBounds(SkRect* localBounds) const { |
| 117 | if (fRC->isEmpty()) { |
| 118 | return false; |
| 119 | } |
| 120 | |
| 121 | SkMatrix inverse; |
| 122 | if (!fMatrix->invert(&inverse)) { |
| 123 | return false; |
| 124 | } |
| 125 | |
| 126 | SkIRect devBounds = fRC->getBounds(); |
| 127 | // outset to have slop for antialasing and hairlines |
| 128 | devBounds.outset(1, 1); |
| 129 | inverse.mapRect(localBounds, SkRect::Make(devBounds)); |
| 130 | return true; |
| 131 | } |
| 132 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 133 | /////////////////////////////////////////////////////////////////////////////// |
| 134 | |
| 135 | typedef void (*BitmapXferProc)(void* pixels, size_t bytes, uint32_t data); |
| 136 | |
| 137 | static void D_Clear_BitmapXferProc(void* pixels, size_t bytes, uint32_t) { |
reed@android.com | 4516f47 | 2009-06-29 16:25:36 +0000 | [diff] [blame] | 138 | sk_bzero(pixels, bytes); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | static void D_Dst_BitmapXferProc(void*, size_t, uint32_t data) {} |
| 142 | |
| 143 | static void D32_Src_BitmapXferProc(void* pixels, size_t bytes, uint32_t data) { |
commit-bot@chromium.org | a8c7f77 | 2014-01-24 21:46:29 +0000 | [diff] [blame] | 144 | sk_memset32((uint32_t*)pixels, data, SkToInt(bytes >> 2)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | static void D16_Src_BitmapXferProc(void* pixels, size_t bytes, uint32_t data) { |
commit-bot@chromium.org | a8c7f77 | 2014-01-24 21:46:29 +0000 | [diff] [blame] | 148 | sk_memset16((uint16_t*)pixels, data, SkToInt(bytes >> 1)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | static void DA8_Src_BitmapXferProc(void* pixels, size_t bytes, uint32_t data) { |
| 152 | memset(pixels, data, bytes); |
| 153 | } |
| 154 | |
| 155 | static BitmapXferProc ChooseBitmapXferProc(const SkBitmap& bitmap, |
| 156 | const SkPaint& paint, |
| 157 | uint32_t* data) { |
| 158 | // todo: we can apply colorfilter up front if no shader, so we wouldn't |
| 159 | // need to abort this fastpath |
| 160 | if (paint.getShader() || paint.getColorFilter()) { |
| 161 | return NULL; |
| 162 | } |
| 163 | |
reed@android.com | 845fdac | 2009-06-23 03:01:32 +0000 | [diff] [blame] | 164 | SkXfermode::Mode mode; |
mike@reedtribe.org | be2aa2a | 2011-11-17 02:32:04 +0000 | [diff] [blame] | 165 | if (!SkXfermode::AsMode(paint.getXfermode(), &mode)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 166 | return NULL; |
| 167 | } |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 168 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 169 | SkColor color = paint.getColor(); |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 170 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 171 | // collaps modes based on color... |
reed@android.com | 845fdac | 2009-06-23 03:01:32 +0000 | [diff] [blame] | 172 | if (SkXfermode::kSrcOver_Mode == mode) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 173 | unsigned alpha = SkColorGetA(color); |
| 174 | if (0 == alpha) { |
reed@android.com | 845fdac | 2009-06-23 03:01:32 +0000 | [diff] [blame] | 175 | mode = SkXfermode::kDst_Mode; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 176 | } else if (0xFF == alpha) { |
reed@android.com | 845fdac | 2009-06-23 03:01:32 +0000 | [diff] [blame] | 177 | mode = SkXfermode::kSrc_Mode; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 178 | } |
| 179 | } |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 180 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 181 | switch (mode) { |
reed@android.com | 845fdac | 2009-06-23 03:01:32 +0000 | [diff] [blame] | 182 | case SkXfermode::kClear_Mode: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 183 | // SkDebugf("--- D_Clear_BitmapXferProc\n"); |
| 184 | return D_Clear_BitmapXferProc; // ignore data |
reed@android.com | 845fdac | 2009-06-23 03:01:32 +0000 | [diff] [blame] | 185 | case SkXfermode::kDst_Mode: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 186 | // SkDebugf("--- D_Dst_BitmapXferProc\n"); |
| 187 | return D_Dst_BitmapXferProc; // ignore data |
reed@android.com | 845fdac | 2009-06-23 03:01:32 +0000 | [diff] [blame] | 188 | case SkXfermode::kSrc_Mode: { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 189 | /* |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 190 | should I worry about dithering for the lower depths? |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 191 | */ |
| 192 | SkPMColor pmc = SkPreMultiplyColor(color); |
reed@google.com | 900ecf2 | 2014-02-20 20:55:37 +0000 | [diff] [blame] | 193 | switch (bitmap.colorType()) { |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 194 | case kN32_SkColorType: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 195 | if (data) { |
| 196 | *data = pmc; |
| 197 | } |
| 198 | // SkDebugf("--- D32_Src_BitmapXferProc\n"); |
| 199 | return D32_Src_BitmapXferProc; |
reed@google.com | 900ecf2 | 2014-02-20 20:55:37 +0000 | [diff] [blame] | 200 | case kRGB_565_SkColorType: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 201 | if (data) { |
| 202 | *data = SkPixel32ToPixel16(pmc); |
| 203 | } |
| 204 | // SkDebugf("--- D16_Src_BitmapXferProc\n"); |
| 205 | return D16_Src_BitmapXferProc; |
reed@google.com | 900ecf2 | 2014-02-20 20:55:37 +0000 | [diff] [blame] | 206 | case kAlpha_8_SkColorType: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 207 | if (data) { |
| 208 | *data = SkGetPackedA32(pmc); |
| 209 | } |
| 210 | // SkDebugf("--- DA8_Src_BitmapXferProc\n"); |
| 211 | return DA8_Src_BitmapXferProc; |
| 212 | default: |
| 213 | break; |
| 214 | } |
| 215 | break; |
| 216 | } |
| 217 | default: |
| 218 | break; |
| 219 | } |
| 220 | return NULL; |
| 221 | } |
| 222 | |
| 223 | static void CallBitmapXferProc(const SkBitmap& bitmap, const SkIRect& rect, |
| 224 | BitmapXferProc proc, uint32_t procData) { |
| 225 | int shiftPerPixel; |
reed@google.com | 900ecf2 | 2014-02-20 20:55:37 +0000 | [diff] [blame] | 226 | switch (bitmap.colorType()) { |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 227 | case kN32_SkColorType: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 228 | shiftPerPixel = 2; |
| 229 | break; |
reed@google.com | 900ecf2 | 2014-02-20 20:55:37 +0000 | [diff] [blame] | 230 | case kRGB_565_SkColorType: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 231 | shiftPerPixel = 1; |
| 232 | break; |
reed@google.com | 900ecf2 | 2014-02-20 20:55:37 +0000 | [diff] [blame] | 233 | case kAlpha_8_SkColorType: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 234 | shiftPerPixel = 0; |
| 235 | break; |
| 236 | default: |
tomhudson@google.com | 0c00f21 | 2011-12-28 14:59:50 +0000 | [diff] [blame] | 237 | SkDEBUGFAIL("Can't use xferproc on this config"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 238 | return; |
| 239 | } |
| 240 | |
| 241 | uint8_t* pixels = (uint8_t*)bitmap.getPixels(); |
| 242 | SkASSERT(pixels); |
| 243 | const size_t rowBytes = bitmap.rowBytes(); |
| 244 | const int widthBytes = rect.width() << shiftPerPixel; |
| 245 | |
| 246 | // skip down to the first scanline and X position |
| 247 | pixels += rect.fTop * rowBytes + (rect.fLeft << shiftPerPixel); |
| 248 | for (int scans = rect.height() - 1; scans >= 0; --scans) { |
| 249 | proc(pixels, widthBytes, procData); |
| 250 | pixels += rowBytes; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | void SkDraw::drawPaint(const SkPaint& paint) const { |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 255 | SkDEBUGCODE(this->validate();) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 256 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 257 | if (fRC->isEmpty()) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 258 | return; |
| 259 | } |
| 260 | |
| 261 | SkIRect devRect; |
| 262 | devRect.set(0, 0, fBitmap->width(), fBitmap->height()); |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 263 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 264 | if (fRC->isBW()) { |
| 265 | /* If we don't have a shader (i.e. we're just a solid color) we may |
| 266 | be faster to operate directly on the device bitmap, rather than invoking |
| 267 | a blitter. Esp. true for xfermodes, which require a colorshader to be |
| 268 | present, which is just redundant work. Since we're drawing everywhere |
| 269 | in the clip, we don't have to worry about antialiasing. |
| 270 | */ |
| 271 | uint32_t procData = 0; // to avoid the warning |
| 272 | BitmapXferProc proc = ChooseBitmapXferProc(*fBitmap, paint, &procData); |
| 273 | if (proc) { |
| 274 | if (D_Dst_BitmapXferProc == proc) { // nothing to do |
| 275 | return; |
| 276 | } |
| 277 | |
| 278 | SkRegion::Iterator iter(fRC->bwRgn()); |
| 279 | while (!iter.done()) { |
| 280 | CallBitmapXferProc(*fBitmap, iter.rect(), proc, procData); |
| 281 | iter.next(); |
| 282 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 283 | return; |
| 284 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 285 | } |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 286 | |
| 287 | // normal case: use a blitter |
| 288 | SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, paint); |
| 289 | SkScan::FillIRect(devRect, *fRC, blitter.get()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | /////////////////////////////////////////////////////////////////////////////// |
| 293 | |
| 294 | struct PtProcRec { |
| 295 | SkCanvas::PointMode fMode; |
| 296 | const SkPaint* fPaint; |
| 297 | const SkRegion* fClip; |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 298 | const SkRasterClip* fRC; |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 299 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 300 | // computed values |
| 301 | SkFixed fRadius; |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 302 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 303 | typedef void (*Proc)(const PtProcRec&, const SkPoint devPts[], int count, |
| 304 | SkBlitter*); |
| 305 | |
| 306 | bool init(SkCanvas::PointMode, const SkPaint&, const SkMatrix* matrix, |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 307 | const SkRasterClip*); |
| 308 | Proc chooseProc(SkBlitter** blitter); |
| 309 | |
| 310 | private: |
| 311 | SkAAClipBlitterWrapper fWrapper; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 312 | }; |
| 313 | |
| 314 | static void bw_pt_rect_hair_proc(const PtProcRec& rec, const SkPoint devPts[], |
| 315 | int count, SkBlitter* blitter) { |
| 316 | SkASSERT(rec.fClip->isRect()); |
| 317 | const SkIRect& r = rec.fClip->getBounds(); |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 318 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 319 | for (int i = 0; i < count; i++) { |
reed@google.com | 2d47a21 | 2012-11-29 21:01:00 +0000 | [diff] [blame] | 320 | int x = SkScalarFloorToInt(devPts[i].fX); |
| 321 | int y = SkScalarFloorToInt(devPts[i].fY); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 322 | if (r.contains(x, y)) { |
| 323 | blitter->blitH(x, y, 1); |
| 324 | } |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | static void bw_pt_rect_16_hair_proc(const PtProcRec& rec, |
| 329 | const SkPoint devPts[], int count, |
| 330 | SkBlitter* blitter) { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 331 | SkASSERT(rec.fRC->isRect()); |
| 332 | const SkIRect& r = rec.fRC->getBounds(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 333 | uint32_t value; |
| 334 | const SkBitmap* bitmap = blitter->justAnOpaqueColor(&value); |
| 335 | SkASSERT(bitmap); |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 336 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 337 | uint16_t* addr = bitmap->getAddr16(0, 0); |
scroggo@google.com | e5f4824 | 2013-02-25 21:47:41 +0000 | [diff] [blame] | 338 | size_t rb = bitmap->rowBytes(); |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 339 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 340 | for (int i = 0; i < count; i++) { |
reed@google.com | 2d47a21 | 2012-11-29 21:01:00 +0000 | [diff] [blame] | 341 | int x = SkScalarFloorToInt(devPts[i].fX); |
| 342 | int y = SkScalarFloorToInt(devPts[i].fY); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 343 | if (r.contains(x, y)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 344 | ((uint16_t*)((char*)addr + y * rb))[x] = SkToU16(value); |
| 345 | } |
| 346 | } |
| 347 | } |
| 348 | |
reed@google.com | 2d47a21 | 2012-11-29 21:01:00 +0000 | [diff] [blame] | 349 | static void bw_pt_rect_32_hair_proc(const PtProcRec& rec, |
| 350 | const SkPoint devPts[], int count, |
| 351 | SkBlitter* blitter) { |
| 352 | SkASSERT(rec.fRC->isRect()); |
| 353 | const SkIRect& r = rec.fRC->getBounds(); |
| 354 | uint32_t value; |
| 355 | const SkBitmap* bitmap = blitter->justAnOpaqueColor(&value); |
| 356 | SkASSERT(bitmap); |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 357 | |
reed@google.com | 2d47a21 | 2012-11-29 21:01:00 +0000 | [diff] [blame] | 358 | SkPMColor* addr = bitmap->getAddr32(0, 0); |
scroggo@google.com | e5f4824 | 2013-02-25 21:47:41 +0000 | [diff] [blame] | 359 | size_t rb = bitmap->rowBytes(); |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 360 | |
reed@google.com | 2d47a21 | 2012-11-29 21:01:00 +0000 | [diff] [blame] | 361 | for (int i = 0; i < count; i++) { |
| 362 | int x = SkScalarFloorToInt(devPts[i].fX); |
| 363 | int y = SkScalarFloorToInt(devPts[i].fY); |
| 364 | if (r.contains(x, y)) { |
| 365 | ((SkPMColor*)((char*)addr + y * rb))[x] = value; |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 370 | static void bw_pt_hair_proc(const PtProcRec& rec, const SkPoint devPts[], |
| 371 | int count, SkBlitter* blitter) { |
| 372 | for (int i = 0; i < count; i++) { |
reed@google.com | e1ca705 | 2013-12-17 19:22:07 +0000 | [diff] [blame] | 373 | int x = SkScalarFloorToInt(devPts[i].fX); |
| 374 | int y = SkScalarFloorToInt(devPts[i].fY); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 375 | if (rec.fClip->contains(x, y)) { |
| 376 | blitter->blitH(x, y, 1); |
| 377 | } |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | static void bw_line_hair_proc(const PtProcRec& rec, const SkPoint devPts[], |
| 382 | int count, SkBlitter* blitter) { |
| 383 | for (int i = 0; i < count; i += 2) { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 384 | SkScan::HairLine(devPts[i], devPts[i+1], *rec.fRC, blitter); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 385 | } |
| 386 | } |
| 387 | |
| 388 | static void bw_poly_hair_proc(const PtProcRec& rec, const SkPoint devPts[], |
| 389 | int count, SkBlitter* blitter) { |
| 390 | for (int i = 0; i < count - 1; i++) { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 391 | SkScan::HairLine(devPts[i], devPts[i+1], *rec.fRC, blitter); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 392 | } |
| 393 | } |
| 394 | |
| 395 | // aa versions |
| 396 | |
| 397 | static void aa_line_hair_proc(const PtProcRec& rec, const SkPoint devPts[], |
| 398 | int count, SkBlitter* blitter) { |
| 399 | for (int i = 0; i < count; i += 2) { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 400 | SkScan::AntiHairLine(devPts[i], devPts[i+1], *rec.fRC, blitter); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 401 | } |
| 402 | } |
| 403 | |
| 404 | static void aa_poly_hair_proc(const PtProcRec& rec, const SkPoint devPts[], |
| 405 | int count, SkBlitter* blitter) { |
| 406 | for (int i = 0; i < count - 1; i++) { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 407 | SkScan::AntiHairLine(devPts[i], devPts[i+1], *rec.fRC, blitter); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | |
| 411 | // square procs (strokeWidth > 0 but matrix is square-scale (sx == sy) |
| 412 | |
| 413 | static void bw_square_proc(const PtProcRec& rec, const SkPoint devPts[], |
| 414 | int count, SkBlitter* blitter) { |
| 415 | const SkFixed radius = rec.fRadius; |
| 416 | for (int i = 0; i < count; i++) { |
| 417 | SkFixed x = SkScalarToFixed(devPts[i].fX); |
| 418 | SkFixed y = SkScalarToFixed(devPts[i].fY); |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 419 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 420 | SkXRect r; |
| 421 | r.fLeft = x - radius; |
| 422 | r.fTop = y - radius; |
| 423 | r.fRight = x + radius; |
| 424 | r.fBottom = y + radius; |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 425 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 426 | SkScan::FillXRect(r, *rec.fRC, blitter); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | |
| 430 | static void aa_square_proc(const PtProcRec& rec, const SkPoint devPts[], |
| 431 | int count, SkBlitter* blitter) { |
| 432 | const SkFixed radius = rec.fRadius; |
| 433 | for (int i = 0; i < count; i++) { |
| 434 | SkFixed x = SkScalarToFixed(devPts[i].fX); |
| 435 | SkFixed y = SkScalarToFixed(devPts[i].fY); |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 436 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 437 | SkXRect r; |
| 438 | r.fLeft = x - radius; |
| 439 | r.fTop = y - radius; |
| 440 | r.fRight = x + radius; |
| 441 | r.fBottom = y + radius; |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 442 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 443 | SkScan::AntiFillXRect(r, *rec.fRC, blitter); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | |
reed@android.com | b4f404a | 2009-07-10 17:02:17 +0000 | [diff] [blame] | 447 | // If this guy returns true, then chooseProc() must return a valid proc |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 448 | bool PtProcRec::init(SkCanvas::PointMode mode, const SkPaint& paint, |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 449 | const SkMatrix* matrix, const SkRasterClip* rc) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 450 | if (paint.getPathEffect()) { |
| 451 | return false; |
| 452 | } |
| 453 | SkScalar width = paint.getStrokeWidth(); |
| 454 | if (0 == width) { |
| 455 | fMode = mode; |
| 456 | fPaint = &paint; |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 457 | fClip = NULL; |
| 458 | fRC = rc; |
reed@google.com | 2d47a21 | 2012-11-29 21:01:00 +0000 | [diff] [blame] | 459 | fRadius = SK_FixedHalf; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 460 | return true; |
| 461 | } |
reed@android.com | b4f404a | 2009-07-10 17:02:17 +0000 | [diff] [blame] | 462 | if (paint.getStrokeCap() != SkPaint::kRound_Cap && |
robertphillips | 9f2251c | 2014-11-04 13:33:50 -0800 | [diff] [blame] | 463 | matrix->isScaleTranslate() && SkCanvas::kPoints_PointMode == mode) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 464 | SkScalar sx = matrix->get(SkMatrix::kMScaleX); |
| 465 | SkScalar sy = matrix->get(SkMatrix::kMScaleY); |
| 466 | if (SkScalarNearlyZero(sx - sy)) { |
| 467 | if (sx < 0) { |
| 468 | sx = -sx; |
| 469 | } |
| 470 | |
| 471 | fMode = mode; |
| 472 | fPaint = &paint; |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 473 | fClip = NULL; |
| 474 | fRC = rc; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 475 | fRadius = SkScalarToFixed(SkScalarMul(width, sx)) >> 1; |
| 476 | return true; |
| 477 | } |
| 478 | } |
| 479 | return false; |
| 480 | } |
| 481 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 482 | PtProcRec::Proc PtProcRec::chooseProc(SkBlitter** blitterPtr) { |
reed@android.com | b4f404a | 2009-07-10 17:02:17 +0000 | [diff] [blame] | 483 | Proc proc = NULL; |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 484 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 485 | SkBlitter* blitter = *blitterPtr; |
| 486 | if (fRC->isBW()) { |
| 487 | fClip = &fRC->bwRgn(); |
| 488 | } else { |
| 489 | fWrapper.init(*fRC, blitter); |
| 490 | fClip = &fWrapper.getRgn(); |
| 491 | blitter = fWrapper.getBlitter(); |
| 492 | *blitterPtr = blitter; |
| 493 | } |
| 494 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 495 | // for our arrays |
| 496 | SkASSERT(0 == SkCanvas::kPoints_PointMode); |
| 497 | SkASSERT(1 == SkCanvas::kLines_PointMode); |
| 498 | SkASSERT(2 == SkCanvas::kPolygon_PointMode); |
| 499 | SkASSERT((unsigned)fMode <= (unsigned)SkCanvas::kPolygon_PointMode); |
| 500 | |
reed@google.com | 2d47a21 | 2012-11-29 21:01:00 +0000 | [diff] [blame] | 501 | if (fPaint->isAntiAlias()) { |
| 502 | if (0 == fPaint->getStrokeWidth()) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 503 | static const Proc gAAProcs[] = { |
| 504 | aa_square_proc, aa_line_hair_proc, aa_poly_hair_proc |
| 505 | }; |
| 506 | proc = gAAProcs[fMode]; |
reed@google.com | 2d47a21 | 2012-11-29 21:01:00 +0000 | [diff] [blame] | 507 | } else if (fPaint->getStrokeCap() != SkPaint::kRound_Cap) { |
| 508 | SkASSERT(SkCanvas::kPoints_PointMode == fMode); |
| 509 | proc = aa_square_proc; |
| 510 | } |
| 511 | } else { // BW |
| 512 | if (fRadius <= SK_FixedHalf) { // small radii and hairline |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 513 | if (SkCanvas::kPoints_PointMode == fMode && fClip->isRect()) { |
| 514 | uint32_t value; |
| 515 | const SkBitmap* bm = blitter->justAnOpaqueColor(&value); |
reed@google.com | 900ecf2 | 2014-02-20 20:55:37 +0000 | [diff] [blame] | 516 | if (bm && kRGB_565_SkColorType == bm->colorType()) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 517 | proc = bw_pt_rect_16_hair_proc; |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 518 | } else if (bm && kN32_SkColorType == bm->colorType()) { |
reed@google.com | 2d47a21 | 2012-11-29 21:01:00 +0000 | [diff] [blame] | 519 | proc = bw_pt_rect_32_hair_proc; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 520 | } else { |
| 521 | proc = bw_pt_rect_hair_proc; |
| 522 | } |
| 523 | } else { |
| 524 | static Proc gBWProcs[] = { |
| 525 | bw_pt_hair_proc, bw_line_hair_proc, bw_poly_hair_proc |
| 526 | }; |
| 527 | proc = gBWProcs[fMode]; |
| 528 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 529 | } else { |
| 530 | proc = bw_square_proc; |
| 531 | } |
| 532 | } |
| 533 | return proc; |
| 534 | } |
| 535 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 536 | // each of these costs 8-bytes of stack space, so don't make it too large |
| 537 | // must be even for lines/polygon to work |
| 538 | #define MAX_DEV_PTS 32 |
| 539 | |
| 540 | void SkDraw::drawPoints(SkCanvas::PointMode mode, size_t count, |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 541 | const SkPoint pts[], const SkPaint& paint, |
| 542 | bool forceUseDevice) const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 543 | // if we're in lines mode, force count to be even |
| 544 | if (SkCanvas::kLines_PointMode == mode) { |
| 545 | count &= ~(size_t)1; |
| 546 | } |
| 547 | |
| 548 | if ((long)count <= 0) { |
| 549 | return; |
| 550 | } |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 551 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 552 | SkASSERT(pts != NULL); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 553 | SkDEBUGCODE(this->validate();) |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 554 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 555 | // nothing to draw |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 556 | if (fRC->isEmpty()) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 557 | return; |
| 558 | } |
| 559 | |
| 560 | PtProcRec rec; |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 561 | if (!forceUseDevice && rec.init(mode, paint, fMatrix, fRC)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 562 | SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, paint); |
| 563 | |
| 564 | SkPoint devPts[MAX_DEV_PTS]; |
| 565 | const SkMatrix* matrix = fMatrix; |
| 566 | SkBlitter* bltr = blitter.get(); |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 567 | PtProcRec::Proc proc = rec.chooseProc(&bltr); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 568 | // we have to back up subsequent passes if we're in polygon mode |
| 569 | const size_t backup = (SkCanvas::kPolygon_PointMode == mode); |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 570 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 571 | do { |
commit-bot@chromium.org | a8c7f77 | 2014-01-24 21:46:29 +0000 | [diff] [blame] | 572 | int n = SkToInt(count); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 573 | if (n > MAX_DEV_PTS) { |
| 574 | n = MAX_DEV_PTS; |
| 575 | } |
| 576 | matrix->mapPoints(devPts, pts, n); |
| 577 | proc(rec, devPts, n, bltr); |
| 578 | pts += n - backup; |
commit-bot@chromium.org | a8c7f77 | 2014-01-24 21:46:29 +0000 | [diff] [blame] | 579 | SkASSERT(SkToInt(count) >= n); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 580 | count -= n; |
| 581 | if (count > 0) { |
| 582 | count += backup; |
| 583 | } |
| 584 | } while (count != 0); |
| 585 | } else { |
| 586 | switch (mode) { |
| 587 | case SkCanvas::kPoints_PointMode: { |
| 588 | // temporarily mark the paint as filling. |
reed@google.com | 40c2ba2 | 2011-07-25 19:41:22 +0000 | [diff] [blame] | 589 | SkPaint newPaint(paint); |
| 590 | newPaint.setStyle(SkPaint::kFill_Style); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 591 | |
reed@google.com | 40c2ba2 | 2011-07-25 19:41:22 +0000 | [diff] [blame] | 592 | SkScalar width = newPaint.getStrokeWidth(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 593 | SkScalar radius = SkScalarHalf(width); |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 594 | |
reed@google.com | 40c2ba2 | 2011-07-25 19:41:22 +0000 | [diff] [blame] | 595 | if (newPaint.getStrokeCap() == SkPaint::kRound_Cap) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 596 | SkPath path; |
| 597 | SkMatrix preMatrix; |
mtklein | 7ef849d | 2014-11-24 09:11:45 -0800 | [diff] [blame] | 598 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 599 | path.addCircle(0, 0, radius); |
| 600 | for (size_t i = 0; i < count; i++) { |
| 601 | preMatrix.setTranslate(pts[i].fX, pts[i].fY); |
| 602 | // pass true for the last point, since we can modify |
| 603 | // then path then |
jvanverth | b3eb687 | 2014-10-24 07:12:51 -0700 | [diff] [blame] | 604 | path.setIsVolatile((count-1) == i); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 605 | if (fDevice) { |
reed@google.com | 40c2ba2 | 2011-07-25 19:41:22 +0000 | [diff] [blame] | 606 | fDevice->drawPath(*this, path, newPaint, &preMatrix, |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 607 | (count-1) == i); |
| 608 | } else { |
reed@google.com | 40c2ba2 | 2011-07-25 19:41:22 +0000 | [diff] [blame] | 609 | this->drawPath(path, newPaint, &preMatrix, |
| 610 | (count-1) == i); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 611 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 612 | } |
| 613 | } else { |
| 614 | SkRect r; |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 615 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 616 | for (size_t i = 0; i < count; i++) { |
| 617 | r.fLeft = pts[i].fX - radius; |
| 618 | r.fTop = pts[i].fY - radius; |
| 619 | r.fRight = r.fLeft + width; |
| 620 | r.fBottom = r.fTop + width; |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 621 | if (fDevice) { |
reed@google.com | 40c2ba2 | 2011-07-25 19:41:22 +0000 | [diff] [blame] | 622 | fDevice->drawRect(*this, r, newPaint); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 623 | } else { |
reed@google.com | 40c2ba2 | 2011-07-25 19:41:22 +0000 | [diff] [blame] | 624 | this->drawRect(r, newPaint); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 625 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 626 | } |
| 627 | } |
| 628 | break; |
| 629 | } |
| 630 | case SkCanvas::kLines_PointMode: |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 631 | if (2 == count && paint.getPathEffect()) { |
robertphillips@google.com | 629ab54 | 2012-11-28 17:18:11 +0000 | [diff] [blame] | 632 | // most likely a dashed line - see if it is one of the ones |
| 633 | // we can accelerate |
| 634 | SkStrokeRec rec(paint); |
robertphillips@google.com | 6d87557 | 2012-12-17 18:56:29 +0000 | [diff] [blame] | 635 | SkPathEffect::PointData pointData; |
robertphillips@google.com | 629ab54 | 2012-11-28 17:18:11 +0000 | [diff] [blame] | 636 | |
| 637 | SkPath path; |
| 638 | path.moveTo(pts[0]); |
| 639 | path.lineTo(pts[1]); |
| 640 | |
reed@google.com | 4bbdeac | 2013-01-24 21:03:11 +0000 | [diff] [blame] | 641 | SkRect cullRect = SkRect::Make(fRC->getBounds()); |
skia.committer@gmail.com | 4024f32 | 2013-01-25 07:06:46 +0000 | [diff] [blame] | 642 | |
reed@google.com | 4bbdeac | 2013-01-24 21:03:11 +0000 | [diff] [blame] | 643 | if (paint.getPathEffect()->asPoints(&pointData, path, rec, |
| 644 | *fMatrix, &cullRect)) { |
robertphillips@google.com | 6d87557 | 2012-12-17 18:56:29 +0000 | [diff] [blame] | 645 | // 'asPoints' managed to find some fast path |
| 646 | |
robertphillips@google.com | 629ab54 | 2012-11-28 17:18:11 +0000 | [diff] [blame] | 647 | SkPaint newP(paint); |
| 648 | newP.setPathEffect(NULL); |
robertphillips@google.com | 935ad02 | 2012-12-05 19:07:21 +0000 | [diff] [blame] | 649 | newP.setStyle(SkPaint::kFill_Style); |
robertphillips@google.com | 629ab54 | 2012-11-28 17:18:11 +0000 | [diff] [blame] | 650 | |
robertphillips@google.com | 6d87557 | 2012-12-17 18:56:29 +0000 | [diff] [blame] | 651 | if (!pointData.fFirst.isEmpty()) { |
| 652 | if (fDevice) { |
| 653 | fDevice->drawPath(*this, pointData.fFirst, newP); |
| 654 | } else { |
| 655 | this->drawPath(pointData.fFirst, newP); |
| 656 | } |
robertphillips@google.com | 629ab54 | 2012-11-28 17:18:11 +0000 | [diff] [blame] | 657 | } |
robertphillips@google.com | 6d87557 | 2012-12-17 18:56:29 +0000 | [diff] [blame] | 658 | |
| 659 | if (!pointData.fLast.isEmpty()) { |
| 660 | if (fDevice) { |
| 661 | fDevice->drawPath(*this, pointData.fLast, newP); |
| 662 | } else { |
| 663 | this->drawPath(pointData.fLast, newP); |
| 664 | } |
robertphillips@google.com | 935ad02 | 2012-12-05 19:07:21 +0000 | [diff] [blame] | 665 | } |
robertphillips@google.com | 6d87557 | 2012-12-17 18:56:29 +0000 | [diff] [blame] | 666 | |
| 667 | if (pointData.fSize.fX == pointData.fSize.fY) { |
| 668 | // The rest of the dashed line can just be drawn as points |
| 669 | SkASSERT(pointData.fSize.fX == SkScalarHalf(newP.getStrokeWidth())); |
| 670 | |
| 671 | if (SkPathEffect::PointData::kCircles_PointFlag & pointData.fFlags) { |
| 672 | newP.setStrokeCap(SkPaint::kRound_Cap); |
| 673 | } else { |
| 674 | newP.setStrokeCap(SkPaint::kButt_Cap); |
| 675 | } |
| 676 | |
| 677 | if (fDevice) { |
skia.committer@gmail.com | 7a03d86 | 2012-12-18 02:03:03 +0000 | [diff] [blame] | 678 | fDevice->drawPoints(*this, |
robertphillips@google.com | 6d87557 | 2012-12-17 18:56:29 +0000 | [diff] [blame] | 679 | SkCanvas::kPoints_PointMode, |
| 680 | pointData.fNumPoints, |
| 681 | pointData.fPoints, |
| 682 | newP); |
| 683 | } else { |
| 684 | this->drawPoints(SkCanvas::kPoints_PointMode, |
| 685 | pointData.fNumPoints, |
| 686 | pointData.fPoints, |
| 687 | newP, |
| 688 | forceUseDevice); |
| 689 | } |
| 690 | break; |
| 691 | } else { |
| 692 | // The rest of the dashed line must be drawn as rects |
skia.committer@gmail.com | 7a03d86 | 2012-12-18 02:03:03 +0000 | [diff] [blame] | 693 | SkASSERT(!(SkPathEffect::PointData::kCircles_PointFlag & |
robertphillips@google.com | 6d87557 | 2012-12-17 18:56:29 +0000 | [diff] [blame] | 694 | pointData.fFlags)); |
| 695 | |
| 696 | SkRect r; |
| 697 | |
| 698 | for (int i = 0; i < pointData.fNumPoints; ++i) { |
| 699 | r.set(pointData.fPoints[i].fX - pointData.fSize.fX, |
| 700 | pointData.fPoints[i].fY - pointData.fSize.fY, |
| 701 | pointData.fPoints[i].fX + pointData.fSize.fX, |
| 702 | pointData.fPoints[i].fY + pointData.fSize.fY); |
| 703 | if (fDevice) { |
| 704 | fDevice->drawRect(*this, r, newP); |
| 705 | } else { |
| 706 | this->drawRect(r, newP); |
| 707 | } |
| 708 | } |
| 709 | } |
| 710 | |
robertphillips@google.com | 629ab54 | 2012-11-28 17:18:11 +0000 | [diff] [blame] | 711 | break; |
| 712 | } |
| 713 | } |
robertphillips@google.com | 629ab54 | 2012-11-28 17:18:11 +0000 | [diff] [blame] | 714 | // couldn't take fast path so fall through! |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 715 | case SkCanvas::kPolygon_PointMode: { |
| 716 | count -= 1; |
| 717 | SkPath path; |
| 718 | SkPaint p(paint); |
| 719 | p.setStyle(SkPaint::kStroke_Style); |
| 720 | size_t inc = (SkCanvas::kLines_PointMode == mode) ? 2 : 1; |
jvanverth | b3eb687 | 2014-10-24 07:12:51 -0700 | [diff] [blame] | 721 | path.setIsVolatile(true); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 722 | for (size_t i = 0; i < count; i += inc) { |
| 723 | path.moveTo(pts[i]); |
| 724 | path.lineTo(pts[i+1]); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 725 | if (fDevice) { |
| 726 | fDevice->drawPath(*this, path, p, NULL, true); |
| 727 | } else { |
| 728 | this->drawPath(path, p, NULL, true); |
| 729 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 730 | path.rewind(); |
| 731 | } |
| 732 | break; |
| 733 | } |
| 734 | } |
| 735 | } |
| 736 | } |
| 737 | |
fmalita | 1a178ca | 2015-01-15 06:01:23 -0800 | [diff] [blame] | 738 | static inline SkPoint compute_stroke_size(const SkPaint& paint, const SkMatrix& matrix) { |
| 739 | SkASSERT(matrix.rectStaysRect()); |
| 740 | SkASSERT(SkPaint::kFill_Style != paint.getStyle()); |
| 741 | |
| 742 | SkVector size; |
| 743 | SkPoint pt = { paint.getStrokeWidth(), paint.getStrokeWidth() }; |
| 744 | matrix.mapVectors(&size, &pt, 1); |
| 745 | return SkPoint::Make(SkScalarAbs(size.fX), SkScalarAbs(size.fY)); |
| 746 | } |
| 747 | |
reed@google.com | 761fb62 | 2011-04-04 18:58:05 +0000 | [diff] [blame] | 748 | static bool easy_rect_join(const SkPaint& paint, const SkMatrix& matrix, |
| 749 | SkPoint* strokeSize) { |
| 750 | if (SkPaint::kMiter_Join != paint.getStrokeJoin() || |
| 751 | paint.getStrokeMiter() < SK_ScalarSqrt2) { |
| 752 | return false; |
| 753 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 754 | |
fmalita | 1a178ca | 2015-01-15 06:01:23 -0800 | [diff] [blame] | 755 | *strokeSize = compute_stroke_size(paint, matrix); |
reed@google.com | 761fb62 | 2011-04-04 18:58:05 +0000 | [diff] [blame] | 756 | return true; |
mike@reedtribe.org | 7ff678b | 2011-04-04 14:38:12 +0000 | [diff] [blame] | 757 | } |
| 758 | |
reed@google.com | 62ab7ad | 2011-04-05 14:08:25 +0000 | [diff] [blame] | 759 | SkDraw::RectType SkDraw::ComputeRectType(const SkPaint& paint, |
| 760 | const SkMatrix& matrix, |
| 761 | SkPoint* strokeSize) { |
| 762 | RectType rtype; |
| 763 | const SkScalar width = paint.getStrokeWidth(); |
| 764 | const bool zeroWidth = (0 == width); |
| 765 | SkPaint::Style style = paint.getStyle(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 766 | |
reed@google.com | 62ab7ad | 2011-04-05 14:08:25 +0000 | [diff] [blame] | 767 | if ((SkPaint::kStrokeAndFill_Style == style) && zeroWidth) { |
| 768 | style = SkPaint::kFill_Style; |
| 769 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 770 | |
reed@google.com | 62ab7ad | 2011-04-05 14:08:25 +0000 | [diff] [blame] | 771 | if (paint.getPathEffect() || paint.getMaskFilter() || |
| 772 | paint.getRasterizer() || !matrix.rectStaysRect() || |
| 773 | SkPaint::kStrokeAndFill_Style == style) { |
| 774 | rtype = kPath_RectType; |
| 775 | } else if (SkPaint::kFill_Style == style) { |
| 776 | rtype = kFill_RectType; |
| 777 | } else if (zeroWidth) { |
| 778 | rtype = kHair_RectType; |
| 779 | } else if (easy_rect_join(paint, matrix, strokeSize)) { |
| 780 | rtype = kStroke_RectType; |
| 781 | } else { |
| 782 | rtype = kPath_RectType; |
| 783 | } |
| 784 | return rtype; |
| 785 | } |
mike@reedtribe.org | 7ff678b | 2011-04-04 14:38:12 +0000 | [diff] [blame] | 786 | |
reed@google.com | 7324415 | 2012-05-11 14:35:23 +0000 | [diff] [blame] | 787 | static const SkPoint* rect_points(const SkRect& r) { |
reed@google.com | fc2f0d0 | 2013-03-29 14:23:56 +0000 | [diff] [blame] | 788 | return SkTCast<const SkPoint*>(&r); |
reed@google.com | 7324415 | 2012-05-11 14:35:23 +0000 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | static SkPoint* rect_points(SkRect& r) { |
reed@google.com | fc2f0d0 | 2013-03-29 14:23:56 +0000 | [diff] [blame] | 792 | return SkTCast<SkPoint*>(&r); |
reed@google.com | 40c2ba2 | 2011-07-25 19:41:22 +0000 | [diff] [blame] | 793 | } |
| 794 | |
reed | 0393912 | 2014-12-15 13:42:51 -0800 | [diff] [blame] | 795 | void SkDraw::drawRect(const SkRect& prePaintRect, const SkPaint& paint, |
| 796 | const SkMatrix* paintMatrix, const SkRect* postPaintRect) const { |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 797 | SkDEBUGCODE(this->validate();) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 798 | |
| 799 | // nothing to draw |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 800 | if (fRC->isEmpty()) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 801 | return; |
| 802 | } |
| 803 | |
reed | 0393912 | 2014-12-15 13:42:51 -0800 | [diff] [blame] | 804 | const SkMatrix* matrix; |
| 805 | SkMatrix combinedMatrixStorage; |
| 806 | if (paintMatrix) { |
| 807 | SkASSERT(postPaintRect); |
| 808 | combinedMatrixStorage.setConcat(*fMatrix, *paintMatrix); |
| 809 | matrix = &combinedMatrixStorage; |
| 810 | } else { |
| 811 | SkASSERT(!postPaintRect); |
| 812 | matrix = fMatrix; |
| 813 | } |
| 814 | |
reed@google.com | 761fb62 | 2011-04-04 18:58:05 +0000 | [diff] [blame] | 815 | SkPoint strokeSize; |
reed@google.com | 62ab7ad | 2011-04-05 14:08:25 +0000 | [diff] [blame] | 816 | RectType rtype = ComputeRectType(paint, *fMatrix, &strokeSize); |
mike@reedtribe.org | 7ff678b | 2011-04-04 14:38:12 +0000 | [diff] [blame] | 817 | |
mike@reedtribe.org | 7ff678b | 2011-04-04 14:38:12 +0000 | [diff] [blame] | 818 | if (kPath_RectType == rtype) { |
reed | 0393912 | 2014-12-15 13:42:51 -0800 | [diff] [blame] | 819 | SkDraw draw(*this); |
| 820 | if (paintMatrix) { |
| 821 | draw.fMatrix = matrix; |
| 822 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 823 | SkPath tmp; |
reed | 0393912 | 2014-12-15 13:42:51 -0800 | [diff] [blame] | 824 | tmp.addRect(prePaintRect); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 825 | tmp.setFillType(SkPath::kWinding_FillType); |
reed | 0393912 | 2014-12-15 13:42:51 -0800 | [diff] [blame] | 826 | draw.drawPath(tmp, paint, NULL, true); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 827 | return; |
| 828 | } |
| 829 | |
reed | 0393912 | 2014-12-15 13:42:51 -0800 | [diff] [blame] | 830 | SkRect devRect; |
fmalita | 1a178ca | 2015-01-15 06:01:23 -0800 | [diff] [blame] | 831 | const SkRect& paintRect = paintMatrix ? *postPaintRect : prePaintRect; |
| 832 | // skip the paintMatrix when transforming the rect by the CTM |
| 833 | fMatrix->mapPoints(rect_points(devRect), rect_points(paintRect), 2); |
reed@google.com | 7324415 | 2012-05-11 14:35:23 +0000 | [diff] [blame] | 834 | devRect.sort(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 835 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 836 | // look for the quick exit, before we build a blitter |
fmalita | 1a178ca | 2015-01-15 06:01:23 -0800 | [diff] [blame] | 837 | SkRect bbox = devRect; |
reed@google.com | 1c028bd | 2013-08-28 15:23:19 +0000 | [diff] [blame] | 838 | if (paint.getStyle() != SkPaint::kFill_Style) { |
| 839 | // extra space for hairlines |
george | b3eba47 | 2014-09-09 11:33:57 -0700 | [diff] [blame] | 840 | if (paint.getStrokeWidth() == 0) { |
fmalita | 1a178ca | 2015-01-15 06:01:23 -0800 | [diff] [blame] | 841 | bbox.outset(1, 1); |
george | b3eba47 | 2014-09-09 11:33:57 -0700 | [diff] [blame] | 842 | } else { |
fmalita | 1a178ca | 2015-01-15 06:01:23 -0800 | [diff] [blame] | 843 | // For kStroke_RectType, strokeSize is already computed. |
| 844 | const SkPoint& ssize = (kStroke_RectType == rtype) |
| 845 | ? strokeSize |
| 846 | : compute_stroke_size(paint, *fMatrix); |
| 847 | bbox.outset(SkScalarHalf(ssize.x()), SkScalarHalf(ssize.y())); |
george | b3eba47 | 2014-09-09 11:33:57 -0700 | [diff] [blame] | 848 | } |
reed@google.com | 1c028bd | 2013-08-28 15:23:19 +0000 | [diff] [blame] | 849 | } |
fmalita | 1a178ca | 2015-01-15 06:01:23 -0800 | [diff] [blame] | 850 | |
| 851 | SkIRect ir = bbox.roundOut(); |
reed@google.com | 1c028bd | 2013-08-28 15:23:19 +0000 | [diff] [blame] | 852 | if (fRC->quickReject(ir)) { |
| 853 | return; |
rmistry@google.com | e09d6f4 | 2013-08-27 18:53:41 +0000 | [diff] [blame] | 854 | } |
| 855 | |
reed@google.com | 1c028bd | 2013-08-28 15:23:19 +0000 | [diff] [blame] | 856 | SkDeviceLooper looper(*fBitmap, *fRC, ir, paint.isAntiAlias()); |
| 857 | while (looper.next()) { |
| 858 | SkRect localDevRect; |
| 859 | looper.mapRect(&localDevRect, devRect); |
| 860 | SkMatrix localMatrix; |
reed | 0393912 | 2014-12-15 13:42:51 -0800 | [diff] [blame] | 861 | looper.mapMatrix(&localMatrix, *matrix); |
rmistry@google.com | e09d6f4 | 2013-08-27 18:53:41 +0000 | [diff] [blame] | 862 | |
reed | 0393912 | 2014-12-15 13:42:51 -0800 | [diff] [blame] | 863 | SkAutoBlitterChoose blitterStorage(looper.getBitmap(), localMatrix, paint); |
reed@google.com | 1c028bd | 2013-08-28 15:23:19 +0000 | [diff] [blame] | 864 | const SkRasterClip& clip = looper.getRC(); |
| 865 | SkBlitter* blitter = blitterStorage.get(); |
| 866 | |
| 867 | // we want to "fill" if we are kFill or kStrokeAndFill, since in the latter |
| 868 | // case we are also hairline (if we've gotten to here), which devolves to |
| 869 | // effectively just kFill |
| 870 | switch (rtype) { |
| 871 | case kFill_RectType: |
| 872 | if (paint.isAntiAlias()) { |
| 873 | SkScan::AntiFillRect(localDevRect, clip, blitter); |
| 874 | } else { |
| 875 | SkScan::FillRect(localDevRect, clip, blitter); |
| 876 | } |
| 877 | break; |
| 878 | case kStroke_RectType: |
| 879 | if (paint.isAntiAlias()) { |
| 880 | SkScan::AntiFrameRect(localDevRect, strokeSize, clip, blitter); |
| 881 | } else { |
| 882 | SkScan::FrameRect(localDevRect, strokeSize, clip, blitter); |
| 883 | } |
| 884 | break; |
| 885 | case kHair_RectType: |
| 886 | if (paint.isAntiAlias()) { |
| 887 | SkScan::AntiHairRect(localDevRect, clip, blitter); |
| 888 | } else { |
| 889 | SkScan::HairRect(localDevRect, clip, blitter); |
| 890 | } |
| 891 | break; |
| 892 | default: |
| 893 | SkDEBUGFAIL("bad rtype"); |
| 894 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 895 | } |
| 896 | } |
| 897 | |
| 898 | void SkDraw::drawDevMask(const SkMask& srcM, const SkPaint& paint) const { |
| 899 | if (srcM.fBounds.isEmpty()) { |
| 900 | return; |
| 901 | } |
| 902 | |
bungeman@google.com | 0a60b3d | 2011-09-26 19:09:08 +0000 | [diff] [blame] | 903 | const SkMask* mask = &srcM; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 904 | |
bungeman@google.com | 0a60b3d | 2011-09-26 19:09:08 +0000 | [diff] [blame] | 905 | SkMask dstM; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 906 | if (paint.getMaskFilter() && |
| 907 | paint.getMaskFilter()->filterMask(&dstM, srcM, *fMatrix, NULL)) { |
| 908 | mask = &dstM; |
bungeman@google.com | bf2ac7e | 2011-09-26 19:51:33 +0000 | [diff] [blame] | 909 | } else { |
| 910 | dstM.fImage = NULL; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 911 | } |
bungeman@google.com | 02f5584 | 2011-10-04 21:25:00 +0000 | [diff] [blame] | 912 | SkAutoMaskFreeImage ami(dstM.fImage); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 913 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 914 | SkAutoBlitterChoose blitterChooser(*fBitmap, *fMatrix, paint); |
| 915 | SkBlitter* blitter = blitterChooser.get(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 916 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 917 | SkAAClipBlitterWrapper wrapper; |
| 918 | const SkRegion* clipRgn; |
| 919 | |
| 920 | if (fRC->isBW()) { |
| 921 | clipRgn = &fRC->bwRgn(); |
| 922 | } else { |
| 923 | wrapper.init(*fRC, blitter); |
| 924 | clipRgn = &wrapper.getRgn(); |
| 925 | blitter = wrapper.getBlitter(); |
| 926 | } |
| 927 | blitter->blitMaskRegion(*mask, *clipRgn); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 928 | } |
| 929 | |
reed@android.com | ebdeeb8 | 2009-09-03 21:45:49 +0000 | [diff] [blame] | 930 | static SkScalar fast_len(const SkVector& vec) { |
| 931 | SkScalar x = SkScalarAbs(vec.fX); |
| 932 | SkScalar y = SkScalarAbs(vec.fY); |
| 933 | if (x < y) { |
| 934 | SkTSwap(x, y); |
| 935 | } |
| 936 | return x + SkScalarHalf(y); |
| 937 | } |
| 938 | |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 939 | bool SkDrawTreatAAStrokeAsHairline(SkScalar strokeWidth, const SkMatrix& matrix, |
| 940 | SkScalar* coverage) { |
| 941 | SkASSERT(strokeWidth > 0); |
| 942 | // We need to try to fake a thick-stroke with a modulated hairline. |
reed@google.com | ecadf99 | 2011-09-19 19:18:18 +0000 | [diff] [blame] | 943 | |
tomhudson@google.com | 8d43018 | 2011-06-06 19:11:19 +0000 | [diff] [blame] | 944 | if (matrix.hasPerspective()) { |
reed@android.com | ebdeeb8 | 2009-09-03 21:45:49 +0000 | [diff] [blame] | 945 | return false; |
| 946 | } |
reed@google.com | ecadf99 | 2011-09-19 19:18:18 +0000 | [diff] [blame] | 947 | |
reed@android.com | ebdeeb8 | 2009-09-03 21:45:49 +0000 | [diff] [blame] | 948 | SkVector src[2], dst[2]; |
reed@google.com | ecadf99 | 2011-09-19 19:18:18 +0000 | [diff] [blame] | 949 | src[0].set(strokeWidth, 0); |
| 950 | src[1].set(0, strokeWidth); |
reed@android.com | ebdeeb8 | 2009-09-03 21:45:49 +0000 | [diff] [blame] | 951 | matrix.mapVectors(dst, src, 2); |
| 952 | SkScalar len0 = fast_len(dst[0]); |
| 953 | SkScalar len1 = fast_len(dst[1]); |
agl@chromium.org | 652807b | 2010-04-27 15:47:34 +0000 | [diff] [blame] | 954 | if (len0 <= SK_Scalar1 && len1 <= SK_Scalar1) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 955 | if (coverage) { |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 956 | *coverage = SkScalarAve(len0, len1); |
| 957 | } |
reed@android.com | ebdeeb8 | 2009-09-03 21:45:49 +0000 | [diff] [blame] | 958 | return true; |
| 959 | } |
| 960 | return false; |
| 961 | } |
| 962 | |
scroggo@google.com | a8e33a9 | 2013-11-08 18:02:53 +0000 | [diff] [blame] | 963 | void SkDraw::drawRRect(const SkRRect& rrect, const SkPaint& paint) const { |
| 964 | SkDEBUGCODE(this->validate()); |
| 965 | |
| 966 | if (fRC->isEmpty()) { |
| 967 | return; |
| 968 | } |
| 969 | |
| 970 | { |
| 971 | // TODO: Investigate optimizing these options. They are in the same |
| 972 | // order as SkDraw::drawPath, which handles each case. It may be |
| 973 | // that there is no way to optimize for these using the SkRRect path. |
| 974 | SkScalar coverage; |
| 975 | if (SkDrawTreatAsHairline(paint, *fMatrix, &coverage)) { |
| 976 | goto DRAW_PATH; |
| 977 | } |
| 978 | |
| 979 | if (paint.getPathEffect() || paint.getStyle() != SkPaint::kFill_Style) { |
| 980 | goto DRAW_PATH; |
| 981 | } |
| 982 | |
| 983 | if (paint.getRasterizer()) { |
| 984 | goto DRAW_PATH; |
| 985 | } |
| 986 | } |
| 987 | |
| 988 | if (paint.getMaskFilter()) { |
| 989 | // Transform the rrect into device space. |
| 990 | SkRRect devRRect; |
| 991 | if (rrect.transform(*fMatrix, &devRRect)) { |
| 992 | SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, paint); |
reed | 868074b | 2014-06-03 10:53:59 -0700 | [diff] [blame] | 993 | if (paint.getMaskFilter()->filterRRect(devRRect, *fMatrix, *fRC, blitter.get(), |
scroggo@google.com | a8e33a9 | 2013-11-08 18:02:53 +0000 | [diff] [blame] | 994 | SkPaint::kFill_Style)) { |
| 995 | return; // filterRRect() called the blitter, so we're done |
| 996 | } |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | DRAW_PATH: |
| 1001 | // Now fall back to the default case of using a path. |
| 1002 | SkPath path; |
| 1003 | path.addRRect(rrect); |
| 1004 | this->drawPath(path, paint, NULL, true); |
| 1005 | } |
| 1006 | |
reed | 05d9044 | 2015-02-12 13:35:52 -0800 | [diff] [blame] | 1007 | static SkScalar compute_res_scale_for_stroking(const SkMatrix& matrix) { |
| 1008 | if (!matrix.hasPerspective()) { |
| 1009 | SkScalar sx = SkPoint::Length(matrix[SkMatrix::kMScaleX], matrix[SkMatrix::kMSkewY]); |
| 1010 | SkScalar sy = SkPoint::Length(matrix[SkMatrix::kMSkewX], matrix[SkMatrix::kMScaleY]); |
| 1011 | if (SkScalarsAreFinite(sx, sy)) { |
| 1012 | return SkTMax(sx, sy); |
| 1013 | } |
| 1014 | } |
| 1015 | return 1; |
| 1016 | } |
| 1017 | |
reed@google.com | 32e5d97 | 2011-07-27 18:25:57 +0000 | [diff] [blame] | 1018 | void SkDraw::drawPath(const SkPath& origSrcPath, const SkPaint& origPaint, |
reed@google.com | 126f7f5 | 2013-11-07 16:06:53 +0000 | [diff] [blame] | 1019 | const SkMatrix* prePathMatrix, bool pathIsMutable, |
krajcevski | 53f0959 | 2014-08-06 11:12:14 -0700 | [diff] [blame] | 1020 | bool drawCoverage, SkBlitter* customBlitter) const { |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 1021 | SkDEBUGCODE(this->validate();) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1022 | |
| 1023 | // nothing to draw |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1024 | if (fRC->isEmpty()) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1025 | return; |
| 1026 | } |
| 1027 | |
| 1028 | SkPath* pathPtr = (SkPath*)&origSrcPath; |
| 1029 | bool doFill = true; |
| 1030 | SkPath tmpPath; |
| 1031 | SkMatrix tmpMatrix; |
| 1032 | const SkMatrix* matrix = fMatrix; |
jvanverth | b3eb687 | 2014-10-24 07:12:51 -0700 | [diff] [blame] | 1033 | tmpPath.setIsVolatile(true); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1034 | |
| 1035 | if (prePathMatrix) { |
reed@google.com | 32e5d97 | 2011-07-27 18:25:57 +0000 | [diff] [blame] | 1036 | if (origPaint.getPathEffect() || origPaint.getStyle() != SkPaint::kFill_Style || |
| 1037 | origPaint.getRasterizer()) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1038 | SkPath* result = pathPtr; |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1039 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1040 | if (!pathIsMutable) { |
| 1041 | result = &tmpPath; |
| 1042 | pathIsMutable = true; |
| 1043 | } |
| 1044 | pathPtr->transform(*prePathMatrix, result); |
| 1045 | pathPtr = result; |
| 1046 | } else { |
commit-bot@chromium.org | 9236238 | 2014-03-18 12:51:48 +0000 | [diff] [blame] | 1047 | tmpMatrix.setConcat(*matrix, *prePathMatrix); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1048 | matrix = &tmpMatrix; |
| 1049 | } |
| 1050 | } |
| 1051 | // at this point we're done with prePathMatrix |
| 1052 | SkDEBUGCODE(prePathMatrix = (const SkMatrix*)0x50FF8001;) |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1053 | |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1054 | SkTCopyOnFirstWrite<SkPaint> paint(origPaint); |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1055 | |
reed@google.com | ecadf99 | 2011-09-19 19:18:18 +0000 | [diff] [blame] | 1056 | { |
bsalomon@google.com | dd1be60 | 2012-01-18 20:34:00 +0000 | [diff] [blame] | 1057 | SkScalar coverage; |
| 1058 | if (SkDrawTreatAsHairline(origPaint, *matrix, &coverage)) { |
| 1059 | if (SK_Scalar1 == coverage) { |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1060 | paint.writable()->setStrokeWidth(0); |
egdaniel | dcfb7cf | 2015-01-22 06:52:29 -0800 | [diff] [blame] | 1061 | } else if (SkXfermode::SupportsCoverageAsAlpha(origPaint.getXfermode())) { |
bsalomon@google.com | dd1be60 | 2012-01-18 20:34:00 +0000 | [diff] [blame] | 1062 | U8CPU newAlpha; |
| 1063 | #if 0 |
| 1064 | newAlpha = SkToU8(SkScalarRoundToInt(coverage * |
| 1065 | origPaint.getAlpha())); |
| 1066 | #else |
| 1067 | // this is the old technique, which we preserve for now so |
| 1068 | // we don't change previous results (testing) |
| 1069 | // the new way seems fine, its just (a tiny bit) different |
| 1070 | int scale = (int)SkScalarMul(coverage, 256); |
| 1071 | newAlpha = origPaint.getAlpha() * scale >> 8; |
| 1072 | #endif |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 1073 | SkPaint* writablePaint = paint.writable(); |
| 1074 | writablePaint->setStrokeWidth(0); |
| 1075 | writablePaint->setAlpha(newAlpha); |
bsalomon@google.com | dd1be60 | 2012-01-18 20:34:00 +0000 | [diff] [blame] | 1076 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1077 | } |
| 1078 | } |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1079 | |
reed@google.com | 32e5d97 | 2011-07-27 18:25:57 +0000 | [diff] [blame] | 1080 | if (paint->getPathEffect() || paint->getStyle() != SkPaint::kFill_Style) { |
reed@google.com | 4bbdeac | 2013-01-24 21:03:11 +0000 | [diff] [blame] | 1081 | SkRect cullRect; |
| 1082 | const SkRect* cullRectPtr = NULL; |
| 1083 | if (this->computeConservativeLocalClipBounds(&cullRect)) { |
| 1084 | cullRectPtr = &cullRect; |
| 1085 | } |
reed | 05d9044 | 2015-02-12 13:35:52 -0800 | [diff] [blame] | 1086 | doFill = paint->getFillPath(*pathPtr, &tmpPath, cullRectPtr, |
| 1087 | compute_res_scale_for_stroking(*fMatrix)); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1088 | pathPtr = &tmpPath; |
| 1089 | } |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1090 | |
reed@google.com | 32e5d97 | 2011-07-27 18:25:57 +0000 | [diff] [blame] | 1091 | if (paint->getRasterizer()) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1092 | SkMask mask; |
reed@google.com | 32e5d97 | 2011-07-27 18:25:57 +0000 | [diff] [blame] | 1093 | if (paint->getRasterizer()->rasterize(*pathPtr, *matrix, |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1094 | &fRC->getBounds(), paint->getMaskFilter(), &mask, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1095 | SkMask::kComputeBoundsAndRenderImage_CreateMode)) { |
reed@google.com | 32e5d97 | 2011-07-27 18:25:57 +0000 | [diff] [blame] | 1096 | this->drawDevMask(mask, *paint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1097 | SkMask::FreeImage(mask.fImage); |
| 1098 | } |
| 1099 | return; |
| 1100 | } |
| 1101 | |
| 1102 | // avoid possibly allocating a new path in transform if we can |
| 1103 | SkPath* devPathPtr = pathIsMutable ? pathPtr : &tmpPath; |
| 1104 | |
| 1105 | // transform the path into device space |
| 1106 | pathPtr->transform(*matrix, devPathPtr); |
| 1107 | |
krajcevski | 53f0959 | 2014-08-06 11:12:14 -0700 | [diff] [blame] | 1108 | SkBlitter* blitter = NULL; |
| 1109 | SkAutoBlitterChoose blitterStorage; |
| 1110 | if (NULL == customBlitter) { |
| 1111 | blitterStorage.choose(*fBitmap, *fMatrix, *paint, drawCoverage); |
| 1112 | blitter = blitterStorage.get(); |
| 1113 | } else { |
| 1114 | blitter = customBlitter; |
| 1115 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1116 | |
junov@chromium.org | 2ac4ef5 | 2012-04-04 15:16:51 +0000 | [diff] [blame] | 1117 | if (paint->getMaskFilter()) { |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1118 | SkPaint::Style style = doFill ? SkPaint::kFill_Style : |
junov@chromium.org | 2ac4ef5 | 2012-04-04 15:16:51 +0000 | [diff] [blame] | 1119 | SkPaint::kStroke_Style; |
krajcevski | 53f0959 | 2014-08-06 11:12:14 -0700 | [diff] [blame] | 1120 | if (paint->getMaskFilter()->filterPath(*devPathPtr, *fMatrix, *fRC, blitter, style)) { |
junov@chromium.org | 2ac4ef5 | 2012-04-04 15:16:51 +0000 | [diff] [blame] | 1121 | return; // filterPath() called the blitter, so we're done |
| 1122 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1123 | } |
| 1124 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1125 | void (*proc)(const SkPath&, const SkRasterClip&, SkBlitter*); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1126 | if (doFill) { |
reed@google.com | 32e5d97 | 2011-07-27 18:25:57 +0000 | [diff] [blame] | 1127 | if (paint->isAntiAlias()) { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1128 | proc = SkScan::AntiFillPath; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1129 | } else { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1130 | proc = SkScan::FillPath; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1131 | } |
| 1132 | } else { // hairline |
reed@google.com | 32e5d97 | 2011-07-27 18:25:57 +0000 | [diff] [blame] | 1133 | if (paint->isAntiAlias()) { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1134 | proc = SkScan::AntiHairPath; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1135 | } else { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1136 | proc = SkScan::HairPath; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1137 | } |
| 1138 | } |
krajcevski | 53f0959 | 2014-08-06 11:12:14 -0700 | [diff] [blame] | 1139 | proc(*devPathPtr, *fRC, blitter); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1140 | } |
| 1141 | |
reed@android.com | 0baf193 | 2009-06-24 12:41:42 +0000 | [diff] [blame] | 1142 | /** For the purposes of drawing bitmaps, if a matrix is "almost" translate |
| 1143 | go ahead and treat it as if it were, so that subsequent code can go fast. |
| 1144 | */ |
| 1145 | static bool just_translate(const SkMatrix& matrix, const SkBitmap& bitmap) { |
reed@google.com | 070dcd8 | 2013-01-07 20:27:52 +0000 | [diff] [blame] | 1146 | unsigned bits = 0; // TODO: find a way to allow the caller to tell us to |
| 1147 | // respect filtering. |
| 1148 | return SkTreatAsSprite(matrix, bitmap.width(), bitmap.height(), bits); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | void SkDraw::drawBitmapAsMask(const SkBitmap& bitmap, |
| 1152 | const SkPaint& paint) const { |
reed@google.com | 900ecf2 | 2014-02-20 20:55:37 +0000 | [diff] [blame] | 1153 | SkASSERT(bitmap.colorType() == kAlpha_8_SkColorType); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1154 | |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1155 | if (just_translate(*fMatrix, bitmap)) { |
reed@google.com | e1ca705 | 2013-12-17 19:22:07 +0000 | [diff] [blame] | 1156 | int ix = SkScalarRoundToInt(fMatrix->getTranslateX()); |
| 1157 | int iy = SkScalarRoundToInt(fMatrix->getTranslateY()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1158 | |
reed@google.com | a641f3f | 2012-12-13 22:16:30 +0000 | [diff] [blame] | 1159 | SkAutoLockPixels alp(bitmap); |
| 1160 | if (!bitmap.readyToDraw()) { |
| 1161 | return; |
| 1162 | } |
| 1163 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1164 | SkMask mask; |
| 1165 | mask.fBounds.set(ix, iy, ix + bitmap.width(), iy + bitmap.height()); |
| 1166 | mask.fFormat = SkMask::kA8_Format; |
scroggo@google.com | e5f4824 | 2013-02-25 21:47:41 +0000 | [diff] [blame] | 1167 | mask.fRowBytes = SkToU32(bitmap.rowBytes()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1168 | mask.fImage = bitmap.getAddr8(0, 0); |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1169 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1170 | this->drawDevMask(mask, paint); |
| 1171 | } else { // need to xform the bitmap first |
| 1172 | SkRect r; |
| 1173 | SkMask mask; |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1174 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1175 | r.set(0, 0, |
| 1176 | SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height())); |
| 1177 | fMatrix->mapRect(&r); |
| 1178 | r.round(&mask.fBounds); |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1179 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1180 | // set the mask's bounds to the transformed bitmap-bounds, |
| 1181 | // clipped to the actual device |
| 1182 | { |
| 1183 | SkIRect devBounds; |
| 1184 | devBounds.set(0, 0, fBitmap->width(), fBitmap->height()); |
| 1185 | // need intersect(l, t, r, b) on irect |
| 1186 | if (!mask.fBounds.intersect(devBounds)) { |
| 1187 | return; |
| 1188 | } |
| 1189 | } |
reed@android.com | 543ed93 | 2009-04-24 12:43:40 +0000 | [diff] [blame] | 1190 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1191 | mask.fFormat = SkMask::kA8_Format; |
| 1192 | mask.fRowBytes = SkAlign4(mask.fBounds.width()); |
reed@android.com | 543ed93 | 2009-04-24 12:43:40 +0000 | [diff] [blame] | 1193 | size_t size = mask.computeImageSize(); |
| 1194 | if (0 == size) { |
| 1195 | // the mask is too big to allocated, draw nothing |
| 1196 | return; |
| 1197 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1198 | |
| 1199 | // allocate (and clear) our temp buffer to hold the transformed bitmap |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1200 | SkAutoMalloc storage(size); |
| 1201 | mask.fImage = (uint8_t*)storage.get(); |
| 1202 | memset(mask.fImage, 0, size); |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1203 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1204 | // now draw our bitmap(src) into mask(dst), transformed by the matrix |
| 1205 | { |
| 1206 | SkBitmap device; |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 1207 | device.installPixels(SkImageInfo::MakeA8(mask.fBounds.width(), mask.fBounds.height()), |
| 1208 | mask.fImage, mask.fRowBytes); |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1209 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1210 | SkCanvas c(device); |
| 1211 | // need the unclipped top/left for the translate |
| 1212 | c.translate(-SkIntToScalar(mask.fBounds.fLeft), |
| 1213 | -SkIntToScalar(mask.fBounds.fTop)); |
| 1214 | c.concat(*fMatrix); |
reed@android.com | 3469c76 | 2009-02-24 19:03:20 +0000 | [diff] [blame] | 1215 | |
| 1216 | // We can't call drawBitmap, or we'll infinitely recurse. Instead |
reed@android.com | fb12c3e | 2009-03-05 20:43:42 +0000 | [diff] [blame] | 1217 | // we manually build a shader and draw that into our new mask |
reed@android.com | 3469c76 | 2009-02-24 19:03:20 +0000 | [diff] [blame] | 1218 | SkPaint tmpPaint; |
| 1219 | tmpPaint.setFlags(paint.getFlags()); |
reed@google.com | 40c2ba2 | 2011-07-25 19:41:22 +0000 | [diff] [blame] | 1220 | SkAutoBitmapShaderInstall install(bitmap, tmpPaint); |
reed@android.com | 3469c76 | 2009-02-24 19:03:20 +0000 | [diff] [blame] | 1221 | SkRect rr; |
| 1222 | rr.set(0, 0, SkIntToScalar(bitmap.width()), |
| 1223 | SkIntToScalar(bitmap.height())); |
reed@google.com | 40c2ba2 | 2011-07-25 19:41:22 +0000 | [diff] [blame] | 1224 | c.drawRect(rr, install.paintWithShader()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1225 | } |
| 1226 | this->drawDevMask(mask, paint); |
| 1227 | } |
| 1228 | } |
| 1229 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1230 | static bool clipped_out(const SkMatrix& m, const SkRasterClip& c, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1231 | const SkRect& srcR) { |
| 1232 | SkRect dstR; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1233 | m.mapRect(&dstR, srcR); |
reed | b07a94f | 2014-11-19 05:03:18 -0800 | [diff] [blame] | 1234 | return c.quickReject(dstR.roundOut()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1235 | } |
| 1236 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1237 | static bool clipped_out(const SkMatrix& matrix, const SkRasterClip& clip, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1238 | int width, int height) { |
| 1239 | SkRect r; |
| 1240 | r.set(0, 0, SkIntToScalar(width), SkIntToScalar(height)); |
| 1241 | return clipped_out(matrix, clip, r); |
| 1242 | } |
| 1243 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1244 | static bool clipHandlesSprite(const SkRasterClip& clip, int x, int y, |
| 1245 | const SkBitmap& bitmap) { |
| 1246 | return clip.isBW() || |
| 1247 | clip.quickContains(x, y, x + bitmap.width(), y + bitmap.height()); |
| 1248 | } |
| 1249 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1250 | void SkDraw::drawBitmap(const SkBitmap& bitmap, const SkMatrix& prematrix, |
reed | 0393912 | 2014-12-15 13:42:51 -0800 | [diff] [blame] | 1251 | const SkRect* dstBounds, const SkPaint& origPaint) const { |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 1252 | SkDEBUGCODE(this->validate();) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1253 | |
| 1254 | // nothing to draw |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1255 | if (fRC->isEmpty() || |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1256 | bitmap.width() == 0 || bitmap.height() == 0 || |
reed@google.com | 900ecf2 | 2014-02-20 20:55:37 +0000 | [diff] [blame] | 1257 | bitmap.colorType() == kUnknown_SkColorType) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1258 | return; |
| 1259 | } |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1260 | |
reed@google.com | 40c2ba2 | 2011-07-25 19:41:22 +0000 | [diff] [blame] | 1261 | SkPaint paint(origPaint); |
| 1262 | paint.setStyle(SkPaint::kFill_Style); |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1263 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1264 | SkMatrix matrix; |
commit-bot@chromium.org | 9236238 | 2014-03-18 12:51:48 +0000 | [diff] [blame] | 1265 | matrix.setConcat(*fMatrix, prematrix); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1266 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1267 | if (clipped_out(matrix, *fRC, bitmap.width(), bitmap.height())) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1268 | return; |
| 1269 | } |
| 1270 | |
reed | 868074b | 2014-06-03 10:53:59 -0700 | [diff] [blame] | 1271 | if (bitmap.colorType() != kAlpha_8_SkColorType && just_translate(matrix, bitmap)) { |
reed@google.com | f7ef56d | 2012-12-14 13:46:53 +0000 | [diff] [blame] | 1272 | // |
| 1273 | // It is safe to call lock pixels now, since we know the matrix is |
| 1274 | // (more or less) identity. |
| 1275 | // |
| 1276 | SkAutoLockPixels alp(bitmap); |
| 1277 | if (!bitmap.readyToDraw()) { |
| 1278 | return; |
| 1279 | } |
reed@google.com | e1ca705 | 2013-12-17 19:22:07 +0000 | [diff] [blame] | 1280 | int ix = SkScalarRoundToInt(matrix.getTranslateX()); |
| 1281 | int iy = SkScalarRoundToInt(matrix.getTranslateY()); |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1282 | if (clipHandlesSprite(*fRC, ix, iy, bitmap)) { |
commit-bot@chromium.org | a5572e5 | 2014-03-07 03:24:41 +0000 | [diff] [blame] | 1283 | SkTBlitterAllocator allocator; |
| 1284 | // blitter will be owned by the allocator. |
| 1285 | SkBlitter* blitter = SkBlitter::ChooseSprite(*fBitmap, paint, bitmap, |
| 1286 | ix, iy, &allocator); |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1287 | if (blitter) { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1288 | SkIRect ir; |
| 1289 | ir.set(ix, iy, ix + bitmap.width(), iy + bitmap.height()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1290 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1291 | SkScan::FillIRect(ir, *fRC, blitter); |
| 1292 | return; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1293 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1294 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1295 | } |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1296 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1297 | // now make a temp draw on the stack, and use it |
| 1298 | // |
| 1299 | SkDraw draw(*this); |
| 1300 | draw.fMatrix = &matrix; |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1301 | |
reed@google.com | 900ecf2 | 2014-02-20 20:55:37 +0000 | [diff] [blame] | 1302 | if (bitmap.colorType() == kAlpha_8_SkColorType) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1303 | draw.drawBitmapAsMask(bitmap, paint); |
| 1304 | } else { |
reed@google.com | 40c2ba2 | 2011-07-25 19:41:22 +0000 | [diff] [blame] | 1305 | SkAutoBitmapShaderInstall install(bitmap, paint); |
reed | 0393912 | 2014-12-15 13:42:51 -0800 | [diff] [blame] | 1306 | const SkPaint& paintWithShader = install.paintWithShader(); |
| 1307 | const SkRect srcBounds = SkRect::MakeIWH(bitmap.width(), bitmap.height()); |
| 1308 | if (dstBounds) { |
| 1309 | this->drawRect(srcBounds, paintWithShader, &prematrix, dstBounds); |
| 1310 | } else { |
| 1311 | draw.drawRect(srcBounds, paintWithShader); |
| 1312 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1313 | } |
| 1314 | } |
| 1315 | |
| 1316 | void SkDraw::drawSprite(const SkBitmap& bitmap, int x, int y, |
reed@google.com | 40c2ba2 | 2011-07-25 19:41:22 +0000 | [diff] [blame] | 1317 | const SkPaint& origPaint) const { |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 1318 | SkDEBUGCODE(this->validate();) |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1319 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1320 | // nothing to draw |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1321 | if (fRC->isEmpty() || |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1322 | bitmap.width() == 0 || bitmap.height() == 0 || |
reed@google.com | 900ecf2 | 2014-02-20 20:55:37 +0000 | [diff] [blame] | 1323 | bitmap.colorType() == kUnknown_SkColorType) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1324 | return; |
| 1325 | } |
| 1326 | |
| 1327 | SkIRect bounds; |
| 1328 | bounds.set(x, y, x + bitmap.width(), y + bitmap.height()); |
| 1329 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1330 | if (fRC->quickReject(bounds)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1331 | return; // nothing to draw |
| 1332 | } |
| 1333 | |
reed@google.com | 40c2ba2 | 2011-07-25 19:41:22 +0000 | [diff] [blame] | 1334 | SkPaint paint(origPaint); |
| 1335 | paint.setStyle(SkPaint::kFill_Style); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1336 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1337 | if (NULL == paint.getColorFilter() && clipHandlesSprite(*fRC, x, y, bitmap)) { |
commit-bot@chromium.org | a5572e5 | 2014-03-07 03:24:41 +0000 | [diff] [blame] | 1338 | SkTBlitterAllocator allocator; |
| 1339 | // blitter will be owned by the allocator. |
| 1340 | SkBlitter* blitter = SkBlitter::ChooseSprite(*fBitmap, paint, bitmap, |
| 1341 | x, y, &allocator); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1342 | |
| 1343 | if (blitter) { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1344 | SkScan::FillIRect(bounds, *fRC, blitter); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1345 | return; |
| 1346 | } |
| 1347 | } |
| 1348 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1349 | SkMatrix matrix; |
| 1350 | SkRect r; |
| 1351 | |
| 1352 | // get a scalar version of our rect |
| 1353 | r.set(bounds); |
| 1354 | |
commit-bot@chromium.org | 9c9005a | 2014-04-28 14:55:39 +0000 | [diff] [blame] | 1355 | // create shader with offset |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1356 | matrix.setTranslate(r.fLeft, r.fTop); |
commit-bot@chromium.org | 9c9005a | 2014-04-28 14:55:39 +0000 | [diff] [blame] | 1357 | SkAutoBitmapShaderInstall install(bitmap, paint, &matrix); |
| 1358 | const SkPaint& shaderPaint = install.paintWithShader(); |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1359 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1360 | SkDraw draw(*this); |
| 1361 | matrix.reset(); |
| 1362 | draw.fMatrix = &matrix; |
| 1363 | // call ourself with a rect |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1364 | // is this OK if paint has a rasterizer? |
reed@google.com | 40c2ba2 | 2011-07-25 19:41:22 +0000 | [diff] [blame] | 1365 | draw.drawRect(r, shaderPaint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | /////////////////////////////////////////////////////////////////////////////// |
| 1369 | |
| 1370 | #include "SkScalerContext.h" |
| 1371 | #include "SkGlyphCache.h" |
reed@google.com | e691376 | 2012-08-07 15:19:47 +0000 | [diff] [blame] | 1372 | #include "SkTextToPathIter.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1373 | #include "SkUtils.h" |
| 1374 | |
| 1375 | static void measure_text(SkGlyphCache* cache, SkDrawCacheProc glyphCacheProc, |
| 1376 | const char text[], size_t byteLength, SkVector* stopVector) { |
| 1377 | SkFixed x = 0, y = 0; |
| 1378 | const char* stop = text + byteLength; |
| 1379 | |
| 1380 | SkAutoKern autokern; |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1381 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1382 | while (text < stop) { |
| 1383 | // don't need x, y here, since all subpixel variants will have the |
| 1384 | // same advance |
| 1385 | const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
| 1386 | |
| 1387 | x += autokern.adjust(glyph) + glyph.fAdvanceX; |
| 1388 | y += glyph.fAdvanceY; |
| 1389 | } |
| 1390 | stopVector->set(SkFixedToScalar(x), SkFixedToScalar(y)); |
| 1391 | |
| 1392 | SkASSERT(text == stop); |
| 1393 | } |
| 1394 | |
commit-bot@chromium.org | 8128d8c | 2013-12-19 16:12:25 +0000 | [diff] [blame] | 1395 | bool SkDraw::ShouldDrawTextAsPaths(const SkPaint& paint, const SkMatrix& ctm) { |
| 1396 | // hairline glyphs are fast enough so we don't need to cache them |
| 1397 | if (SkPaint::kStroke_Style == paint.getStyle() && 0 == paint.getStrokeWidth()) { |
| 1398 | return true; |
| 1399 | } |
| 1400 | |
| 1401 | // we don't cache perspective |
| 1402 | if (ctm.hasPerspective()) { |
| 1403 | return true; |
| 1404 | } |
| 1405 | |
| 1406 | SkMatrix textM; |
| 1407 | return SkPaint::TooBigToUseCache(ctm, *paint.setTextMatrix(&textM)); |
| 1408 | } |
| 1409 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1410 | void SkDraw::drawText_asPaths(const char text[], size_t byteLength, |
| 1411 | SkScalar x, SkScalar y, |
| 1412 | const SkPaint& paint) const { |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 1413 | SkDEBUGCODE(this->validate();) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1414 | |
djsollen@google.com | 166e653 | 2012-03-20 14:24:38 +0000 | [diff] [blame] | 1415 | SkTextToPathIter iter(text, byteLength, paint, true); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1416 | |
| 1417 | SkMatrix matrix; |
| 1418 | matrix.setScale(iter.getPathScale(), iter.getPathScale()); |
| 1419 | matrix.postTranslate(x, y); |
| 1420 | |
| 1421 | const SkPath* iterPath; |
| 1422 | SkScalar xpos, prevXPos = 0; |
| 1423 | |
reed@google.com | 7b4531f | 2012-08-07 15:53:00 +0000 | [diff] [blame] | 1424 | while (iter.next(&iterPath, &xpos)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1425 | matrix.postTranslate(xpos - prevXPos, 0); |
reed@google.com | 7b4531f | 2012-08-07 15:53:00 +0000 | [diff] [blame] | 1426 | if (iterPath) { |
| 1427 | const SkPaint& pnt = iter.getPaint(); |
| 1428 | if (fDevice) { |
| 1429 | fDevice->drawPath(*this, *iterPath, pnt, &matrix, false); |
| 1430 | } else { |
| 1431 | this->drawPath(*iterPath, pnt, &matrix, false); |
| 1432 | } |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 1433 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1434 | prevXPos = xpos; |
| 1435 | } |
| 1436 | } |
| 1437 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1438 | // disable warning : local variable used without having been initialized |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1439 | #if defined _WIN32 && _MSC_VER >= 1300 |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1440 | #pragma warning ( push ) |
| 1441 | #pragma warning ( disable : 4701 ) |
| 1442 | #endif |
| 1443 | |
| 1444 | ////////////////////////////////////////////////////////////////////////////// |
| 1445 | |
reed | 868074b | 2014-06-03 10:53:59 -0700 | [diff] [blame] | 1446 | static void D1G_RectClip(const SkDraw1Glyph& state, SkFixed fx, SkFixed fy, const SkGlyph& glyph) { |
mike@reedtribe.org | 9fb0041 | 2014-01-06 03:02:37 +0000 | [diff] [blame] | 1447 | int left = SkFixedFloorToInt(fx); |
| 1448 | int top = SkFixedFloorToInt(fy); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1449 | SkASSERT(glyph.fWidth > 0 && glyph.fHeight > 0); |
tomhudson@google.com | 83a4446 | 2011-10-27 15:27:51 +0000 | [diff] [blame] | 1450 | SkASSERT((NULL == state.fClip && state.fAAClip) || |
| 1451 | (state.fClip && NULL == state.fAAClip && state.fClip->isRect())); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1452 | |
| 1453 | left += glyph.fLeft; |
| 1454 | top += glyph.fTop; |
| 1455 | |
| 1456 | int right = left + glyph.fWidth; |
| 1457 | int bottom = top + glyph.fHeight; |
| 1458 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1459 | SkMask mask; |
| 1460 | SkIRect storage; |
| 1461 | SkIRect* bounds = &mask.fBounds; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1462 | |
tomhudson@google.com | 83a4446 | 2011-10-27 15:27:51 +0000 | [diff] [blame] | 1463 | mask.fBounds.set(left, top, right, bottom); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1464 | |
tomhudson@google.com | 83a4446 | 2011-10-27 15:27:51 +0000 | [diff] [blame] | 1465 | // this extra test is worth it, assuming that most of the time it succeeds |
| 1466 | // since we can avoid writing to storage |
| 1467 | if (!state.fClipBounds.containsNoEmptyCheck(left, top, right, bottom)) { |
| 1468 | if (!storage.intersectNoEmptyCheck(mask.fBounds, state.fClipBounds)) |
| 1469 | return; |
| 1470 | bounds = &storage; |
| 1471 | } |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1472 | |
tomhudson@google.com | 83a4446 | 2011-10-27 15:27:51 +0000 | [diff] [blame] | 1473 | uint8_t* aa = (uint8_t*)glyph.fImage; |
| 1474 | if (NULL == aa) { |
| 1475 | aa = (uint8_t*)state.fCache->findImage(glyph); |
| 1476 | if (NULL == aa) { |
| 1477 | return; // can't rasterize glyph |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1478 | } |
tomhudson@google.com | 83a4446 | 2011-10-27 15:27:51 +0000 | [diff] [blame] | 1479 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1480 | |
tomhudson@google.com | 83a4446 | 2011-10-27 15:27:51 +0000 | [diff] [blame] | 1481 | mask.fRowBytes = glyph.rowBytes(); |
| 1482 | mask.fFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); |
| 1483 | mask.fImage = aa; |
reed@google.com | 5bdfb33 | 2013-05-02 18:55:44 +0000 | [diff] [blame] | 1484 | state.blitMask(mask, *bounds); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1485 | } |
| 1486 | |
reed | 868074b | 2014-06-03 10:53:59 -0700 | [diff] [blame] | 1487 | static void D1G_RgnClip(const SkDraw1Glyph& state, SkFixed fx, SkFixed fy, const SkGlyph& glyph) { |
mike@reedtribe.org | 9fb0041 | 2014-01-06 03:02:37 +0000 | [diff] [blame] | 1488 | int left = SkFixedFloorToInt(fx); |
| 1489 | int top = SkFixedFloorToInt(fy); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1490 | SkASSERT(glyph.fWidth > 0 && glyph.fHeight > 0); |
tomhudson@google.com | 83a4446 | 2011-10-27 15:27:51 +0000 | [diff] [blame] | 1491 | SkASSERT(!state.fClip->isRect()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1492 | |
| 1493 | SkMask mask; |
| 1494 | |
| 1495 | left += glyph.fLeft; |
| 1496 | top += glyph.fTop; |
| 1497 | |
| 1498 | mask.fBounds.set(left, top, left + glyph.fWidth, top + glyph.fHeight); |
tomhudson@google.com | 83a4446 | 2011-10-27 15:27:51 +0000 | [diff] [blame] | 1499 | SkRegion::Cliperator clipper(*state.fClip, mask.fBounds); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1500 | |
tomhudson@google.com | 83a4446 | 2011-10-27 15:27:51 +0000 | [diff] [blame] | 1501 | if (!clipper.done()) { |
| 1502 | const SkIRect& cr = clipper.rect(); |
| 1503 | const uint8_t* aa = (const uint8_t*)glyph.fImage; |
| 1504 | if (NULL == aa) { |
| 1505 | aa = (uint8_t*)state.fCache->findImage(glyph); |
| 1506 | if (NULL == aa) { |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1507 | return; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1508 | } |
tomhudson@google.com | 83a4446 | 2011-10-27 15:27:51 +0000 | [diff] [blame] | 1509 | } |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1510 | |
tomhudson@google.com | 83a4446 | 2011-10-27 15:27:51 +0000 | [diff] [blame] | 1511 | mask.fRowBytes = glyph.rowBytes(); |
| 1512 | mask.fFormat = static_cast<SkMask::Format>(glyph.fMaskFormat); |
| 1513 | mask.fImage = (uint8_t*)aa; |
| 1514 | do { |
reed@google.com | 5bdfb33 | 2013-05-02 18:55:44 +0000 | [diff] [blame] | 1515 | state.blitMask(mask, cr); |
tomhudson@google.com | 83a4446 | 2011-10-27 15:27:51 +0000 | [diff] [blame] | 1516 | clipper.next(); |
| 1517 | } while (!clipper.done()); |
| 1518 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1519 | } |
| 1520 | |
reed@google.com | fd4236e | 2011-07-25 21:16:22 +0000 | [diff] [blame] | 1521 | static bool hasCustomD1GProc(const SkDraw& draw) { |
| 1522 | return draw.fProcs && draw.fProcs->fD1GProc; |
| 1523 | } |
| 1524 | |
| 1525 | static bool needsRasterTextBlit(const SkDraw& draw) { |
| 1526 | return !hasCustomD1GProc(draw); |
| 1527 | } |
| 1528 | |
reed | 868074b | 2014-06-03 10:53:59 -0700 | [diff] [blame] | 1529 | SkDraw1Glyph::Proc SkDraw1Glyph::init(const SkDraw* draw, SkBlitter* blitter, SkGlyphCache* cache, |
| 1530 | const SkPaint& pnt) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1531 | fDraw = draw; |
bungeman@google.com | 2211b62 | 2012-01-13 15:02:58 +0000 | [diff] [blame] | 1532 | fBlitter = blitter; |
| 1533 | fCache = cache; |
reed@google.com | 5bdfb33 | 2013-05-02 18:55:44 +0000 | [diff] [blame] | 1534 | fPaint = &pnt; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1535 | |
bungeman@google.com | 9447103 | 2013-02-25 15:55:13 +0000 | [diff] [blame] | 1536 | if (cache->isSubpixel()) { |
| 1537 | fHalfSampleX = fHalfSampleY = (SK_FixedHalf >> SkGlyph::kSubBits); |
| 1538 | } else { |
| 1539 | fHalfSampleX = fHalfSampleY = SK_FixedHalf; |
| 1540 | } |
| 1541 | |
reed@google.com | 1d6ee0b | 2011-07-05 17:44:56 +0000 | [diff] [blame] | 1542 | if (hasCustomD1GProc(*draw)) { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1543 | // todo: fix this assumption about clips w/ custom |
| 1544 | fClip = draw->fClip; |
| 1545 | fClipBounds = fClip->getBounds(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1546 | return draw->fProcs->fD1GProc; |
| 1547 | } |
| 1548 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1549 | if (draw->fRC->isBW()) { |
| 1550 | fAAClip = NULL; |
| 1551 | fClip = &draw->fRC->bwRgn(); |
| 1552 | fClipBounds = fClip->getBounds(); |
reed | 868074b | 2014-06-03 10:53:59 -0700 | [diff] [blame] | 1553 | if (fClip->isRect()) { |
| 1554 | return D1G_RectClip; |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1555 | } else { |
reed | 868074b | 2014-06-03 10:53:59 -0700 | [diff] [blame] | 1556 | return D1G_RgnClip; |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1557 | } |
| 1558 | } else { // aaclip |
| 1559 | fAAClip = &draw->fRC->aaRgn(); |
| 1560 | fClip = NULL; |
| 1561 | fClipBounds = fAAClip->getBounds(); |
reed | 868074b | 2014-06-03 10:53:59 -0700 | [diff] [blame] | 1562 | return D1G_RectClip; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1563 | } |
| 1564 | } |
| 1565 | |
reed@google.com | 5bdfb33 | 2013-05-02 18:55:44 +0000 | [diff] [blame] | 1566 | void SkDraw1Glyph::blitMaskAsSprite(const SkMask& mask) const { |
| 1567 | SkASSERT(SkMask::kARGB32_Format == mask.fFormat); |
| 1568 | |
| 1569 | SkBitmap bm; |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 1570 | bm.installPixels(SkImageInfo::MakeN32Premul(mask.fBounds.width(), mask.fBounds.height()), |
| 1571 | (SkPMColor*)mask.fImage, mask.fRowBytes); |
reed@google.com | 5bdfb33 | 2013-05-02 18:55:44 +0000 | [diff] [blame] | 1572 | |
| 1573 | fDraw->drawSprite(bm, mask.fBounds.x(), mask.fBounds.y(), *fPaint); |
| 1574 | } |
| 1575 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1576 | /////////////////////////////////////////////////////////////////////////////// |
| 1577 | |
| 1578 | void SkDraw::drawText(const char text[], size_t byteLength, |
| 1579 | SkScalar x, SkScalar y, const SkPaint& paint) const { |
| 1580 | SkASSERT(byteLength == 0 || text != NULL); |
| 1581 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 1582 | SkDEBUGCODE(this->validate();) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1583 | |
| 1584 | // nothing to draw |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1585 | if (text == NULL || byteLength == 0 || fRC->isEmpty()) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1586 | return; |
| 1587 | } |
| 1588 | |
bsalomon@google.com | 36d6eda | 2012-10-10 16:12:14 +0000 | [diff] [blame] | 1589 | // SkScalarRec doesn't currently have a way of representing hairline stroke and |
| 1590 | // will fill if its frame-width is 0. |
reed@google.com | ed43dff | 2013-06-04 16:56:27 +0000 | [diff] [blame] | 1591 | if (ShouldDrawTextAsPaths(paint, *fMatrix)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1592 | this->drawText_asPaths(text, byteLength, x, y, paint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1593 | return; |
| 1594 | } |
| 1595 | |
| 1596 | SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc(); |
| 1597 | |
reed | e010f1c | 2014-09-17 10:49:38 -0700 | [diff] [blame] | 1598 | SkAutoGlyphCache autoCache(paint, &fDevice->getLeakyProperties(), fMatrix); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1599 | SkGlyphCache* cache = autoCache.getCache(); |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1600 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1601 | // transform our starting point |
| 1602 | { |
| 1603 | SkPoint loc; |
bungeman@google.com | 9447103 | 2013-02-25 15:55:13 +0000 | [diff] [blame] | 1604 | fMatrix->mapXY(x, y, &loc); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1605 | x = loc.fX; |
| 1606 | y = loc.fY; |
| 1607 | } |
| 1608 | |
| 1609 | // need to measure first |
| 1610 | if (paint.getTextAlign() != SkPaint::kLeft_Align) { |
| 1611 | SkVector stop; |
| 1612 | |
| 1613 | measure_text(cache, glyphCacheProc, text, byteLength, &stop); |
| 1614 | |
| 1615 | SkScalar stopX = stop.fX; |
| 1616 | SkScalar stopY = stop.fY; |
| 1617 | |
| 1618 | if (paint.getTextAlign() == SkPaint::kCenter_Align) { |
| 1619 | stopX = SkScalarHalf(stopX); |
| 1620 | stopY = SkScalarHalf(stopY); |
| 1621 | } |
| 1622 | x -= stopX; |
| 1623 | y -= stopY; |
| 1624 | } |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1625 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1626 | const char* stop = text + byteLength; |
| 1627 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1628 | SkAAClipBlitter aaBlitter; |
| 1629 | SkAutoBlitterChoose blitterChooser; |
| 1630 | SkBlitter* blitter = NULL; |
reed@google.com | 1d6ee0b | 2011-07-05 17:44:56 +0000 | [diff] [blame] | 1631 | if (needsRasterTextBlit(*this)) { |
bungeman@google.com | 9447103 | 2013-02-25 15:55:13 +0000 | [diff] [blame] | 1632 | blitterChooser.choose(*fBitmap, *fMatrix, paint); |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1633 | blitter = blitterChooser.get(); |
| 1634 | if (fRC->isAA()) { |
| 1635 | aaBlitter.init(blitter, &fRC->aaRgn()); |
| 1636 | blitter = &aaBlitter; |
| 1637 | } |
reed@google.com | 1d6ee0b | 2011-07-05 17:44:56 +0000 | [diff] [blame] | 1638 | } |
| 1639 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1640 | SkAutoKern autokern; |
bungeman@google.com | 52c748b | 2011-08-22 21:30:43 +0000 | [diff] [blame] | 1641 | SkDraw1Glyph d1g; |
reed@google.com | 5bdfb33 | 2013-05-02 18:55:44 +0000 | [diff] [blame] | 1642 | SkDraw1Glyph::Proc proc = d1g.init(this, blitter, cache, paint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1643 | |
bungeman@google.com | 9447103 | 2013-02-25 15:55:13 +0000 | [diff] [blame] | 1644 | SkFixed fxMask = ~0; |
| 1645 | SkFixed fyMask = ~0; |
| 1646 | if (cache->isSubpixel()) { |
| 1647 | SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(*fMatrix); |
| 1648 | if (kX_SkAxisAlignment == baseline) { |
| 1649 | fyMask = 0; |
| 1650 | d1g.fHalfSampleY = SK_FixedHalf; |
| 1651 | } else if (kY_SkAxisAlignment == baseline) { |
| 1652 | fxMask = 0; |
| 1653 | d1g.fHalfSampleX = SK_FixedHalf; |
| 1654 | } |
| 1655 | } |
| 1656 | |
| 1657 | SkFixed fx = SkScalarToFixed(x) + d1g.fHalfSampleX; |
| 1658 | SkFixed fy = SkScalarToFixed(y) + d1g.fHalfSampleY; |
| 1659 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1660 | while (text < stop) { |
bungeman@google.com | 2211b62 | 2012-01-13 15:02:58 +0000 | [diff] [blame] | 1661 | const SkGlyph& glyph = glyphCacheProc(cache, &text, fx & fxMask, fy & fyMask); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1662 | |
| 1663 | fx += autokern.adjust(glyph); |
| 1664 | |
| 1665 | if (glyph.fWidth) { |
bungeman@google.com | 52c748b | 2011-08-22 21:30:43 +0000 | [diff] [blame] | 1666 | proc(d1g, fx, fy, glyph); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1667 | } |
jvanverth@google.com | d830d13 | 2013-11-11 20:54:09 +0000 | [diff] [blame] | 1668 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1669 | fx += glyph.fAdvanceX; |
| 1670 | fy += glyph.fAdvanceY; |
| 1671 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1672 | } |
| 1673 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1674 | ////////////////////////////////////////////////////////////////////////////// |
| 1675 | |
reed@google.com | ed43dff | 2013-06-04 16:56:27 +0000 | [diff] [blame] | 1676 | void SkDraw::drawPosText_asPaths(const char text[], size_t byteLength, |
fmalita | 05c4a43 | 2014-09-29 06:29:53 -0700 | [diff] [blame] | 1677 | const SkScalar pos[], int scalarsPerPosition, |
| 1678 | const SkPoint& offset, const SkPaint& origPaint) const { |
reed@google.com | ed43dff | 2013-06-04 16:56:27 +0000 | [diff] [blame] | 1679 | // setup our std paint, in hopes of getting hits in the cache |
| 1680 | SkPaint paint(origPaint); |
| 1681 | SkScalar matrixScale = paint.setupForAsPaths(); |
| 1682 | |
reed@google.com | 5a64902 | 2013-06-05 18:00:30 +0000 | [diff] [blame] | 1683 | SkMatrix matrix; |
| 1684 | matrix.setScale(matrixScale, matrixScale); |
skia.committer@gmail.com | 8f6ef40 | 2013-06-05 07:01:06 +0000 | [diff] [blame] | 1685 | |
commit-bot@chromium.org | 4e82cdb | 2014-05-23 12:32:23 +0000 | [diff] [blame] | 1686 | // Temporarily jam in kFill, so we only ever ask for the raw outline from the cache. |
| 1687 | paint.setStyle(SkPaint::kFill_Style); |
| 1688 | paint.setPathEffect(NULL); |
| 1689 | |
reed@google.com | ed43dff | 2013-06-04 16:56:27 +0000 | [diff] [blame] | 1690 | SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc(); |
| 1691 | SkAutoGlyphCache autoCache(paint, NULL, NULL); |
| 1692 | SkGlyphCache* cache = autoCache.getCache(); |
| 1693 | |
| 1694 | const char* stop = text + byteLength; |
kkinnunen | cb9a2c8 | 2014-06-12 23:06:28 -0700 | [diff] [blame] | 1695 | SkTextAlignProcScalar alignProc(paint.getTextAlign()); |
fmalita | 05c4a43 | 2014-09-29 06:29:53 -0700 | [diff] [blame] | 1696 | SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition); |
skia.committer@gmail.com | 8f6ef40 | 2013-06-05 07:01:06 +0000 | [diff] [blame] | 1697 | |
commit-bot@chromium.org | 4e82cdb | 2014-05-23 12:32:23 +0000 | [diff] [blame] | 1698 | // Now restore the original settings, so we "draw" with whatever style/stroking. |
| 1699 | paint.setStyle(origPaint.getStyle()); |
| 1700 | paint.setPathEffect(origPaint.getPathEffect()); |
| 1701 | |
reed@google.com | ed43dff | 2013-06-04 16:56:27 +0000 | [diff] [blame] | 1702 | while (text < stop) { |
| 1703 | const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
| 1704 | if (glyph.fWidth) { |
| 1705 | const SkPath* path = cache->findPath(glyph); |
| 1706 | if (path) { |
kkinnunen | cb9a2c8 | 2014-06-12 23:06:28 -0700 | [diff] [blame] | 1707 | SkPoint tmsLoc; |
| 1708 | tmsProc(pos, &tmsLoc); |
bungeman@google.com | cfd90d6 | 2013-12-13 21:26:02 +0000 | [diff] [blame] | 1709 | SkPoint loc; |
kkinnunen | cb9a2c8 | 2014-06-12 23:06:28 -0700 | [diff] [blame] | 1710 | alignProc(tmsLoc, glyph, &loc); |
skia.committer@gmail.com | 8f6ef40 | 2013-06-05 07:01:06 +0000 | [diff] [blame] | 1711 | |
bungeman@google.com | cfd90d6 | 2013-12-13 21:26:02 +0000 | [diff] [blame] | 1712 | matrix[SkMatrix::kMTransX] = loc.fX; |
| 1713 | matrix[SkMatrix::kMTransY] = loc.fY; |
reed@google.com | 5a64902 | 2013-06-05 18:00:30 +0000 | [diff] [blame] | 1714 | if (fDevice) { |
| 1715 | fDevice->drawPath(*this, *path, paint, &matrix, false); |
| 1716 | } else { |
| 1717 | this->drawPath(*path, paint, &matrix, false); |
| 1718 | } |
reed@google.com | ed43dff | 2013-06-04 16:56:27 +0000 | [diff] [blame] | 1719 | } |
| 1720 | } |
| 1721 | pos += scalarsPerPosition; |
| 1722 | } |
| 1723 | } |
| 1724 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1725 | void SkDraw::drawPosText(const char text[], size_t byteLength, |
fmalita | 05c4a43 | 2014-09-29 06:29:53 -0700 | [diff] [blame] | 1726 | const SkScalar pos[], int scalarsPerPosition, |
| 1727 | const SkPoint& offset, const SkPaint& paint) const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1728 | SkASSERT(byteLength == 0 || text != NULL); |
| 1729 | SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
| 1730 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 1731 | SkDEBUGCODE(this->validate();) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1732 | |
| 1733 | // nothing to draw |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1734 | if (text == NULL || byteLength == 0 || fRC->isEmpty()) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1735 | return; |
| 1736 | } |
| 1737 | |
reed@google.com | ed43dff | 2013-06-04 16:56:27 +0000 | [diff] [blame] | 1738 | if (ShouldDrawTextAsPaths(paint, *fMatrix)) { |
fmalita | 05c4a43 | 2014-09-29 06:29:53 -0700 | [diff] [blame] | 1739 | this->drawPosText_asPaths(text, byteLength, pos, scalarsPerPosition, offset, paint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1740 | return; |
| 1741 | } |
| 1742 | |
| 1743 | SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc(); |
reed | e010f1c | 2014-09-17 10:49:38 -0700 | [diff] [blame] | 1744 | SkAutoGlyphCache autoCache(paint, &fDevice->getLeakyProperties(), fMatrix); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1745 | SkGlyphCache* cache = autoCache.getCache(); |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1746 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1747 | SkAAClipBlitterWrapper wrapper; |
| 1748 | SkAutoBlitterChoose blitterChooser; |
| 1749 | SkBlitter* blitter = NULL; |
reed@google.com | 1d6ee0b | 2011-07-05 17:44:56 +0000 | [diff] [blame] | 1750 | if (needsRasterTextBlit(*this)) { |
bungeman@google.com | 9447103 | 2013-02-25 15:55:13 +0000 | [diff] [blame] | 1751 | blitterChooser.choose(*fBitmap, *fMatrix, paint); |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1752 | blitter = blitterChooser.get(); |
| 1753 | if (fRC->isAA()) { |
| 1754 | wrapper.init(*fRC, blitter); |
| 1755 | blitter = wrapper.getBlitter(); |
| 1756 | } |
reed@google.com | 1d6ee0b | 2011-07-05 17:44:56 +0000 | [diff] [blame] | 1757 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1758 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1759 | const char* stop = text + byteLength; |
kkinnunen | cb9a2c8 | 2014-06-12 23:06:28 -0700 | [diff] [blame] | 1760 | SkTextAlignProc alignProc(paint.getTextAlign()); |
bungeman@google.com | 2211b62 | 2012-01-13 15:02:58 +0000 | [diff] [blame] | 1761 | SkDraw1Glyph d1g; |
reed@google.com | 5bdfb33 | 2013-05-02 18:55:44 +0000 | [diff] [blame] | 1762 | SkDraw1Glyph::Proc proc = d1g.init(this, blitter, cache, paint); |
fmalita | 05c4a43 | 2014-09-29 06:29:53 -0700 | [diff] [blame] | 1763 | SkTextMapStateProc tmsProc(*fMatrix, offset, scalarsPerPosition); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1764 | |
bungeman@google.com | 2211b62 | 2012-01-13 15:02:58 +0000 | [diff] [blame] | 1765 | if (cache->isSubpixel()) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1766 | // maybe we should skip the rounding if linearText is set |
bungeman@google.com | 9447103 | 2013-02-25 15:55:13 +0000 | [diff] [blame] | 1767 | SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(*fMatrix); |
| 1768 | |
| 1769 | SkFixed fxMask = ~0; |
| 1770 | SkFixed fyMask = ~0; |
| 1771 | if (kX_SkAxisAlignment == baseline) { |
| 1772 | fyMask = 0; |
bungeman@google.com | 9447103 | 2013-02-25 15:55:13 +0000 | [diff] [blame] | 1773 | d1g.fHalfSampleY = SK_FixedHalf; |
bungeman@google.com | 9447103 | 2013-02-25 15:55:13 +0000 | [diff] [blame] | 1774 | } else if (kY_SkAxisAlignment == baseline) { |
| 1775 | fxMask = 0; |
bungeman@google.com | 9447103 | 2013-02-25 15:55:13 +0000 | [diff] [blame] | 1776 | d1g.fHalfSampleX = SK_FixedHalf; |
bungeman@google.com | 9447103 | 2013-02-25 15:55:13 +0000 | [diff] [blame] | 1777 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1778 | |
| 1779 | if (SkPaint::kLeft_Align == paint.getTextAlign()) { |
| 1780 | while (text < stop) { |
kkinnunen | cb9a2c8 | 2014-06-12 23:06:28 -0700 | [diff] [blame] | 1781 | SkPoint tmsLoc; |
| 1782 | tmsProc(pos, &tmsLoc); |
| 1783 | SkFixed fx = SkScalarToFixed(tmsLoc.fX) + d1g.fHalfSampleX; |
| 1784 | SkFixed fy = SkScalarToFixed(tmsLoc.fY) + d1g.fHalfSampleY; |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1785 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 1786 | const SkGlyph& glyph = glyphCacheProc(cache, &text, |
| 1787 | fx & fxMask, fy & fyMask); |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1788 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1789 | if (glyph.fWidth) { |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 1790 | proc(d1g, fx, fy, glyph); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1791 | } |
| 1792 | pos += scalarsPerPosition; |
| 1793 | } |
| 1794 | } else { |
| 1795 | while (text < stop) { |
bungeman@google.com | 9330cfe | 2012-01-04 14:17:00 +0000 | [diff] [blame] | 1796 | const char* currentText = text; |
bungeman@google.com | 9447103 | 2013-02-25 15:55:13 +0000 | [diff] [blame] | 1797 | const SkGlyph& metricGlyph = glyphCacheProc(cache, &text, 0, 0); |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1798 | |
bungeman@google.com | 9447103 | 2013-02-25 15:55:13 +0000 | [diff] [blame] | 1799 | if (metricGlyph.fWidth) { |
| 1800 | SkDEBUGCODE(SkFixed prevAdvX = metricGlyph.fAdvanceX;) |
| 1801 | SkDEBUGCODE(SkFixed prevAdvY = metricGlyph.fAdvanceY;) |
kkinnunen | cb9a2c8 | 2014-06-12 23:06:28 -0700 | [diff] [blame] | 1802 | SkPoint tmsLoc; |
| 1803 | tmsProc(pos, &tmsLoc); |
bungeman@google.com | 9447103 | 2013-02-25 15:55:13 +0000 | [diff] [blame] | 1804 | SkIPoint fixedLoc; |
kkinnunen | cb9a2c8 | 2014-06-12 23:06:28 -0700 | [diff] [blame] | 1805 | alignProc(tmsLoc, metricGlyph, &fixedLoc); |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1806 | |
bungeman@google.com | 9447103 | 2013-02-25 15:55:13 +0000 | [diff] [blame] | 1807 | SkFixed fx = fixedLoc.fX + d1g.fHalfSampleX; |
| 1808 | SkFixed fy = fixedLoc.fY + d1g.fHalfSampleY; |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1809 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1810 | // have to call again, now that we've been "aligned" |
bungeman@google.com | 9447103 | 2013-02-25 15:55:13 +0000 | [diff] [blame] | 1811 | const SkGlyph& glyph = glyphCacheProc(cache, ¤tText, |
| 1812 | fx & fxMask, fy & fyMask); |
| 1813 | // the assumption is that the metrics haven't changed |
| 1814 | SkASSERT(prevAdvX == glyph.fAdvanceX); |
| 1815 | SkASSERT(prevAdvY == glyph.fAdvanceY); |
| 1816 | SkASSERT(glyph.fWidth); |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1817 | |
bungeman@google.com | 9447103 | 2013-02-25 15:55:13 +0000 | [diff] [blame] | 1818 | proc(d1g, fx, fy, glyph); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1819 | } |
| 1820 | pos += scalarsPerPosition; |
| 1821 | } |
| 1822 | } |
| 1823 | } else { // not subpixel |
reed@google.com | aeb0786 | 2012-04-18 18:32:04 +0000 | [diff] [blame] | 1824 | if (SkPaint::kLeft_Align == paint.getTextAlign()) { |
| 1825 | while (text < stop) { |
| 1826 | // the last 2 parameters are ignored |
| 1827 | const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1828 | |
reed@google.com | aeb0786 | 2012-04-18 18:32:04 +0000 | [diff] [blame] | 1829 | if (glyph.fWidth) { |
kkinnunen | cb9a2c8 | 2014-06-12 23:06:28 -0700 | [diff] [blame] | 1830 | SkPoint tmsLoc; |
| 1831 | tmsProc(pos, &tmsLoc); |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1832 | |
reed@google.com | aeb0786 | 2012-04-18 18:32:04 +0000 | [diff] [blame] | 1833 | proc(d1g, |
kkinnunen | cb9a2c8 | 2014-06-12 23:06:28 -0700 | [diff] [blame] | 1834 | SkScalarToFixed(tmsLoc.fX) + SK_FixedHalf, //d1g.fHalfSampleX, |
| 1835 | SkScalarToFixed(tmsLoc.fY) + SK_FixedHalf, //d1g.fHalfSampleY, |
reed@google.com | aeb0786 | 2012-04-18 18:32:04 +0000 | [diff] [blame] | 1836 | glyph); |
| 1837 | } |
| 1838 | pos += scalarsPerPosition; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1839 | } |
reed@google.com | aeb0786 | 2012-04-18 18:32:04 +0000 | [diff] [blame] | 1840 | } else { |
| 1841 | while (text < stop) { |
| 1842 | // the last 2 parameters are ignored |
| 1843 | const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
| 1844 | |
| 1845 | if (glyph.fWidth) { |
kkinnunen | cb9a2c8 | 2014-06-12 23:06:28 -0700 | [diff] [blame] | 1846 | SkPoint tmsLoc; |
| 1847 | tmsProc(pos, &tmsLoc); |
reed@google.com | aeb0786 | 2012-04-18 18:32:04 +0000 | [diff] [blame] | 1848 | |
| 1849 | SkIPoint fixedLoc; |
kkinnunen | cb9a2c8 | 2014-06-12 23:06:28 -0700 | [diff] [blame] | 1850 | alignProc(tmsLoc, glyph, &fixedLoc); |
reed@google.com | aeb0786 | 2012-04-18 18:32:04 +0000 | [diff] [blame] | 1851 | |
| 1852 | proc(d1g, |
bungeman@google.com | 9447103 | 2013-02-25 15:55:13 +0000 | [diff] [blame] | 1853 | fixedLoc.fX + SK_FixedHalf, //d1g.fHalfSampleX, |
| 1854 | fixedLoc.fY + SK_FixedHalf, //d1g.fHalfSampleY, |
reed@google.com | aeb0786 | 2012-04-18 18:32:04 +0000 | [diff] [blame] | 1855 | glyph); |
| 1856 | } |
| 1857 | pos += scalarsPerPosition; |
| 1858 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1859 | } |
| 1860 | } |
| 1861 | } |
| 1862 | |
| 1863 | #if defined _WIN32 && _MSC_VER >= 1300 |
| 1864 | #pragma warning ( pop ) |
| 1865 | #endif |
| 1866 | |
| 1867 | /////////////////////////////////////////////////////////////////////////////// |
| 1868 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 1869 | typedef void (*HairProc)(const SkPoint&, const SkPoint&, const SkRasterClip&, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1870 | SkBlitter*); |
| 1871 | |
| 1872 | static HairProc ChooseHairProc(bool doAntiAlias) { |
| 1873 | return doAntiAlias ? SkScan::AntiHairLine : SkScan::HairLine; |
| 1874 | } |
| 1875 | |
| 1876 | static bool texture_to_matrix(const VertState& state, const SkPoint verts[], |
| 1877 | const SkPoint texs[], SkMatrix* matrix) { |
| 1878 | SkPoint src[3], dst[3]; |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1879 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1880 | src[0] = texs[state.f0]; |
| 1881 | src[1] = texs[state.f1]; |
| 1882 | src[2] = texs[state.f2]; |
| 1883 | dst[0] = verts[state.f0]; |
| 1884 | dst[1] = verts[state.f1]; |
| 1885 | dst[2] = verts[state.f2]; |
| 1886 | return matrix->setPolyToPoly(src, dst, 3); |
| 1887 | } |
| 1888 | |
| 1889 | class SkTriColorShader : public SkShader { |
| 1890 | public: |
| 1891 | SkTriColorShader() {} |
| 1892 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 1893 | size_t contextSize() const SK_OVERRIDE; |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1894 | |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 1895 | class TriColorShaderContext : public SkShader::Context { |
| 1896 | public: |
commit-bot@chromium.org | e901b6d | 2014-05-01 19:31:31 +0000 | [diff] [blame] | 1897 | TriColorShaderContext(const SkTriColorShader& shader, const ContextRec&); |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 1898 | virtual ~TriColorShaderContext(); |
| 1899 | |
| 1900 | bool setup(const SkPoint pts[], const SkColor colors[], int, int, int); |
| 1901 | |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 1902 | void shadeSpan(int x, int y, SkPMColor dstC[], int count) SK_OVERRIDE; |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 1903 | |
| 1904 | private: |
| 1905 | SkMatrix fDstToUnit; |
| 1906 | SkPMColor fColors[3]; |
| 1907 | |
| 1908 | typedef SkShader::Context INHERITED; |
| 1909 | }; |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1910 | |
commit-bot@chromium.org | 0f10f7b | 2014-03-13 18:02:17 +0000 | [diff] [blame] | 1911 | SK_TO_STRING_OVERRIDE() |
mtklein | 7e44bb1 | 2015-01-07 09:06:08 -0800 | [diff] [blame] | 1912 | |
| 1913 | // For serialization. This will never be called. |
| 1914 | Factory getFactory() const SK_OVERRIDE { sk_throw(); return NULL; } |
djsollen@google.com | ba28d03 | 2012-03-26 17:57:35 +0000 | [diff] [blame] | 1915 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1916 | protected: |
mtklein | 72c9faa | 2015-01-09 10:06:39 -0800 | [diff] [blame] | 1917 | Context* onCreateContext(const ContextRec& rec, void* storage) const SK_OVERRIDE { |
commit-bot@chromium.org | ce56d96 | 2014-05-05 18:39:18 +0000 | [diff] [blame] | 1918 | return SkNEW_PLACEMENT_ARGS(storage, TriColorShaderContext, (*this, rec)); |
| 1919 | } |
| 1920 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1921 | private: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1922 | typedef SkShader INHERITED; |
| 1923 | }; |
| 1924 | |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 1925 | bool SkTriColorShader::TriColorShaderContext::setup(const SkPoint pts[], const SkColor colors[], |
| 1926 | int index0, int index1, int index2) { |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1927 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1928 | fColors[0] = SkPreMultiplyColor(colors[index0]); |
| 1929 | fColors[1] = SkPreMultiplyColor(colors[index1]); |
| 1930 | fColors[2] = SkPreMultiplyColor(colors[index2]); |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1931 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1932 | SkMatrix m, im; |
| 1933 | m.reset(); |
| 1934 | m.set(0, pts[index1].fX - pts[index0].fX); |
| 1935 | m.set(1, pts[index2].fX - pts[index0].fX); |
| 1936 | m.set(2, pts[index0].fX); |
| 1937 | m.set(3, pts[index1].fY - pts[index0].fY); |
| 1938 | m.set(4, pts[index2].fY - pts[index0].fY); |
| 1939 | m.set(5, pts[index0].fY); |
| 1940 | if (!m.invert(&im)) { |
| 1941 | return false; |
| 1942 | } |
commit-bot@chromium.org | 80116dc | 2014-05-06 17:16:03 +0000 | [diff] [blame] | 1943 | // We can't call getTotalInverse(), because we explicitly don't want to look at the localmatrix |
| 1944 | // as our interators are intrinsically tied to the vertices, and nothing else. |
| 1945 | SkMatrix ctmInv; |
| 1946 | if (!this->getCTM().invert(&ctmInv)) { |
| 1947 | return false; |
| 1948 | } |
| 1949 | fDstToUnit.setConcat(im, ctmInv); |
commit-bot@chromium.org | 9236238 | 2014-03-18 12:51:48 +0000 | [diff] [blame] | 1950 | return true; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1951 | } |
| 1952 | |
| 1953 | #include "SkColorPriv.h" |
reed@android.com | 689411a | 2008-12-18 02:52:32 +0000 | [diff] [blame] | 1954 | #include "SkComposeShader.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1955 | |
| 1956 | static int ScalarTo256(SkScalar v) { |
| 1957 | int scale = SkScalarToFixed(v) >> 8; |
| 1958 | if (scale < 0) { |
| 1959 | scale = 0; |
| 1960 | } |
| 1961 | if (scale > 255) { |
| 1962 | scale = 255; |
| 1963 | } |
| 1964 | return SkAlpha255To256(scale); |
| 1965 | } |
| 1966 | |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 1967 | |
commit-bot@chromium.org | e901b6d | 2014-05-01 19:31:31 +0000 | [diff] [blame] | 1968 | SkTriColorShader::TriColorShaderContext::TriColorShaderContext(const SkTriColorShader& shader, |
| 1969 | const ContextRec& rec) |
| 1970 | : INHERITED(shader, rec) {} |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 1971 | |
| 1972 | SkTriColorShader::TriColorShaderContext::~TriColorShaderContext() {} |
| 1973 | |
| 1974 | size_t SkTriColorShader::contextSize() const { |
| 1975 | return sizeof(TriColorShaderContext); |
| 1976 | } |
| 1977 | void SkTriColorShader::TriColorShaderContext::shadeSpan(int x, int y, SkPMColor dstC[], int count) { |
commit-bot@chromium.org | 06a3206 | 2014-05-05 21:35:09 +0000 | [diff] [blame] | 1978 | const int alphaScale = Sk255To256(this->getPaintAlpha()); |
| 1979 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1980 | SkPoint src; |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1981 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1982 | for (int i = 0; i < count; i++) { |
| 1983 | fDstToUnit.mapXY(SkIntToScalar(x), SkIntToScalar(y), &src); |
| 1984 | x += 1; |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1985 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1986 | int scale1 = ScalarTo256(src.fX); |
| 1987 | int scale2 = ScalarTo256(src.fY); |
| 1988 | int scale0 = 256 - scale1 - scale2; |
| 1989 | if (scale0 < 0) { |
| 1990 | if (scale1 > scale2) { |
| 1991 | scale2 = 256 - scale1; |
| 1992 | } else { |
| 1993 | scale1 = 256 - scale2; |
| 1994 | } |
| 1995 | scale0 = 0; |
| 1996 | } |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 1997 | |
commit-bot@chromium.org | 06a3206 | 2014-05-05 21:35:09 +0000 | [diff] [blame] | 1998 | if (256 != alphaScale) { |
| 1999 | scale0 = SkAlphaMul(scale0, alphaScale); |
| 2000 | scale1 = SkAlphaMul(scale1, alphaScale); |
| 2001 | scale2 = SkAlphaMul(scale2, alphaScale); |
| 2002 | } |
| 2003 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2004 | dstC[i] = SkAlphaMulQ(fColors[0], scale0) + |
commit-bot@chromium.org | 06a3206 | 2014-05-05 21:35:09 +0000 | [diff] [blame] | 2005 | SkAlphaMulQ(fColors[1], scale1) + |
| 2006 | SkAlphaMulQ(fColors[2], scale2); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2007 | } |
| 2008 | } |
| 2009 | |
commit-bot@chromium.org | 0f10f7b | 2014-03-13 18:02:17 +0000 | [diff] [blame] | 2010 | #ifndef SK_IGNORE_TO_STRING |
robertphillips@google.com | 76f9e93 | 2013-01-15 20:17:47 +0000 | [diff] [blame] | 2011 | void SkTriColorShader::toString(SkString* str) const { |
| 2012 | str->append("SkTriColorShader: ("); |
| 2013 | |
| 2014 | this->INHERITED::toString(str); |
| 2015 | |
| 2016 | str->append(")"); |
| 2017 | } |
| 2018 | #endif |
| 2019 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2020 | void SkDraw::drawVertices(SkCanvas::VertexMode vmode, int count, |
| 2021 | const SkPoint vertices[], const SkPoint textures[], |
| 2022 | const SkColor colors[], SkXfermode* xmode, |
| 2023 | const uint16_t indices[], int indexCount, |
| 2024 | const SkPaint& paint) const { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 2025 | SkASSERT(0 == count || vertices); |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 2026 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2027 | // abort early if there is nothing to draw |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 2028 | if (count < 3 || (indices && indexCount < 3) || fRC->isEmpty()) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2029 | return; |
| 2030 | } |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 2031 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2032 | // transform out vertices into device coordinates |
| 2033 | SkAutoSTMalloc<16, SkPoint> storage(count); |
| 2034 | SkPoint* devVerts = storage.get(); |
| 2035 | fMatrix->mapPoints(devVerts, vertices, count); |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 2036 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2037 | /* |
| 2038 | We can draw the vertices in 1 of 4 ways: |
| 2039 | |
| 2040 | - solid color (no shader/texture[], no colors[]) |
| 2041 | - just colors (no shader/texture[], has colors[]) |
| 2042 | - just texture (has shader/texture[], no colors[]) |
| 2043 | - colors * texture (has shader/texture[], has colors[]) |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 2044 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2045 | Thus for texture drawing, we need both texture[] and a shader. |
| 2046 | */ |
| 2047 | |
| 2048 | SkTriColorShader triShader; // must be above declaration of p |
| 2049 | SkPaint p(paint); |
| 2050 | |
| 2051 | SkShader* shader = p.getShader(); |
| 2052 | if (NULL == shader) { |
| 2053 | // if we have no shader, we ignore the texture coordinates |
| 2054 | textures = NULL; |
| 2055 | } else if (NULL == textures) { |
| 2056 | // if we don't have texture coordinates, ignore the shader |
| 2057 | p.setShader(NULL); |
| 2058 | shader = NULL; |
| 2059 | } |
| 2060 | |
| 2061 | // setup the custom shader (if needed) |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 2062 | SkAutoTUnref<SkComposeShader> composeShader; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 2063 | if (colors) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2064 | if (NULL == textures) { |
| 2065 | // just colors (no texture) |
reed@google.com | a641f3f | 2012-12-13 22:16:30 +0000 | [diff] [blame] | 2066 | shader = p.setShader(&triShader); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2067 | } else { |
| 2068 | // colors * texture |
| 2069 | SkASSERT(shader); |
| 2070 | bool releaseMode = false; |
| 2071 | if (NULL == xmode) { |
reed@google.com | 8d3cd7a | 2013-01-30 21:36:11 +0000 | [diff] [blame] | 2072 | xmode = SkXfermode::Create(SkXfermode::kModulate_Mode); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2073 | releaseMode = true; |
| 2074 | } |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 2075 | composeShader.reset(SkNEW_ARGS(SkComposeShader, (&triShader, shader, xmode))); |
| 2076 | p.setShader(composeShader); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2077 | if (releaseMode) { |
| 2078 | xmode->unref(); |
| 2079 | } |
| 2080 | } |
| 2081 | } |
| 2082 | |
| 2083 | SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, p); |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 2084 | // Abort early if we failed to create a shader context. |
reed@google.com | ea03360 | 2012-12-14 13:13:55 +0000 | [diff] [blame] | 2085 | if (blitter->isNullBlitter()) { |
| 2086 | return; |
| 2087 | } |
| 2088 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2089 | // setup our state and function pointer for iterating triangles |
| 2090 | VertState state(count, indices, indexCount); |
| 2091 | VertState::Proc vertProc = state.chooseProc(vmode); |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 2092 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 2093 | if (textures || colors) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2094 | while (vertProc(&state)) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 2095 | if (textures) { |
commit-bot@chromium.org | 80116dc | 2014-05-06 17:16:03 +0000 | [diff] [blame] | 2096 | SkMatrix tempM; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2097 | if (texture_to_matrix(state, vertices, textures, &tempM)) { |
commit-bot@chromium.org | 80116dc | 2014-05-06 17:16:03 +0000 | [diff] [blame] | 2098 | SkShader::ContextRec rec(*fBitmap, p, *fMatrix); |
| 2099 | rec.fLocalMatrix = &tempM; |
| 2100 | if (!blitter->resetShaderContext(rec)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2101 | continue; |
| 2102 | } |
| 2103 | } |
| 2104 | } |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 2105 | if (colors) { |
commit-bot@chromium.org | 87fcd95 | 2014-04-23 19:10:51 +0000 | [diff] [blame] | 2106 | // Find the context for triShader. |
| 2107 | SkTriColorShader::TriColorShaderContext* triColorShaderContext; |
| 2108 | |
| 2109 | SkShader::Context* shaderContext = blitter->getShaderContext(); |
| 2110 | SkASSERT(shaderContext); |
| 2111 | if (p.getShader() == &triShader) { |
| 2112 | triColorShaderContext = |
| 2113 | static_cast<SkTriColorShader::TriColorShaderContext*>(shaderContext); |
| 2114 | } else { |
| 2115 | // The shader is a compose shader and triShader is its first shader. |
| 2116 | SkASSERT(p.getShader() == composeShader); |
| 2117 | SkASSERT(composeShader->getShaderA() == &triShader); |
| 2118 | SkComposeShader::ComposeShaderContext* composeShaderContext = |
| 2119 | static_cast<SkComposeShader::ComposeShaderContext*>(shaderContext); |
| 2120 | SkShader::Context* shaderContextA = composeShaderContext->getShaderContextA(); |
| 2121 | triColorShaderContext = |
| 2122 | static_cast<SkTriColorShader::TriColorShaderContext*>(shaderContextA); |
| 2123 | } |
| 2124 | |
| 2125 | if (!triColorShaderContext->setup(vertices, colors, |
| 2126 | state.f0, state.f1, state.f2)) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2127 | continue; |
| 2128 | } |
| 2129 | } |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 2130 | |
| 2131 | SkPoint tmp[] = { |
| 2132 | devVerts[state.f0], devVerts[state.f1], devVerts[state.f2] |
| 2133 | }; |
| 2134 | SkScan::FillTriangle(tmp, *fRC, blitter.get()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2135 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2136 | } else { |
commit-bot@chromium.org | 559a883 | 2014-05-30 10:08:22 +0000 | [diff] [blame] | 2137 | // no colors[] and no texture, stroke hairlines with paint's color. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2138 | HairProc hairProc = ChooseHairProc(paint.isAntiAlias()); |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 2139 | const SkRasterClip& clip = *fRC; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2140 | while (vertProc(&state)) { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 2141 | hairProc(devVerts[state.f0], devVerts[state.f1], clip, blitter.get()); |
| 2142 | hairProc(devVerts[state.f1], devVerts[state.f2], clip, blitter.get()); |
| 2143 | hairProc(devVerts[state.f2], devVerts[state.f0], clip, blitter.get()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2144 | } |
| 2145 | } |
| 2146 | } |
| 2147 | |
reed@google.com | 0a0a236 | 2011-03-23 13:51:55 +0000 | [diff] [blame] | 2148 | /////////////////////////////////////////////////////////////////////////////// |
| 2149 | /////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2150 | |
| 2151 | #ifdef SK_DEBUG |
| 2152 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 2153 | void SkDraw::validate() const { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2154 | SkASSERT(fBitmap != NULL); |
| 2155 | SkASSERT(fMatrix != NULL); |
| 2156 | SkASSERT(fClip != NULL); |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 2157 | SkASSERT(fRC != NULL); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2158 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 2159 | const SkIRect& cr = fRC->getBounds(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2160 | SkIRect br; |
| 2161 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 2162 | br.set(0, 0, fBitmap->width(), fBitmap->height()); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2163 | SkASSERT(cr.isEmpty() || br.contains(cr)); |
| 2164 | } |
| 2165 | |
| 2166 | #endif |
| 2167 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2168 | //////////////////////////////////////////////////////////////////////////////////////////////// |
| 2169 | |
| 2170 | #include "SkPath.h" |
| 2171 | #include "SkDraw.h" |
| 2172 | #include "SkRegion.h" |
| 2173 | #include "SkBlitter.h" |
| 2174 | |
| 2175 | static bool compute_bounds(const SkPath& devPath, const SkIRect* clipBounds, |
reed | b07a94f | 2014-11-19 05:03:18 -0800 | [diff] [blame] | 2176 | const SkMaskFilter* filter, const SkMatrix* filterMatrix, |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2177 | SkIRect* bounds) { |
| 2178 | if (devPath.isEmpty()) { |
| 2179 | return false; |
| 2180 | } |
| 2181 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2182 | // init our bounds from the path |
| 2183 | { |
reed@android.com | d252db0 | 2009-04-01 18:31:44 +0000 | [diff] [blame] | 2184 | SkRect pathBounds = devPath.getBounds(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2185 | pathBounds.inset(-SK_ScalarHalf, -SK_ScalarHalf); |
| 2186 | pathBounds.roundOut(bounds); |
| 2187 | } |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 2188 | |
tomhudson@google.com | 6db75fc | 2012-03-23 14:46:48 +0000 | [diff] [blame] | 2189 | SkIPoint margin = SkIPoint::Make(0, 0); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2190 | if (filter) { |
| 2191 | SkASSERT(filterMatrix); |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 2192 | |
bungeman@google.com | 5af16f8 | 2011-09-02 15:06:44 +0000 | [diff] [blame] | 2193 | SkMask srcM, dstM; |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 2194 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2195 | srcM.fBounds = *bounds; |
| 2196 | srcM.fFormat = SkMask::kA8_Format; |
| 2197 | srcM.fImage = NULL; |
| 2198 | if (!filter->filterMask(&dstM, srcM, *filterMatrix, &margin)) { |
| 2199 | return false; |
| 2200 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2201 | } |
| 2202 | |
bungeman@google.com | 5af16f8 | 2011-09-02 15:06:44 +0000 | [diff] [blame] | 2203 | // (possibly) trim the bounds to reflect the clip |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2204 | // (plus whatever slop the filter needs) |
bungeman@google.com | 5af16f8 | 2011-09-02 15:06:44 +0000 | [diff] [blame] | 2205 | if (clipBounds) { |
| 2206 | SkIRect tmp = *clipBounds; |
reed@android.com | 3555591 | 2009-03-16 18:46:55 +0000 | [diff] [blame] | 2207 | // Ugh. Guard against gigantic margins from wacky filters. Without this |
| 2208 | // check we can request arbitrary amounts of slop beyond our visible |
| 2209 | // clip, and bring down the renderer (at least on finite RAM machines |
| 2210 | // like handsets, etc.). Need to balance this invented value between |
| 2211 | // quality of large filters like blurs, and the corresponding memory |
| 2212 | // requests. |
| 2213 | static const int MAX_MARGIN = 128; |
| 2214 | tmp.inset(-SkMin32(margin.fX, MAX_MARGIN), |
| 2215 | -SkMin32(margin.fY, MAX_MARGIN)); |
bungeman@google.com | 5af16f8 | 2011-09-02 15:06:44 +0000 | [diff] [blame] | 2216 | if (!bounds->intersect(tmp)) { |
| 2217 | return false; |
| 2218 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2219 | } |
| 2220 | |
| 2221 | return true; |
| 2222 | } |
| 2223 | |
junov@chromium.org | 2ac4ef5 | 2012-04-04 15:16:51 +0000 | [diff] [blame] | 2224 | static void draw_into_mask(const SkMask& mask, const SkPath& devPath, |
| 2225 | SkPaint::Style style) { |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 2226 | SkBitmap bm; |
| 2227 | SkDraw draw; |
| 2228 | SkRasterClip clip; |
| 2229 | SkMatrix matrix; |
| 2230 | SkPaint paint; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2231 | |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 2232 | bm.installPixels(SkImageInfo::MakeA8(mask.fBounds.width(), mask.fBounds.height()), |
| 2233 | mask.fImage, mask.fRowBytes); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2234 | |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 2235 | clip.setRect(SkIRect::MakeWH(mask.fBounds.width(), mask.fBounds.height())); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2236 | matrix.setTranslate(-SkIntToScalar(mask.fBounds.fLeft), |
| 2237 | -SkIntToScalar(mask.fBounds.fTop)); |
| 2238 | |
| 2239 | draw.fBitmap = &bm; |
reed@google.com | 045e62d | 2011-10-24 12:19:46 +0000 | [diff] [blame] | 2240 | draw.fRC = &clip; |
| 2241 | draw.fClip = &clip.bwRgn(); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2242 | draw.fMatrix = &matrix; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2243 | paint.setAntiAlias(true); |
junov@chromium.org | 2ac4ef5 | 2012-04-04 15:16:51 +0000 | [diff] [blame] | 2244 | paint.setStyle(style); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2245 | draw.drawPath(devPath, paint); |
| 2246 | } |
| 2247 | |
| 2248 | bool SkDraw::DrawToMask(const SkPath& devPath, const SkIRect* clipBounds, |
reed@google.com | 30711b7 | 2012-12-18 19:18:39 +0000 | [diff] [blame] | 2249 | const SkMaskFilter* filter, const SkMatrix* filterMatrix, |
junov@chromium.org | 2ac4ef5 | 2012-04-04 15:16:51 +0000 | [diff] [blame] | 2250 | SkMask* mask, SkMask::CreateMode mode, |
| 2251 | SkPaint::Style style) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2252 | if (SkMask::kJustRenderImage_CreateMode != mode) { |
| 2253 | if (!compute_bounds(devPath, clipBounds, filter, filterMatrix, &mask->fBounds)) |
| 2254 | return false; |
| 2255 | } |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 2256 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2257 | if (SkMask::kComputeBoundsAndRenderImage_CreateMode == mode) { |
| 2258 | mask->fFormat = SkMask::kA8_Format; |
| 2259 | mask->fRowBytes = mask->fBounds.width(); |
reed@android.com | 543ed93 | 2009-04-24 12:43:40 +0000 | [diff] [blame] | 2260 | size_t size = mask->computeImageSize(); |
| 2261 | if (0 == size) { |
| 2262 | // we're too big to allocate the mask, abort |
| 2263 | return false; |
| 2264 | } |
| 2265 | mask->fImage = SkMask::AllocImage(size); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2266 | memset(mask->fImage, 0, mask->computeImageSize()); |
| 2267 | } |
| 2268 | |
| 2269 | if (SkMask::kJustComputeBounds_CreateMode != mode) { |
junov@chromium.org | 2ac4ef5 | 2012-04-04 15:16:51 +0000 | [diff] [blame] | 2270 | draw_into_mask(*mask, devPath, style); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2271 | } |
reed@google.com | a76de3d | 2011-01-13 18:30:42 +0000 | [diff] [blame] | 2272 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 2273 | return true; |
| 2274 | } |