15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* 25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2003, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2008-2009 Torch Mobile, Inc. 453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) * Copyright (C) 2013 Google Inc. All rights reserved. 55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without 75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions 85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * are met: 95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 1. Redistributions of source code must retain the above copyright 105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * notice, this list of conditions and the following disclaimer. 115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright 125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * notice, this list of conditions and the following disclaimer in the 135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * documentation and/or other materials provided with the distribution. 145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */ 275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef GraphicsContext_h 295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define GraphicsContext_h 305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 31a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/PlatformExport.h" 321e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "platform/TraceEvent.h" 33a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/fonts/Font.h" 341e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "platform/geometry/FloatRect.h" 35f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)#include "platform/graphics/DashArray.h" 36f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)#include "platform/graphics/DrawLooper.h" 37a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/graphics/ImageBufferSurface.h" 381e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "platform/graphics/ImageOrientation.h" 39a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/graphics/GraphicsContextAnnotation.h" 40a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/graphics/GraphicsContextState.h" 41a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/graphics/skia/OpaqueRegionSkia.h" 42a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/graphics/skia/SkiaUtils.h" 43c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)// TODO(robertphillips): replace this include with "class SkBaseDevice;" 44c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles)#include "third_party/skia/include/core/SkDevice.h" 45e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "wtf/FastAllocBase.h" 46e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "wtf/Forward.h" 47e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "wtf/Noncopyable.h" 48e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "wtf/PassOwnPtr.h" 495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 50591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdochclass SkBitmap; 51591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdochclass SkPaint; 52591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdochclass SkPath; 53591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdochclass SkRRect; 54591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdochstruct SkRect; 55591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch 565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)namespace WebCore { 575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 5819cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles)class DisplayList; 5981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)class ImageBuffer; 6081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)class KURL; 6181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 62a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)class PLATFORM_EXPORT GraphicsContext { 6381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) WTF_MAKE_NONCOPYABLE(GraphicsContext); WTF_MAKE_FAST_ALLOCATED; 6481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)public: 6581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) enum AntiAliasingMode { 6681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) NotAntiAliased, 6781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) AntiAliased 6881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) }; 6981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) enum AccessMode { 7081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) ReadOnly, 7181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) ReadWrite 725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) }; 735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 7481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) explicit GraphicsContext(SkCanvas*); 7581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) ~GraphicsContext(); 7681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 7781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // Returns the canvas used for painting, NOT guaranteed to be non-null. 7881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // Accessing the backing canvas this way flushes all queued save ops, 7981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // so it should be avoided. Use the corresponding draw/matrix/clip methods instead. 8081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) SkCanvas* canvas() 8181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) { 8281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // Flush any pending saves. 8381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) realizeSave(SkCanvas::kMatrixClip_SaveFlag); 8481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 8581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) return m_canvas; 8681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) } 8781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) const SkCanvas* canvas() const { return m_canvas; } 8893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) bool paintingDisabled() const { return !m_canvas; } 8981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 90591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch const SkBitmap* bitmap() const; 91591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch const SkBitmap& layerBitmap(AccessMode = ReadOnly) const; 9281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 9393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) // ---------- State management methods ----------------- 9493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void save(); 9593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void restore(); 9693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 9793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void saveLayer(const SkRect* bounds, const SkPaint*, SkCanvas::SaveFlags = SkCanvas::kARGB_ClipLayer_SaveFlag); 9893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void restoreLayer(); 9993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 100521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) float strokeThickness() const { return m_state->m_strokeData.thickness(); } 101521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) void setStrokeThickness(float thickness) { m_state->m_strokeData.setThickness(thickness); } 10293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 103521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) StrokeStyle strokeStyle() const { return m_state->m_strokeData.style(); } 104521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) void setStrokeStyle(StrokeStyle style) { m_state->m_strokeData.setStyle(style); } 10593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 106521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) Color strokeColor() const { return m_state->m_strokeData.color(); } 1075267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) void setStrokeColor(const Color&); 10881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 109521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) Pattern* strokePattern() const { return m_state->m_strokeData.pattern(); } 11081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void setStrokePattern(PassRefPtr<Pattern>); 11181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 112521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) Gradient* strokeGradient() const { return m_state->m_strokeData.gradient(); } 11381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void setStrokeGradient(PassRefPtr<Gradient>); 11481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 115521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) void setLineCap(LineCap cap) { m_state->m_strokeData.setLineCap(cap); } 116521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) void setLineDash(const DashArray& dashes, float dashOffset) { m_state->m_strokeData.setLineDash(dashes, dashOffset); } 117521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) void setLineJoin(LineJoin join) { m_state->m_strokeData.setLineJoin(join); } 118521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) void setMiterLimit(float limit) { m_state->m_strokeData.setMiterLimit(limit); } 11993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 12093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) WindRule fillRule() const { return m_state->m_fillRule; } 12193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void setFillRule(WindRule fillRule) { m_state->m_fillRule = fillRule; } 12293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 12393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) Color fillColor() const { return m_state->m_fillColor; } 1245267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) void setFillColor(const Color&); 12593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) SkColor effectiveFillColor() const { return m_state->applyAlpha(m_state->m_fillColor.rgb()); } 12681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 12781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void setFillPattern(PassRefPtr<Pattern>); 12893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) Pattern* fillPattern() const { return m_state->m_fillPattern.get(); } 12981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 13081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void setFillGradient(PassRefPtr<Gradient>); 13193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) Gradient* fillGradient() const { return m_state->m_fillGradient.get(); } 13281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 133e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch SkDrawLooper* drawLooper() const { return m_state->m_looper.get(); } 134521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) SkColor effectiveStrokeColor() const { return m_state->applyAlpha(m_state->m_strokeData.color().rgb()); } 135e52495584422c5edb5b2944981473a2e208da323Torne (Richard Coles) 13693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) int getNormalizedAlpha() const; 13781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 13893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) bool getClipBounds(SkRect* bounds) const; 13906f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles) bool getTransformedClipBounds(FloatRect* bounds) const; 14051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) SkMatrix getTotalMatrix() const; 14193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) bool isPrintingDevice() const; 14281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 14393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void setShouldAntialias(bool antialias) { m_state->m_shouldAntialias = antialias; } 14493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) bool shouldAntialias() const { return m_state->m_shouldAntialias; } 14581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 1469bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) void setShouldClampToSourceRect(bool clampToSourceRect) { m_state->m_shouldClampToSourceRect = clampToSourceRect; } 1479bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) bool shouldClampToSourceRect() const { return m_state->m_shouldClampToSourceRect; } 1489bbd2f5e390b01907d97ecffde80aa1b06113aacTorne (Richard Coles) 14993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void setShouldSmoothFonts(bool smoothFonts) { m_state->m_shouldSmoothFonts = smoothFonts; } 15093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) bool shouldSmoothFonts() const { return m_state->m_shouldSmoothFonts; } 15181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 15293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) // Turn off LCD text for the paint if not supported on this context. 15393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void adjustTextRenderMode(SkPaint*); 15493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) bool couldUseLCDRenderedText(); 15581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 15693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) TextDrawingModeFlags textDrawingMode() const { return m_state->m_textDrawingMode; } 15793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void setTextDrawingMode(TextDrawingModeFlags mode) { m_state->m_textDrawingMode = mode; } 15881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 15993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void setAlpha(float alpha) { m_state->m_alpha = alpha; } 16081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 16193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void setImageInterpolationQuality(InterpolationQuality quality) { m_state->m_interpolationQuality = quality; } 16293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) InterpolationQuality imageInterpolationQuality() const { return m_state->m_interpolationQuality; } 16381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 164a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void setCompositeOperation(CompositeOperator, blink::WebBlendMode = blink::WebBlendModeNormal); 16593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) CompositeOperator compositeOperation() const { return m_state->m_compositeOperator; } 166a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) blink::WebBlendMode blendModeOperation() const { return m_state->m_blendMode; } 16781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 16881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // Change the way document markers are rendered. 16981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // Any deviceScaleFactor higher than 1.5 is enough to justify setting this flag. 17081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void setUseHighResMarkers(bool isHighRes) { m_useHighResMarker = isHighRes; } 17181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 17281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // If true we are (most likely) rendering to a web page and the 17381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // canvas has been prepared with an opaque background. If false, 17481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // the canvas may havbe transparency (as is the case when rendering 17581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // to a canvas object). 17681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void setCertainlyOpaque(bool isOpaque) { m_isCertainlyOpaque = isOpaque; } 17781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) bool isCertainlyOpaque() const { return m_isCertainlyOpaque; } 17881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 17981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // Returns if the context is a printing context instead of a display 18081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // context. Bitmap shouldn't be resampled when printing to keep the best 18181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // possible quality. 18281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) bool printing() const { return m_printing; } 18381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void setPrinting(bool printing) { m_printing = printing; } 18481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 18581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) bool isAccelerated() const { return m_accelerated; } 18681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void setAccelerated(bool accelerated) { m_accelerated = accelerated; } 18781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 18881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // The opaque region is empty until tracking is turned on. 18981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // It is never clerared by the context. 19081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void setTrackOpaqueRegion(bool track) { m_trackOpaqueRegion = track; } 19181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) const OpaqueRegionSkia& opaqueRegion() const { return m_opaqueRegion; } 19281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 19393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) // The text region is empty until tracking is turned on. 19493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) // It is never clerared by the context. 19593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void setTrackTextRegion(bool track) { m_trackTextRegion = track; } 19693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) const SkRect& textRegion() const { return m_textRegion; } 19781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 19893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) bool updatingControlTints() const { return m_updatingControlTints; } 19993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void setUpdatingControlTints(bool updatingTints) { m_updatingControlTints = updatingTints; } 2005267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 2015267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) AnnotationModeFlags annotationMode() const { return m_annotationMode; } 2025267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) void setAnnotationMode(const AnnotationModeFlags mode) { m_annotationMode = mode; } 203c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) 2041e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) SkColorFilter* colorFilter(); 2051e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) void setColorFilter(ColorFilter); 20693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) // ---------- End state management methods ----------------- 20781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 20893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) // Get the contents of the image buffer 20993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) bool readPixels(SkBitmap*, int, int, SkCanvas::Config8888 = SkCanvas::kNative_Premul_Config8888); 21081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 21181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // Sets up the paint for the current fill style. 21281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void setupPaintForFilling(SkPaint*) const; 21381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 21493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) // Sets up the paint for stroking. Returns a float representing the 21593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) // effective width of the pen. If a non-zero length is provided, the 21693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) // number of dashes/dots on a dashed/dotted line will be adjusted to 21781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // start and end that length with a dash/dot. 218521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) float setupPaintForStroking(SkPaint*, int length = 0) const; 21981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 22081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // These draw methods will do both stroking and filling. 22181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // FIXME: ...except drawRect(), which fills properly but always strokes 22281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // using a 1-pixel stroke inset from the rect borders (of the correct 22381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // stroke color). 22481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void drawRect(const IntRect&); 22581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void drawLine(const IntPoint&, const IntPoint&); 22681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void drawEllipse(const IntRect&); 22781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void drawConvexPolygon(size_t numPoints, const FloatPoint*, bool shouldAntialias = false); 22881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 22981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void fillPath(const Path&); 23081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void strokePath(const Path&); 23181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 23281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void fillEllipse(const FloatRect&); 23381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void strokeEllipse(const FloatRect&); 23481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 23581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void fillRect(const FloatRect&); 2365267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) void fillRect(const FloatRect&, const Color&); 2375267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) void fillRect(const FloatRect&, const Color&, CompositeOperator); 2385267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) void fillRoundedRect(const IntRect&, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight, const Color&); 2395267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) void fillRoundedRect(const RoundedRect&, const Color&); 24081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 24181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void clearRect(const FloatRect&); 24281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 24381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void strokeRect(const FloatRect&, float lineWidth); 24481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 24519cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) void drawDisplayList(DisplayList*); 24619cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) 2475267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) void drawImage(Image*, const IntPoint&, CompositeOperator = CompositeSourceOver, RespectImageOrientationEnum = DoNotRespectImageOrientation); 2485267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) void drawImage(Image*, const IntRect&, CompositeOperator = CompositeSourceOver, RespectImageOrientationEnum = DoNotRespectImageOrientation, bool useLowQualityScale = false); 2495267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) void drawImage(Image*, const IntPoint& destPoint, const IntRect& srcRect, CompositeOperator = CompositeSourceOver, RespectImageOrientationEnum = DoNotRespectImageOrientation); 2505267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) void drawImage(Image*, const FloatRect& destRect); 2515267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) void drawImage(Image*, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator = CompositeSourceOver, RespectImageOrientationEnum = DoNotRespectImageOrientation, bool useLowQualityScale = false); 252a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void drawImage(Image*, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator, blink::WebBlendMode, RespectImageOrientationEnum = DoNotRespectImageOrientation, bool useLowQualityScale = false); 25381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 2545267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) void drawTiledImage(Image*, const IntRect& destRect, const IntPoint& srcPoint, const IntSize& tileSize, 255a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) CompositeOperator = CompositeSourceOver, bool useLowQualityScale = false, blink::WebBlendMode = blink::WebBlendModeNormal, const IntSize& repeatSpacing = IntSize()); 2565267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) void drawTiledImage(Image*, const IntRect& destRect, const IntRect& srcRect, 25781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) const FloatSize& tileScaleFactor, Image::TileRule hRule = Image::StretchTile, Image::TileRule vRule = Image::StretchTile, 25881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) CompositeOperator = CompositeSourceOver, bool useLowQualityScale = false); 25981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 260a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void drawImageBuffer(ImageBuffer*, const IntPoint&, CompositeOperator = CompositeSourceOver, blink::WebBlendMode = blink::WebBlendModeNormal); 261a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void drawImageBuffer(ImageBuffer*, const IntRect&, CompositeOperator = CompositeSourceOver, blink::WebBlendMode = blink::WebBlendModeNormal, bool useLowQualityScale = false); 262a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void drawImageBuffer(ImageBuffer*, const IntPoint& destPoint, const IntRect& srcRect, CompositeOperator = CompositeSourceOver, blink::WebBlendMode = blink::WebBlendModeNormal); 263a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void drawImageBuffer(ImageBuffer*, const IntRect& destRect, const IntRect& srcRect, CompositeOperator = CompositeSourceOver, blink::WebBlendMode = blink::WebBlendModeNormal, bool useLowQualityScale = false); 2645267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) void drawImageBuffer(ImageBuffer*, const FloatRect& destRect); 265a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void drawImageBuffer(ImageBuffer*, const FloatRect& destRect, const FloatRect& srcRect, CompositeOperator = CompositeSourceOver, blink::WebBlendMode = blink::WebBlendModeNormal, bool useLowQualityScale = false); 26681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 26781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // These methods write to the canvas and modify the opaque region, if tracked. 26881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // Also drawLine(const IntPoint& point1, const IntPoint& point2) and fillRoundedRect 26981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void writePixels(const SkBitmap&, int x, int y, SkCanvas::Config8888 = SkCanvas::kNative_Premul_Config8888); 27081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void drawBitmap(const SkBitmap&, SkScalar, SkScalar, const SkPaint* = 0); 2715267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) void drawBitmapRect(const SkBitmap&, const SkRect*, const SkRect&, const SkPaint* = 0); 27281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void drawOval(const SkRect&, const SkPaint&); 27381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void drawPath(const SkPath&, const SkPaint&); 27481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // After drawing directly to the context's canvas, use this function to notify the context so 27581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // it can track the opaque region. 27681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // FIXME: this is still needed only because ImageSkia::paintSkBitmap() may need to notify for a 27781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // smaller rect than the one drawn to, due to its clipping logic. 27881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void didDrawRect(const SkRect&, const SkPaint&, const SkBitmap* = 0); 27981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void drawRect(const SkRect&, const SkPaint&); 28093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void drawPosText(const void* text, size_t byteLength, const SkPoint pos[], const SkRect& textRect, const SkPaint&); 28193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void drawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], SkScalar constY, const SkRect& textRect, const SkPaint&); 28293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void drawTextOnPath(const void* text, size_t byteLength, const SkPath&, const SkRect& textRect, const SkMatrix*, const SkPaint&); 28381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 28493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void clip(const IntRect& rect) { clip(FloatRect(rect)); } 28593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void clip(const FloatRect& rect) { clipRect(rect); } 28681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void clipRoundedRect(const RoundedRect&); 28793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void clipOut(const IntRect& rect) { clipRect(rect, NotAntiAliased, SkRegion::kDifference_Op); } 28881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void clipOutRoundedRect(const RoundedRect&); 28993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void clipPath(const Path&, WindRule = RULE_EVENODD); 29081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void clipConvexPolygon(size_t numPoints, const FloatPoint*, bool antialias = true); 29193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) bool clipRect(const SkRect&, AntiAliasingMode = NotAntiAliased, SkRegion::Op = SkRegion::kIntersect_Op); 29281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 29393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void drawText(const Font&, const TextRunPaintInfo&, const FloatPoint&); 29493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void drawEmphasisMarks(const Font&, const TextRunPaintInfo&, const AtomicString& mark, const FloatPoint&); 29593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void drawBidiText(const Font&, const TextRunPaintInfo&, const FloatPoint&, Font::CustomFontNotReadyAction = Font::DoNotPaintIfFontNotReady); 2965267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) void drawHighlightForText(const Font&, const TextRun&, const FloatPoint&, int h, const Color& backgroundColor, int from = 0, int to = -1); 29781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 29881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void drawLineForText(const FloatPoint&, float width, bool printing); 29981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) enum DocumentMarkerLineStyle { 30081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) DocumentMarkerSpellingLineStyle, 301e52495584422c5edb5b2944981473a2e208da323Torne (Richard Coles) DocumentMarkerGrammarLineStyle 3025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) }; 30381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void drawLineForDocumentMarker(const FloatPoint&, float width, DocumentMarkerLineStyle); 3045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 305c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) void beginTransparencyLayer(float opacity, const FloatRect* = 0); 3061e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) void beginLayer(float opacity, CompositeOperator, const FloatRect* = 0, ColorFilter = ColorFilterNone); 307c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) void endLayer(); 3085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 30919cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) // Instead of being dispatched to the active canvas, draw commands following beginRecording() 31019cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) // are stored in a display list that can be replayed at a later time. 31119cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) void beginRecording(const FloatRect& bounds); 31219cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) PassRefPtr<DisplayList> endRecording(); 31319cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) 31481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) bool hasShadow() const; 31593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void setShadow(const FloatSize& offset, float blur, const Color&, 316591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch DrawLooper::ShadowTransformMode = DrawLooper::ShadowRespectsTransforms, 31793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) DrawLooper::ShadowAlphaMode = DrawLooper::ShadowRespectsAlpha); 31893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void clearShadow() { clearDrawLooper(); } 3195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 32093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) // It is assumed that this draw looper is used only for shadows 32193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) // (i.e. a draw looper is set if and only if there is a shadow). 32293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void setDrawLooper(const DrawLooper&); 32393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void clearDrawLooper(); 3245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 32581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void drawFocusRing(const Vector<IntRect>&, int width, int offset, const Color&); 32681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void drawFocusRing(const Path&, int width, int offset, const Color&); 3275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 328591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch enum Edge { 329591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch NoEdge = 0, 330591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch TopEdge = 1 << 1, 331591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch RightEdge = 1 << 2, 332591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch BottomEdge = 1 << 3, 333591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch LeftEdge = 1 << 4 334591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch }; 335591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch typedef unsigned Edges; 336591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch void drawInnerShadow(const RoundedRect&, const Color& shadowColor, const IntSize shadowOffset, int shadowBlur, int shadowSpread, Edges clippedEdges = NoEdge); 337591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch 33881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // This clip function is used only by <canvas> code. It allows 33981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // implementations to handle clipping on the canvas differently since 34081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // the discipline is different. 34181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void canvasClip(const Path&, WindRule = RULE_EVENODD); 34281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void clipOut(const Path&); 34353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) 34493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) // ---------- Transformation methods ----------------- 34593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) enum IncludeDeviceScale { DefinitelyIncludeDeviceScale, PossiblyIncludeDeviceScale }; 34693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) AffineTransform getCTM(IncludeDeviceScale includeScale = PossiblyIncludeDeviceScale) const; 3471e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) void concatCTM(const AffineTransform& affine) { concat(affineTransformToSkMatrix(affine)); } 3481e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) void setCTM(const AffineTransform& affine) { setMatrix(affineTransformToSkMatrix(affine)); } 34993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void setMatrix(const SkMatrix&); 35093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 35181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void scale(const FloatSize&); 35281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void rotate(float angleInRadians); 35381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void translate(const FloatSize& size) { translate(size.width(), size.height()); } 35481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void translate(float x, float y); 3555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 35693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) // This function applies the device scale factor to the context, making the context capable of 35793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) // acting as a base-level context for a HiDPI environment. 35893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void applyDeviceScaleFactor(float deviceScaleFactor) { scale(FloatSize(deviceScaleFactor, deviceScaleFactor)); } 35993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) // ---------- End transformation methods ----------------- 3605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 36193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) // URL drawing 36293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void setURLForRect(const KURL&, const IntRect&); 36381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void setURLFragmentForRect(const String& name, const IntRect&); 36481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void addURLTargetAtPoint(const String& name, const IntPoint&); 36593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) bool supportsURLFragments() { return printing(); } 36653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) 36781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // Create an image buffer compatible with this context, with suitable resolution 36881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // for drawing into the buffer and then into this context. 369a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) PassOwnPtr<ImageBuffer> createCompatibleBuffer(const IntSize&, OpacityMode = NonOpaque) const; 3705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 37181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) static void adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2, float strokeWidth, StrokeStyle); 37281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 373a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void beginAnnotation(const char*, const char*, const String&, const String&, const String&); 3745267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) void endAnnotation(); 3755267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 37681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)private: 37781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) static void addCornerArc(SkPath*, const SkRect&, const IntSize&, int); 37881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) static void setPathFromConvexPoints(SkPath*, size_t, const FloatPoint*); 37981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) static void setRadii(SkVector*, IntSize, IntSize, IntSize, IntSize); 38081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 3811e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) static PassRefPtr<SkColorFilter> WebCoreColorFilterToSkiaColorFilter(ColorFilter); 3821e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) 3838abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)#if OS(MACOSX) 38481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) static inline int getFocusRingOutset(int offset) { return offset + 2; } 38581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)#else 38681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) static inline int getFocusRingOutset(int offset) { return 0; } 38781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) static const SkPMColor lineColors(int); 38881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) static const SkPMColor antiColors1(int); 38981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) static const SkPMColor antiColors2(int); 39081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) static void draw1xMarker(SkBitmap*, int); 39181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) static void draw2xMarker(SkBitmap*, int); 39281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)#endif 39381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 39481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // Return value % max, but account for value possibly being negative. 39581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) static int fastMod(int value, int max) 39681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) { 39781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) bool isNeg = false; 39881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) if (value < 0) { 39981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) value = -value; 40081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) isNeg = true; 40181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) } 40281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) if (value >= max) 40381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) value %= max; 40481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) if (isNeg) 40581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) value = -value; 40681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) return value; 40781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) } 40881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 40981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // Sets up the common flags on a paint for antialiasing, effects, etc. 41081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // This is implicitly called by setupPaintFill and setupPaintStroke, but 41181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // you may wish to call it directly sometimes if you don't want that other 41281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // behavior. 41381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void setupPaintCommon(SkPaint*) const; 41481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 41581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // Helpers for drawing a focus ring (drawFocusRing) 41681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void drawOuterPath(const SkPath&, SkPaint&, int); 41781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void drawInnerPath(const SkPath&, SkPaint&, int); 41881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 41981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // SkCanvas wrappers. 42081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) bool isDrawingToLayer() const { return m_canvas->isDrawingToLayer(); } 42181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 42293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) bool clipPath(const SkPath&, AntiAliasingMode = NotAntiAliased, SkRegion::Op = SkRegion::kIntersect_Op); 42393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) bool clipRRect(const SkRRect&, AntiAliasingMode = NotAntiAliased, SkRegion::Op = SkRegion::kIntersect_Op); 42481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 42593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) bool concat(const SkMatrix&); 42681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 42781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // common code between setupPaintFor[Filling,Stroking] 42881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void setupShader(SkPaint*, Gradient*, Pattern*, SkColor) const; 42981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 43081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // Apply deferred saves 43181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) void realizeSave(SkCanvas::SaveFlags flags) 43281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) { 43381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) if (m_deferredSaveFlags & flags) { 43481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) m_canvas->save((SkCanvas::SaveFlags)m_deferredSaveFlags); 43581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) m_deferredSaveFlags = 0; 43681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) } 43781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) } 43881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 43993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void didDrawTextInRect(const SkRect& textRect); 44093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 441591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch void fillRectWithRoundedHole(const IntRect&, const RoundedRect& roundedHoleRect, const Color&); 442591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch 44351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) bool isRecording() const; 44451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 44581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // null indicates painting is disabled. Never delete this object. 44681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) SkCanvas* m_canvas; 44781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 448e52495584422c5edb5b2944981473a2e208da323Torne (Richard Coles) // Pointer to the current drawing state. This is a cached value of m_stateStack.last(). 449e52495584422c5edb5b2944981473a2e208da323Torne (Richard Coles) GraphicsContextState* m_state; 45081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // States stack. Enables local drawing state change with save()/restore() calls. 451e52495584422c5edb5b2944981473a2e208da323Torne (Richard Coles) // Use OwnPtr to avoid copying the large state structure. 452e52495584422c5edb5b2944981473a2e208da323Torne (Richard Coles) Vector<OwnPtr<GraphicsContextState> > m_stateStack; 45381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 45481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // Currently pending save flags. 45581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // FIXME: While defined as a bitmask of SkCanvas::SaveFlags, this is mostly used as a bool. 45681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // It will come in handy when adding granular save() support (clip vs. matrix vs. paint). 45781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // crbug.com/233713 45881a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) struct DeferredSaveState; 45981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) unsigned m_deferredSaveFlags; 46081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) Vector<DeferredSaveState> m_saveStateStack; 46181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 4625267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) AnnotationModeFlags m_annotationMode; 4635267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 46419cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) struct RecordingState; 46519cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) Vector<RecordingState> m_recordingStateStack; 46619cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) 46781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)#if !ASSERT_DISABLED 4685267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) unsigned m_annotationCount; 469c0e19a689c8ac22cdc96b291a8d33a5d3b0b34a4Torne (Richard Coles) unsigned m_layerCount; 47081a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)#endif 47181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // Tracks the region painted opaque via the GraphicsContext. 47281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) OpaqueRegionSkia m_opaqueRegion; 473e52495584422c5edb5b2944981473a2e208da323Torne (Richard Coles) bool m_trackOpaqueRegion : 1; 47481a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) 47593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) // Tracks the region where text is painted via the GraphicsContext. 47693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) bool m_trackTextRegion : 1; 47793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) SkRect m_textRegion; 47893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 479e52495584422c5edb5b2944981473a2e208da323Torne (Richard Coles) // Are we on a high DPI display? If so, spelling and grammar markers are larger. 480e52495584422c5edb5b2944981473a2e208da323Torne (Richard Coles) bool m_useHighResMarker : 1; 48181a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) // FIXME: Make this go away: crbug.com/236892 482e52495584422c5edb5b2944981473a2e208da323Torne (Richard Coles) bool m_updatingControlTints : 1; 483e52495584422c5edb5b2944981473a2e208da323Torne (Richard Coles) bool m_accelerated : 1; 484e52495584422c5edb5b2944981473a2e208da323Torne (Richard Coles) bool m_isCertainlyOpaque : 1; 485e52495584422c5edb5b2944981473a2e208da323Torne (Richard Coles) bool m_printing : 1; 48681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)}; 4875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 4885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} // namespace WebCore 4895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 4905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif // GraphicsContext_h 491