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

Unified Diff: Source/platform/graphics/CrossfadeGeneratedImage.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: 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/CrossfadeGeneratedImage.cpp
diff --git a/Source/platform/graphics/CrossfadeGeneratedImage.cpp b/Source/platform/graphics/CrossfadeGeneratedImage.cpp
index aad20e899760c99fe5fc8e158d4c7824f48de101..a8b2dd7d6a7fa088d173cbc7416c629b6dbbb54c 100644
--- a/Source/platform/graphics/CrossfadeGeneratedImage.cpp
+++ b/Source/platform/graphics/CrossfadeGeneratedImage.cpp
@@ -40,54 +40,51 @@ CrossfadeGeneratedImage::CrossfadeGeneratedImage(Image* fromImage, Image* toImag
{
}
-void CrossfadeGeneratedImage::drawCrossfade(GraphicsContext* context, SkXfermode::Mode xferMode)
+void CrossfadeGeneratedImage::drawCrossfade(SkCanvas* canvas, const SkPaint& paint)
{
- float inversePercentage = 1 - m_percentage;
-
- IntSize fromImageSize = m_fromImage->size();
- IntSize toImageSize = m_toImage->size();
-
- context->beginLayer(1, xferMode);
-
- // Draw the image we're fading away from.
- context->save();
- if (m_crossfadeSize != fromImageSize) {
- context->scale(
- static_cast<float>(m_crossfadeSize.width()) / fromImageSize.width(),
- static_cast<float>(m_crossfadeSize.height()) / fromImageSize.height());
- }
- context->setAlphaAsFloat(inversePercentage);
- context->drawImage(m_fromImage, IntPoint());
- context->restore();
-
- // Draw the image we're fading towards.
- context->save();
- if (m_crossfadeSize != toImageSize) {
- context->scale(
- static_cast<float>(m_crossfadeSize.width()) / toImageSize.width(),
- static_cast<float>(m_crossfadeSize.height()) / toImageSize.height());
- }
- context->setAlphaAsFloat(m_percentage);
- context->drawImage(m_toImage, IntPoint(), SkXfermode::kPlus_Mode);
- context->restore();
-
- context->endLayer();
+ FloatRect fromImageRect(FloatPoint(), m_fromImage->size());
+ FloatRect toImageRect(FloatPoint(), m_toImage->size());
+ FloatRect destRect(FloatPoint(), m_crossfadeSize);
+
+ // TODO(junov): The various effects encoded into paint should probably be applied here
+ // instead of inside the layer. This probably faulty behavior was maintained in order
+ // to preserve pre-existing behavior while refactoring this code. This should be
+ // investigated further. crbug.com/472634
+ SkXfermode::Mode compositeOp;
+ if (!SkXfermode::AsMode(paint.getXfermode(), &compositeOp))
+ compositeOp = SkXfermode::kSrcOver_Mode;
+ SkPaint layerPaint;
+ layerPaint.setXfermodeMode(compositeOp);
+ canvas->saveLayer(nullptr, &layerPaint);
+
+ SkPaint imagePaint(paint);
+ imagePaint.setXfermodeMode(SkXfermode::kPlus_Mode);
+ imagePaint.setColor(scaleAlpha(SK_ColorBLACK, 1 - m_percentage));
+ // TODO(junov): This code should probably be propagating the RespectImageOrientationEnum
+ // form CrossfadeGeneratedImage::draw. Code was written this way during refactoring to
+ // avoid modifying existing behavior, but this warrants further investigation. crbug.com/472634
+ m_fromImage->draw(canvas, imagePaint, destRect, fromImageRect, DoNotRespectImageOrientation);
+ imagePaint.setColor(scaleAlpha(SK_ColorBLACK, m_percentage));
+ m_toImage->draw(canvas, imagePaint, destRect, toImageRect, DoNotRespectImageOrientation);
+
+ canvas->restore();
}
-void CrossfadeGeneratedImage::draw(GraphicsContext* context, const FloatRect& dstRect, const FloatRect& srcRect, SkXfermode::Mode compositeOp, RespectImageOrientationEnum)
+void CrossfadeGeneratedImage::draw(SkCanvas* canvas, const SkPaint& paint, const FloatRect& dstRect, const FloatRect& srcRect, RespectImageOrientationEnum)
{
// Draw nothing if either of the images hasn't loaded yet.
if (m_fromImage == Image::nullImage() || m_toImage == Image::nullImage())
return;
- GraphicsContextStateSaver stateSaver(*context);
- context->clip(dstRect);
- context->translate(dstRect.x(), dstRect.y());
+ canvas->save();
+ canvas->clipRect(dstRect);
+ canvas->translate(dstRect.x(), dstRect.y());
if (dstRect.size() != srcRect.size())
- context->scale(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.height());
- context->translate(-srcRect.x(), -srcRect.y());
+ canvas->scale(dstRect.width() / srcRect.width(), dstRect.height() / srcRect.height());
+ canvas->translate(-srcRect.x(), -srcRect.y());
- drawCrossfade(context, compositeOp);
+ drawCrossfade(canvas, paint);
+ canvas->restore();
}
void CrossfadeGeneratedImage::drawTile(GraphicsContext* context, const FloatRect& srcRect)
@@ -96,7 +93,9 @@ void CrossfadeGeneratedImage::drawTile(GraphicsContext* context, const FloatRect
if (m_fromImage == Image::nullImage() || m_toImage == Image::nullImage())
return;
- drawCrossfade(context, SkXfermode::kSrcOver_Mode);
+ SkPaint paint = context->fillPaint();
+ paint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
+ drawCrossfade(context->canvas(), paint);
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698