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

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: todo 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..4a1127e03f5870ff9b9a36c30738817fe91c94c9 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,49 @@ void GraphicsContext::drawImage(Image* image, const FloatRect& dest, const Float
m_paintController.setImagePainted();
}
+void GraphicsContext::drawImageRRect(Image* image, const FloatRoundedRect& dest,
+ const FloatRect& srcRect, SkXfermode::Mode op, RespectImageOrientationEnum respectOrientation)
+{
+ if (contextDisabled() || !image)
+ return;
+
+ if (!dest.isRounded()) {
+ drawImage(image, dest.rect(), &srcRect, op, respectOrientation);
+ return;
+ }
+
+ DCHECK(dest.isRenderable());
+
+ const FloatRect visibleSrc = intersection(srcRect, 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(), srcRect));
+ imagePaint.setAntiAlias(shouldAntialias());
+
+ bool useShader = (visibleSrc == srcRect) && (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(), srcRect, respectOrientation, Image::ClampImageToSourceRect);
+ }
+
+ m_paintController.setImagePainted();
+}
+
SkFilterQuality GraphicsContext::computeFilterQuality(Image* image, const FloatRect& dest, const FloatRect& src) const
{
InterpolationQuality resampling;
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/GraphicsContext.h ('k') | third_party/WebKit/Source/platform/graphics/Image.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698