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" |
(...skipping 1435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1446 | 1446 |
1447 ///////////////////////////////////////////////////////////////////////////// | 1447 ///////////////////////////////////////////////////////////////////////////// |
1448 | 1448 |
1449 void SkCanvas::internalDrawDevice(SkBaseDevice* srcDev, int x, int y, const SkPa int* paint) { | 1449 void SkCanvas::internalDrawDevice(SkBaseDevice* srcDev, int x, int y, const SkPa int* paint) { |
1450 SkPaint tmp; | 1450 SkPaint tmp; |
1451 if (nullptr == paint) { | 1451 if (nullptr == paint) { |
1452 paint = &tmp; | 1452 paint = &tmp; |
1453 } | 1453 } |
1454 | 1454 |
1455 LOOPER_BEGIN_DRAWDEVICE(*paint, SkDrawFilter::kBitmap_Type) | 1455 LOOPER_BEGIN_DRAWDEVICE(*paint, SkDrawFilter::kBitmap_Type) |
1456 | |
1456 while (iter.next()) { | 1457 while (iter.next()) { |
1457 SkBaseDevice* dstDev = iter.fDevice; | 1458 SkBaseDevice* dstDev = iter.fDevice; |
1458 paint = &looper.paint(); | 1459 paint = &looper.paint(); |
1459 SkImageFilter* filter = paint->getImageFilter(); | 1460 SkImageFilter* filter = paint->getImageFilter(); |
1460 SkIPoint pos = { x - iter.getX(), y - iter.getY() }; | 1461 SkIPoint pos = { x - iter.getX(), y - iter.getY() }; |
robertphillips
2016/07/18 17:01:58
Why not just call drawSpecial in both cases ?
reed1
2016/07/18 22:06:07
PDFDevice doesn't return a special (he will have r
| |
1461 if (filter) { | 1462 if (filter) { |
1462 const SkBitmap& srcBM = srcDev->accessBitmap(false); | 1463 dstDev->drawSpecial(iter, srcDev->asSpecial().get(), pos.x(), pos.y( ), *paint); |
1463 dstDev->drawSpriteWithFilter(iter, srcBM, pos.x(), pos.y(), *paint); | |
1464 } else { | 1464 } else { |
1465 dstDev->drawDevice(iter, srcDev, pos.x(), pos.y(), *paint); | 1465 dstDev->drawDevice(iter, srcDev, pos.x(), pos.y(), *paint); |
1466 } | 1466 } |
1467 } | 1467 } |
1468 | |
1468 LOOPER_END | 1469 LOOPER_END |
1469 } | 1470 } |
1470 | 1471 |
1471 ///////////////////////////////////////////////////////////////////////////// | 1472 ///////////////////////////////////////////////////////////////////////////// |
1472 | 1473 |
1473 void SkCanvas::translate(SkScalar dx, SkScalar dy) { | 1474 void SkCanvas::translate(SkScalar dx, SkScalar dy) { |
1474 SkMatrix m; | 1475 SkMatrix m; |
1475 m.setTranslate(dx, dy); | 1476 m.setTranslate(dx, dy); |
1476 this->concat(m); | 1477 this->concat(m); |
1477 } | 1478 } |
(...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2305 if (this->quickReject(tmp)) { | 2306 if (this->quickReject(tmp)) { |
2306 return; | 2307 return; |
2307 } | 2308 } |
2308 } | 2309 } |
2309 | 2310 |
2310 SkLazyPaint lazy; | 2311 SkLazyPaint lazy; |
2311 if (nullptr == paint) { | 2312 if (nullptr == paint) { |
2312 paint = lazy.init(); | 2313 paint = lazy.init(); |
2313 } | 2314 } |
2314 | 2315 |
2316 sk_sp<SkSpecialImage> special; | |
2315 bool drawAsSprite = this->canDrawBitmapAsSprite(x, y, image->width(), image- >height(), | 2317 bool drawAsSprite = this->canDrawBitmapAsSprite(x, y, image->width(), image- >height(), |
2316 *paint); | 2318 *paint); |
2317 if (drawAsSprite && paint->getImageFilter()) { | 2319 if (drawAsSprite && paint->getImageFilter()) { |
2318 SkBitmap bitmap; | 2320 // Until imagefilters are updated, they cannot handle any src type but N 32... |
2319 if (!as_IB(image)->asBitmapForImageFilters(&bitmap)) { | 2321 if (!as_IB(image)->canBeImageFiltered()) { |
2320 drawAsSprite = false; | 2322 drawAsSprite = false; |
2321 } else{ | 2323 } else { |
2322 // Until imagefilters are updated, they cannot handle any src type b ut N32... | 2324 special = this->getDevice()->makeSpecial(image); |
2323 if (bitmap.info().colorType() != kN32_SkColorType || bitmap.info().g ammaCloseToSRGB()) { | 2325 if (!special) { |
2324 drawAsSprite = false; | 2326 drawAsSprite = false; |
2325 } | 2327 } |
2326 } | 2328 } |
2327 } | 2329 } |
2328 | 2330 |
2329 LOOPER_BEGIN_DRAWBITMAP(*paint, drawAsSprite, &bounds) | 2331 LOOPER_BEGIN_DRAWBITMAP(*paint, drawAsSprite, &bounds) |
2330 | 2332 |
2331 while (iter.next()) { | 2333 while (iter.next()) { |
2332 const SkPaint& pnt = looper.paint(); | 2334 const SkPaint& pnt = looper.paint(); |
robertphillips
2016/07/18 17:01:58
ditch drawAsSprite and just use special here ?
reed1
2016/07/19 15:07:41
Done.
| |
2333 if (drawAsSprite && pnt.getImageFilter()) { | 2335 if (drawAsSprite && pnt.getImageFilter()) { |
2334 SkBitmap bitmap; | 2336 SkPoint pt; |
2335 if (as_IB(image)->asBitmapForImageFilters(&bitmap)) { | 2337 iter.fMatrix->mapXY(x, y, &pt); |
2336 SkPoint pt; | 2338 iter.fDevice->drawSpecial(iter, special.get(), |
2337 iter.fMatrix->mapXY(x, y, &pt); | 2339 SkScalarRoundToInt(pt.fX), |
2338 iter.fDevice->drawSpriteWithFilter(iter, bitmap, | 2340 SkScalarRoundToInt(pt.fY), pnt); |
2339 SkScalarRoundToInt(pt.fX), | |
2340 SkScalarRoundToInt(pt.fY), pn t); | |
2341 } | |
2342 } else { | 2341 } else { |
2343 iter.fDevice->drawImage(iter, image, x, y, pnt); | 2342 iter.fDevice->drawImage(iter, image, x, y, pnt); |
2344 } | 2343 } |
2345 } | 2344 } |
2346 | 2345 |
2347 LOOPER_END | 2346 LOOPER_END |
2348 } | 2347 } |
2349 | 2348 |
2350 void SkCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const Sk Rect& dst, | 2349 void SkCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const Sk Rect& dst, |
2351 const SkPaint* paint, SrcRectConstraint constrain t) { | 2350 const SkPaint* paint, SrcRectConstraint constrain t) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2394 if (paint->canComputeFastBounds()) { | 2393 if (paint->canComputeFastBounds()) { |
2395 bitmap.getBounds(&storage); | 2394 bitmap.getBounds(&storage); |
2396 matrix.mapRect(&storage); | 2395 matrix.mapRect(&storage); |
2397 SkRect tmp = storage; | 2396 SkRect tmp = storage; |
2398 if (this->quickReject(paint->computeFastBounds(tmp, &tmp))) { | 2397 if (this->quickReject(paint->computeFastBounds(tmp, &tmp))) { |
2399 return; | 2398 return; |
2400 } | 2399 } |
2401 bounds = &storage; | 2400 bounds = &storage; |
2402 } | 2401 } |
2403 | 2402 |
2403 sk_sp<SkSpecialImage> special; | |
2404 bool drawAsSprite = bounds && this->canDrawBitmapAsSprite(x, y, bitmap.width (), bitmap.height(), | 2404 bool drawAsSprite = bounds && this->canDrawBitmapAsSprite(x, y, bitmap.width (), bitmap.height(), |
2405 *paint); | 2405 *paint); |
2406 if (drawAsSprite && paint->getImageFilter()) { | 2406 if (drawAsSprite && paint->getImageFilter()) { |
2407 // Until imagefilters are updated, they cannot handle any src type but N 32... | 2407 // Until imagefilters are updated, they cannot handle any src type but N 32... |
2408 if (bitmap.info().colorType() != kN32_SkColorType || bitmap.info().gamma CloseToSRGB()) { | 2408 if (bitmap.info().colorType() != kN32_SkColorType || bitmap.info().gamma CloseToSRGB()) { |
2409 drawAsSprite = false; | 2409 drawAsSprite = false; |
2410 } else { | |
2411 special = this->getDevice()->makeSpecial(bitmap); | |
robertphillips
2016/07/18 17:01:58
I think we don't need the following if block
| |
2412 if (!special) { | |
2413 drawAsSprite = false; | |
2414 } | |
2410 } | 2415 } |
2411 } | 2416 } |
2412 | 2417 |
2413 LOOPER_BEGIN_DRAWBITMAP(*paint, drawAsSprite, bounds) | 2418 LOOPER_BEGIN_DRAWBITMAP(*paint, drawAsSprite, bounds) |
2414 | 2419 |
2415 while (iter.next()) { | 2420 while (iter.next()) { |
2416 const SkPaint& pnt = looper.paint(); | 2421 const SkPaint& pnt = looper.paint(); |
2417 if (drawAsSprite && pnt.getImageFilter()) { | 2422 if (special) { |
2418 SkPoint pt; | 2423 SkPoint pt; |
2419 iter.fMatrix->mapXY(x, y, &pt); | 2424 iter.fMatrix->mapXY(x, y, &pt); |
2420 iter.fDevice->drawSpriteWithFilter(iter, bitmap, | 2425 iter.fDevice->drawSpecial(iter, special.get(), |
2421 SkScalarRoundToInt(pt.fX), | 2426 SkScalarRoundToInt(pt.fX), |
2422 SkScalarRoundToInt(pt.fY), pnt); | 2427 SkScalarRoundToInt(pt.fY), pnt); |
2423 } else { | 2428 } else { |
2424 iter.fDevice->drawBitmap(iter, bitmap, matrix, looper.paint()); | 2429 iter.fDevice->drawBitmap(iter, bitmap, matrix, looper.paint()); |
2425 } | 2430 } |
2426 } | 2431 } |
2427 | 2432 |
2428 LOOPER_END | 2433 LOOPER_END |
2429 } | 2434 } |
2430 | 2435 |
2431 // this one is non-virtual, so it can be called safely by other canvas apis | 2436 // this one is non-virtual, so it can be called safely by other canvas apis |
2432 void SkCanvas::internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, | 2437 void SkCanvas::internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, |
2433 const SkRect& dst, const SkPaint* paint, | 2438 const SkRect& dst, const SkPaint* paint, |
2434 SrcRectConstraint constraint) { | 2439 SrcRectConstraint constraint) { |
2435 if (bitmap.drawsNothing() || dst.isEmpty()) { | 2440 if (bitmap.drawsNothing() || dst.isEmpty()) { |
2436 return; | 2441 return; |
2437 } | 2442 } |
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3119 | 3124 |
3120 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 3125 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
3121 fCanvas->restoreToCount(fSaveCount); | 3126 fCanvas->restoreToCount(fSaveCount); |
3122 } | 3127 } |
3123 | 3128 |
3124 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API | 3129 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API |
3125 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) { | 3130 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) { |
3126 return this->makeSurface(info, props).release(); | 3131 return this->makeSurface(info, props).release(); |
3127 } | 3132 } |
3128 #endif | 3133 #endif |
OLD | NEW |