robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 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 | |
Mike Reed | 986480a | 2017-01-13 22:43:16 +0000 | [diff] [blame] | 8 | #include "SkBitmapDevice.h" |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 9 | #include "SkDraw.h" |
reed | e51c356 | 2016-07-19 14:33:20 -0700 | [diff] [blame] | 10 | #include "SkImageFilter.h" |
senorblanco | 900c367 | 2016-04-27 11:31:23 -0700 | [diff] [blame] | 11 | #include "SkImageFilterCache.h" |
mtklein | cd49541 | 2015-11-05 09:46:23 -0800 | [diff] [blame] | 12 | #include "SkMallocPixelRef.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 13 | #include "SkMatrix.h" |
| 14 | #include "SkPaint.h" |
| 15 | #include "SkPath.h" |
reed | 884e97c | 2015-05-26 11:31:54 -0700 | [diff] [blame] | 16 | #include "SkPixelRef.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 17 | #include "SkPixmap.h" |
reed | e51c356 | 2016-07-19 14:33:20 -0700 | [diff] [blame] | 18 | #include "SkRasterClip.h" |
Mike Reed | 356f7c2 | 2017-01-10 11:58:39 -0500 | [diff] [blame] | 19 | #include "SkRasterHandleAllocator.h" |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 20 | #include "SkShader.h" |
reed | e51c356 | 2016-07-19 14:33:20 -0700 | [diff] [blame] | 21 | #include "SkSpecialImage.h" |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 22 | #include "SkSurface.h" |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 23 | #include "SkVertices.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 24 | |
| 25 | class SkColorTable; |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 26 | |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 27 | static bool valid_for_bitmap_device(const SkImageInfo& info, |
| 28 | SkAlphaType* newAlphaType) { |
| 29 | if (info.width() < 0 || info.height() < 0) { |
| 30 | return false; |
| 31 | } |
| 32 | |
| 33 | // TODO: can we stop supporting kUnknown in SkBitmkapDevice? |
| 34 | if (kUnknown_SkColorType == info.colorType()) { |
| 35 | if (newAlphaType) { |
reed | 4497748 | 2015-02-27 10:23:00 -0800 | [diff] [blame] | 36 | *newAlphaType = kUnknown_SkAlphaType; |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 37 | } |
| 38 | return true; |
| 39 | } |
skia.committer@gmail.com | 969588f | 2014-02-16 03:01:56 +0000 | [diff] [blame] | 40 | |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 41 | switch (info.alphaType()) { |
| 42 | case kPremul_SkAlphaType: |
| 43 | case kOpaque_SkAlphaType: |
| 44 | break; |
| 45 | default: |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | SkAlphaType canonicalAlphaType = info.alphaType(); |
| 50 | |
| 51 | switch (info.colorType()) { |
| 52 | case kAlpha_8_SkColorType: |
| 53 | break; |
| 54 | case kRGB_565_SkColorType: |
| 55 | canonicalAlphaType = kOpaque_SkAlphaType; |
| 56 | break; |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 57 | case kN32_SkColorType: |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 58 | break; |
reed | a34be68 | 2016-02-15 07:48:35 -0800 | [diff] [blame] | 59 | case kRGBA_F16_SkColorType: |
| 60 | break; |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 61 | default: |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | if (newAlphaType) { |
| 66 | *newAlphaType = canonicalAlphaType; |
| 67 | } |
| 68 | return true; |
| 69 | } |
| 70 | |
robertphillips | 9a53fd7 | 2015-06-22 09:46:59 -0700 | [diff] [blame] | 71 | SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap) |
reed | 589a39e | 2016-08-20 07:59:19 -0700 | [diff] [blame] | 72 | : INHERITED(bitmap.info(), SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)) |
reed | 2c9e200 | 2016-07-25 08:05:22 -0700 | [diff] [blame] | 73 | , fBitmap(bitmap) |
Mike Reed | c42a1cd | 2017-02-14 14:25:14 -0500 | [diff] [blame] | 74 | , fRCStack(bitmap.width(), bitmap.height()) |
reed | 2c9e200 | 2016-07-25 08:05:22 -0700 | [diff] [blame] | 75 | { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 76 | SkASSERT(valid_for_bitmap_device(bitmap.info(), nullptr)); |
reed | 2c9e200 | 2016-07-25 08:05:22 -0700 | [diff] [blame] | 77 | fBitmap.lockPixels(); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 78 | } |
| 79 | |
robertphillips | 9a53fd7 | 2015-06-22 09:46:59 -0700 | [diff] [blame] | 80 | SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& info) { |
| 81 | return Create(info, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)); |
| 82 | } |
| 83 | |
Mike Reed | 356f7c2 | 2017-01-10 11:58:39 -0500 | [diff] [blame] | 84 | SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkSurfaceProps& surfaceProps, |
| 85 | SkRasterHandleAllocator::Handle hndl) |
reed | 589a39e | 2016-08-20 07:59:19 -0700 | [diff] [blame] | 86 | : INHERITED(bitmap.info(), surfaceProps) |
reed | 2c9e200 | 2016-07-25 08:05:22 -0700 | [diff] [blame] | 87 | , fBitmap(bitmap) |
Mike Reed | 356f7c2 | 2017-01-10 11:58:39 -0500 | [diff] [blame] | 88 | , fRasterHandle(hndl) |
Mike Reed | c42a1cd | 2017-02-14 14:25:14 -0500 | [diff] [blame] | 89 | , fRCStack(bitmap.width(), bitmap.height()) |
reed | 2c9e200 | 2016-07-25 08:05:22 -0700 | [diff] [blame] | 90 | { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 91 | SkASSERT(valid_for_bitmap_device(bitmap.info(), nullptr)); |
reed | 2c9e200 | 2016-07-25 08:05:22 -0700 | [diff] [blame] | 92 | fBitmap.lockPixels(); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 93 | } |
| 94 | |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 95 | SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo, |
Mike Reed | 356f7c2 | 2017-01-10 11:58:39 -0500 | [diff] [blame] | 96 | const SkSurfaceProps& surfaceProps, |
| 97 | SkRasterHandleAllocator* allocator) { |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 98 | SkAlphaType newAT = origInfo.alphaType(); |
| 99 | if (!valid_for_bitmap_device(origInfo, &newAT)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 100 | return nullptr; |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 101 | } |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 102 | |
Mike Reed | 356f7c2 | 2017-01-10 11:58:39 -0500 | [diff] [blame] | 103 | SkRasterHandleAllocator::Handle hndl = nullptr; |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 104 | const SkImageInfo info = origInfo.makeAlphaType(newAT); |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 105 | SkBitmap bitmap; |
| 106 | |
| 107 | if (kUnknown_SkColorType == info.colorType()) { |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 108 | if (!bitmap.setInfo(info)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 109 | return nullptr; |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 110 | } |
Mike Reed | 356f7c2 | 2017-01-10 11:58:39 -0500 | [diff] [blame] | 111 | } else if (allocator) { |
| 112 | hndl = allocator->allocBitmap(info, &bitmap); |
| 113 | if (!hndl) { |
| 114 | return nullptr; |
| 115 | } |
lsalzman | 04d975a | 2016-01-08 11:20:14 -0800 | [diff] [blame] | 116 | } else if (info.isOpaque()) { |
mtklein | cd49541 | 2015-11-05 09:46:23 -0800 | [diff] [blame] | 117 | // If this bitmap is opaque, we don't have any sensible default color, |
| 118 | // so we just return uninitialized pixels. |
reed | 8482504 | 2014-09-02 12:50:45 -0700 | [diff] [blame] | 119 | if (!bitmap.tryAllocPixels(info)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 120 | return nullptr; |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 121 | } |
mtklein | cd49541 | 2015-11-05 09:46:23 -0800 | [diff] [blame] | 122 | } else { |
| 123 | // This bitmap has transparency, so we'll zero the pixels (to transparent). |
Mike Reed | 6b3155c | 2017-04-03 14:41:44 -0400 | [diff] [blame] | 124 | // We use the flag as a faster alloc-then-eraseColor(SK_ColorTRANSPARENT). |
| 125 | if (!bitmap.tryAllocPixels(info, nullptr/*colortable*/, SkBitmap::kZeroPixels_AllocFlag)) { |
mtklein | cd49541 | 2015-11-05 09:46:23 -0800 | [diff] [blame] | 126 | return nullptr; |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | |
Mike Reed | 356f7c2 | 2017-01-10 11:58:39 -0500 | [diff] [blame] | 130 | return new SkBitmapDevice(bitmap, surfaceProps, hndl); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { |
| 134 | SkASSERT(bm.width() == fBitmap.width()); |
| 135 | SkASSERT(bm.height() == fBitmap.height()); |
| 136 | fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config) |
| 137 | fBitmap.lockPixels(); |
reed | 589a39e | 2016-08-20 07:59:19 -0700 | [diff] [blame] | 138 | this->privateResize(fBitmap.info().width(), fBitmap.info().height()); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 139 | } |
| 140 | |
reed | 76033be | 2015-03-14 10:54:31 -0700 | [diff] [blame] | 141 | SkBaseDevice* SkBitmapDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint*) { |
robertphillips | 9a53fd7 | 2015-06-22 09:46:59 -0700 | [diff] [blame] | 142 | const SkSurfaceProps surfaceProps(this->surfaceProps().flags(), cinfo.fPixelGeometry); |
Mike Reed | 356f7c2 | 2017-01-10 11:58:39 -0500 | [diff] [blame] | 143 | return SkBitmapDevice::Create(cinfo.fInfo, surfaceProps, cinfo.fAllocator); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 144 | } |
| 145 | |
reed | 884e97c | 2015-05-26 11:31:54 -0700 | [diff] [blame] | 146 | bool SkBitmapDevice::onAccessPixels(SkPixmap* pmap) { |
reed | b560b5c | 2016-07-24 12:30:34 -0700 | [diff] [blame] | 147 | if (this->onPeekPixels(pmap)) { |
reed | 6e76485 | 2015-06-05 14:11:32 -0700 | [diff] [blame] | 148 | fBitmap.notifyPixelsChanged(); |
| 149 | return true; |
| 150 | } |
| 151 | return false; |
reed | 9572a10 | 2015-05-26 19:22:17 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | bool SkBitmapDevice::onPeekPixels(SkPixmap* pmap) { |
reed | 884e97c | 2015-05-26 11:31:54 -0700 | [diff] [blame] | 155 | const SkImageInfo info = fBitmap.info(); |
| 156 | if (fBitmap.getPixels() && (kUnknown_SkColorType != info.colorType())) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 157 | SkColorTable* ctable = nullptr; |
reed | 884e97c | 2015-05-26 11:31:54 -0700 | [diff] [blame] | 158 | pmap->reset(fBitmap.info(), fBitmap.getPixels(), fBitmap.rowBytes(), ctable); |
| 159 | return true; |
reed@google.com | 9c135db | 2014-03-12 18:28:35 +0000 | [diff] [blame] | 160 | } |
reed | 884e97c | 2015-05-26 11:31:54 -0700 | [diff] [blame] | 161 | return false; |
reed@google.com | 9c135db | 2014-03-12 18:28:35 +0000 | [diff] [blame] | 162 | } |
| 163 | |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 164 | bool SkBitmapDevice::onWritePixels(const SkImageInfo& srcInfo, const void* srcPixels, |
| 165 | size_t srcRowBytes, int x, int y) { |
reed@google.com | 0d30c51 | 2014-03-14 14:02:58 +0000 | [diff] [blame] | 166 | // since we don't stop creating un-pixeled devices yet, check for no pixels here |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 167 | if (nullptr == fBitmap.getPixels()) { |
reed@google.com | 0d30c51 | 2014-03-14 14:02:58 +0000 | [diff] [blame] | 168 | return false; |
| 169 | } |
| 170 | |
Mike Reed | 68dd8d0 | 2017-01-04 16:34:31 -0500 | [diff] [blame] | 171 | if (fBitmap.writePixels(SkPixmap(srcInfo, srcPixels, srcRowBytes), x, y)) { |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 172 | fBitmap.notifyPixelsChanged(); |
| 173 | return true; |
| 174 | } |
| 175 | return false; |
| 176 | } |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 177 | |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 178 | bool SkBitmapDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, |
| 179 | int x, int y) { |
reed | b184f7f | 2014-07-13 04:32:32 -0700 | [diff] [blame] | 180 | return fBitmap.readPixels(dstInfo, dstPixels, dstRowBytes, x, y); |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 181 | } |
| 182 | |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 183 | /////////////////////////////////////////////////////////////////////////////// |
| 184 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 185 | class SkBitmapDevice::BDDraw : public SkDraw { |
Mike Reed | c42a1cd | 2017-02-14 14:25:14 -0500 | [diff] [blame] | 186 | public: |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 187 | BDDraw(SkBitmapDevice* dev) { |
| 188 | // we need fDst to be set, and if we're actually drawing, to dirty the genID |
| 189 | if (!dev->accessPixels(&fDst)) { |
| 190 | // NoDrawDevice uses us (why?) so we have to catch this case w/ no pixels |
| 191 | fDst.reset(dev->imageInfo(), nullptr, 0); |
| 192 | } |
| 193 | fMatrix = &dev->ctm(); |
| 194 | fRC = &dev->fRCStack.rc(); |
Mike Reed | c42a1cd | 2017-02-14 14:25:14 -0500 | [diff] [blame] | 195 | } |
| 196 | }; |
Mike Reed | c42a1cd | 2017-02-14 14:25:14 -0500 | [diff] [blame] | 197 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 198 | void SkBitmapDevice::drawPaint(const SkPaint& paint) { |
| 199 | BDDraw(this).drawPaint(paint); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 202 | void SkBitmapDevice::drawPoints(SkCanvas::PointMode mode, size_t count, |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 203 | const SkPoint pts[], const SkPaint& paint) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 204 | BDDraw(this).drawPoints(mode, count, pts, paint, nullptr); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 205 | } |
| 206 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 207 | void SkBitmapDevice::drawRect(const SkRect& r, const SkPaint& paint) { |
| 208 | BDDraw(this).drawRect(r, paint); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 211 | void SkBitmapDevice::drawOval(const SkRect& oval, const SkPaint& paint) { |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 212 | SkPath path; |
| 213 | path.addOval(oval); |
| 214 | // call the VIRTUAL version, so any subclasses who do handle drawPath aren't |
| 215 | // required to override drawOval. |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 216 | this->drawPath(path, paint, nullptr, true); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 217 | } |
| 218 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 219 | void SkBitmapDevice::drawRRect(const SkRRect& rrect, const SkPaint& paint) { |
robertphillips@google.com | 50a7600 | 2013-11-12 01:16:56 +0000 | [diff] [blame] | 220 | #ifdef SK_IGNORE_BLURRED_RRECT_OPT |
| 221 | SkPath path; |
| 222 | |
| 223 | path.addRRect(rrect); |
| 224 | // call the VIRTUAL version, so any subclasses who do handle drawPath aren't |
| 225 | // required to override drawRRect. |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 226 | this->drawPath(path, paint, nullptr, true); |
robertphillips@google.com | 50a7600 | 2013-11-12 01:16:56 +0000 | [diff] [blame] | 227 | #else |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 228 | BDDraw(this).drawRRect(rrect, paint); |
robertphillips@google.com | 50a7600 | 2013-11-12 01:16:56 +0000 | [diff] [blame] | 229 | #endif |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 230 | } |
| 231 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 232 | void SkBitmapDevice::drawPath(const SkPath& path, |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 233 | const SkPaint& paint, const SkMatrix* prePathMatrix, |
| 234 | bool pathIsMutable) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 235 | BDDraw(this).drawPath(path, paint, prePathMatrix, pathIsMutable); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 236 | } |
| 237 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 238 | void SkBitmapDevice::drawBitmap(const SkBitmap& bitmap, |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 239 | const SkMatrix& matrix, const SkPaint& paint) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 240 | LogDrawScaleFactor(SkMatrix::Concat(this->ctm(), matrix), paint.getFilterQuality()); |
| 241 | BDDraw(this).drawBitmap(bitmap, matrix, nullptr, paint); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 242 | } |
| 243 | |
fmalita | ab83da7 | 2016-08-26 13:04:14 -0700 | [diff] [blame] | 244 | static inline bool CanApplyDstMatrixAsCTM(const SkMatrix& m, const SkPaint& paint) { |
| 245 | if (!paint.getMaskFilter()) { |
| 246 | return true; |
| 247 | } |
| 248 | |
| 249 | // Some mask filters parameters (sigma) depend on the CTM/scale. |
| 250 | return m.getType() <= SkMatrix::kTranslate_Mask; |
| 251 | } |
| 252 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 253 | void SkBitmapDevice::drawBitmapRect(const SkBitmap& bitmap, |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 254 | const SkRect* src, const SkRect& dst, |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 255 | const SkPaint& paint, SkCanvas::SrcRectConstraint constraint) { |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 256 | SkMatrix matrix; |
| 257 | SkRect bitmapBounds, tmpSrc, tmpDst; |
| 258 | SkBitmap tmpBitmap; |
| 259 | |
| 260 | bitmapBounds.isetWH(bitmap.width(), bitmap.height()); |
| 261 | |
| 262 | // Compute matrix from the two rectangles |
| 263 | if (src) { |
| 264 | tmpSrc = *src; |
| 265 | } else { |
| 266 | tmpSrc = bitmapBounds; |
| 267 | } |
| 268 | matrix.setRectToRect(tmpSrc, dst, SkMatrix::kFill_ScaleToFit); |
| 269 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 270 | LogDrawScaleFactor(SkMatrix::Concat(this->ctm(), matrix), paint.getFilterQuality()); |
ericrk | 983294f | 2016-04-18 09:14:00 -0700 | [diff] [blame] | 271 | |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 272 | const SkRect* dstPtr = &dst; |
| 273 | const SkBitmap* bitmapPtr = &bitmap; |
| 274 | |
| 275 | // clip the tmpSrc to the bounds of the bitmap, and recompute dstRect if |
| 276 | // needed (if the src was clipped). No check needed if src==null. |
| 277 | if (src) { |
| 278 | if (!bitmapBounds.contains(*src)) { |
| 279 | if (!tmpSrc.intersect(bitmapBounds)) { |
| 280 | return; // nothing to draw |
| 281 | } |
| 282 | // recompute dst, based on the smaller tmpSrc |
| 283 | matrix.mapRect(&tmpDst, tmpSrc); |
| 284 | dstPtr = &tmpDst; |
| 285 | } |
reed | 27efa23 | 2016-07-25 19:10:10 -0700 | [diff] [blame] | 286 | } |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 287 | |
reed | 27efa23 | 2016-07-25 19:10:10 -0700 | [diff] [blame] | 288 | if (src && !src->contains(bitmapBounds) && |
| 289 | SkCanvas::kFast_SrcRectConstraint == constraint && |
| 290 | paint.getFilterQuality() != kNone_SkFilterQuality) { |
| 291 | // src is smaller than the bounds of the bitmap, and we are filtering, so we don't know |
| 292 | // how much more of the bitmap we need, so we can't use extractSubset or drawBitmap, |
| 293 | // but we must use a shader w/ dst bounds (which can access all of the bitmap needed). |
| 294 | goto USE_SHADER; |
| 295 | } |
| 296 | |
| 297 | if (src) { |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 298 | // since we may need to clamp to the borders of the src rect within |
| 299 | // the bitmap, we extract a subset. |
reed | b07a94f | 2014-11-19 05:03:18 -0800 | [diff] [blame] | 300 | const SkIRect srcIR = tmpSrc.roundOut(); |
bsalomon | 19fe41e | 2016-08-23 14:02:54 -0700 | [diff] [blame] | 301 | if (!bitmap.extractSubset(&tmpBitmap, srcIR)) { |
| 302 | return; |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 303 | } |
| 304 | bitmapPtr = &tmpBitmap; |
| 305 | |
| 306 | // Since we did an extract, we need to adjust the matrix accordingly |
| 307 | SkScalar dx = 0, dy = 0; |
| 308 | if (srcIR.fLeft > 0) { |
| 309 | dx = SkIntToScalar(srcIR.fLeft); |
| 310 | } |
| 311 | if (srcIR.fTop > 0) { |
| 312 | dy = SkIntToScalar(srcIR.fTop); |
| 313 | } |
| 314 | if (dx || dy) { |
| 315 | matrix.preTranslate(dx, dy); |
| 316 | } |
| 317 | |
lsalzman | c0e52f4 | 2017-04-05 21:42:54 -0700 | [diff] [blame^] | 318 | #ifdef SK_DRAWBITMAPRECT_FAST_OFFSET |
| 319 | SkRect extractedBitmapBounds = SkRect::MakeXYWH(dx, dy, |
| 320 | SkIntToScalar(bitmapPtr->width()), |
| 321 | SkIntToScalar(bitmapPtr->height())); |
| 322 | #else |
mtklein | 65c74f1 | 2017-03-31 18:36:39 -0700 | [diff] [blame] | 323 | SkRect extractedBitmapBounds; |
| 324 | extractedBitmapBounds.isetWH(bitmapPtr->width(), bitmapPtr->height()); |
lsalzman | c0e52f4 | 2017-04-05 21:42:54 -0700 | [diff] [blame^] | 325 | #endif |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 326 | if (extractedBitmapBounds == tmpSrc) { |
| 327 | // no fractional part in src, we can just call drawBitmap |
| 328 | goto USE_DRAWBITMAP; |
| 329 | } |
| 330 | } else { |
| 331 | USE_DRAWBITMAP: |
| 332 | // We can go faster by just calling drawBitmap, which will concat the |
| 333 | // matrix with the CTM, and try to call drawSprite if it can. If not, |
| 334 | // it will make a shader and call drawRect, as we do below. |
fmalita | ab83da7 | 2016-08-26 13:04:14 -0700 | [diff] [blame] | 335 | if (CanApplyDstMatrixAsCTM(matrix, paint)) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 336 | BDDraw(this).drawBitmap(*bitmapPtr, matrix, dstPtr, paint); |
fmalita | ab83da7 | 2016-08-26 13:04:14 -0700 | [diff] [blame] | 337 | return; |
| 338 | } |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 339 | } |
| 340 | |
reed | 27efa23 | 2016-07-25 19:10:10 -0700 | [diff] [blame] | 341 | USE_SHADER: |
reed | f77c47b | 2016-08-05 10:15:00 -0700 | [diff] [blame] | 342 | |
Herb Derby | 83e939b | 2017-02-07 14:25:11 -0500 | [diff] [blame] | 343 | // TODO(herb): Move this over to SkArenaAlloc when arena alloc has a facility to return sk_sps. |
reed | f77c47b | 2016-08-05 10:15:00 -0700 | [diff] [blame] | 344 | // Since the shader need only live for our stack-frame, pass in a custom allocator. This |
| 345 | // can save malloc calls, and signals to SkMakeBitmapShader to not try to copy the bitmap |
| 346 | // if its mutable, since that precaution is not needed (give the short lifetime of the shader). |
Herb Derby | bfdc87a | 2017-02-14 15:06:23 +0000 | [diff] [blame] | 347 | |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 348 | // construct a shader, so we can call drawRect with the dst |
reed | f77c47b | 2016-08-05 10:15:00 -0700 | [diff] [blame] | 349 | auto s = SkMakeBitmapShader(*bitmapPtr, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, |
Herb Derby | bfdc87a | 2017-02-14 15:06:23 +0000 | [diff] [blame] | 350 | &matrix, kNever_SkCopyPixelsMode); |
reed | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 351 | if (!s) { |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 352 | return; |
| 353 | } |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 354 | |
| 355 | SkPaint paintWithShader(paint); |
| 356 | paintWithShader.setStyle(SkPaint::kFill_Style); |
reed | f77c47b | 2016-08-05 10:15:00 -0700 | [diff] [blame] | 357 | paintWithShader.setShader(s); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 358 | |
| 359 | // Call ourself, in case the subclass wanted to share this setup code |
| 360 | // but handle the drawRect code themselves. |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 361 | this->drawRect(*dstPtr, paintWithShader); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 362 | } |
| 363 | |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 364 | void SkBitmapDevice::drawSprite(const SkBitmap& bitmap, int x, int y, const SkPaint& paint) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 365 | BDDraw(this).drawSprite(bitmap, x, y, paint); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 366 | } |
| 367 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 368 | void SkBitmapDevice::drawText(const void* text, size_t len, |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 369 | SkScalar x, SkScalar y, const SkPaint& paint) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 370 | BDDraw(this).drawText((const char*)text, len, x, y, paint, &fSurfaceProps); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 371 | } |
| 372 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 373 | void SkBitmapDevice::drawPosText(const void* text, size_t len, const SkScalar xpos[], |
| 374 | int scalarsPerPos, const SkPoint& offset, const SkPaint& paint) { |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 375 | BDDraw(this).drawPosText((const char*)text, len, xpos, scalarsPerPos, offset, paint, |
| 376 | &fSurfaceProps); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 377 | } |
| 378 | |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 379 | void SkBitmapDevice::drawVertices(const SkVertices* vertices, SkBlendMode bmode, |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 380 | const SkPaint& paint) { |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 381 | BDDraw(this).drawVertices(vertices->mode(), vertices->vertexCount(), vertices->positions(), |
| 382 | vertices->texCoords(), vertices->colors(), bmode, |
| 383 | vertices->indices(), vertices->indexCount(), paint); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 384 | } |
| 385 | |
Mike Reed | 2f6b5a4 | 2017-03-19 15:04:17 -0400 | [diff] [blame] | 386 | void SkBitmapDevice::drawDevice(SkBaseDevice* device, int x, int y, const SkPaint& paint) { |
reed | cf5c846 | 2016-07-20 12:28:40 -0700 | [diff] [blame] | 387 | SkASSERT(!paint.getImageFilter()); |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 388 | BDDraw(this).drawSprite(static_cast<SkBitmapDevice*>(device)->fBitmap, x, y, paint); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 389 | } |
| 390 | |
reed | e51c356 | 2016-07-19 14:33:20 -0700 | [diff] [blame] | 391 | /////////////////////////////////////////////////////////////////////////////// |
| 392 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 393 | void SkBitmapDevice::drawSpecial(SkSpecialImage* srcImg, int x, int y, |
reed | e51c356 | 2016-07-19 14:33:20 -0700 | [diff] [blame] | 394 | const SkPaint& paint) { |
| 395 | SkASSERT(!srcImg->isTextureBacked()); |
| 396 | |
| 397 | SkBitmap resultBM; |
| 398 | |
| 399 | SkImageFilter* filter = paint.getImageFilter(); |
| 400 | if (filter) { |
| 401 | SkIPoint offset = SkIPoint::Make(0, 0); |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 402 | SkMatrix matrix = this->ctm(); |
reed | e51c356 | 2016-07-19 14:33:20 -0700 | [diff] [blame] | 403 | matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y)); |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 404 | const SkIRect clipBounds = fRCStack.rc().getBounds().makeOffset(-x, -y); |
Hal Canary | 704cd32 | 2016-11-07 14:13:52 -0500 | [diff] [blame] | 405 | sk_sp<SkImageFilterCache> cache(this->getImageFilterCache()); |
brianosman | 2a75e5d | 2016-09-22 07:15:37 -0700 | [diff] [blame] | 406 | SkImageFilter::OutputProperties outputProperties(fBitmap.colorSpace()); |
| 407 | SkImageFilter::Context ctx(matrix, clipBounds, cache.get(), outputProperties); |
liyuqian | 2add0ff | 2016-10-20 11:04:39 -0700 | [diff] [blame] | 408 | |
reed | e51c356 | 2016-07-19 14:33:20 -0700 | [diff] [blame] | 409 | sk_sp<SkSpecialImage> resultImg(filter->filterImage(srcImg, ctx, &offset)); |
| 410 | if (resultImg) { |
| 411 | SkPaint tmpUnfiltered(paint); |
| 412 | tmpUnfiltered.setImageFilter(nullptr); |
| 413 | if (resultImg->getROPixels(&resultBM)) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 414 | this->drawSprite(resultBM, x + offset.x(), y + offset.y(), tmpUnfiltered); |
reed | e51c356 | 2016-07-19 14:33:20 -0700 | [diff] [blame] | 415 | } |
| 416 | } |
| 417 | } else { |
| 418 | if (srcImg->getROPixels(&resultBM)) { |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 419 | this->drawSprite(resultBM, x, y, paint); |
reed | e51c356 | 2016-07-19 14:33:20 -0700 | [diff] [blame] | 420 | } |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | sk_sp<SkSpecialImage> SkBitmapDevice::makeSpecial(const SkBitmap& bitmap) { |
| 425 | return SkSpecialImage::MakeFromRaster(bitmap.bounds(), bitmap); |
| 426 | } |
| 427 | |
| 428 | sk_sp<SkSpecialImage> SkBitmapDevice::makeSpecial(const SkImage* image) { |
| 429 | return SkSpecialImage::MakeFromImage(SkIRect::MakeWH(image->width(), image->height()), |
Brian Osman | 61624f0 | 2016-12-09 14:51:59 -0500 | [diff] [blame] | 430 | image->makeNonTextureImage(), fBitmap.colorSpace()); |
reed | e51c356 | 2016-07-19 14:33:20 -0700 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | sk_sp<SkSpecialImage> SkBitmapDevice::snapSpecial() { |
| 434 | return this->makeSpecial(fBitmap); |
| 435 | } |
| 436 | |
| 437 | /////////////////////////////////////////////////////////////////////////////// |
| 438 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 439 | sk_sp<SkSurface> SkBitmapDevice::makeSurface(const SkImageInfo& info, const SkSurfaceProps& props) { |
| 440 | return SkSurface::MakeRaster(info, &props); |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 441 | } |
| 442 | |
senorblanco | 900c367 | 2016-04-27 11:31:23 -0700 | [diff] [blame] | 443 | SkImageFilterCache* SkBitmapDevice::getImageFilterCache() { |
| 444 | SkImageFilterCache* cache = SkImageFilterCache::Get(); |
senorblanco | 55b6d8b | 2014-07-30 11:26:46 -0700 | [diff] [blame] | 445 | cache->ref(); |
| 446 | return cache; |
| 447 | } |
| 448 | |
Mike Reed | 7627fa5 | 2017-02-08 10:07:53 -0500 | [diff] [blame] | 449 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 450 | |
reed | b2db898 | 2014-11-13 12:41:02 -0800 | [diff] [blame] | 451 | bool SkBitmapDevice::onShouldDisableLCD(const SkPaint& paint) const { |
commit-bot@chromium.org | cba7378 | 2014-05-29 15:57:47 +0000 | [diff] [blame] | 452 | if (kN32_SkColorType != fBitmap.colorType() || |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 453 | paint.getRasterizer() || |
| 454 | paint.getPathEffect() || |
| 455 | paint.isFakeBoldText() || |
| 456 | paint.getStyle() != SkPaint::kFill_Style || |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 457 | !paint.isSrcOver()) |
reed | b2db898 | 2014-11-13 12:41:02 -0800 | [diff] [blame] | 458 | { |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 459 | return true; |
| 460 | } |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 461 | return false; |
| 462 | } |
Mike Reed | 7627fa5 | 2017-02-08 10:07:53 -0500 | [diff] [blame] | 463 | |
| 464 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 465 | |
| 466 | void SkBitmapDevice::onSave() { |
Mike Reed | c42a1cd | 2017-02-14 14:25:14 -0500 | [diff] [blame] | 467 | fRCStack.save(); |
Mike Reed | 7627fa5 | 2017-02-08 10:07:53 -0500 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | void SkBitmapDevice::onRestore() { |
Mike Reed | c42a1cd | 2017-02-14 14:25:14 -0500 | [diff] [blame] | 471 | fRCStack.restore(); |
Mike Reed | 7627fa5 | 2017-02-08 10:07:53 -0500 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | void SkBitmapDevice::onClipRect(const SkRect& rect, SkClipOp op, bool aa) { |
Mike Reed | c42a1cd | 2017-02-14 14:25:14 -0500 | [diff] [blame] | 475 | fRCStack.clipRect(this->ctm(), rect, op, aa); |
Mike Reed | 7627fa5 | 2017-02-08 10:07:53 -0500 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | void SkBitmapDevice::onClipRRect(const SkRRect& rrect, SkClipOp op, bool aa) { |
Mike Reed | c42a1cd | 2017-02-14 14:25:14 -0500 | [diff] [blame] | 479 | fRCStack.clipRRect(this->ctm(), rrect, op, aa); |
Mike Reed | 7627fa5 | 2017-02-08 10:07:53 -0500 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | void SkBitmapDevice::onClipPath(const SkPath& path, SkClipOp op, bool aa) { |
Mike Reed | c42a1cd | 2017-02-14 14:25:14 -0500 | [diff] [blame] | 483 | fRCStack.clipPath(this->ctm(), path, op, aa); |
Mike Reed | 7627fa5 | 2017-02-08 10:07:53 -0500 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | void SkBitmapDevice::onClipRegion(const SkRegion& rgn, SkClipOp op) { |
Mike Reed | c42a1cd | 2017-02-14 14:25:14 -0500 | [diff] [blame] | 487 | SkIPoint origin = this->getOrigin(); |
| 488 | SkRegion tmp; |
| 489 | const SkRegion* ptr = &rgn; |
| 490 | if (origin.fX | origin.fY) { |
| 491 | // translate from "global/canvas" coordinates to relative to this device |
| 492 | rgn.translate(-origin.fX, -origin.fY, &tmp); |
| 493 | ptr = &tmp; |
| 494 | } |
| 495 | fRCStack.clipRegion(*ptr, op); |
| 496 | } |
| 497 | |
| 498 | void SkBitmapDevice::onSetDeviceClipRestriction(SkIRect* mutableClipRestriction) { |
| 499 | fRCStack.setDeviceClipRestriction(mutableClipRestriction); |
Mike Reed | d519d48 | 2017-02-16 11:04:52 -0500 | [diff] [blame] | 500 | if (!mutableClipRestriction->isEmpty()) { |
| 501 | SkRegion rgn(*mutableClipRestriction); |
| 502 | fRCStack.clipRegion(rgn, SkClipOp::kIntersect); |
| 503 | } |
Mike Reed | c42a1cd | 2017-02-14 14:25:14 -0500 | [diff] [blame] | 504 | } |
| 505 | |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 506 | bool SkBitmapDevice::onClipIsAA() const { |
| 507 | const SkRasterClip& rc = fRCStack.rc(); |
| 508 | return !rc.isEmpty() && rc.isAA(); |
| 509 | } |
| 510 | |
| 511 | void SkBitmapDevice::onAsRgnClip(SkRegion* rgn) const { |
| 512 | const SkRasterClip& rc = fRCStack.rc(); |
| 513 | if (rc.isAA()) { |
| 514 | rgn->setRect(rc.getBounds()); |
| 515 | } else { |
| 516 | *rgn = rc.bwRgn(); |
| 517 | } |
| 518 | } |
| 519 | |
Mike Reed | c42a1cd | 2017-02-14 14:25:14 -0500 | [diff] [blame] | 520 | void SkBitmapDevice::validateDevBounds(const SkIRect& drawClipBounds) { |
| 521 | #ifdef SK_DEBUG |
| 522 | const SkIRect& stackBounds = fRCStack.rc().getBounds(); |
| 523 | SkASSERT(drawClipBounds == stackBounds); |
| 524 | #endif |
Mike Reed | 7627fa5 | 2017-02-08 10:07:53 -0500 | [diff] [blame] | 525 | } |
Mike Reed | a136136 | 2017-03-07 09:37:29 -0500 | [diff] [blame] | 526 | |
| 527 | SkBaseDevice::ClipType SkBitmapDevice::onGetClipType() const { |
| 528 | const SkRasterClip& rc = fRCStack.rc(); |
| 529 | if (rc.isEmpty()) { |
| 530 | return kEmpty_ClipType; |
| 531 | } else if (rc.isRect()) { |
| 532 | return kRect_ClipType; |
| 533 | } else { |
| 534 | return kComplex_ClipType; |
| 535 | } |
| 536 | } |