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

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: fix for overdraw optimization failures and fix for mac build Created 5 years, 8 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 8a8c8b7bb8da8fcf8dbe1aff48dfbea6f905c086..df9a7268a58472b8944e95c46421469a49c2c99c 100644
--- a/Source/platform/graphics/BitmapImage.cpp
+++ b/Source/platform/graphics/BitmapImage.cpp
@@ -272,7 +272,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)
{
TRACE_EVENT0("skia", "BitmapImage::draw");
SkBitmap bitmap;
@@ -290,15 +306,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
@@ -307,22 +323,11 @@ 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;
+ canvas->drawBitmapRectToRect(bitmap, &skSrcRect, normDstRect, &paint);
+ 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