Title: [90767] trunk/Source/WebCore
Revision
90767
Author
[email protected]
Date
2011-07-11 11:39:11 -0700 (Mon, 11 Jul 2011)

Log Message

[skia] remove platform helpers for gradients and patterns
https://bugs.webkit.org/show_bug.cgi?id=64281

Patch by Mike Reed <[email protected]> on 2011-07-11
Reviewed by Stephen White.

No new tests. fixes canvas/philip/tests/2d.gradient.object.update.html

Remove (now empty) platform helpers for fill/stroke gradients/patterns. We now pickup the platformGradient
and platformPattern fresh when they're needed, so we can see any edits that have occurred to them
2d.gradient.object.update.html sets the fillgradient, and then edits the gradient object. This CL allows
us to see that edit.

* platform/graphics/GraphicsContext.cpp:
(WebCore::GraphicsContext::setStrokePattern):
(WebCore::GraphicsContext::setFillPattern):
(WebCore::GraphicsContext::setStrokeGradient):
(WebCore::GraphicsContext::setFillGradient):
* platform/graphics/GraphicsContext.h:
* platform/graphics/skia/GraphicsContextSkia.cpp:
(WebCore::GraphicsContext::platformInit):
* platform/graphics/skia/PlatformContextSkia.cpp:
(WebCore::PlatformContextSkia::State::State):
(WebCore::PlatformContextSkia::State::~State):
(WebCore::PlatformContextSkia::PlatformContextSkia):
(WebCore::PlatformContextSkia::drawRect):
(WebCore::PlatformContextSkia::setupShader):
(WebCore::PlatformContextSkia::setupPaintForFilling):
(WebCore::PlatformContextSkia::setupPaintForStroking):
(WebCore::PlatformContextSkia::setFillColor):
(WebCore::PlatformContextSkia::setStrokeColor):
(WebCore::PlatformContextSkia::canAccelerate):
* platform/graphics/skia/PlatformContextSkia.h:
(WebCore::PlatformContextSkia::setGraphicsContext):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (90766 => 90767)


--- trunk/Source/WebCore/ChangeLog	2011-07-11 18:22:17 UTC (rev 90766)
+++ trunk/Source/WebCore/ChangeLog	2011-07-11 18:39:11 UTC (rev 90767)
@@ -1,3 +1,39 @@
+2011-07-11  Mike Reed  <[email protected]>
+
+        [skia] remove platform helpers for gradients and patterns
+        https://bugs.webkit.org/show_bug.cgi?id=64281
+
+        Reviewed by Stephen White.
+
+        No new tests. fixes canvas/philip/tests/2d.gradient.object.update.html
+
+        Remove (now empty) platform helpers for fill/stroke gradients/patterns. We now pickup the platformGradient
+        and platformPattern fresh when they're needed, so we can see any edits that have occurred to them
+        2d.gradient.object.update.html sets the fillgradient, and then edits the gradient object. This CL allows
+        us to see that edit.
+
+        * platform/graphics/GraphicsContext.cpp:
+        (WebCore::GraphicsContext::setStrokePattern):
+        (WebCore::GraphicsContext::setFillPattern):
+        (WebCore::GraphicsContext::setStrokeGradient):
+        (WebCore::GraphicsContext::setFillGradient):
+        * platform/graphics/GraphicsContext.h:
+        * platform/graphics/skia/GraphicsContextSkia.cpp:
+        (WebCore::GraphicsContext::platformInit):
+        * platform/graphics/skia/PlatformContextSkia.cpp:
+        (WebCore::PlatformContextSkia::State::State):
+        (WebCore::PlatformContextSkia::State::~State):
+        (WebCore::PlatformContextSkia::PlatformContextSkia):
+        (WebCore::PlatformContextSkia::drawRect):
+        (WebCore::PlatformContextSkia::setupShader):
+        (WebCore::PlatformContextSkia::setupPaintForFilling):
+        (WebCore::PlatformContextSkia::setupPaintForStroking):
+        (WebCore::PlatformContextSkia::setFillColor):
+        (WebCore::PlatformContextSkia::setStrokeColor):
+        (WebCore::PlatformContextSkia::canAccelerate):
+        * platform/graphics/skia/PlatformContextSkia.h:
+        (WebCore::PlatformContextSkia::setGraphicsContext):
+
 2011-07-11  Young Han Lee  <[email protected]>
 
         Reviewed by Simon Fraser.

Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp (90766 => 90767)


--- trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp	2011-07-11 18:22:17 UTC (rev 90766)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp	2011-07-11 18:39:11 UTC (rev 90767)
@@ -265,7 +265,6 @@
     }
     m_state.strokeGradient.clear();
     m_state.strokePattern = pattern;
-    setPlatformStrokePattern(m_state.strokePattern.get());
 }
 
 void GraphicsContext::setFillPattern(PassRefPtr<Pattern> pattern)
@@ -277,7 +276,6 @@
     }
     m_state.fillGradient.clear();
     m_state.fillPattern = pattern;
-    setPlatformFillPattern(m_state.fillPattern.get());
 }
 
 void GraphicsContext::setStrokeGradient(PassRefPtr<Gradient> gradient)
@@ -289,7 +287,6 @@
     }
     m_state.strokeGradient = gradient;
     m_state.strokePattern.clear();
-    setPlatformStrokeGradient(m_state.strokeGradient.get());
 }
 
 void GraphicsContext::setFillGradient(PassRefPtr<Gradient> gradient)
@@ -301,7 +298,6 @@
     }
     m_state.fillGradient = gradient;
     m_state.fillPattern.clear();
-    setPlatformFillGradient(m_state.fillGradient.get());
 }
 
 Gradient* GraphicsContext::fillGradient() const
@@ -668,24 +664,6 @@
     return m_state.compositeOperator;
 }
 
-#if !USE(SKIA)
-void GraphicsContext::setPlatformFillGradient(Gradient*)
-{
-}
-
-void GraphicsContext::setPlatformFillPattern(Pattern*)
-{
-}
-
-void GraphicsContext::setPlatformStrokeGradient(Gradient*)
-{
-}
-
-void GraphicsContext::setPlatformStrokePattern(Pattern*)
-{
-}
-#endif
-
 #if !USE(CG) && !USE(SKIA)
 // Implement this if you want to go ahead and push the drawing mode into your native context
 // immediately.

Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext.h (90766 => 90767)


--- trunk/Source/WebCore/platform/graphics/GraphicsContext.h	2011-07-11 18:22:17 UTC (rev 90766)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext.h	2011-07-11 18:39:11 UTC (rev 90767)
@@ -535,12 +535,8 @@
         void setPlatformStrokeColor(const Color&, ColorSpace);
         void setPlatformStrokeStyle(StrokeStyle);
         void setPlatformStrokeThickness(float);
-        void setPlatformStrokeGradient(Gradient*);
-        void setPlatformStrokePattern(Pattern*);
 
         void setPlatformFillColor(const Color&, ColorSpace);
-        void setPlatformFillGradient(Gradient*);
-        void setPlatformFillPattern(Pattern*);
 
         void setPlatformShouldAntialias(bool);
         void setPlatformShouldSmoothFonts(bool);

Modified: trunk/Source/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp (90766 => 90767)


--- trunk/Source/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp	2011-07-11 18:22:17 UTC (rev 90766)
+++ trunk/Source/WebCore/platform/graphics/skia/GraphicsContextSkia.cpp	2011-07-11 18:39:11 UTC (rev 90767)
@@ -225,6 +225,9 @@
 // no painting.
 void GraphicsContext::platformInit(PlatformGraphicsContext* gc)
 {
+    if (gc)
+        gc->setGraphicsContext(this);
+
     // the caller owns the gc
     m_data = gc;
     setPaintingDisabled(!gc || !gc->canvas());
@@ -1046,22 +1049,6 @@
     platformContext()->setFillColor(color.rgb());
 }
 
-void GraphicsContext::setPlatformFillGradient(Gradient* gradient)
-{
-    if (paintingDisabled())
-        return;
-
-    platformContext()->setFillShader(gradient->platformGradient());
-}
-
-void GraphicsContext::setPlatformFillPattern(Pattern* pattern)
-{
-    if (paintingDisabled())
-        return;
-
-    platformContext()->setFillShader(pattern->platformPattern(getCTM()));
-}
-
 void GraphicsContext::setPlatformShadow(const FloatSize& size,
                                         float blurFloat,
                                         const Color& color,
@@ -1171,22 +1158,6 @@
     platformContext()->setStrokeThickness(thickness);
 }
 
-void GraphicsContext::setPlatformStrokeGradient(Gradient* gradient)
-{
-    if (paintingDisabled())
-        return;
-
-    platformContext()->setStrokeShader(gradient->platformGradient());
-}
-
-void GraphicsContext::setPlatformStrokePattern(Pattern* pattern)
-{
-    if (paintingDisabled())
-        return;
-
-    platformContext()->setStrokeShader(pattern->platformPattern(getCTM()));
-}
-
 void GraphicsContext::setPlatformTextDrawingMode(TextDrawingModeFlags mode)
 {
     if (paintingDisabled())

Modified: trunk/Source/WebCore/platform/graphics/skia/PlatformContextSkia.cpp (90766 => 90767)


--- trunk/Source/WebCore/platform/graphics/skia/PlatformContextSkia.cpp	2011-07-11 18:22:17 UTC (rev 90766)
+++ trunk/Source/WebCore/platform/graphics/skia/PlatformContextSkia.cpp	2011-07-11 18:39:11 UTC (rev 90767)
@@ -83,12 +83,10 @@
 
     // Fill.
     SkColor m_fillColor;
-    SkShader* m_fillShader;
 
     // Stroke.
     StrokeStyle m_strokeStyle;
     SkColor m_strokeColor;
-    SkShader* m_strokeShader;
     float m_strokeThickness;
     int m_dashRatio;  // Ratio of the length of a dash to its width.
     float m_miterLimit;
@@ -129,10 +127,8 @@
     , m_useAntialiasing(true)
     , m_looper(0)
     , m_fillColor(0xFF000000)
-    , m_fillShader(0)
     , m_strokeStyle(SolidStroke)
     , m_strokeColor(Color::black)
-    , m_strokeShader(0)
     , m_strokeThickness(0)
     , m_dashRatio(3)
     , m_miterLimit(4)
@@ -151,10 +147,8 @@
     , m_useAntialiasing(other.m_useAntialiasing)
     , m_looper(other.m_looper)
     , m_fillColor(other.m_fillColor)
-    , m_fillShader(other.m_fillShader)
     , m_strokeStyle(other.m_strokeStyle)
     , m_strokeColor(other.m_strokeColor)
-    , m_strokeShader(other.m_strokeShader)
     , m_strokeThickness(other.m_strokeThickness)
     , m_dashRatio(other.m_dashRatio)
     , m_miterLimit(other.m_miterLimit)
@@ -171,16 +165,12 @@
     // Up the ref count of these. SkSafeRef does nothing if its argument is 0.
     SkSafeRef(m_looper);
     SkSafeRef(m_dash);
-    SkSafeRef(m_fillShader);
-    SkSafeRef(m_strokeShader);
 }
 
 PlatformContextSkia::State::~State()
 {
     SkSafeUnref(m_looper);
     SkSafeUnref(m_dash);
-    SkSafeUnref(m_fillShader);
-    SkSafeUnref(m_strokeShader);
 }
 
 // Returns a new State with all of this object's inherited properties copied.
@@ -218,6 +208,9 @@
 {
     m_stateStack.append(State());
     m_state = &m_stateStack.last();
+
+    // will be assigned in setGraphicsContext()
+    m_gc = 0;
 }
 
 PlatformContextSkia::~PlatformContextSkia()
@@ -349,14 +342,11 @@
     if (m_state->m_strokeStyle != NoStroke
         && (m_state->m_strokeColor & 0xFF000000)) {
         // We do a fill of four rects to simulate the stroke of a border.
-        SkColor oldFillColor = m_state->m_fillColor;
-
-        // setFillColor() will set the shader to NULL, so save a ref to it now.
-        SkShader* oldFillShader = m_state->m_fillShader;
-        SkSafeRef(oldFillShader);
-        setFillColor(m_state->m_strokeColor);
         paint.reset();
         setupPaintForFilling(&paint);
+        // need to jam in the strokeColor
+        paint.setColor(this->effectiveStrokeColor());
+
         SkRect topBorder = { rect.fLeft, rect.fTop, rect.fRight, rect.fTop + 1 };
         canvas()->drawRect(topBorder, paint);
         SkRect bottomBorder = { rect.fLeft, rect.fBottom - 1, rect.fRight, rect.fBottom };
@@ -365,9 +355,6 @@
         canvas()->drawRect(leftBorder, paint);
         SkRect rightBorder = { rect.fRight - 1, rect.fTop + 1, rect.fRight, rect.fBottom - 1 };
         canvas()->drawRect(rightBorder, paint);
-        setFillColor(oldFillColor);
-        setFillShader(oldFillShader);
-        SkSafeUnref(oldFillShader);
     }
 }
 
@@ -385,20 +372,39 @@
     paint->setLooper(m_state->m_looper);
 }
 
+void PlatformContextSkia::setupShader(SkPaint* paint, Gradient* grad, Pattern* pat, SkColor color) const
+{
+    SkShader* shader = 0;
+
+    if (grad) {
+        shader = grad->platformGradient();
+        color = SK_ColorBLACK;
+    } else if (pat) {
+        shader = pat->platformPattern(m_gc->getCTM());
+        color = SK_ColorBLACK;
+    }
+
+    paint->setColor(m_state->applyAlpha(color));
+    paint->setShader(shader);
+}
+
 void PlatformContextSkia::setupPaintForFilling(SkPaint* paint) const
 {
     setupPaintCommon(paint);
-    paint->setColor(m_state->applyAlpha(m_state->m_fillColor));
-    paint->setShader(m_state->m_fillShader);
+
+    const GraphicsContextState& state = m_gc->state();
+    setupShader(paint, state.fillGradient.get(), state.fillPattern.get(), m_state->m_fillColor);
 }
 
 float PlatformContextSkia::setupPaintForStroking(SkPaint* paint, SkRect* rect, int length) const
 {
     setupPaintCommon(paint);
+
+    const GraphicsContextState& state = m_gc->state();
+    setupShader(paint, state.strokeGradient.get(), state.strokePattern.get(), m_state->m_strokeColor);
+
     float width = m_state->m_strokeThickness;
 
-    paint->setColor(m_state->applyAlpha(m_state->m_strokeColor));
-    paint->setShader(m_state->m_strokeShader);
     paint->setStyle(SkPaint::kStroke_Style);
     paint->setStrokeWidth(SkFloatToScalar(width));
     paint->setStrokeCap(m_state->m_lineCap);
@@ -476,7 +482,6 @@
 void PlatformContextSkia::setFillColor(SkColor color)
 {
     m_state->m_fillColor = color;
-    setFillShader(0);
 }
 
 SkDrawLooper* PlatformContextSkia::getDrawLooper() const
@@ -497,7 +502,6 @@
 void PlatformContextSkia::setStrokeColor(SkColor strokeColor)
 {
     m_state->m_strokeColor = strokeColor;
-    setStrokeShader(0);
 }
 
 float PlatformContextSkia::getStrokeThickness() const
@@ -510,18 +514,6 @@
     m_state->m_strokeThickness = thickness;
 }
 
-void PlatformContextSkia::setStrokeShader(SkShader* strokeShader)
-{
-    if (strokeShader)
-        m_state->m_strokeColor = Color::black;
-
-    if (strokeShader != m_state->m_strokeShader) {
-        SkSafeUnref(m_state->m_strokeShader);
-        m_state->m_strokeShader = strokeShader;
-        SkSafeRef(m_state->m_strokeShader);
-    }
-}
-
 TextDrawingModeFlags PlatformContextSkia::getTextDrawingMode() const
 {
     return m_state->m_textDrawingMode;
@@ -571,18 +563,6 @@
     m_canvas->clipPath(path);
 }
 
-void PlatformContextSkia::setFillShader(SkShader* fillShader)
-{
-    if (fillShader)
-        m_state->m_fillColor = Color::black;
-
-    if (fillShader != m_state->m_fillShader) {
-        SkSafeUnref(m_state->m_fillShader);
-        m_state->m_fillShader = fillShader;
-        SkSafeRef(m_state->m_fillShader);
-    }
-}
-
 InterpolationQuality PlatformContextSkia::interpolationQuality() const
 {
     return m_state->m_interpolationQuality;
@@ -696,7 +676,9 @@
 
 bool PlatformContextSkia::canAccelerate() const
 {
-    return !m_state->m_fillShader; // Can't accelerate with a fill gradient or pattern.
+    // Can't accelerate with a fill gradient or pattern.
+    const GraphicsContextState& state = m_gc->state();
+    return !state.fillGradient.get() && !state.fillPattern.get();
 }
 
 bool PlatformContextSkia::canvasClipApplied() const

Modified: trunk/Source/WebCore/platform/graphics/skia/PlatformContextSkia.h (90766 => 90767)


--- trunk/Source/WebCore/platform/graphics/skia/PlatformContextSkia.h	2011-07-11 18:22:17 UTC (rev 90766)
+++ trunk/Source/WebCore/platform/graphics/skia/PlatformContextSkia.h	2011-07-11 18:39:11 UTC (rev 90767)
@@ -81,6 +81,10 @@
     PlatformContextSkia(SkCanvas*);
     ~PlatformContextSkia();
 
+    // Sets the graphics context associated with this context.
+    // GraphicsContextSkia calls this from its constructor.
+    void setGraphicsContext(const GraphicsContext* gc) { m_gc = gc; }
+
     // Sets the canvas associated with this context. Use when supplying NULL
     // to the constructor.
     void setCanvas(SkCanvas*);
@@ -126,11 +130,9 @@
     void setLineJoin(SkPaint::Join);
     void setXfermodeMode(SkXfermode::Mode);
     void setFillColor(SkColor);
-    void setFillShader(SkShader*);
     void setStrokeStyle(StrokeStyle);
     void setStrokeColor(SkColor);
     void setStrokeThickness(float thickness);
-    void setStrokeShader(SkShader*);
     void setTextDrawingMode(TextDrawingModeFlags mode);
     void setUseAntialiasing(bool enable);
     void setDashPathEffect(SkDashPathEffect*);
@@ -210,11 +212,15 @@
     void uploadSoftwareToHardware(CompositeOperator) const;
     void readbackHardwareToSoftware() const;
 
+    // common code between setupPaintFor[Filling,Stroking]
+    void setupShader(SkPaint*, Gradient*, Pattern*, SkColor) const;
+
     // Defines drawing style.
     struct State;
 
     // NULL indicates painting is disabled. Never delete this object.
     SkCanvas* m_canvas;
+    const GraphicsContext* m_gc;
 
     // States stack. Enables local drawing state change with save()/restore()
     // calls.
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to