2009-01-09 Dimitri Glazkov <dglazkov@chromium.org>
authoreric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Jan 2009 22:55:20 +0000 (22:55 +0000)
committereric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Jan 2009 22:55:20 +0000 (22:55 +0000)
        Reviewed by Eric Seidel.

        Add PlatformContextSkia and PlatformGraphics.h to platform/graphics/skia
        https://bugs.webkit.org/show_bug.cgi?id=23215

        * platform/graphics/skia/PlatformContextSkia.cpp: Added.
        (PlatformContextSkia::State::State):
        (PlatformContextSkia::State::~State):
        (PlatformContextSkia::State::applyAlpha):
        (PlatformContextSkia::PlatformContextSkia):
        (PlatformContextSkia::~PlatformContextSkia):
        (PlatformContextSkia::setCanvas):
        (PlatformContextSkia::save):
        (PlatformContextSkia::restore):
        (PlatformContextSkia::drawRect):
        (PlatformContextSkia::setupPaintCommon):
        (PlatformContextSkia::setupPaintForFilling):
        (PlatformContextSkia::setupPaintForStroking):
        (PlatformContextSkia::setDrawLooper):
        (PlatformContextSkia::setMiterLimit):
        (PlatformContextSkia::setAlpha):
        (PlatformContextSkia::setLineCap):
        (PlatformContextSkia::setLineJoin):
        (PlatformContextSkia::setPorterDuffMode):
        (PlatformContextSkia::setFillColor):
        (PlatformContextSkia::getDrawLooper):
        (PlatformContextSkia::getStrokeStyle):
        (PlatformContextSkia::setStrokeStyle):
        (PlatformContextSkia::setStrokeColor):
        (PlatformContextSkia::getStrokeThickness):
        (PlatformContextSkia::setStrokeThickness):
        (PlatformContextSkia::getTextDrawingMode):
        (PlatformContextSkia::setTextDrawingMode):
        (PlatformContextSkia::setUseAntialiasing):
        (PlatformContextSkia::fillColor):
        (PlatformContextSkia::beginPath):
        (PlatformContextSkia::addPath):
        (PlatformContextSkia::setFillRule):
        (PlatformContextSkia::setGradient):
        (PlatformContextSkia::setPattern):
        (PlatformContextSkia::setDashPathEffect):
        (PlatformContextSkia::paintSkPaint):
        (PlatformContextSkia::bitmap):
        (PlatformContextSkia::isPrinting):
        * platform/graphics/skia/PlatformContextSkia.h: Added.
        (PlatformContextSkia::currentPath):
        (PlatformContextSkia::canvas):
        (PlatformContextSkia::gdk_skia):
        * platform/graphics/skia/PlatformGraphics.h: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@39766 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/platform/graphics/skia/PlatformContextSkia.cpp [new file with mode: 0644]
WebCore/platform/graphics/skia/PlatformContextSkia.h [new file with mode: 0644]
WebCore/platform/graphics/skia/PlatformGraphics.h [new file with mode: 0644]

index 0ff4e0513b53dd1951c5a58af7d88a675cb586b9..edc488f57e5a1b4e17f91fdb37a2d5d46f1608f1 100644 (file)
@@ -4,6 +4,58 @@
         
         * WebCore.LP64.exp:
 
+2009-01-09  Dimitri Glazkov  <dglazkov@chromium.org>
+
+        Reviewed by Eric Seidel.
+
+        Add PlatformContextSkia and PlatformGraphics.h to platform/graphics/skia
+        https://bugs.webkit.org/show_bug.cgi?id=23215
+
+        * platform/graphics/skia/PlatformContextSkia.cpp: Added.
+        (PlatformContextSkia::State::State):
+        (PlatformContextSkia::State::~State):
+        (PlatformContextSkia::State::applyAlpha):
+        (PlatformContextSkia::PlatformContextSkia):
+        (PlatformContextSkia::~PlatformContextSkia):
+        (PlatformContextSkia::setCanvas):
+        (PlatformContextSkia::save):
+        (PlatformContextSkia::restore):
+        (PlatformContextSkia::drawRect):
+        (PlatformContextSkia::setupPaintCommon):
+        (PlatformContextSkia::setupPaintForFilling):
+        (PlatformContextSkia::setupPaintForStroking):
+        (PlatformContextSkia::setDrawLooper):
+        (PlatformContextSkia::setMiterLimit):
+        (PlatformContextSkia::setAlpha):
+        (PlatformContextSkia::setLineCap):
+        (PlatformContextSkia::setLineJoin):
+        (PlatformContextSkia::setPorterDuffMode):
+        (PlatformContextSkia::setFillColor):
+        (PlatformContextSkia::getDrawLooper):
+        (PlatformContextSkia::getStrokeStyle):
+        (PlatformContextSkia::setStrokeStyle):
+        (PlatformContextSkia::setStrokeColor):
+        (PlatformContextSkia::getStrokeThickness):
+        (PlatformContextSkia::setStrokeThickness):
+        (PlatformContextSkia::getTextDrawingMode):
+        (PlatformContextSkia::setTextDrawingMode):
+        (PlatformContextSkia::setUseAntialiasing):
+        (PlatformContextSkia::fillColor):
+        (PlatformContextSkia::beginPath):
+        (PlatformContextSkia::addPath):
+        (PlatformContextSkia::setFillRule):
+        (PlatformContextSkia::setGradient):
+        (PlatformContextSkia::setPattern):
+        (PlatformContextSkia::setDashPathEffect):
+        (PlatformContextSkia::paintSkPaint):
+        (PlatformContextSkia::bitmap):
+        (PlatformContextSkia::isPrinting):
+        * platform/graphics/skia/PlatformContextSkia.h: Added.
+        (PlatformContextSkia::currentPath):
+        (PlatformContextSkia::canvas):
+        (PlatformContextSkia::gdk_skia):
+        * platform/graphics/skia/PlatformGraphics.h: Added.
+
 2009-01-09  Dimitri Glazkov  <dglazkov@chromium.org>
 
         Reviewed by Eric Seidel.
diff --git a/WebCore/platform/graphics/skia/PlatformContextSkia.cpp b/WebCore/platform/graphics/skia/PlatformContextSkia.cpp
new file mode 100644 (file)
index 0000000..60dbbe0
--- /dev/null
@@ -0,0 +1,427 @@
+/*
+ * Copyright (c) 2008, Google Inc. All rights reserved.
+ * 
+ * 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.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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 "GraphicsContext.h"
+#include "NativeImageSkia.h"
+#include "PlatformContextSkia.h"
+#include "SkiaUtils.h"
+
+#include "skia/ext/image_operations.h"
+#include "skia/ext/platform_canvas.h"
+
+#include "SkBitmap.h"
+#include "SkColorPriv.h"
+#include "SkShader.h"
+#include "SkDashPathEffect.h"
+
+#include <wtf/MathExtras.h>
+
+#if defined(__linux__)
+#include "GdkSkia.h"
+#endif
+
+// State -----------------------------------------------------------------------
+
+// Encapsulates the additional painting state information we store for each
+// pushed graphics state.
+struct PlatformContextSkia::State {
+    State();
+    State(const State&);
+    ~State();
+
+    // Common shader state.
+    float m_alpha;
+    SkPorterDuff::Mode m_porterDuffMode;
+    SkShader* m_gradient;
+    SkShader* m_pattern;
+    bool m_useAntialiasing;
+    SkDrawLooper* m_looper;
+
+    // Fill.
+    SkColor m_fillColor;
+
+    // Stroke.
+    WebCore::StrokeStyle m_strokeStyle;
+    SkColor m_strokeColor;
+    float m_strokeThickness;
+    int m_dashRatio;  // Ratio of the length of a dash to its width.
+    float m_miterLimit;
+    SkPaint::Cap m_lineCap;
+    SkPaint::Join m_lineJoin;
+    SkDashPathEffect* m_dash;
+
+    // Text. (See cTextFill & friends in GraphicsContext.h.)
+    int m_textDrawingMode;
+
+    // Helper function for applying the state's alpha value to the given input
+    // color to produce a new output color.
+    SkColor applyAlpha(SkColor) const;
+
+private:
+    // Not supported.
+    void operator=(const State&);
+};
+
+// Note: Keep theses default values in sync with GraphicsContextState.
+PlatformContextSkia::State::State()
+    : m_alpha(1)
+    , m_porterDuffMode(SkPorterDuff::kSrcOver_Mode)
+    , m_gradient(0)
+    , m_pattern(0)
+    , m_useAntialiasing(true)
+    , m_looper(0)
+    , m_fillColor(0xFF000000)
+    , m_strokeStyle(WebCore::SolidStroke)
+    , m_strokeColor(WebCore::Color::black)
+    , m_strokeThickness(0)
+    , m_dashRatio(3)
+    , m_miterLimit(4)
+    , m_lineCap(SkPaint::kDefault_Cap)
+    , m_lineJoin(SkPaint::kDefault_Join)
+    , m_dash(0)
+    , m_textDrawingMode(WebCore::cTextFill)
+{
+}
+
+PlatformContextSkia::State::State(const State& other)
+{
+    memcpy(this, &other, sizeof(State));
+
+    m_looper->safeRef();
+    m_dash->safeRef();
+    m_gradient->safeRef();
+    m_pattern->safeRef();
+}
+
+PlatformContextSkia::State::~State()
+{
+    m_looper->safeUnref();
+    m_dash->safeUnref();
+    m_gradient->safeUnref();
+    m_pattern->safeUnref();
+}
+
+SkColor PlatformContextSkia::State::applyAlpha(SkColor c) const
+{
+    int s = roundf(m_alpha * 256);
+    if (s >= 256)
+        return c;
+    if (s < 0)
+        return 0;
+
+    int a = SkAlphaMul(SkColorGetA(c), s);
+    return (c & 0x00FFFFFF) | (a << 24);
+}
+
+// PlatformContextSkia ---------------------------------------------------------
+
+// Danger: canvas can be NULL.
+PlatformContextSkia::PlatformContextSkia(skia::PlatformCanvas* canvas)
+    : m_canvas(canvas)
+    , m_stateStack(sizeof(State))
+{
+    m_stateStack.append(State());
+    m_state = &m_stateStack.last();
+#if defined(OS_LINUX)
+    m_gdkskia = m_canvas ? gdk_skia_new(m_canvas) : 0;
+#endif
+}
+
+PlatformContextSkia::~PlatformContextSkia()
+{
+#if defined(OS_LINUX)
+    if (m_gdkskia) {
+        g_object_unref(m_gdkskia);
+        m_gdkskia = 0;
+    }
+#endif
+}
+
+void PlatformContextSkia::setCanvas(skia::PlatformCanvas* canvas)
+{
+    m_canvas = canvas;
+}
+
+void PlatformContextSkia::save()
+{
+    m_stateStack.append(*m_state);
+    m_state = &m_stateStack.last();
+
+    // Save our native canvas.
+    canvas()->save();
+}
+
+void PlatformContextSkia::restore()
+{
+    m_stateStack.removeLast();
+    m_state = &m_stateStack.last();
+
+    // Restore our native canvas.
+    canvas()->restore();
+}
+
+void PlatformContextSkia::drawRect(SkRect rect)
+{
+    SkPaint paint;
+    int fillcolorNotTransparent = m_state->m_fillColor & 0xFF000000;
+    if (fillcolorNotTransparent) {
+        setupPaintForFilling(&paint);
+        canvas()->drawRect(rect, paint);
+    }
+
+    if (m_state->m_strokeStyle != WebCore::NoStroke &&
+        (m_state->m_strokeColor & 0xFF000000)) {
+        if (fillcolorNotTransparent) {
+            // This call is expensive so don't call it unnecessarily.
+            paint.reset();
+        }
+        setupPaintForStroking(&paint, &rect, 0);
+        canvas()->drawRect(rect, paint);
+    }
+}
+
+void PlatformContextSkia::setupPaintCommon(SkPaint* paint) const
+{
+#ifdef SK_DEBUGx
+    {
+        SkPaint defaultPaint;
+        SkASSERT(*paint == defaultPaint);
+    }
+#endif
+
+    paint->setAntiAlias(m_state->m_useAntialiasing);
+    paint->setPorterDuffXfermode(m_state->m_porterDuffMode);
+    paint->setLooper(m_state->m_looper);
+
+    if (m_state->m_gradient)
+        paint->setShader(m_state->m_gradient);
+    else if (m_state->m_pattern)
+        paint->setShader(m_state->m_pattern);
+}
+
+void PlatformContextSkia::setupPaintForFilling(SkPaint* paint) const
+{
+    setupPaintCommon(paint);
+    paint->setColor(m_state->applyAlpha(m_state->m_fillColor));
+}
+
+float PlatformContextSkia::setupPaintForStroking(SkPaint* paint, SkRect* rect, int length) const
+{
+    setupPaintCommon(paint);
+    float width = m_state->m_strokeThickness;
+
+    // This allows dashing and dotting to work properly for hairline strokes.
+    if (width == 0)
+        width = 1;
+
+    paint->setColor(m_state->applyAlpha(m_state->m_strokeColor));
+    paint->setStyle(SkPaint::kStroke_Style);
+    paint->setStrokeWidth(SkFloatToScalar(width));
+    paint->setStrokeCap(m_state->m_lineCap);
+    paint->setStrokeJoin(m_state->m_lineJoin);
+    paint->setStrokeMiter(SkFloatToScalar(m_state->m_miterLimit));
+
+    if (rect != 0 && (static_cast<int>(roundf(width)) & 1))
+        rect->inset(-SK_ScalarHalf, -SK_ScalarHalf);
+
+    if (m_state->m_dash)
+        paint->setPathEffect(m_state->m_dash);
+    else {
+        switch (m_state->m_strokeStyle) {
+        case WebCore::NoStroke:
+        case WebCore::SolidStroke:
+            break;
+        case WebCore::DashedStroke:
+            width = m_state->m_dashRatio * width;
+            // Fall through.
+        case WebCore::DottedStroke:
+            SkScalar dashLength;
+            if (length) {
+                // Determine about how many dashes or dots we should have.
+                int numDashes = length / roundf(width);
+                if (!(numDashes & 1))
+                    numDashes++;    // Make it odd so we end on a dash/dot.
+                // Use the number of dashes to determine the length of a
+                // dash/dot, which will be approximately width
+                dashLength = SkScalarDiv(SkIntToScalar(length), SkIntToScalar(numDashes));
+            } else
+                dashLength = SkFloatToScalar(width);
+            SkScalar intervals[2] = { dashLength, dashLength };
+            paint->setPathEffect(new SkDashPathEffect(intervals, 2, 0))->unref();
+        }
+    }
+
+    return width;
+}
+
+void PlatformContextSkia::setDrawLooper(SkDrawLooper* dl)
+{
+    SkRefCnt_SafeAssign(m_state->m_looper, dl);
+}
+
+void PlatformContextSkia::setMiterLimit(float ml)
+{
+    m_state->m_miterLimit = ml;
+}
+
+void PlatformContextSkia::setAlpha(float alpha)
+{
+    m_state->m_alpha = alpha;
+}
+
+void PlatformContextSkia::setLineCap(SkPaint::Cap lc)
+{
+    m_state->m_lineCap = lc;
+}
+
+void PlatformContextSkia::setLineJoin(SkPaint::Join lj)
+{
+    m_state->m_lineJoin = lj;
+}
+
+void PlatformContextSkia::setPorterDuffMode(SkPorterDuff::Mode pdm)
+{
+    m_state->m_porterDuffMode = pdm;
+}
+
+void PlatformContextSkia::setFillColor(SkColor color)
+{
+    m_state->m_fillColor = color;
+}
+
+SkDrawLooper* PlatformContextSkia::getDrawLooper() const
+{
+    return m_state->m_looper;
+}
+
+WebCore::StrokeStyle PlatformContextSkia::getStrokeStyle() const
+{
+    return m_state->m_strokeStyle;
+}
+
+void PlatformContextSkia::setStrokeStyle(WebCore::StrokeStyle strokeStyle)
+{
+    m_state->m_strokeStyle = strokeStyle;
+}
+
+void PlatformContextSkia::setStrokeColor(SkColor strokeColor)
+{
+    m_state->m_strokeColor = strokeColor;
+}
+
+float PlatformContextSkia::getStrokeThickness() const
+{
+    return m_state->m_strokeThickness;
+}
+
+void PlatformContextSkia::setStrokeThickness(float thickness)
+{
+    m_state->m_strokeThickness = thickness;
+}
+
+int PlatformContextSkia::getTextDrawingMode() const
+{
+    return m_state->m_textDrawingMode;
+}
+
+void PlatformContextSkia::setTextDrawingMode(int mode)
+{
+  // cTextClip is never used, so we assert that it isn't set:
+  // https://bugs.webkit.org/show_bug.cgi?id=21898
+  ASSERT((mode & WebCore::cTextClip) == 0);
+  m_state->m_textDrawingMode = mode;
+}
+
+void PlatformContextSkia::setUseAntialiasing(bool enable)
+{
+    m_state->m_useAntialiasing = enable;
+}
+
+SkColor PlatformContextSkia::fillColor() const
+{
+    return m_state->m_fillColor;
+}
+
+void PlatformContextSkia::beginPath()
+{
+    m_path.reset();
+}
+
+void PlatformContextSkia::addPath(const SkPath& path)
+{
+    m_path.addPath(path);
+}
+
+void PlatformContextSkia::setFillRule(SkPath::FillType fr)
+{
+    m_path.setFillType(fr);
+}
+
+void PlatformContextSkia::setGradient(SkShader* gradient)
+{
+    if (gradient != m_state->m_gradient) {
+        m_state->m_gradient->safeUnref();
+        m_state->m_gradient = gradient;
+    }
+}
+
+void PlatformContextSkia::setPattern(SkShader* pattern)
+{
+    if (pattern != m_state->m_pattern) {
+        m_state->m_pattern->safeUnref();
+        m_state->m_pattern = pattern;
+    }
+}
+
+void PlatformContextSkia::setDashPathEffect(SkDashPathEffect* dash)
+{
+    if (dash != m_state->m_dash) {
+        m_state->m_dash->safeUnref();
+        m_state->m_dash = dash;
+    }
+}
+
+void PlatformContextSkia::paintSkPaint(const SkRect& rect,
+                                       const SkPaint& paint)
+{
+    m_canvas->drawRect(rect, paint);
+}
+
+const SkBitmap* PlatformContextSkia::bitmap() const
+{
+    return &m_canvas->getDevice()->accessBitmap(false);
+}
+
+bool PlatformContextSkia::isPrinting()
+{
+    return m_canvas->getTopPlatformDevice().IsVectorial();
+}
diff --git a/WebCore/platform/graphics/skia/PlatformContextSkia.h b/WebCore/platform/graphics/skia/PlatformContextSkia.h
new file mode 100644 (file)
index 0000000..78e9a19
--- /dev/null
@@ -0,0 +1,173 @@
+/*
+ * Copyright (c) 2008, Google Inc. All rights reserved.
+ * 
+ * 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.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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.
+ */
+
+#ifndef PlatformContextSkia_h
+#define PlatformContextSkia_h
+
+#include "GraphicsContext.h"
+#include "Noncopyable.h"
+
+#include "SkDashPathEffect.h"
+#include "SkDrawLooper.h"
+#include "SkDeque.h"
+#include "skia/ext/platform_canvas.h"
+#include "SkPaint.h"
+#include "SkPath.h"
+
+#include <wtf/Vector.h>
+
+typedef struct _GdkDrawable GdkSkia;
+
+// This class holds the platform-specific state for GraphicsContext. We put
+// most of our Skia wrappers on this class. In theory, a lot of this stuff could
+// be moved to GraphicsContext directly, except that some code external to this
+// would like to poke at our graphics layer as well (like the Image and Font
+// stuff, which needs some amount of our wrappers and state around SkCanvas).
+//
+// So in general, this class uses just Skia types except when there's no easy
+// conversion. GraphicsContext is responsible for converting the WebKit types to
+// Skia types and setting up the eventual call to the Skia functions.
+//
+// This class then keeps track of all the current Skia state. WebKit expects
+// that the graphics state that is pushed and popped by save() and restore()
+// includes things like colors and pen styles. Skia does this differently, where
+// push and pop only includes transforms and bitmaps, and the application is
+// responsible for managing the painting state which is store in separate
+// SkPaint objects. This class provides the adaptor that allows the painting
+// state to be pushed and popped along with the bitmap.
+class PlatformContextSkia : Noncopyable {
+public:
+    // For printing, there shouldn't be any canvas. canvas can be NULL. If you
+    // supply a NULL canvas, you can also call setCanvas later.
+    PlatformContextSkia(skia::PlatformCanvas*);
+    ~PlatformContextSkia();
+
+    // Sets the canvas associated with this context. Use when supplying NULL
+    // to the constructor.
+    void setCanvas(skia::PlatformCanvas*);
+
+    void save();
+    void restore();
+
+    // Sets up the common flags on a paint for antialiasing, effects, etc.
+    // This is implicitly called by setupPaintFill and setupPaintStroke, but
+    // you may wish to call it directly sometimes if you don't want that other
+    // behavior.
+    void setupPaintCommon(SkPaint*) const;
+
+    // Sets up the paint for the current fill style.
+    void setupPaintForFilling(SkPaint*) const;
+
+    // Sets up the paint for stroking. Returns an int representing the width of
+    // the pen, or 1 if the pen's width is 0 if a non-zero length is provided,
+    // the number of dashes/dots on a dashed/dotted line will be adjusted to
+    // start and end that length with a dash/dot.
+    float setupPaintForStroking(SkPaint*, SkRect*, int length) const;
+
+    // State setting functions.
+    void setDrawLooper(SkDrawLooper*);  // Note: takes an additional ref.
+    void setMiterLimit(float);
+    void setAlpha(float);
+    void setLineCap(SkPaint::Cap);
+    void setLineJoin(SkPaint::Join);
+    void setFillRule(SkPath::FillType);
+    void setPorterDuffMode(SkPorterDuff::Mode);
+    void setFillColor(SkColor);
+    void setStrokeStyle(WebCore::StrokeStyle);
+    void setStrokeColor(SkColor);
+    void setStrokeThickness(float thickness);
+    void setTextDrawingMode(int mode);
+    void setUseAntialiasing(bool enable);
+    void setGradient(SkShader*);
+    void setPattern(SkShader*);
+    void setDashPathEffect(SkDashPathEffect*);
+
+    SkDrawLooper* getDrawLooper() const;
+    WebCore::StrokeStyle getStrokeStyle() const;
+    float getStrokeThickness() const;
+    int getTextDrawingMode() const;
+
+    void beginPath();
+    void addPath(const SkPath&);
+    const SkPath* currentPath() const { return &m_path; }
+
+    SkColor fillColor() const;
+
+    skia::PlatformCanvas* canvas() { return m_canvas; }
+
+    // FIXME: This should be pushed down to GraphicsContext.
+    void drawRect(SkRect rect);
+
+    // FIXME: I'm still unsure how I will serialize this call.
+    void paintSkPaint(const SkRect&, const SkPaint&);
+
+    const SkBitmap* bitmap() const;
+
+    // Returns the canvas used for painting, NOT guaranteed to be non-NULL.
+    //
+    // Warning: This function is deprecated so the users are reminded that they
+    // should use this layer of indirection instead of using the canvas
+    // directly. This is to help with the eventual serialization.
+    skia::PlatformCanvas* canvas() const;
+
+    // Returns if the context is a printing context instead of a display
+    // context. Bitmap shouldn't be resampled when printing to keep the best
+    // possible quality.
+    bool isPrinting();
+
+#if defined(__linux__)
+    // FIXME: should be camelCase.
+    GdkSkia* gdk_skia() const { return m_gdkskia; }
+#endif
+
+private:
+    // Defines drawing style.
+    struct State;
+
+    // NULL indicates painting is disabled. Never delete this object.
+    skia::PlatformCanvas* m_canvas;
+
+    // States stack. Enables local drawing state change with save()/restore()
+    // calls.
+    WTF::Vector<State> m_stateStack;
+    // Pointer to the current drawing state. This is a cached value of
+    // mStateStack.back().
+    State* m_state;
+
+    // Current path.
+    SkPath m_path;
+
+#if defined(__linux__)
+    // A pointer to a GDK Drawable wrapping of this Skia canvas
+    GdkSkia* m_gdkskia;
+#endif
+};
+
+#endif  // PlatformContextSkia_h
diff --git a/WebCore/platform/graphics/skia/PlatformGraphics.h b/WebCore/platform/graphics/skia/PlatformGraphics.h
new file mode 100644 (file)
index 0000000..4ae8835
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2008, Google Inc. All rights reserved.
+ * 
+ * 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.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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.
+ */
+
+#ifndef PlatformGraphics_h
+#define PlatformGraphics_h
+
+typedef class SkShader* PlatformGradient;
+typedef class SkShader* PlatformPattern;
+
+#endif // PlatformGraphics_h