Chromium Code Reviews| Index: src/gpu/SkGpuDevice.cpp |
| diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp |
| index 6a317d5edc057a36aa9a090c26152a42bb4f25fb..b6341335c945b435610c1aec93fb1158ca32559e 100644 |
| --- a/src/gpu/SkGpuDevice.cpp |
| +++ b/src/gpu/SkGpuDevice.cpp |
| @@ -13,6 +13,7 @@ |
| #include "GrFontScaler.h" |
| #include "GrGpu.h" |
| #include "GrGpuResourcePriv.h" |
| +#include "GrImageIDTextureAdjuster.h" |
| #include "GrLayerHoister.h" |
| #include "GrRecordReplaceDraw.h" |
| #include "GrStrokeInfo.h" |
| @@ -847,6 +848,20 @@ void SkGpuDevice::drawBitmap(const SkDraw& origDraw, |
| concat.setConcat(*draw->fMatrix, m); |
| draw.writable()->fMatrix = &concat; |
| } |
| + |
| + GrTexture* texture = bitmap.getTexture(); |
| + if (texture) { |
| + CHECK_SHOULD_DRAW(*draw); |
| + // src and dst rects are the same. |
| + SkRect rect = SkRect::MakeWH(SkIntToScalar(bitmap.width()), SkIntToScalar(bitmap.height())); |
| + // Since the src rect is the bitmap dimensions, no need to enforce a bleed constraint. |
| + static const SkCanvas::SrcRectConstraint kSrcRectConstraint = |
| + SkCanvas::kFast_SrcRectConstraint; |
| + bool alphaBitmap = kAlpha_8_SkColorType == bitmap.colorType(); |
| + this->drawTextureRect(&GrBitmapTextureAdjuster(&bitmap), alphaBitmap, rect, |
| + rect, *draw->fMatrix, fClip, paint, kSrcRectConstraint); |
| + return; |
| + } |
| this->drawBitmapCommon(*draw, bitmap, nullptr, nullptr, paint, SkCanvas::kStrict_SrcRectConstraint); |
| } |
| @@ -1184,7 +1199,7 @@ void SkGpuDevice::drawTiledBitmap(const SkBitmap& bitmap, |
| const SkRect& srcRect, |
| const SkIRect& clippedSrcIRect, |
| const GrTextureParams& params, |
| - const SkPaint& paint, |
| + const SkPaint& origPaint, |
| SkCanvas::SrcRectConstraint constraint, |
| int tileSize, |
| bool bicubic) { |
| @@ -1193,6 +1208,15 @@ void SkGpuDevice::drawTiledBitmap(const SkBitmap& bitmap, |
| // at each tile in cases where 'bitmap' holds an SkDiscardablePixelRef that |
| // is larger than the limit of the discardable memory pool. |
| SkAutoLockPixels alp(bitmap); |
| + |
| + const SkPaint* paint = &origPaint; |
| + SkPaint tempPaint; |
| + if (origPaint.isAntiAlias() && !fRenderTarget->isUnifiedMultisampled()) { |
| + // Drop antialiasing to avoid seams at tile boundaries. |
| + tempPaint = origPaint; |
| + tempPaint.setAntiAlias(false); |
| + paint = &tempPaint; |
| + } |
| SkRect clippedSrcRect = SkRect::Make(clippedSrcIRect); |
| int nx = bitmap.width() / tileSize; |
| @@ -1254,7 +1278,7 @@ void SkGpuDevice::drawTiledBitmap(const SkBitmap& bitmap, |
| viewM, |
| tileR, |
| paramsTemp, |
| - paint, |
| + *paint, |
| constraint, |
| bicubic, |
| needsTextureDomain); |
| @@ -1482,6 +1506,43 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, |
| void SkGpuDevice::drawBitmapRect(const SkDraw& origDraw, const SkBitmap& bitmap, |
| const SkRect* src, const SkRect& dst, |
| const SkPaint& paint, SkCanvas::SrcRectConstraint constraint) { |
| + SkBitmap bm; |
| + if (GrTexture* tex = bitmap.getTexture()) { |
| + CHECK_SHOULD_DRAW(origDraw); |
| + // Will hold the src dst rect after clipping against the image bounds. |
| + SkRect clippedSrcRect; |
| + SkRect clippedDstRect; |
| + SkIRect contentArea = SkIRect::MakeWH(bitmap.width(), bitmap.height()); |
| + bool alphaBitmap = GrPixelConfigIsAlphaOnly(tex->config()); |
| + if (src) { |
| + SkRect bmpSrcBounds = SkRect::MakeIWH(bitmap.width(), bitmap.height()); |
| + if (!bmpSrcBounds.contains(*src)) { |
| + clippedSrcRect = *src; |
| + if (!clippedSrcRect.intersect(bmpSrcBounds)) { |
| + return; |
| + } |
| + SkMatrix srcToDstMatrix; |
| + srcToDstMatrix.setRectToRect(*src, dst, SkMatrix::kFill_ScaleToFit); |
| + srcToDstMatrix.mapRect(&clippedDstRect, clippedSrcRect); |
| + // Since went through the trouble to compute the local matrix, call this version and |
| + // return. |
| + this->drawTextureRectPrecomputedLocalMatrix( |
| + &GrBitmapTextureAdjuster(&bitmap), alphaBitmap, clippedSrcRect, clippedDstRect, |
| + *origDraw.fMatrix, srcToDstMatrix, fClip, paint, constraint); |
| + return; |
| + } else { |
| + clippedSrcRect = *src; |
| + clippedDstRect = dst; |
| + } |
| + } else { |
| + clippedSrcRect = SkRect::MakeWH(SkIntToScalar(bitmap.width()), |
| + SkIntToScalar(bitmap.height())); |
| + } |
| + this->drawTextureRect(&GrBitmapTextureAdjuster(&bitmap), alphaBitmap, clippedSrcRect, |
| + clippedDstRect, *origDraw.fMatrix, fClip, paint, constraint); |
| + return; |
| + } |
| + |
| SkMatrix matrix; |
| SkRect bitmapBounds, tmpSrc; |
| @@ -1643,7 +1704,17 @@ void SkGpuDevice::drawImage(const SkDraw& draw, const SkImage* image, SkScalar x |
| const SkPaint& paint) { |
| SkBitmap bm; |
| if (GrTexture* tex = as_IB(image)->peekTexture()) { |
| - GrWrapTextureInBitmap(tex, image->width(), image->height(), image->isOpaque(), &bm); |
| + CHECK_SHOULD_DRAW(draw); |
| + SkRect srcRect = SkRect::MakeIWH(image->width(), image->height()); |
| + SkRect dstRect = srcRect; |
| + dstRect.offset(x, y); |
| + bool alphaBitmap = GrPixelConfigIsAlphaOnly(tex->config()); |
| + // Since the src rect is the image dimensions, no need to enforce a bleed constraint. |
| + static const SkCanvas::SrcRectConstraint kSrcRectConstraint = |
| + SkCanvas::kFast_SrcRectConstraint; |
| + this->drawTextureRect(&GrImageTextureAdjuster(as_IB(image)), alphaBitmap, srcRect, dstRect, |
| + *draw.fMatrix, fClip, paint, kSrcRectConstraint); |
| + return; |
| } else { |
| if (this->shouldTileImage(image, nullptr, SkCanvas::kFast_SrcRectConstraint, |
| paint.getFilterQuality(), *draw.fMatrix)) { |
| @@ -1665,21 +1736,51 @@ void SkGpuDevice::drawImageRect(const SkDraw& draw, const SkImage* image, const |
| SkCanvas::SrcRectConstraint constraint) { |
| SkBitmap bm; |
| if (GrTexture* tex = as_IB(image)->peekTexture()) { |
| - GrWrapTextureInBitmap(tex, image->width(), image->height(), image->isOpaque(), &bm); |
| - } else { |
| - SkMatrix viewMatrix = *draw.fMatrix; |
| - viewMatrix.preScale(dst.width() / (src ? src->width() : image->width()), |
| - dst.height() / (src ? src->height() : image->height())); |
| - |
| - if (this->shouldTileImage(image, src, constraint, paint.getFilterQuality(), viewMatrix)) { |
| - // only support tiling as bitmap at the moment, so force raster-version |
| - if (!as_IB(image)->getROPixels(&bm)) { |
| + CHECK_SHOULD_DRAW(draw); |
| + // Will hold the src dst rect after clipping against the image bounds. |
| + SkRect clippedSrcRect; |
| + SkRect clippedDstRect; |
| + bool alphaBitmap = GrPixelConfigIsAlphaOnly(tex->config()); |
| + if (src) { |
| + SkRect imgSrcBounds = SkRect::MakeIWH(image->width(), image->height()); |
| + if (!imgSrcBounds.contains(*src)) { |
| + clippedSrcRect = *src; |
| + if (!clippedSrcRect.intersect(imgSrcBounds)) { |
| + return; |
| + } |
| + SkMatrix srcToDstMatrix; |
| + srcToDstMatrix.setRectToRect(*src, dst, SkMatrix::kFill_ScaleToFit); |
| + srcToDstMatrix.mapRect(&clippedDstRect, clippedSrcRect); |
| + // Since went through the trouble to compute the local matrix, call this version and |
| + // return. |
| + this->drawTextureRectPrecomputedLocalMatrix( |
| + &GrImageTextureAdjuster(as_IB(image)), alphaBitmap, clippedSrcRect, |
| + clippedDstRect, *draw.fMatrix, srcToDstMatrix, fClip, paint, constraint); |
|
joshualitt
2015/11/05 19:53:12
can this be made a helper? or do we want it to be
bsalomon
2015/11/05 20:10:37
I'm not sure I understand what you're asking/sugge
bsalomon
2015/11/06 15:24:26
Done.
|
| return; |
| + } else { |
| + clippedSrcRect = *src; |
| + clippedDstRect = dst; |
| } |
| } else { |
| - if (!wrap_as_bm(this->context(), image, &bm)) { |
| - return; |
| - } |
| + clippedSrcRect = SkRect::MakeWH(SkIntToScalar(image->width()), |
| + SkIntToScalar(image->height())); |
| + clippedDstRect = dst; |
| + } |
| + this->drawTextureRect(&GrImageTextureAdjuster(as_IB(image)), alphaBitmap, clippedSrcRect, |
| + clippedDstRect, *draw.fMatrix, fClip, paint, constraint); |
| + return; |
| + } |
| + SkMatrix viewMatrix = *draw.fMatrix; |
| + viewMatrix.preScale(dst.width() / (src ? src->width() : image->width()), |
| + dst.height() / (src ? src->height() : image->height())); |
| + if (this->shouldTileImage(image, src, constraint, paint.getFilterQuality(), viewMatrix)) { |
| + // only support tiling as bitmap at the moment, so force raster-version |
| + if (!as_IB(image)->getROPixels(&bm)) { |
| + return; |
| + } |
| + } else { |
| + if (!wrap_as_bm(this->context(), image, &bm)) { |
| + return; |
| } |
| } |
| this->drawBitmapRect(draw, bm, src, dst, paint, constraint); |