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 | |
| 8 | #include "SkBitmapDevice.h" |
| 9 | #include "SkConfig8888.h" |
| 10 | #include "SkDraw.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame^] | 11 | #include "SkMatrix.h" |
| 12 | #include "SkPaint.h" |
| 13 | #include "SkPath.h" |
reed | 884e97c | 2015-05-26 11:31:54 -0700 | [diff] [blame] | 14 | #include "SkPixelRef.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame^] | 15 | #include "SkPixmap.h" |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 16 | #include "SkShader.h" |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 17 | #include "SkSurface.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame^] | 18 | #include "SkXfermode.h" |
| 19 | |
| 20 | class SkColorTable; |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 21 | |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 22 | #define CHECK_FOR_ANNOTATION(paint) \ |
| 23 | do { if (paint.getAnnotation()) { return; } } while (0) |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 24 | |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 25 | static bool valid_for_bitmap_device(const SkImageInfo& info, |
| 26 | SkAlphaType* newAlphaType) { |
| 27 | if (info.width() < 0 || info.height() < 0) { |
| 28 | return false; |
| 29 | } |
| 30 | |
| 31 | // TODO: can we stop supporting kUnknown in SkBitmkapDevice? |
| 32 | if (kUnknown_SkColorType == info.colorType()) { |
| 33 | if (newAlphaType) { |
reed | 4497748 | 2015-02-27 10:23:00 -0800 | [diff] [blame] | 34 | *newAlphaType = kUnknown_SkAlphaType; |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 35 | } |
| 36 | return true; |
| 37 | } |
skia.committer@gmail.com | 969588f | 2014-02-16 03:01:56 +0000 | [diff] [blame] | 38 | |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 39 | switch (info.alphaType()) { |
| 40 | case kPremul_SkAlphaType: |
| 41 | case kOpaque_SkAlphaType: |
| 42 | break; |
| 43 | default: |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | SkAlphaType canonicalAlphaType = info.alphaType(); |
| 48 | |
| 49 | switch (info.colorType()) { |
| 50 | case kAlpha_8_SkColorType: |
| 51 | break; |
| 52 | case kRGB_565_SkColorType: |
| 53 | canonicalAlphaType = kOpaque_SkAlphaType; |
| 54 | break; |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 55 | case kN32_SkColorType: |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 56 | break; |
| 57 | default: |
| 58 | return false; |
| 59 | } |
| 60 | |
| 61 | if (newAlphaType) { |
| 62 | *newAlphaType = canonicalAlphaType; |
| 63 | } |
| 64 | return true; |
| 65 | } |
| 66 | |
robertphillips | 9a53fd7 | 2015-06-22 09:46:59 -0700 | [diff] [blame] | 67 | SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap) |
| 68 | : INHERITED(SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)) |
| 69 | , fBitmap(bitmap) { |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 70 | SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL)); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 71 | } |
| 72 | |
robertphillips | 9a53fd7 | 2015-06-22 09:46:59 -0700 | [diff] [blame] | 73 | SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& info) { |
| 74 | return Create(info, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)); |
| 75 | } |
| 76 | |
robertphillips | fcf7829 | 2015-06-19 11:49:52 -0700 | [diff] [blame] | 77 | SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkSurfaceProps& surfaceProps) |
robertphillips | 9a53fd7 | 2015-06-22 09:46:59 -0700 | [diff] [blame] | 78 | : INHERITED(surfaceProps) |
| 79 | , fBitmap(bitmap) { |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 80 | SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL)); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 81 | } |
| 82 | |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 83 | SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo, |
robertphillips | 9a53fd7 | 2015-06-22 09:46:59 -0700 | [diff] [blame] | 84 | const SkSurfaceProps& surfaceProps) { |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 85 | SkAlphaType newAT = origInfo.alphaType(); |
| 86 | if (!valid_for_bitmap_device(origInfo, &newAT)) { |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 87 | return NULL; |
| 88 | } |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 89 | |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 90 | const SkImageInfo info = origInfo.makeAlphaType(newAT); |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 91 | SkBitmap bitmap; |
| 92 | |
| 93 | if (kUnknown_SkColorType == info.colorType()) { |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 94 | if (!bitmap.setInfo(info)) { |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 95 | return NULL; |
| 96 | } |
| 97 | } else { |
reed | 8482504 | 2014-09-02 12:50:45 -0700 | [diff] [blame] | 98 | if (!bitmap.tryAllocPixels(info)) { |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 99 | return NULL; |
| 100 | } |
| 101 | if (!bitmap.info().isOpaque()) { |
| 102 | bitmap.eraseColor(SK_ColorTRANSPARENT); |
| 103 | } |
| 104 | } |
| 105 | |
robertphillips | 9a53fd7 | 2015-06-22 09:46:59 -0700 | [diff] [blame] | 106 | return SkNEW_ARGS(SkBitmapDevice, (bitmap, surfaceProps)); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 107 | } |
| 108 | |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 109 | SkImageInfo SkBitmapDevice::imageInfo() const { |
| 110 | return fBitmap.info(); |
| 111 | } |
| 112 | |
mtklein | feaadee | 2015-04-08 11:25:48 -0700 | [diff] [blame] | 113 | void SkBitmapDevice::setNewSize(const SkISize& size) { |
| 114 | SkASSERT(!fBitmap.pixelRef()); |
| 115 | fBitmap.setInfo(fBitmap.info().makeWH(size.fWidth, size.fHeight)); |
| 116 | } |
| 117 | |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 118 | void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) { |
| 119 | SkASSERT(bm.width() == fBitmap.width()); |
| 120 | SkASSERT(bm.height() == fBitmap.height()); |
| 121 | fBitmap = bm; // intent is to use bm's pixelRef (and rowbytes/config) |
| 122 | fBitmap.lockPixels(); |
| 123 | } |
| 124 | |
reed | 76033be | 2015-03-14 10:54:31 -0700 | [diff] [blame] | 125 | SkBaseDevice* SkBitmapDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint*) { |
robertphillips | 9a53fd7 | 2015-06-22 09:46:59 -0700 | [diff] [blame] | 126 | const SkSurfaceProps surfaceProps(this->surfaceProps().flags(), cinfo.fPixelGeometry); |
| 127 | return SkBitmapDevice::Create(cinfo.fInfo, surfaceProps); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 128 | } |
| 129 | |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 130 | const SkBitmap& SkBitmapDevice::onAccessBitmap() { |
| 131 | return fBitmap; |
| 132 | } |
| 133 | |
reed | 884e97c | 2015-05-26 11:31:54 -0700 | [diff] [blame] | 134 | bool SkBitmapDevice::onAccessPixels(SkPixmap* pmap) { |
reed | 6e76485 | 2015-06-05 14:11:32 -0700 | [diff] [blame] | 135 | if (fBitmap.lockPixelsAreWritable() && this->onPeekPixels(pmap)) { |
| 136 | fBitmap.notifyPixelsChanged(); |
| 137 | return true; |
| 138 | } |
| 139 | return false; |
reed | 9572a10 | 2015-05-26 19:22:17 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | bool SkBitmapDevice::onPeekPixels(SkPixmap* pmap) { |
reed | 884e97c | 2015-05-26 11:31:54 -0700 | [diff] [blame] | 143 | const SkImageInfo info = fBitmap.info(); |
| 144 | if (fBitmap.getPixels() && (kUnknown_SkColorType != info.colorType())) { |
| 145 | SkColorTable* ctable = NULL; |
| 146 | pmap->reset(fBitmap.info(), fBitmap.getPixels(), fBitmap.rowBytes(), ctable); |
| 147 | return true; |
reed@google.com | 9c135db | 2014-03-12 18:28:35 +0000 | [diff] [blame] | 148 | } |
reed | 884e97c | 2015-05-26 11:31:54 -0700 | [diff] [blame] | 149 | return false; |
reed@google.com | 9c135db | 2014-03-12 18:28:35 +0000 | [diff] [blame] | 150 | } |
| 151 | |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 152 | bool SkBitmapDevice::onWritePixels(const SkImageInfo& srcInfo, const void* srcPixels, |
| 153 | size_t srcRowBytes, int x, int y) { |
reed@google.com | 0d30c51 | 2014-03-14 14:02:58 +0000 | [diff] [blame] | 154 | // since we don't stop creating un-pixeled devices yet, check for no pixels here |
| 155 | if (NULL == fBitmap.getPixels()) { |
| 156 | return false; |
| 157 | } |
| 158 | |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 159 | const SkImageInfo dstInfo = fBitmap.info().makeWH(srcInfo.width(), srcInfo.height()); |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 160 | |
| 161 | void* dstPixels = fBitmap.getAddr(x, y); |
| 162 | size_t dstRowBytes = fBitmap.rowBytes(); |
| 163 | |
reed | b184f7f | 2014-07-13 04:32:32 -0700 | [diff] [blame] | 164 | if (SkPixelInfo::CopyPixels(dstInfo, dstPixels, dstRowBytes, srcInfo, srcPixels, srcRowBytes)) { |
commit-bot@chromium.org | 4cd9e21 | 2014-03-07 03:25:16 +0000 | [diff] [blame] | 165 | fBitmap.notifyPixelsChanged(); |
| 166 | return true; |
| 167 | } |
| 168 | return false; |
| 169 | } |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 170 | |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 171 | bool SkBitmapDevice::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, |
| 172 | int x, int y) { |
reed | b184f7f | 2014-07-13 04:32:32 -0700 | [diff] [blame] | 173 | return fBitmap.readPixels(dstInfo, dstPixels, dstRowBytes, x, y); |
commit-bot@chromium.org | a713f9c | 2014-03-17 21:31:26 +0000 | [diff] [blame] | 174 | } |
| 175 | |
reed | cd1d41e | 2015-05-25 21:21:27 -0700 | [diff] [blame] | 176 | void SkBitmapDevice::onAttachToCanvas(SkCanvas* canvas) { |
| 177 | INHERITED::onAttachToCanvas(canvas); |
| 178 | if (fBitmap.lockPixelsAreWritable()) { |
| 179 | fBitmap.lockPixels(); |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | void SkBitmapDevice::onDetachFromCanvas() { |
| 184 | INHERITED::onDetachFromCanvas(); |
| 185 | if (fBitmap.lockPixelsAreWritable()) { |
| 186 | fBitmap.unlockPixels(); |
| 187 | } |
| 188 | } |
| 189 | |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 190 | /////////////////////////////////////////////////////////////////////////////// |
| 191 | |
| 192 | void SkBitmapDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) { |
| 193 | draw.drawPaint(paint); |
| 194 | } |
| 195 | |
| 196 | void SkBitmapDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, size_t count, |
| 197 | const SkPoint pts[], const SkPaint& paint) { |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 198 | CHECK_FOR_ANNOTATION(paint); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 199 | draw.drawPoints(mode, count, pts, paint); |
| 200 | } |
| 201 | |
| 202 | void SkBitmapDevice::drawRect(const SkDraw& draw, const SkRect& r, const SkPaint& paint) { |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 203 | CHECK_FOR_ANNOTATION(paint); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 204 | draw.drawRect(r, paint); |
| 205 | } |
| 206 | |
| 207 | void SkBitmapDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint& paint) { |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 208 | CHECK_FOR_ANNOTATION(paint); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 209 | |
| 210 | SkPath path; |
| 211 | path.addOval(oval); |
| 212 | // call the VIRTUAL version, so any subclasses who do handle drawPath aren't |
| 213 | // required to override drawOval. |
| 214 | this->drawPath(draw, path, paint, NULL, true); |
| 215 | } |
| 216 | |
| 217 | void SkBitmapDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect, const SkPaint& paint) { |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 218 | CHECK_FOR_ANNOTATION(paint); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 219 | |
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. |
| 226 | this->drawPath(draw, path, paint, NULL, true); |
| 227 | #else |
scroggo@google.com | a8e33a9 | 2013-11-08 18:02:53 +0000 | [diff] [blame] | 228 | draw.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 | |
| 232 | void SkBitmapDevice::drawPath(const SkDraw& draw, const SkPath& path, |
| 233 | const SkPaint& paint, const SkMatrix* prePathMatrix, |
| 234 | bool pathIsMutable) { |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 235 | CHECK_FOR_ANNOTATION(paint); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 236 | draw.drawPath(path, paint, prePathMatrix, pathIsMutable); |
| 237 | } |
| 238 | |
| 239 | void SkBitmapDevice::drawBitmap(const SkDraw& draw, const SkBitmap& bitmap, |
| 240 | const SkMatrix& matrix, const SkPaint& paint) { |
reed | 0393912 | 2014-12-15 13:42:51 -0800 | [diff] [blame] | 241 | draw.drawBitmap(bitmap, matrix, NULL, paint); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | void SkBitmapDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap, |
| 245 | const SkRect* src, const SkRect& dst, |
reed | 562fe47 | 2015-07-28 07:35:14 -0700 | [diff] [blame] | 246 | const SkPaint& paint, SkCanvas::SrcRectConstraint constraint) { |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 247 | SkMatrix matrix; |
| 248 | SkRect bitmapBounds, tmpSrc, tmpDst; |
| 249 | SkBitmap tmpBitmap; |
| 250 | |
| 251 | bitmapBounds.isetWH(bitmap.width(), bitmap.height()); |
| 252 | |
| 253 | // Compute matrix from the two rectangles |
| 254 | if (src) { |
| 255 | tmpSrc = *src; |
| 256 | } else { |
| 257 | tmpSrc = bitmapBounds; |
| 258 | } |
| 259 | matrix.setRectToRect(tmpSrc, dst, SkMatrix::kFill_ScaleToFit); |
| 260 | |
| 261 | const SkRect* dstPtr = &dst; |
| 262 | const SkBitmap* bitmapPtr = &bitmap; |
| 263 | |
| 264 | // clip the tmpSrc to the bounds of the bitmap, and recompute dstRect if |
| 265 | // needed (if the src was clipped). No check needed if src==null. |
| 266 | if (src) { |
| 267 | if (!bitmapBounds.contains(*src)) { |
| 268 | if (!tmpSrc.intersect(bitmapBounds)) { |
| 269 | return; // nothing to draw |
| 270 | } |
| 271 | // recompute dst, based on the smaller tmpSrc |
| 272 | matrix.mapRect(&tmpDst, tmpSrc); |
| 273 | dstPtr = &tmpDst; |
| 274 | } |
| 275 | |
| 276 | // since we may need to clamp to the borders of the src rect within |
| 277 | // the bitmap, we extract a subset. |
reed | b07a94f | 2014-11-19 05:03:18 -0800 | [diff] [blame] | 278 | const SkIRect srcIR = tmpSrc.roundOut(); |
piotaixr | 0e97705 | 2014-09-17 16:24:04 -0700 | [diff] [blame] | 279 | if(bitmap.pixelRef()->getTexture()) { |
| 280 | // Accelerated source canvas, don't use extractSubset but readPixels to get the subset. |
| 281 | // This way, the pixels are copied in CPU memory instead of GPU memory. |
| 282 | bitmap.pixelRef()->readPixels(&tmpBitmap, &srcIR); |
| 283 | } else { |
| 284 | if (!bitmap.extractSubset(&tmpBitmap, srcIR)) { |
| 285 | return; |
| 286 | } |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 287 | } |
| 288 | bitmapPtr = &tmpBitmap; |
| 289 | |
| 290 | // Since we did an extract, we need to adjust the matrix accordingly |
| 291 | SkScalar dx = 0, dy = 0; |
| 292 | if (srcIR.fLeft > 0) { |
| 293 | dx = SkIntToScalar(srcIR.fLeft); |
| 294 | } |
| 295 | if (srcIR.fTop > 0) { |
| 296 | dy = SkIntToScalar(srcIR.fTop); |
| 297 | } |
| 298 | if (dx || dy) { |
| 299 | matrix.preTranslate(dx, dy); |
| 300 | } |
| 301 | |
| 302 | SkRect extractedBitmapBounds; |
| 303 | extractedBitmapBounds.isetWH(bitmapPtr->width(), bitmapPtr->height()); |
| 304 | if (extractedBitmapBounds == tmpSrc) { |
| 305 | // no fractional part in src, we can just call drawBitmap |
| 306 | goto USE_DRAWBITMAP; |
| 307 | } |
| 308 | } else { |
| 309 | USE_DRAWBITMAP: |
| 310 | // We can go faster by just calling drawBitmap, which will concat the |
| 311 | // matrix with the CTM, and try to call drawSprite if it can. If not, |
| 312 | // it will make a shader and call drawRect, as we do below. |
reed | 0393912 | 2014-12-15 13:42:51 -0800 | [diff] [blame] | 313 | draw.drawBitmap(*bitmapPtr, matrix, dstPtr, paint); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 314 | return; |
| 315 | } |
| 316 | |
| 317 | // construct a shader, so we can call drawRect with the dst |
| 318 | SkShader* s = SkShader::CreateBitmapShader(*bitmapPtr, |
| 319 | SkShader::kClamp_TileMode, |
commit-bot@chromium.org | 9c9005a | 2014-04-28 14:55:39 +0000 | [diff] [blame] | 320 | SkShader::kClamp_TileMode, |
| 321 | &matrix); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 322 | if (NULL == s) { |
| 323 | return; |
| 324 | } |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 325 | |
| 326 | SkPaint paintWithShader(paint); |
| 327 | paintWithShader.setStyle(SkPaint::kFill_Style); |
| 328 | paintWithShader.setShader(s)->unref(); |
| 329 | |
| 330 | // Call ourself, in case the subclass wanted to share this setup code |
| 331 | // but handle the drawRect code themselves. |
| 332 | this->drawRect(draw, *dstPtr, paintWithShader); |
| 333 | } |
| 334 | |
| 335 | void SkBitmapDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, |
| 336 | int x, int y, const SkPaint& paint) { |
| 337 | draw.drawSprite(bitmap, x, y, paint); |
| 338 | } |
| 339 | |
| 340 | void SkBitmapDevice::drawText(const SkDraw& draw, const void* text, size_t len, |
| 341 | SkScalar x, SkScalar y, const SkPaint& paint) { |
| 342 | draw.drawText((const char*)text, len, x, y, paint); |
| 343 | } |
| 344 | |
| 345 | void SkBitmapDevice::drawPosText(const SkDraw& draw, const void* text, size_t len, |
fmalita | 05c4a43 | 2014-09-29 06:29:53 -0700 | [diff] [blame] | 346 | const SkScalar xpos[], int scalarsPerPos, |
| 347 | const SkPoint& offset, const SkPaint& paint) { |
| 348 | draw.drawPosText((const char*)text, len, xpos, scalarsPerPos, offset, paint); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 349 | } |
| 350 | |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 351 | void SkBitmapDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, |
| 352 | int vertexCount, |
| 353 | const SkPoint verts[], const SkPoint textures[], |
| 354 | const SkColor colors[], SkXfermode* xmode, |
| 355 | const uint16_t indices[], int indexCount, |
| 356 | const SkPaint& paint) { |
| 357 | draw.drawVertices(vmode, vertexCount, verts, textures, colors, xmode, |
| 358 | indices, indexCount, paint); |
| 359 | } |
| 360 | |
| 361 | void SkBitmapDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device, |
| 362 | int x, int y, const SkPaint& paint) { |
reed | 9572a10 | 2015-05-26 19:22:17 -0700 | [diff] [blame] | 363 | draw.drawSprite(static_cast<SkBitmapDevice*>(device)->fBitmap, x, y, paint); |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 364 | } |
| 365 | |
reed | 4a8126e | 2014-09-22 07:29:03 -0700 | [diff] [blame] | 366 | SkSurface* SkBitmapDevice::newSurface(const SkImageInfo& info, const SkSurfaceProps& props) { |
| 367 | return SkSurface::NewRaster(info, &props); |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 368 | } |
| 369 | |
senorblanco | be129b2 | 2014-08-08 07:14:35 -0700 | [diff] [blame] | 370 | SkImageFilter::Cache* SkBitmapDevice::getImageFilterCache() { |
| 371 | SkImageFilter::Cache* cache = SkImageFilter::Cache::Get(); |
senorblanco | 55b6d8b | 2014-07-30 11:26:46 -0700 | [diff] [blame] | 372 | cache->ref(); |
| 373 | return cache; |
| 374 | } |
| 375 | |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 376 | /////////////////////////////////////////////////////////////////////////////// |
| 377 | |
reed | b2db898 | 2014-11-13 12:41:02 -0800 | [diff] [blame] | 378 | bool SkBitmapDevice::onShouldDisableLCD(const SkPaint& paint) const { |
commit-bot@chromium.org | cba7378 | 2014-05-29 15:57:47 +0000 | [diff] [blame] | 379 | if (kN32_SkColorType != fBitmap.colorType() || |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 380 | paint.getRasterizer() || |
| 381 | paint.getPathEffect() || |
| 382 | paint.isFakeBoldText() || |
| 383 | paint.getStyle() != SkPaint::kFill_Style || |
reed | b2db898 | 2014-11-13 12:41:02 -0800 | [diff] [blame] | 384 | !SkXfermode::IsMode(paint.getXfermode(), SkXfermode::kSrcOver_Mode)) |
| 385 | { |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 386 | return true; |
| 387 | } |
robertphillips@google.com | 53238bc | 2013-08-30 13:12:10 +0000 | [diff] [blame] | 388 | return false; |
| 389 | } |