15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* 25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (c) 2006,2007,2008, Google Inc. All rights reserved. 302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * 45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without 55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions are 65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * met: 702772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * 85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * * Redistributions of source code must retain the above copyright 95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * notice, this list of conditions and the following disclaimer. 105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * * Redistributions in binary form must reproduce the above 115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer 125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * in the documentation and/or other materials provided with the 135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * distribution. 145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * * Neither the name of Google Inc. nor the names of its 155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * contributors may be used to endorse or promote products derived from 165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * this software without specific prior written permission. 1702772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * 185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */ 305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// All of the functions in this file should move to new homes and this file should be deleted. 325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef SkiaUtils_h 345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define SkiaUtils_h 355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 361e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "SkMatrix.h" 37323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)#include "SkPaint.h" 385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "SkPath.h" 395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "SkXfermode.h" 40a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/PlatformExport.h" 411e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "platform/geometry/FloatRect.h" 42f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)#include "platform/graphics/Color.h" 43f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)#include "platform/graphics/GraphicsTypes.h" 441e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "platform/transforms/AffineTransform.h" 457757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch#include "wtf/MathExtras.h" 461e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "wtf/PassRefPtr.h" 475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class SkCanvas; 495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class SkRegion; 505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)namespace WebCore { 525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 531e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)class GraphicsContext; 541e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) 55a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)PassRefPtr<SkXfermode> WebCoreCompositeToSkiaComposite(CompositeOperator, blink::WebBlendMode = blink::WebBlendModeNormal); 565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// move this guy into SkColor.h 585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)SkColor SkPMColorToColor(SkPMColor); 595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 60323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)inline SkPaint::FilterLevel WebCoreInterpolationQualityToSkFilterLevel(InterpolationQuality quality) 61323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles){ 62323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) // FIXME: this reflects existing client mappings, but should probably 63323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) // be expanded to map higher level interpolations more accurately. 64323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) return quality != InterpolationNone ? SkPaint::kLow_FilterLevel : SkPaint::kNone_FilterLevel; 65323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles)} 66323480423219ecd77329f8326dc5e0e3b50926d4Torne (Richard Coles) 675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// Skia has problems when passed infinite, etc floats, filter them to 0. 685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)inline SkScalar WebCoreFloatToSkScalar(float f) 695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 70926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) return SkFloatToScalar(std::isfinite(f) ? f : 0); 715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)inline SkScalar WebCoreDoubleToSkScalar(double d) 745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 75926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) return SkDoubleToScalar(std::isfinite(d) ? d : 0); 765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 7853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)inline SkRect WebCoreFloatRectToSKRect(const FloatRect& rect) 7953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles){ 8053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) return SkRect::MakeLTRB(SkFloatToScalar(rect.x()), SkFloatToScalar(rect.y()), 8153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) SkFloatToScalar(rect.maxX()), SkFloatToScalar(rect.maxY())); 8253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)} 8353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) 8409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)inline bool WebCoreFloatNearlyEqual(float a, float b) 8509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){ 8609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) return SkScalarNearlyEqual(WebCoreFloatToSkScalar(a), WebCoreFloatToSkScalar(b)); 8709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)} 885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// Determine if a given WebKit point is contained in a path 90a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)bool PLATFORM_EXPORT SkPathContainsPoint(const SkPath&, const FloatPoint&, SkPath::FillType); 915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 92a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)SkMatrix PLATFORM_EXPORT affineTransformToSkMatrix(const AffineTransform&); 931e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) 945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} // namespace WebCore 955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif // SkiaUtils_h 97