| OLD | NEW |
| 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 Loading... |
| 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& srcRect, SkXfermode::Mode op, RespectImageOrientationEnum r
espectOrientation) |
| 816 { |
| 817 if (contextDisabled() || !image) |
| 818 return; |
| 819 |
| 820 if (!dest.isRounded()) { |
| 821 drawImage(image, dest.rect(), &srcRect, op, respectOrientation); |
| 822 return; |
| 823 } |
| 824 |
| 825 DCHECK(dest.isRenderable()); |
| 826 |
| 827 const FloatRect visibleSrc = intersection(srcRect, image->rect()); |
| 828 if (dest.isEmpty() || visibleSrc.isEmpty()) |
| 829 return; |
| 830 |
| 831 SkPaint imagePaint = immutableState()->fillPaint(); |
| 832 imagePaint.setXfermodeMode(op); |
| 833 imagePaint.setColor(SK_ColorBLACK); |
| 834 imagePaint.setFilterQuality(computeFilterQuality(image, dest.rect(), srcRect
)); |
| 835 imagePaint.setAntiAlias(shouldAntialias()); |
| 836 |
| 837 bool useShader = (visibleSrc == srcRect) && (respectOrientation == DoNotResp
ectImageOrientation); |
| 838 if (useShader) { |
| 839 const SkMatrix localMatrix = |
| 840 SkMatrix::MakeRectToRect(visibleSrc, dest.rect(), SkMatrix::kFill_Sc
aleToFit); |
| 841 useShader = image->applyShader(imagePaint, localMatrix.isIdentity() ? nu
llptr : &localMatrix); |
| 842 } |
| 843 |
| 844 if (useShader) { |
| 845 // Shader-based fast path. |
| 846 m_canvas->drawRRect(dest, imagePaint); |
| 847 } else { |
| 848 // Clip-based fallback. |
| 849 SkAutoCanvasRestore autoRestore(m_canvas, true); |
| 850 m_canvas->clipRRect(dest, SkRegion::kIntersect_Op, imagePaint.isAntiAlia
s()); |
| 851 image->draw(m_canvas, imagePaint, dest.rect(), srcRect, respectOrientati
on, Image::ClampImageToSourceRect); |
| 852 } |
| 853 |
| 854 m_paintController.setImagePainted(); |
| 855 } |
| 856 |
| 812 SkFilterQuality GraphicsContext::computeFilterQuality(Image* image, const FloatR
ect& dest, const FloatRect& src) const | 857 SkFilterQuality GraphicsContext::computeFilterQuality(Image* image, const FloatR
ect& dest, const FloatRect& src) const |
| 813 { | 858 { |
| 814 InterpolationQuality resampling; | 859 InterpolationQuality resampling; |
| 815 if (printing()) { | 860 if (printing()) { |
| 816 resampling = InterpolationNone; | 861 resampling = InterpolationNone; |
| 817 } else if (image->currentFrameIsLazyDecoded()) { | 862 } else if (image->currentFrameIsLazyDecoded()) { |
| 818 resampling = InterpolationHigh; | 863 resampling = InterpolationHigh; |
| 819 } else { | 864 } else { |
| 820 resampling = computeInterpolationQuality( | 865 resampling = computeInterpolationQuality( |
| 821 SkScalarToFloat(src.width()), SkScalarToFloat(src.height()), | 866 SkScalarToFloat(src.width()), SkScalarToFloat(src.height()), |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1354 static const SkPMColor colors[] = { | 1399 static const SkPMColor colors[] = { |
| 1355 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red | 1400 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red |
| 1356 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray | 1401 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray |
| 1357 }; | 1402 }; |
| 1358 | 1403 |
| 1359 return colors[index]; | 1404 return colors[index]; |
| 1360 } | 1405 } |
| 1361 #endif | 1406 #endif |
| 1362 | 1407 |
| 1363 } // namespace blink | 1408 } // namespace blink |
| OLD | NEW |