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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
13 * 13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24 * THE POSSIBILITY OF SUCH DAMAGE. 24 * THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 #include "platform/graphics/GraphicsContext.h" 27 #include "platform/graphics/GraphicsContext.h"
28 28
29 #include "platform/TraceEvent.h" 29 #include "platform/TraceEvent.h"
30 #include "platform/geometry/FloatRect.h"
31 #include "platform/geometry/FloatRoundedRect.h"
30 #include "platform/geometry/IntRect.h" 32 #include "platform/geometry/IntRect.h"
31 #include "platform/graphics/ColorSpace.h" 33 #include "platform/graphics/ColorSpace.h"
32 #include "platform/graphics/Gradient.h" 34 #include "platform/graphics/Gradient.h"
33 #include "platform/graphics/GraphicsContextStateSaver.h" 35 #include "platform/graphics/GraphicsContextStateSaver.h"
34 #include "platform/graphics/ImageBuffer.h" 36 #include "platform/graphics/ImageBuffer.h"
35 #include "platform/graphics/Path.h" 37 #include "platform/graphics/Path.h"
36 #include "platform/graphics/paint/PaintController.h" 38 #include "platform/graphics/paint/PaintController.h"
37 #include "platform/weborigin/KURL.h" 39 #include "platform/weborigin/KURL.h"
38 #include "skia/ext/platform_canvas.h" 40 #include "skia/ext/platform_canvas.h"
39 #include "third_party/skia/include/core/SkAnnotation.h" 41 #include "third_party/skia/include/core/SkAnnotation.h"
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 804
803 SkPaint imagePaint = immutableState()->fillPaint(); 805 SkPaint imagePaint = immutableState()->fillPaint();
804 imagePaint.setXfermodeMode(op); 806 imagePaint.setXfermodeMode(op);
805 imagePaint.setColor(SK_ColorBLACK); 807 imagePaint.setColor(SK_ColorBLACK);
806 imagePaint.setFilterQuality(computeFilterQuality(image, dest, src)); 808 imagePaint.setFilterQuality(computeFilterQuality(image, dest, src));
807 imagePaint.setAntiAlias(shouldAntialias()); 809 imagePaint.setAntiAlias(shouldAntialias());
808 image->draw(m_canvas, imagePaint, dest, src, shouldRespectImageOrientation, Image::ClampImageToSourceRect); 810 image->draw(m_canvas, imagePaint, dest, src, shouldRespectImageOrientation, Image::ClampImageToSourceRect);
809 m_paintController.setImagePainted(); 811 m_paintController.setImagePainted();
810 } 812 }
811 813
814 void GraphicsContext::drawImageRRect(Image* image, const FloatRoundedRect& dest,
815 const FloatRect* srcPtr, SkXfermode::Mode op, RespectImageOrientationEnum re spectOrientation)
816 {
817 if (contextDisabled() || !image)
818 return;
819
820 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.
821 drawImage(image, dest.rect(), srcPtr, op, respectOrientation);
822 return;
823 }
824
825 const FloatRect src = srcPtr ? *srcPtr : image->rect();
826 const FloatRect visibleSrc = intersection(src, image->rect());
827 if (dest.isEmpty() || visibleSrc.isEmpty())
828 return;
829
830 SkPaint imagePaint = immutableState()->fillPaint();
831 imagePaint.setXfermodeMode(op);
832 imagePaint.setColor(SK_ColorBLACK);
833 imagePaint.setFilterQuality(computeFilterQuality(image, dest.rect(), src));
834 imagePaint.setAntiAlias(shouldAntialias());
835
836 bool useShader = (visibleSrc == src) && (respectOrientation == DoNotRespectI mageOrientation);
837 if (useShader) {
838 const SkMatrix localMatrix =
839 SkMatrix::MakeRectToRect(visibleSrc, dest.rect(), SkMatrix::kFill_Sc aleToFit);
840 useShader = image->applyShader(imagePaint, localMatrix.isIdentity() ? nu llptr : &localMatrix);
841 }
842
843 if (useShader) {
844 // Shader-based fast path.
845 m_canvas->drawRRect(dest, imagePaint);
846 } else {
847 // Clip-based fallback.
848 SkAutoCanvasRestore autoRestore(m_canvas, true);
849 m_canvas->clipRRect(dest, SkRegion::kIntersect_Op, imagePaint.isAntiAlia s());
850 image->draw(m_canvas, imagePaint, dest.rect(), src, respectOrientation, Image::ClampImageToSourceRect);
851 }
852
853 m_paintController.setImagePainted();
854 }
855
812 SkFilterQuality GraphicsContext::computeFilterQuality(Image* image, const FloatR ect& dest, const FloatRect& src) const 856 SkFilterQuality GraphicsContext::computeFilterQuality(Image* image, const FloatR ect& dest, const FloatRect& src) const
813 { 857 {
814 InterpolationQuality resampling; 858 InterpolationQuality resampling;
815 if (printing()) { 859 if (printing()) {
816 resampling = InterpolationNone; 860 resampling = InterpolationNone;
817 } else if (image->currentFrameIsLazyDecoded()) { 861 } else if (image->currentFrameIsLazyDecoded()) {
818 resampling = InterpolationHigh; 862 resampling = InterpolationHigh;
819 } else { 863 } else {
820 resampling = computeInterpolationQuality( 864 resampling = computeInterpolationQuality(
821 SkScalarToFloat(src.width()), SkScalarToFloat(src.height()), 865 SkScalarToFloat(src.width()), SkScalarToFloat(src.height()),
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
1354 static const SkPMColor colors[] = { 1398 static const SkPMColor colors[] = {
1355 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red 1399 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red
1356 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray 1400 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray
1357 }; 1401 };
1358 1402
1359 return colors[index]; 1403 return colors[index];
1360 } 1404 }
1361 #endif 1405 #endif
1362 1406
1363 } // namespace blink 1407 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698