Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2008 The Android Open Source Project | 2 * Copyright 2008 The Android Open Source Project |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkBitmapDevice.h" | 8 #include "SkBitmapDevice.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkCanvasPriv.h" | 10 #include "SkCanvasPriv.h" |
| 11 #include "SkClipStack.h" | 11 #include "SkClipStack.h" |
| 12 #include "SkColorFilter.h" | 12 #include "SkColorFilter.h" |
| 13 #include "SkDevice.h" | 13 #include "SkDevice.h" |
| 14 #include "SkDraw.h" | 14 #include "SkDraw.h" |
| 15 #include "SkDrawable.h" | 15 #include "SkDrawable.h" |
| 16 #include "SkDrawFilter.h" | 16 #include "SkDrawFilter.h" |
| 17 #include "SkDrawLooper.h" | 17 #include "SkDrawLooper.h" |
| 18 #include "SkErrorInternals.h" | 18 #include "SkErrorInternals.h" |
| 19 #include "SkImage.h" | 19 #include "SkImage.h" |
| 20 #include "SkImage_Base.h" | |
| 20 #include "SkMetaData.h" | 21 #include "SkMetaData.h" |
| 21 #include "SkNinePatchIter.h" | 22 #include "SkNinePatchIter.h" |
| 22 #include "SkPaintPriv.h" | 23 #include "SkPaintPriv.h" |
| 23 #include "SkPatchUtils.h" | 24 #include "SkPatchUtils.h" |
| 24 #include "SkPicture.h" | 25 #include "SkPicture.h" |
| 25 #include "SkRasterClip.h" | 26 #include "SkRasterClip.h" |
| 26 #include "SkReadPixelsRec.h" | 27 #include "SkReadPixelsRec.h" |
| 27 #include "SkRRect.h" | 28 #include "SkRRect.h" |
| 28 #include "SkSmallAllocator.h" | 29 #include "SkSmallAllocator.h" |
| 29 #include "SkSurface_Base.h" | 30 #include "SkSurface_Base.h" |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 585 // call this after any possible paint modifiers | 586 // call this after any possible paint modifiers |
| 586 if (fPaint->nothingToDraw()) { | 587 if (fPaint->nothingToDraw()) { |
| 587 fPaint = nullptr; | 588 fPaint = nullptr; |
| 588 return false; | 589 return false; |
| 589 } | 590 } |
| 590 return true; | 591 return true; |
| 591 } | 592 } |
| 592 | 593 |
| 593 ////////// macros to place around the internal draw calls ////////////////// | 594 ////////// macros to place around the internal draw calls ////////////////// |
| 594 | 595 |
| 596 #define LOOPER_BEGIN_DRAWBITMAP(paint, skipLayerForFilter, bounds) \ | |
| 597 this->predrawNotify(); \ | |
| 598 AutoDrawLooper looper(this, fProps, paint, skipLayerForFilter, bounds); \ | |
| 599 while (looper.next(SkDrawFilter::kBitmap_Type)) { \ | |
| 600 SkDrawIter iter(this); | |
| 601 | |
| 602 | |
| 595 #define LOOPER_BEGIN_DRAWDEVICE(paint, type) \ | 603 #define LOOPER_BEGIN_DRAWDEVICE(paint, type) \ |
| 596 this->predrawNotify(); \ | 604 this->predrawNotify(); \ |
| 597 AutoDrawLooper looper(this, fProps, paint, true); \ | 605 AutoDrawLooper looper(this, fProps, paint, true); \ |
| 598 while (looper.next(type)) { \ | 606 while (looper.next(type)) { \ |
| 599 SkDrawIter iter(this); | 607 SkDrawIter iter(this); |
| 600 | 608 |
| 601 #define LOOPER_BEGIN(paint, type, bounds) \ | 609 #define LOOPER_BEGIN(paint, type, bounds) \ |
| 602 this->predrawNotify(); \ | 610 this->predrawNotify(); \ |
| 603 AutoDrawLooper looper(this, fProps, paint, false, bounds); \ | 611 AutoDrawLooper looper(this, fProps, paint, false, bounds); \ |
| 604 while (looper.next(type)) { \ | 612 while (looper.next(type)) { \ |
| (...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1397 SkDEBUGCODE(bitmap.validate();) | 1405 SkDEBUGCODE(bitmap.validate();) |
| 1398 | 1406 |
| 1399 SkPaint tmp; | 1407 SkPaint tmp; |
| 1400 if (nullptr == paint) { | 1408 if (nullptr == paint) { |
| 1401 paint = &tmp; | 1409 paint = &tmp; |
| 1402 } | 1410 } |
| 1403 | 1411 |
| 1404 LOOPER_BEGIN_DRAWDEVICE(*paint, SkDrawFilter::kBitmap_Type) | 1412 LOOPER_BEGIN_DRAWDEVICE(*paint, SkDrawFilter::kBitmap_Type) |
| 1405 | 1413 |
| 1406 while (iter.next()) { | 1414 while (iter.next()) { |
| 1407 paint = &looper.paint(); | 1415 const SkIPoint pos = { x - iter.getX(), y - iter.getY() }; |
| 1408 SkImageFilter* filter = paint->getImageFilter(); | 1416 iter.fDevice->filterSprite(iter, bitmap, pos.x(), pos.y(), looper.paint( )); |
| 1409 SkIPoint pos = { x - iter.getX(), y - iter.getY() }; | |
| 1410 if (filter && !iter.fDevice->canHandleImageFilter(filter)) { | |
| 1411 SkImageFilter::DeviceProxy proxy(iter.fDevice); | |
| 1412 SkBitmap dst; | |
| 1413 SkIPoint offset = SkIPoint::Make(0, 0); | |
| 1414 SkMatrix matrix = *iter.fMatrix; | |
| 1415 matrix.postTranslate(SkIntToScalar(-pos.x()), SkIntToScalar(-pos.y() )); | |
| 1416 const SkIRect clipBounds = bitmap.bounds(); | |
| 1417 SkAutoTUnref<SkImageFilter::Cache> cache(iter.fDevice->getImageFilte rCache()); | |
| 1418 SkImageFilter::Context ctx(matrix, clipBounds, cache.get(), | |
| 1419 SkImageFilter::kApprox_SizeConstraint); | |
| 1420 if (filter->filterImage(&proxy, bitmap, ctx, &dst, &offset)) { | |
| 1421 SkPaint tmpUnfiltered(*paint); | |
| 1422 tmpUnfiltered.setImageFilter(nullptr); | |
| 1423 iter.fDevice->drawSprite(iter, dst, pos.x() + offset.x(), pos.y( ) + offset.y(), | |
| 1424 tmpUnfiltered); | |
| 1425 } | |
| 1426 } else { | |
| 1427 iter.fDevice->drawSprite(iter, bitmap, pos.x(), pos.y(), *paint); | |
| 1428 } | |
| 1429 } | 1417 } |
| 1430 LOOPER_END | 1418 LOOPER_END |
| 1431 } | 1419 } |
| 1432 | 1420 |
| 1433 ///////////////////////////////////////////////////////////////////////////// | 1421 ///////////////////////////////////////////////////////////////////////////// |
| 1434 void SkCanvas::translate(SkScalar dx, SkScalar dy) { | 1422 void SkCanvas::translate(SkScalar dx, SkScalar dy) { |
| 1435 SkMatrix m; | 1423 SkMatrix m; |
| 1436 m.setTranslate(dx, dy); | 1424 m.setTranslate(dx, dy); |
| 1437 this->concat(m); | 1425 this->concat(m); |
| 1438 } | 1426 } |
| (...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2190 | 2178 |
| 2191 LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, bounds) | 2179 LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, bounds) |
| 2192 | 2180 |
| 2193 while (iter.next()) { | 2181 while (iter.next()) { |
| 2194 iter.fDevice->drawPath(iter, path, looper.paint()); | 2182 iter.fDevice->drawPath(iter, path, looper.paint()); |
| 2195 } | 2183 } |
| 2196 | 2184 |
| 2197 LOOPER_END | 2185 LOOPER_END |
| 2198 } | 2186 } |
| 2199 | 2187 |
| 2188 bool SkCanvas::canCallFilterSprite(const SkRect& bounds, const SkPaint& paint) { | |
| 2189 #ifdef SK_SUPPORT_LEGACY_LAYER_BITMAP_IMAGEFILTERS | |
| 2190 return false; | |
| 2191 #endif | |
| 2192 | |
| 2193 if (!paint.getImageFilter()) { | |
| 2194 return false; | |
| 2195 } | |
| 2196 | |
| 2197 const SkMatrix& ctm = this->getTotalMatrix(); | |
| 2198 if (ctm.getType() & ~SkMatrix::kTranslate_Mask) { | |
|
Stephen White
2015/12/04 19:22:51
Don't we also need to ensure that the translation
reed1
2015/12/04 19:33:29
Good question. I *think* we ignore fractional tran
reed1
2015/12/04 19:44:03
Checked. We do not respect fractional translate to
Stephen White
2015/12/04 20:18:16
Thanks for checking. Perhaps we should be using Sk
| |
| 2199 return false; | |
| 2200 } | |
| 2201 | |
| 2202 // Currently we can only use the filterSprite code if we are clipped to the bitmap's bounds. | |
| 2203 // Once we can filter and the filter will return a result larger than itself , we should be | |
| 2204 // able to remove this constraint. | |
| 2205 // skbug.com/4526 | |
| 2206 // | |
| 2207 SkPoint pt; | |
| 2208 ctm.mapXY(bounds.x(), bounds.y(), &pt); | |
| 2209 SkIRect ibounds = bounds.makeOffset(pt.fX, pt.fY).round(); | |
| 2210 return ibounds.contains(fMCRec->fRasterClip.getBounds()); | |
| 2211 } | |
| 2212 | |
| 2200 void SkCanvas::onDrawImage(const SkImage* image, SkScalar x, SkScalar y, const S kPaint* paint) { | 2213 void SkCanvas::onDrawImage(const SkImage* image, SkScalar x, SkScalar y, const S kPaint* paint) { |
| 2201 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImage()"); | 2214 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImage()"); |
| 2202 SkRect bounds = SkRect::MakeXYWH(x, y, | 2215 SkRect bounds = SkRect::MakeXYWH(x, y, |
| 2203 SkIntToScalar(image->width()), SkIntToScala r(image->height())); | 2216 SkIntToScalar(image->width()), SkIntToScala r(image->height())); |
| 2204 if (nullptr == paint || paint->canComputeFastBounds()) { | 2217 if (nullptr == paint || paint->canComputeFastBounds()) { |
| 2205 SkRect tmp = bounds; | 2218 SkRect tmp = bounds; |
| 2206 if (paint) { | 2219 if (paint) { |
| 2207 paint->computeFastBounds(tmp, &tmp); | 2220 paint->computeFastBounds(tmp, &tmp); |
| 2208 } | 2221 } |
| 2209 if (this->quickReject(tmp)) { | 2222 if (this->quickReject(tmp)) { |
| 2210 return; | 2223 return; |
| 2211 } | 2224 } |
| 2212 } | 2225 } |
| 2213 | 2226 |
| 2214 SkLazyPaint lazy; | 2227 SkLazyPaint lazy; |
| 2215 if (nullptr == paint) { | 2228 if (nullptr == paint) { |
| 2216 paint = lazy.init(); | 2229 paint = lazy.init(); |
| 2217 } | 2230 } |
| 2218 | 2231 |
| 2219 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &bounds) | 2232 const bool drawAsSprite = this->canCallFilterSprite(bounds, *paint); |
| 2220 | 2233 LOOPER_BEGIN_DRAWBITMAP(*paint, drawAsSprite, &bounds) |
| 2234 | |
| 2221 while (iter.next()) { | 2235 while (iter.next()) { |
| 2222 iter.fDevice->drawImage(iter, image, x, y, looper.paint()); | 2236 const SkPaint& pnt = looper.paint(); |
| 2237 if (drawAsSprite && pnt.getImageFilter()) { | |
| 2238 SkBitmap bitmap; | |
| 2239 if (as_IB(image)->asBitmapForImageFilters(&bitmap)) { | |
| 2240 SkPoint pt; | |
| 2241 iter.fMatrix->mapXY(x, y, &pt); | |
| 2242 iter.fDevice->filterSprite(iter, bitmap, | |
| 2243 SkScalarRoundToInt(pt.fX), | |
| 2244 SkScalarRoundToInt(pt.fY), pnt); | |
| 2245 } | |
| 2246 } else { | |
| 2247 iter.fDevice->drawImage(iter, image, x, y, pnt); | |
| 2248 } | |
| 2223 } | 2249 } |
| 2224 | 2250 |
| 2225 LOOPER_END | 2251 LOOPER_END |
| 2226 } | 2252 } |
| 2227 | 2253 |
| 2228 void SkCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const Sk Rect& dst, | 2254 void SkCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const Sk Rect& dst, |
| 2229 const SkPaint* paint, SrcRectConstraint constrain t) { | 2255 const SkPaint* paint, SrcRectConstraint constrain t) { |
| 2230 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImageRect()"); | 2256 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImageRect()"); |
| 2231 SkRect storage; | 2257 SkRect storage; |
| 2232 const SkRect* bounds = &dst; | 2258 const SkRect* bounds = &dst; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2274 if (paint->canComputeFastBounds()) { | 2300 if (paint->canComputeFastBounds()) { |
| 2275 bitmap.getBounds(&storage); | 2301 bitmap.getBounds(&storage); |
| 2276 matrix.mapRect(&storage); | 2302 matrix.mapRect(&storage); |
| 2277 SkRect tmp = storage; | 2303 SkRect tmp = storage; |
| 2278 if (this->quickReject(paint->computeFastBounds(tmp, &tmp))) { | 2304 if (this->quickReject(paint->computeFastBounds(tmp, &tmp))) { |
| 2279 return; | 2305 return; |
| 2280 } | 2306 } |
| 2281 bounds = &storage; | 2307 bounds = &storage; |
| 2282 } | 2308 } |
| 2283 | 2309 |
| 2284 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, bounds) | 2310 const bool drawAsSprite = bounds && this->canCallFilterSprite(*bounds, *pain t); |
| 2311 LOOPER_BEGIN_DRAWBITMAP(*paint, drawAsSprite, bounds) | |
| 2285 | 2312 |
| 2286 while (iter.next()) { | 2313 while (iter.next()) { |
| 2287 iter.fDevice->drawBitmap(iter, bitmap, matrix, looper.paint()); | 2314 const SkPaint& pnt = looper.paint(); |
| 2315 if (drawAsSprite && pnt.getImageFilter()) { | |
| 2316 SkPoint pt; | |
| 2317 iter.fMatrix->mapXY(x, y, &pt); | |
| 2318 iter.fDevice->filterSprite(iter, bitmap, | |
| 2319 SkScalarRoundToInt(pt.fX), | |
| 2320 SkScalarRoundToInt(pt.fY), pnt); | |
| 2321 } else { | |
| 2322 iter.fDevice->drawBitmap(iter, bitmap, matrix, looper.paint()); | |
| 2323 } | |
| 2288 } | 2324 } |
| 2289 | 2325 |
| 2290 LOOPER_END | 2326 LOOPER_END |
| 2291 } | 2327 } |
| 2292 | 2328 |
| 2293 // this one is non-virtual, so it can be called safely by other canvas apis | 2329 // this one is non-virtual, so it can be called safely by other canvas apis |
| 2294 void SkCanvas::internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, | 2330 void SkCanvas::internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, |
| 2295 const SkRect& dst, const SkPaint* paint, | 2331 const SkRect& dst, const SkPaint* paint, |
| 2296 SrcRectConstraint constraint) { | 2332 SrcRectConstraint constraint) { |
| 2297 if (bitmap.drawsNothing() || dst.isEmpty()) { | 2333 if (bitmap.drawsNothing() || dst.isEmpty()) { |
| 2298 return; | 2334 return; |
| 2299 } | 2335 } |
| (...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2963 } | 2999 } |
| 2964 | 3000 |
| 2965 if (matrix) { | 3001 if (matrix) { |
| 2966 canvas->concat(*matrix); | 3002 canvas->concat(*matrix); |
| 2967 } | 3003 } |
| 2968 } | 3004 } |
| 2969 | 3005 |
| 2970 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 3006 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
| 2971 fCanvas->restoreToCount(fSaveCount); | 3007 fCanvas->restoreToCount(fSaveCount); |
| 2972 } | 3008 } |
| OLD | NEW |