Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2060)

Unified Diff: Source/platform/graphics/BitmapImage.cpp

Issue 1093673002: Removing the dependency on GraphicsContext for drawing images in 2D canvas (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: pdr corrections + needsrebaselines Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/platform/graphics/BitmapImage.cpp
diff --git a/Source/platform/graphics/BitmapImage.cpp b/Source/platform/graphics/BitmapImage.cpp
index a937da22617ae000cc3bec3b2157c5e1582a433e..d206eb090fd4ba3a2576f5a4de4ece05f84c1ac7 100644
--- a/Source/platform/graphics/BitmapImage.cpp
+++ b/Source/platform/graphics/BitmapImage.cpp
@@ -280,7 +280,23 @@ String BitmapImage::filenameExtension() const
return m_source.filenameExtension();
}
-void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dstRect, const FloatRect& srcRect, SkXfermode::Mode compositeOp, RespectImageOrientationEnum shouldRespectImageOrientation)
+bool BitmapImage::isLazyDecodedBitmap()
+{
+ SkBitmap bitmap;
+ if (!bitmapForCurrentFrame(&bitmap))
+ return false;
+ return DeferredImageDecoder::isLazyDecoded(bitmap);
+}
+
+bool BitmapImage::isImmutableBitmap()
+{
+ SkBitmap bitmap;
+ if (!bitmapForCurrentFrame(&bitmap))
+ return false;
+ return bitmap.isImmutable();
+}
+
+void BitmapImage::draw(SkCanvas* canvas, const SkPaint& paint, const FloatRect& dstRect, const FloatRect& srcRect, RespectImageOrientationEnum shouldRespectImageOrientation, const ImageFilterQualityHelper* filterHelper)
{
TRACE_EVENT0("skia", "BitmapImage::draw");
SkBitmap bitmap;
@@ -298,15 +314,15 @@ void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dstRect, const Fl
if (shouldRespectImageOrientation == RespectImageOrientation)
orientation = frameOrientationAtIndex(m_currentFrame);
- GraphicsContextStateSaver saveContext(*ctxt, false);
+ int initialSaveCount = canvas->getSaveCount();
if (orientation != DefaultImageOrientation) {
- saveContext.save();
+ canvas->save();
// ImageOrientation expects the origin to be at (0, 0)
- ctxt->translate(normDstRect.x(), normDstRect.y());
+ canvas->translate(normDstRect.x(), normDstRect.y());
normDstRect.setLocation(FloatPoint());
- ctxt->concatCTM(orientation.transformFromDefault(normDstRect.size()));
+ canvas->concat(affineTransformToSkMatrix(orientation.transformFromDefault(normDstRect.size())));
if (orientation.usesWidthAsHeight()) {
// The destination rect will have it's width and height already reversed for the orientation of
@@ -315,22 +331,16 @@ void BitmapImage::draw(GraphicsContext* ctxt, const FloatRect& dstRect, const Fl
}
}
- bool isLazyDecoded = DeferredImageDecoder::isLazyDecoded(bitmap);
- bool isOpaque = bitmap.isOpaque();
-
- {
- SkPaint paint;
- SkRect skSrcRect = normSrcRect;
- int initialSaveCount = ctxt->preparePaintForDrawRectToRect(&paint, skSrcRect, normDstRect, compositeOp, !isOpaque, isLazyDecoded, bitmap.isImmutable());
- // We want to filter it if we decided to do interpolation above, or if
- // there is something interesting going on with the matrix (like a rotation).
- // Note: for serialization, we will want to subset the bitmap first so we
- // don't send extra pixels.
- ctxt->drawBitmapRect(bitmap, &skSrcRect, normDstRect, &paint);
- ctxt->canvas()->restoreToCount(initialSaveCount);
- }
+ SkRect skSrcRect = normSrcRect;
+ SkPaint bitmapPaint = paint;
+ bitmapPaint.setFilterQuality(filterHelper->computeFilterQuality(this, normDstRect, skSrcRect));
+ SkCanvas::DrawBitmapRectFlags flags =
+ filterHelper->shouldClampToSourceRect() ? SkCanvas::kNone_DrawBitmapRectFlag : SkCanvas::kBleed_DrawBitmapRectFlag;
+ bitmapPaint.setAntiAlias(filterHelper->shouldDrawAntiAliased(normDstRect));
+ canvas->drawBitmapRectToRect(bitmap, &skSrcRect, normDstRect, &bitmapPaint, flags);
+ canvas->restoreToCount(initialSaveCount);
- if (isLazyDecoded)
+ if (DeferredImageDecoder::isLazyDecoded(bitmap))
PlatformInstrumentation::didDrawLazyPixelRef(bitmap.getGenerationID());
if (ImageObserver* observer = imageObserver())

Powered by Google App Engine
This is Rietveld 408576698