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

Unified Diff: third_party/WebKit/Source/platform/graphics/GraphicsContext.cpp

Issue 1949253004: Rounded background image fast path (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review Created 4 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: third_party/WebKit/Source/platform/graphics/GraphicsContext.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/GraphicsContext.cpp b/third_party/WebKit/Source/platform/graphics/GraphicsContext.cpp
index 1d30391b3b0e3387e42aa38e8a3fd3f04157c6fb..ad4fcc6bf72a5115101627370b599cc18fb9fda4 100644
--- a/third_party/WebKit/Source/platform/graphics/GraphicsContext.cpp
+++ b/third_party/WebKit/Source/platform/graphics/GraphicsContext.cpp
@@ -27,6 +27,8 @@
#include "platform/graphics/GraphicsContext.h"
#include "platform/TraceEvent.h"
+#include "platform/geometry/FloatRect.h"
+#include "platform/geometry/FloatRoundedRect.h"
#include "platform/geometry/IntRect.h"
#include "platform/graphics/ColorSpace.h"
#include "platform/graphics/Gradient.h"
@@ -809,6 +811,48 @@ void GraphicsContext::drawImage(Image* image, const FloatRect& dest, const Float
m_paintController.setImagePainted();
}
+void GraphicsContext::drawImageRRect(Image* image, const FloatRoundedRect& dest,
+ const FloatRect* srcPtr, SkXfermode::Mode op, RespectImageOrientationEnum respectOrientation)
+{
+ if (contextDisabled() || !image)
+ return;
+
+ if (!dest.isRounded() || !dest.isRenderable()) {
chrishtr 2016/05/20 15:44:13 should isRenderable() be considered illegal?
f(malita) 2016/05/20 19:17:11 Done.
+ drawImage(image, dest.rect(), srcPtr, op, respectOrientation);
+ return;
+ }
+
+ const FloatRect src = srcPtr ? *srcPtr : image->rect();
+ const FloatRect visibleSrc = intersection(src, image->rect());
+ if (dest.isEmpty() || visibleSrc.isEmpty())
+ return;
+
+ SkPaint imagePaint = immutableState()->fillPaint();
+ imagePaint.setXfermodeMode(op);
+ imagePaint.setColor(SK_ColorBLACK);
+ imagePaint.setFilterQuality(computeFilterQuality(image, dest.rect(), src));
+ imagePaint.setAntiAlias(shouldAntialias());
+
+ bool useShader = (visibleSrc == src) && (respectOrientation == DoNotRespectImageOrientation);
+ if (useShader) {
+ const SkMatrix localMatrix =
+ SkMatrix::MakeRectToRect(visibleSrc, dest.rect(), SkMatrix::kFill_ScaleToFit);
+ useShader = image->applyShader(imagePaint, localMatrix.isIdentity() ? nullptr : &localMatrix);
+ }
+
+ if (useShader) {
+ // Shader-based fast path.
+ m_canvas->drawRRect(dest, imagePaint);
+ } else {
+ // Clip-based fallback.
+ SkAutoCanvasRestore autoRestore(m_canvas, true);
+ m_canvas->clipRRect(dest, SkRegion::kIntersect_Op, imagePaint.isAntiAlias());
+ image->draw(m_canvas, imagePaint, dest.rect(), src, respectOrientation, Image::ClampImageToSourceRect);
+ }
+
+ m_paintController.setImagePainted();
+}
+
SkFilterQuality GraphicsContext::computeFilterQuality(Image* image, const FloatRect& dest, const FloatRect& src) const
{
InterpolationQuality resampling;

Powered by Google App Engine
This is Rietveld 408576698