diff options
Diffstat (limited to 'Source/WebCore')
4 files changed, 45 insertions, 146 deletions
diff --git a/Source/WebCore/Android.mk b/Source/WebCore/Android.mk index 3cf8d54..794a4a8 100644 --- a/Source/WebCore/Android.mk +++ b/Source/WebCore/Android.mk @@ -634,7 +634,6 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \ platform/graphics/WidthIterator.cpp \ \ platform/graphics/android/BitmapAllocatorAndroid.cpp \ - platform/graphics/android/GradientAndroid.cpp \ platform/graphics/android/GraphicsLayerAndroid.cpp \ platform/graphics/android/GLWebViewState.cpp \ platform/graphics/android/ImageAndroid.cpp \ @@ -728,6 +727,7 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \ platform/graphics/skia/FloatPointSkia.cpp \ platform/graphics/skia/FloatRectSkia.cpp \ platform/graphics/skia/GlyphPageTreeNodeSkia.cpp \ + platform/graphics/skia/GradientSkia.cpp \ platform/graphics/skia/IntPointSkia.cpp \ platform/graphics/skia/IntRectSkia.cpp \ platform/graphics/skia/NativeImageSkia.cpp \ diff --git a/Source/WebCore/platform/graphics/Gradient.cpp b/Source/WebCore/platform/graphics/Gradient.cpp index 7541646..7e3984f 100644 --- a/Source/WebCore/platform/graphics/Gradient.cpp +++ b/Source/WebCore/platform/graphics/Gradient.cpp @@ -221,7 +221,7 @@ void Gradient::setGradientSpaceTransform(const AffineTransform& gradientSpaceTra setPlatformGradientSpaceTransform(gradientSpaceTransformation); } -#if !(USE(SKIA) && !PLATFORM(ANDROID)) && !USE(CAIRO) +#if !USE(SKIA) && !USE(CAIRO) void Gradient::setPlatformGradientSpaceTransform(const AffineTransform&) { } diff --git a/Source/WebCore/platform/graphics/android/GradientAndroid.cpp b/Source/WebCore/platform/graphics/android/GradientAndroid.cpp deleted file mode 100644 index 7bc69c5..0000000 --- a/Source/WebCore/platform/graphics/android/GradientAndroid.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright 2006, The Android Open Source Project - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "Gradient.h" - -#include "CSSParser.h" -#include "GraphicsContext.h" -#include "NotImplemented.h" -#include "SkCanvas.h" -#include "SkColorShader.h" -#include "SkGradientShader.h" -#include "SkPaint.h" - -namespace WebCore { - -void Gradient::platformDestroy() -{ - delete m_gradient; - m_gradient = 0; -} - -static U8CPU F2B(float x) -{ - return (int)(x * 255); -} - -SkShader* Gradient::platformGradient() -{ - if (m_gradient) - return m_gradient; - - // need to ensure that the m_stops array is sorted. We call getColor() - // which, as a side effect, does the sort. - // TODO: refactor Gradient.h to formally expose a sort method - { - float r, g, b, a; - this->getColor(0, &r, &g, &b, &a); - } - - SkShader::TileMode mode = SkShader::kClamp_TileMode; - switch (m_spreadMethod) { - case SpreadMethodReflect: - mode = SkShader::kMirror_TileMode; - break; - case SpreadMethodRepeat: - mode = SkShader::kRepeat_TileMode; - break; - case SpreadMethodPad: - mode = SkShader::kClamp_TileMode; - break; - } - - SkPoint pts[2] = { m_p0, m_p1 }; // convert to SkPoint - - const size_t count = m_stops.size(); - SkAutoMalloc storage(count * (sizeof(SkColor) + sizeof(SkScalar))); - SkColor* colors = (SkColor*)storage.get(); - SkScalar* pos = (SkScalar*)(colors + count); - - Vector<ColorStop>::iterator iter = m_stops.begin(); - for (int i = 0; iter != m_stops.end(); i++) { - pos[i] = SkFloatToScalar(iter->stop); - colors[i] = SkColorSetARGB(F2B(iter->alpha), F2B(iter->red), - F2B(iter->green), F2B(iter->blue)); - ++iter; - } - - if (m_radial) { - m_gradient = SkGradientShader::CreateTwoPointRadial(pts[0], - SkFloatToScalar(m_r0), - pts[1], - SkFloatToScalar(m_r1), - colors, pos, count, mode); - } else - m_gradient = SkGradientShader::CreateLinear(pts, colors, pos, count, mode); - - if (!m_gradient) - m_gradient = new SkColorShader(0); - - SkMatrix matrix = m_gradientSpaceTransformation; - m_gradient->setLocalMatrix(matrix); - - return m_gradient; -} - -void Gradient::fill(GraphicsContext* context, const FloatRect& rect) -{ - context->setFillGradient(this); - context->fillRect(rect); -} - - -} //namespace diff --git a/Source/WebCore/platform/graphics/android/context/GraphicsContextAndroid.cpp b/Source/WebCore/platform/graphics/android/context/GraphicsContextAndroid.cpp index 12b53a3..f2d1400 100644 --- a/Source/WebCore/platform/graphics/android/context/GraphicsContextAndroid.cpp +++ b/Source/WebCore/platform/graphics/android/context/GraphicsContextAndroid.cpp @@ -66,13 +66,31 @@ private: PlatformGraphicsContext* m_context; }; -static SkShader* extractShader(Pattern* pat, Gradient* grad) +static void syncPlatformContext(GraphicsContext* gc) { - if (pat) - return pat->platformPattern(AffineTransform()); - else if (grad) - return grad->platformGradient(); - return 0; + // Stroke and fill sometimes reference each other, so always + // sync them both to make sure our state is consistent. + + PlatformGraphicsContext* pgc = gc->platformContext(); + Gradient* grad = gc->state().fillGradient.get(); + Pattern* pat = gc->state().fillPattern.get(); + + if (grad) + pgc->setFillShader(grad->platformGradient()); + else if (pat) + pgc->setFillShader(pat->platformPattern(AffineTransform())); + else + pgc->setFillColor(gc->state().fillColor); + + grad = gc->state().strokeGradient.get(); + pat = gc->state().strokePattern.get(); + + if (grad) + pgc->setStrokeShader(grad->platformGradient()); + else if (pat) + pgc->setStrokeShader(pat->platformPattern(AffineTransform())); + else + pgc->setStrokeColor(gc->state().strokeColor); } //////////////////////////////////////////////////////////////////////////////////////////////// @@ -137,6 +155,7 @@ void GraphicsContext::drawRect(const IntRect& rect) if (paintingDisabled()) return; + syncPlatformContext(this); platformContext()->drawRect(rect); } @@ -146,6 +165,7 @@ void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2) if (paintingDisabled()) return; + syncPlatformContext(this); platformContext()->drawLine(point1, point2); } @@ -154,6 +174,7 @@ void GraphicsContext::drawLineForText(const FloatPoint& pt, float width, bool /* if (paintingDisabled()) return; + syncPlatformContext(this); platformContext()->drawLineForText(pt, width); } @@ -163,6 +184,7 @@ void GraphicsContext::drawLineForTextChecking(const FloatPoint& pt, float width, if (paintingDisabled()) return; + syncPlatformContext(this); platformContext()->drawLineForTextChecking(pt, width, style); } @@ -172,6 +194,7 @@ void GraphicsContext::drawEllipse(const IntRect& rect) if (paintingDisabled()) return; + syncPlatformContext(this); platformContext()->drawEllipse(rect); } @@ -180,6 +203,7 @@ void GraphicsContext::strokeArc(const IntRect& r, int startAngle, int angleSpan) if (paintingDisabled()) return; + syncPlatformContext(this); platformContext()->strokeArc(r, startAngle, angleSpan); } @@ -189,6 +213,7 @@ void GraphicsContext::drawConvexPolygon(size_t numPoints, const FloatPoint* poin if (paintingDisabled()) return; + syncPlatformContext(this); platformContext()->drawConvexPolygon(numPoints, points, shouldAntialias); } @@ -199,6 +224,7 @@ void GraphicsContext::fillRoundedRect(const IntRect& rect, const IntSize& topLef if (paintingDisabled()) return; + syncPlatformContext(this); platformContext()->fillRoundedRect(rect, topLeft, topRight, bottomLeft, bottomRight, color, colorSpace); } @@ -208,6 +234,7 @@ void GraphicsContext::fillRect(const FloatRect& rect) if (paintingDisabled()) return; + syncPlatformContext(this); platformContext()->fillRect(rect); } @@ -216,6 +243,7 @@ void GraphicsContext::fillRect(const FloatRect& rect, const Color& color, ColorS if (paintingDisabled()) return; + syncPlatformContext(this); platformContext()->fillRect(rect, color, colorSpace); } @@ -308,6 +336,7 @@ void GraphicsContext::setupFillPaint(SkPaint* paint) { if (paintingDisabled()) return; + syncPlatformContext(this); platformContext()->setupPaintFill(paint); } @@ -315,6 +344,7 @@ void GraphicsContext::setupStrokePaint(SkPaint* paint) { if (paintingDisabled()) return; + syncPlatformContext(this); platformContext()->setupPaintStroke(paint, 0); } @@ -322,14 +352,12 @@ bool GraphicsContext::setupShadowPaint(SkPaint* paint, SkPoint* offset) { if (paintingDisabled()) return false; + syncPlatformContext(this); return platformContext()->setupPaintShadow(paint, offset); } void GraphicsContext::setPlatformStrokeColor(const Color& c, ColorSpace) { - if (paintingDisabled()) - return; - platformContext()->setStrokeColor(c); } void GraphicsContext::setPlatformStrokeThickness(float f) @@ -348,9 +376,6 @@ void GraphicsContext::setPlatformStrokeStyle(StrokeStyle style) void GraphicsContext::setPlatformFillColor(const Color& c, ColorSpace) { - if (paintingDisabled()) - return; - platformContext()->setFillColor(c); } void GraphicsContext::setPlatformShadow(const FloatSize& size, float blur, const Color& color, ColorSpace) @@ -384,6 +409,7 @@ void GraphicsContext::drawFocusRing(const Vector<IntRect>& rects, int width, int if (paintingDisabled()) return; + syncPlatformContext(this); platformContext()->drawFocusRing(rects, width, offset, color); } @@ -424,6 +450,7 @@ void GraphicsContext::clearRect(const FloatRect& rect) if (paintingDisabled()) return; + syncPlatformContext(this); platformContext()->clearRect(rect); } @@ -432,6 +459,7 @@ void GraphicsContext::strokeRect(const FloatRect& rect, float lineWidth) if (paintingDisabled()) return; + syncPlatformContext(this); platformContext()->strokeRect(rect, lineWidth); } @@ -520,34 +548,18 @@ void GraphicsContext::setPlatformShouldAntialias(bool useAA) void GraphicsContext::setPlatformFillGradient(Gradient* fillGradient) { - if (paintingDisabled()) - return; - SkShader* shader = extractShader(0, fillGradient); - platformContext()->setFillShader(shader); } void GraphicsContext::setPlatformFillPattern(Pattern* fillPattern) { - if (paintingDisabled()) - return; - SkShader* shader = extractShader(fillPattern, 0); - platformContext()->setFillShader(shader); } void GraphicsContext::setPlatformStrokeGradient(Gradient* strokeGradient) { - if (paintingDisabled()) - return; - SkShader* shader = extractShader(0, strokeGradient); - platformContext()->setStrokeShader(shader); } void GraphicsContext::setPlatformStrokePattern(Pattern* strokePattern) { - if (paintingDisabled()) - return; - SkShader* shader = extractShader(strokePattern, 0); - platformContext()->setStrokeShader(shader); } AffineTransform GraphicsContext::getCTM() const @@ -579,6 +591,7 @@ void GraphicsContext::fillPath(const Path& pathToFill) if (paintingDisabled()) return; + syncPlatformContext(this); platformContext()->fillPath(pathToFill, fillRule()); } @@ -587,6 +600,7 @@ void GraphicsContext::strokePath(const Path& pathToStroke) if (paintingDisabled()) return; + syncPlatformContext(this); platformContext()->strokePath(pathToStroke); } @@ -634,6 +648,7 @@ void GraphicsContext::drawHighlightForText(const Font& font, const TextRun& run, if (paintingDisabled()) return; + syncPlatformContext(this); platformContext()->drawHighlightForText(font, run, point, h, backgroundColor, colorSpace, from, to, isActive); } |