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)) { \ | |
robertphillips
2015/12/02 22:37:18
indent this ?
reed1
2015/12/03 21:26:51
Done.
| |
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 if (true) { |
Stephen White
2015/12/02 23:45:15
Remove this?
reed1
2015/12/03 21:26:51
Done.
| |
1408 SkImageFilter* filter = paint->getImageFilter(); | 1416 const SkPaint& pnt = looper.paint(); |
1409 SkIPoint pos = { x - iter.getX(), y - iter.getY() }; | 1417 const SkIPoint pos = { x - iter.getX(), y - iter.getY() }; |
1410 if (filter && !iter.fDevice->canHandleImageFilter(filter)) { | 1418 if (iter.fDevice->canCallFilterSprite(nullptr, pnt)) { |
1411 SkImageFilter::DeviceProxy proxy(iter.fDevice); | 1419 iter.fDevice->filterSprite(iter, bitmap, pos.x(), pos.y(), |
robertphillips
2015/12/02 22:37:18
looper.paint() -> pnt & all on one line ?
Stephen White
2015/12/02 23:45:15
Do we have any benches which exercise these differ
reed1
2015/12/03 21:26:51
Done.
reed1
2015/12/03 21:26:51
Done.
| |
1412 SkBitmap dst; | 1420 looper.paint()); |
1413 SkIPoint offset = SkIPoint::Make(0, 0); | 1421 } else { |
1414 SkMatrix matrix = *iter.fMatrix; | 1422 iter.fDevice->drawSprite(iter, bitmap, pos.x(), pos.y(), pnt); |
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 } | 1423 } |
1426 } else { | 1424 } else { |
1427 iter.fDevice->drawSprite(iter, bitmap, pos.x(), pos.y(), *paint); | 1425 paint = &looper.paint(); |
1426 SkImageFilter* filter = paint->getImageFilter(); | |
1427 SkIPoint pos = { x - iter.getX(), y - iter.getY() }; | |
1428 if (filter && !iter.fDevice->canHandleImageFilter(filter)) { | |
1429 SkImageFilter::DeviceProxy proxy(iter.fDevice); | |
1430 SkBitmap dst; | |
1431 SkIPoint offset = SkIPoint::Make(0, 0); | |
1432 SkMatrix matrix = *iter.fMatrix; | |
1433 matrix.postTranslate(SkIntToScalar(-pos.x()), SkIntToScalar(-pos .y())); | |
1434 const SkIRect clipBounds = bitmap.bounds(); | |
1435 SkAutoTUnref<SkImageFilter::Cache> cache(iter.fDevice->getImageF ilterCache()); | |
1436 SkImageFilter::Context ctx(matrix, clipBounds, cache.get(), | |
1437 SkImageFilter::kApprox_SizeConstraint ); | |
1438 if (filter->filterImage(&proxy, bitmap, ctx, &dst, &offset)) { | |
1439 SkPaint tmpUnfiltered(*paint); | |
1440 tmpUnfiltered.setImageFilter(nullptr); | |
1441 iter.fDevice->drawSprite(iter, dst, pos.x() + offset.x(), po s.y() + offset.y(), | |
1442 tmpUnfiltered); | |
1443 } | |
1444 } else { | |
1445 iter.fDevice->drawSprite(iter, bitmap, pos.x(), pos.y(), *paint) ; | |
1446 } | |
1428 } | 1447 } |
1429 } | 1448 } |
1430 LOOPER_END | 1449 LOOPER_END |
1431 } | 1450 } |
1432 | 1451 |
1433 ///////////////////////////////////////////////////////////////////////////// | 1452 ///////////////////////////////////////////////////////////////////////////// |
1434 void SkCanvas::translate(SkScalar dx, SkScalar dy) { | 1453 void SkCanvas::translate(SkScalar dx, SkScalar dy) { |
1435 SkMatrix m; | 1454 SkMatrix m; |
1436 m.setTranslate(dx, dy); | 1455 m.setTranslate(dx, dy); |
1437 this->concat(m); | 1456 this->concat(m); |
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2190 | 2209 |
2191 LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, bounds) | 2210 LOOPER_BEGIN(paint, SkDrawFilter::kPath_Type, bounds) |
2192 | 2211 |
2193 while (iter.next()) { | 2212 while (iter.next()) { |
2194 iter.fDevice->drawPath(iter, path, looper.paint()); | 2213 iter.fDevice->drawPath(iter, path, looper.paint()); |
2195 } | 2214 } |
2196 | 2215 |
2197 LOOPER_END | 2216 LOOPER_END |
2198 } | 2217 } |
2199 | 2218 |
2219 bool SkCanvas::canCallFilterSprite(const SkRect& bounds, const SkPaint& paint) { | |
2220 #ifdef SK_SUPPORT_LEGACY_LAYER_BITMAP_IMAGEFILTERS | |
2221 return false; | |
2222 #endif | |
2223 | |
2224 const SkMatrix& ctm = this->getTotalMatrix(); | |
2225 SkBaseDevice* baseDevice = this->getDevice(); | |
2226 bool handleFilter = baseDevice->canCallFilterSprite(&ctm, paint); | |
2227 // Currently we can only use the filterSprite code if we are clipped to the bitmap's bounds. | |
2228 // Once we can filter and the filter will return a result larger than itself , we should be | |
2229 // able to remove this constraint. | |
2230 if (handleFilter) { | |
2231 SkPoint pt; | |
2232 ctm.mapXY(bounds.x(), bounds.y(), &pt); | |
2233 SkIRect ibounds = bounds.makeOffset(pt.fX, pt.fY).round(); | |
2234 if (!ibounds.contains(fMCRec->fRasterClip.getBounds())) { | |
2235 handleFilter = false; | |
2236 } else { | |
2237 // SkDebugf("------- handleFilter survived!\n"); | |
2238 } | |
2239 } | |
2240 return handleFilter; | |
2241 } | |
2242 | |
2200 void SkCanvas::onDrawImage(const SkImage* image, SkScalar x, SkScalar y, const S kPaint* paint) { | 2243 void SkCanvas::onDrawImage(const SkImage* image, SkScalar x, SkScalar y, const S kPaint* paint) { |
2201 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImage()"); | 2244 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImage()"); |
2202 SkRect bounds = SkRect::MakeXYWH(x, y, | 2245 SkRect bounds = SkRect::MakeXYWH(x, y, |
2203 SkIntToScalar(image->width()), SkIntToScala r(image->height())); | 2246 SkIntToScalar(image->width()), SkIntToScala r(image->height())); |
2204 if (nullptr == paint || paint->canComputeFastBounds()) { | 2247 if (nullptr == paint || paint->canComputeFastBounds()) { |
2205 SkRect tmp = bounds; | 2248 SkRect tmp = bounds; |
2206 if (paint) { | 2249 if (paint) { |
2207 paint->computeFastBounds(tmp, &tmp); | 2250 paint->computeFastBounds(tmp, &tmp); |
2208 } | 2251 } |
2209 if (this->quickReject(tmp)) { | 2252 if (this->quickReject(tmp)) { |
2210 return; | 2253 return; |
2211 } | 2254 } |
2212 } | 2255 } |
2213 | 2256 |
2214 SkLazyPaint lazy; | 2257 SkLazyPaint lazy; |
2215 if (nullptr == paint) { | 2258 if (nullptr == paint) { |
2216 paint = lazy.init(); | 2259 paint = lazy.init(); |
2217 } | 2260 } |
2218 | 2261 |
2219 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &bounds) | 2262 const bool handleFilter = this->canCallFilterSprite(bounds, *paint); |
2220 | 2263 LOOPER_BEGIN_DRAWBITMAP(*paint, handleFilter, &bounds) |
2264 | |
2221 while (iter.next()) { | 2265 while (iter.next()) { |
2222 iter.fDevice->drawImage(iter, image, x, y, looper.paint()); | 2266 const SkPaint& pnt = looper.paint(); |
2267 if (handleFilter && pnt.getImageFilter()) { | |
2268 SkBitmap bitmap; | |
2269 if (as_IB(image)->asBitmapForImageFilters(&bitmap)) { | |
2270 SkPoint pt; | |
2271 iter.fMatrix->mapXY(x, y, &pt); | |
2272 iter.fDevice->filterSprite(iter, bitmap, | |
2273 SkScalarRoundToInt(pt.fX), | |
2274 SkScalarRoundToInt(pt.fY), pnt); | |
2275 } | |
2276 } else { | |
2277 iter.fDevice->drawImage(iter, image, x, y, pnt); | |
2278 } | |
2223 } | 2279 } |
2224 | 2280 |
2225 LOOPER_END | 2281 LOOPER_END |
2226 } | 2282 } |
2227 | 2283 |
2228 void SkCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const Sk Rect& dst, | 2284 void SkCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const Sk Rect& dst, |
2229 const SkPaint* paint, SrcRectConstraint constrain t) { | 2285 const SkPaint* paint, SrcRectConstraint constrain t) { |
2230 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImageRect()"); | 2286 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImageRect()"); |
2231 SkRect storage; | 2287 SkRect storage; |
2232 const SkRect* bounds = &dst; | 2288 const SkRect* bounds = &dst; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2274 if (paint->canComputeFastBounds()) { | 2330 if (paint->canComputeFastBounds()) { |
2275 bitmap.getBounds(&storage); | 2331 bitmap.getBounds(&storage); |
2276 matrix.mapRect(&storage); | 2332 matrix.mapRect(&storage); |
2277 SkRect tmp = storage; | 2333 SkRect tmp = storage; |
2278 if (this->quickReject(paint->computeFastBounds(tmp, &tmp))) { | 2334 if (this->quickReject(paint->computeFastBounds(tmp, &tmp))) { |
2279 return; | 2335 return; |
2280 } | 2336 } |
2281 bounds = &storage; | 2337 bounds = &storage; |
2282 } | 2338 } |
2283 | 2339 |
2284 LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, bounds) | 2340 const bool handleFilter = bounds && this->canCallFilterSprite(*bounds, *pain t); |
2341 LOOPER_BEGIN_DRAWBITMAP(*paint, handleFilter, bounds) | |
2285 | 2342 |
2286 while (iter.next()) { | 2343 while (iter.next()) { |
2287 iter.fDevice->drawBitmap(iter, bitmap, matrix, looper.paint()); | 2344 const SkPaint& pnt = looper.paint(); |
2345 if (handleFilter && pnt.getImageFilter()) { | |
2346 SkPoint pt; | |
2347 iter.fMatrix->mapXY(x, y, &pt); | |
2348 iter.fDevice->filterSprite(iter, bitmap, | |
2349 SkScalarRoundToInt(pt.fX), | |
2350 SkScalarRoundToInt(pt.fY), pnt); | |
2351 } else { | |
2352 iter.fDevice->drawBitmap(iter, bitmap, matrix, looper.paint()); | |
2353 } | |
2288 } | 2354 } |
2289 | 2355 |
2290 LOOPER_END | 2356 LOOPER_END |
2291 } | 2357 } |
2292 | 2358 |
2293 // this one is non-virtual, so it can be called safely by other canvas apis | 2359 // 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, | 2360 void SkCanvas::internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, |
2295 const SkRect& dst, const SkPaint* paint, | 2361 const SkRect& dst, const SkPaint* paint, |
2296 SrcRectConstraint constraint) { | 2362 SrcRectConstraint constraint) { |
2297 if (bitmap.drawsNothing() || dst.isEmpty()) { | 2363 if (bitmap.drawsNothing() || dst.isEmpty()) { |
2298 return; | 2364 return; |
2299 } | 2365 } |
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2963 } | 3029 } |
2964 | 3030 |
2965 if (matrix) { | 3031 if (matrix) { |
2966 canvas->concat(*matrix); | 3032 canvas->concat(*matrix); |
2967 } | 3033 } |
2968 } | 3034 } |
2969 | 3035 |
2970 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 3036 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
2971 fCanvas->restoreToCount(fSaveCount); | 3037 fCanvas->restoreToCount(fSaveCount); |
2972 } | 3038 } |
OLD | NEW |