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