| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2006,2007,2008, Google Inc. All rights reserved. | 2 * Copyright (c) 2006,2007,2008, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 // All of the functions in this file should move to new homes and this file shou
ld be deleted. | 31 // All of the functions in this file should move to new homes and this file |
| 32 // should be deleted. |
| 32 | 33 |
| 33 #ifndef SkiaUtils_h | 34 #ifndef SkiaUtils_h |
| 34 #define SkiaUtils_h | 35 #define SkiaUtils_h |
| 35 | 36 |
| 36 #include "platform/PlatformExport.h" | 37 #include "platform/PlatformExport.h" |
| 37 #include "platform/graphics/GraphicsTypes.h" | 38 #include "platform/graphics/GraphicsTypes.h" |
| 38 #include "platform/graphics/Image.h" | 39 #include "platform/graphics/Image.h" |
| 39 #include "platform/transforms/AffineTransform.h" | 40 #include "platform/transforms/AffineTransform.h" |
| 40 #include "third_party/skia/include/core/SkCanvas.h" | 41 #include "third_party/skia/include/core/SkCanvas.h" |
| 41 #include "third_party/skia/include/core/SkColor.h" | 42 #include "third_party/skia/include/core/SkColor.h" |
| 42 #include "third_party/skia/include/core/SkRefCnt.h" | 43 #include "third_party/skia/include/core/SkRefCnt.h" |
| 43 #include "third_party/skia/include/core/SkScalar.h" | 44 #include "third_party/skia/include/core/SkScalar.h" |
| 44 #include "third_party/skia/include/core/SkXfermode.h" | 45 #include "third_party/skia/include/core/SkXfermode.h" |
| 45 #include "wtf/MathExtras.h" | 46 #include "wtf/MathExtras.h" |
| 46 | 47 |
| 47 namespace blink { | 48 namespace blink { |
| 48 | 49 |
| 49 class GraphicsContext; | 50 class GraphicsContext; |
| 50 | 51 |
| 51 /**** constants ****/ | 52 /**** constants ****/ |
| 52 | 53 |
| 53 enum { | 54 enum { |
| 54 // Firefox limits width/height to 32767 pixels, but slows down dramatically be
fore it | 55 // Firefox limits width/height to 32767 pixels, but slows down dramatically |
| 55 // reaches that limit. We limit by area instead, giving us larger maximum dime
nsions, | 56 // before it reaches that limit. We limit by area instead, giving us larger |
| 56 // in exchange for a smaller maximum canvas size. | 57 // maximum dimensions, in exchange for a smaller maximum canvas size. |
| 57 kMaxCanvasArea = 32768 * 8192, // Maximum canvas area in CSS pixels | 58 kMaxCanvasArea = 32768 * 8192, // Maximum canvas area in CSS pixels |
| 58 | 59 |
| 59 // In Skia, we will also limit width/height to 32767. | 60 // In Skia, we will also limit width/height to 32767. |
| 60 kMaxSkiaDim = 32767 // Maximum width/height in CSS pixels. | 61 kMaxSkiaDim = 32767 // Maximum width/height in CSS pixels. |
| 61 }; | 62 }; |
| 62 | 63 |
| 63 SkXfermode::Mode PLATFORM_EXPORT | 64 SkXfermode::Mode PLATFORM_EXPORT |
| 64 WebCoreCompositeToSkiaComposite(CompositeOperator, | 65 WebCoreCompositeToSkiaComposite(CompositeOperator, |
| 65 WebBlendMode = WebBlendModeNormal); | 66 WebBlendMode = WebBlendModeNormal); |
| 66 CompositeOperator PLATFORM_EXPORT compositeOperatorFromSkia(SkXfermode::Mode); | 67 CompositeOperator PLATFORM_EXPORT compositeOperatorFromSkia(SkXfermode::Mode); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 | 114 |
| 114 InterpolationQuality limitInterpolationQuality(const GraphicsContext&, | 115 InterpolationQuality limitInterpolationQuality(const GraphicsContext&, |
| 115 InterpolationQuality resampling); | 116 InterpolationQuality resampling); |
| 116 | 117 |
| 117 InterpolationQuality computeInterpolationQuality(float srcWidth, | 118 InterpolationQuality computeInterpolationQuality(float srcWidth, |
| 118 float srcHeight, | 119 float srcHeight, |
| 119 float destWidth, | 120 float destWidth, |
| 120 float destHeight, | 121 float destHeight, |
| 121 bool isDataComplete = true); | 122 bool isDataComplete = true); |
| 122 | 123 |
| 123 // This replicates the old skia behavior when it used to take radius for blur. N
ow it takes sigma. | 124 // This replicates the old skia behavior when it used to take radius for blur. |
| 125 // Now it takes sigma. |
| 124 inline SkScalar skBlurRadiusToSigma(SkScalar radius) { | 126 inline SkScalar skBlurRadiusToSigma(SkScalar radius) { |
| 125 SkASSERT(radius >= 0); | 127 SkASSERT(radius >= 0); |
| 126 if (radius == 0) | 128 if (radius == 0) |
| 127 return 0.0f; | 129 return 0.0f; |
| 128 return 0.288675f * radius + 0.5f; | 130 return 0.288675f * radius + 0.5f; |
| 129 } | 131 } |
| 130 | 132 |
| 131 template <typename PrimitiveType> | 133 template <typename PrimitiveType> |
| 132 void drawPlatformFocusRing(const PrimitiveType&, SkCanvas*, SkColor, int width); | 134 void drawPlatformFocusRing(const PrimitiveType&, SkCanvas*, SkColor, int width); |
| 133 | 135 |
| 134 // TODO(fmalita): remove in favor of direct SrcRectConstraint use. | 136 // TODO(fmalita): remove in favor of direct SrcRectConstraint use. |
| 135 inline SkCanvas::SrcRectConstraint WebCoreClampingModeToSkiaRectConstraint( | 137 inline SkCanvas::SrcRectConstraint WebCoreClampingModeToSkiaRectConstraint( |
| 136 Image::ImageClampingMode clampMode) { | 138 Image::ImageClampingMode clampMode) { |
| 137 return clampMode == Image::ClampImageToSourceRect | 139 return clampMode == Image::ClampImageToSourceRect |
| 138 ? SkCanvas::kStrict_SrcRectConstraint | 140 ? SkCanvas::kStrict_SrcRectConstraint |
| 139 : SkCanvas::kFast_SrcRectConstraint; | 141 : SkCanvas::kFast_SrcRectConstraint; |
| 140 } | 142 } |
| 141 | 143 |
| 142 // Skia's smart pointer APIs are preferable over their legacy raw pointer counte
rparts. | 144 // Skia's smart pointer APIs are preferable over their legacy raw pointer |
| 145 // counterparts. |
| 143 // | 146 // |
| 144 // General guidelines | 147 // General guidelines |
| 145 // | 148 // |
| 146 // When receiving ref counted objects from Skia: | 149 // When receiving ref counted objects from Skia: |
| 147 // | 150 // |
| 148 // 1) use sk_sp-based Skia factories if available (e.g. SkShader::MakeFoo() in
stead of | 151 // 1) Use sk_sp-based Skia factories if available (e.g. SkShader::MakeFoo() |
| 149 // SkShader::CreateFoo()) | 152 // instead of SkShader::CreateFoo()). |
| 150 // | 153 // 2) Use sk_sp<T> locals for all objects. |
| 151 // 2) use sk_sp<T> locals for all objects | |
| 152 // | 154 // |
| 153 // When passing ref counted objects to Skia: | 155 // When passing ref counted objects to Skia: |
| 154 // | 156 // |
| 155 // 1) use sk_sp-based Skia APIs when available (e.g. SkPaint::setShader(sk_sp<
SkShader>) | 157 // 1) Use sk_sp-based Skia APIs when available (e.g. |
| 156 // instead of SkPaint::setShader(SkShader*)) | 158 // SkPaint::setShader(sk_sp<SkShader>) instead of |
| 157 // | 159 // SkPaint::setShader(SkShader*)). |
| 158 // 2) if the object ownership is being passed to Skia, use std::move(sk_sp<T>) | 160 // 2) If object ownership is being passed to Skia, use std::move(sk_sp<T>). |
| 159 // | 161 // |
| 160 // Example (creating a SkShader and setting it on SkPaint): | 162 // Example (creating a SkShader and setting it on SkPaint): |
| 161 // | 163 // |
| 162 // a) ownership transferred | 164 // a) ownership transferred |
| 163 // | 165 // |
| 164 // // using Skia smart pointer locals | 166 // // using Skia smart pointer locals |
| 165 // sk_sp<SkShader> shader = SkShader::MakeFoo(...); | 167 // sk_sp<SkShader> shader = SkShader::MakeFoo(...); |
| 166 // paint.setShader(std::move(shader)); | 168 // paint.setShader(std::move(shader)); |
| 167 // | 169 // |
| 168 // // using no locals | 170 // // using no locals |
| 169 // paint.setShader(SkShader::MakeFoo(...)); | 171 // paint.setShader(SkShader::MakeFoo(...)); |
| 170 // | 172 // |
| 171 // b) shared ownership | 173 // b) shared ownership |
| 172 // | 174 // |
| 173 // sk_sp<SkShader> shader = SkShader::MakeFoo(...); | 175 // sk_sp<SkShader> shader = SkShader::MakeFoo(...); |
| 174 // paint.setShader(shader); | 176 // paint.setShader(shader); |
| 175 | 177 |
| 176 } // namespace blink | 178 } // namespace blink |
| 177 | 179 |
| 178 #endif // SkiaUtils_h | 180 #endif // SkiaUtils_h |
| OLD | NEW |