Changeset 54089 in webkit


Ignore:
Timestamp:
Jan 29, 2010 4:48:51 PM (14 years ago)
Author:
jpetsovits@rim.com
Message:

2010-01-29 Jakob Petsovits <jpetsovits@rim.com>

Reviewed by Nikolas Zimmermann.

[OpenVG] Implement more graphics primitives
https://bugs.webkit.org/show_bug.cgi?id=34339

Adds lines, arcs, ellipses, polygons and rounded
rectangles to PainterOpenVG and GraphicsContext.

Rounded rects support by Eli Fidler <efidler@rim.com>.

  • platform/graphics/openvg/GraphicsContextOpenVG.cpp: (WebCore::GraphicsContext::drawLine): (WebCore::GraphicsContext::drawEllipse): (WebCore::GraphicsContext::strokeArc): (WebCore::GraphicsContext::drawConvexPolygon): (WebCore::GraphicsContext::fillRect): (WebCore::GraphicsContext::fillRoundedRect): (WebCore::GraphicsContext::drawFocusRing): (WebCore::GraphicsContext::drawLineForText): (WebCore::GraphicsContext::clearRect): (WebCore::GraphicsContext::strokeRect):
  • platform/graphics/openvg/PainterOpenVG.cpp: (WebCore::PainterOpenVG::drawRect): (WebCore::PainterOpenVG::drawRoundedRect): (WebCore::PainterOpenVG::drawLine): (WebCore::PainterOpenVG::drawArc): (WebCore::PainterOpenVG::drawEllipse): (WebCore::PainterOpenVG::drawPolygon):
  • platform/graphics/openvg/PainterOpenVG.h:
Location:
trunk/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r54085 r54089  
     12010-01-29  Jakob Petsovits  <jpetsovits@rim.com>
     2
     3        Reviewed by Nikolas Zimmermann.
     4
     5        [OpenVG] Implement more graphics primitives
     6        https://bugs.webkit.org/show_bug.cgi?id=34339
     7
     8        Adds lines, arcs, ellipses, polygons and rounded
     9        rectangles to PainterOpenVG and GraphicsContext.
     10
     11        Rounded rects support by Eli Fidler <efidler@rim.com>.
     12
     13        * platform/graphics/openvg/GraphicsContextOpenVG.cpp:
     14        (WebCore::GraphicsContext::drawLine):
     15        (WebCore::GraphicsContext::drawEllipse):
     16        (WebCore::GraphicsContext::strokeArc):
     17        (WebCore::GraphicsContext::drawConvexPolygon):
     18        (WebCore::GraphicsContext::fillRect):
     19        (WebCore::GraphicsContext::fillRoundedRect):
     20        (WebCore::GraphicsContext::drawFocusRing):
     21        (WebCore::GraphicsContext::drawLineForText):
     22        (WebCore::GraphicsContext::clearRect):
     23        (WebCore::GraphicsContext::strokeRect):
     24        * platform/graphics/openvg/PainterOpenVG.cpp:
     25        (WebCore::PainterOpenVG::drawRect):
     26        (WebCore::PainterOpenVG::drawRoundedRect):
     27        (WebCore::PainterOpenVG::drawLine):
     28        (WebCore::PainterOpenVG::drawArc):
     29        (WebCore::PainterOpenVG::drawEllipse):
     30        (WebCore::PainterOpenVG::drawPolygon):
     31        * platform/graphics/openvg/PainterOpenVG.h:
     32
    1332010-01-29  Jeremy Orlow  <jorlow@chromium.org>
    234
  • trunk/WebCore/platform/graphics/openvg/GraphicsContextOpenVG.cpp

    r54063 r54089  
    107107        return;
    108108
    109     notImplemented();
    110     UNUSED_PARAM(from);
    111     UNUSED_PARAM(to);
     109    m_data->drawLine(from, to);
    112110}
    113111
     
    120118        return;
    121119
    122     notImplemented();
    123     UNUSED_PARAM(rect);
     120    m_data->drawEllipse(rect);
    124121}
    125122
     
    129126        return;
    130127
    131     notImplemented();
    132     UNUSED_PARAM(rect);
    133     UNUSED_PARAM(startAngle);
    134     UNUSED_PARAM(angleSpan);
     128    m_data->drawArc(rect, startAngle, angleSpan, VG_STROKE_PATH);
    135129}
    136130
     
    140134        return;
    141135
    142     notImplemented();
    143     UNUSED_PARAM(numPoints);
    144     UNUSED_PARAM(points);
    145     UNUSED_PARAM(shouldAntialias);
     136    m_data->drawPolygon(numPoints, points);
     137
     138    UNUSED_PARAM(shouldAntialias); // FIXME
    146139}
    147140
     
    175168        return;
    176169
    177     PainterOpenVG* painter = m_data;
    178     Color oldColor = painter->fillColor();
    179     painter->setFillColor(color);
    180     painter->drawRect(rect, VG_FILL_PATH);
    181     painter->setFillColor(oldColor);
     170    Color oldColor = m_data->fillColor();
     171    m_data->setFillColor(color);
     172    m_data->drawRect(rect, VG_FILL_PATH);
     173    m_data->setFillColor(oldColor);
    182174
    183175    UNUSED_PARAM(colorSpace); // FIXME
     
    189181        return;
    190182
    191     notImplemented();
    192     UNUSED_PARAM(rect);
    193     UNUSED_PARAM(topLeft);
    194     UNUSED_PARAM(topRight);
    195     UNUSED_PARAM(bottomLeft);
    196     UNUSED_PARAM(bottomRight);
    197     UNUSED_PARAM(color);
    198     UNUSED_PARAM(colorSpace);
     183    Color oldColor = m_data->fillColor();
     184    m_data->setFillColor(color);
     185    m_data->drawRoundedRect(rect, topLeft, topRight, bottomLeft, bottomRight, VG_FILL_PATH);
     186    m_data->setFillColor(oldColor);
     187
     188    UNUSED_PARAM(colorSpace); // FIXME
    199189}
    200190
     
    251241    }
    252242
    253     PainterOpenVG* painter = m_data;
    254     StrokeStyle oldStyle = painter->strokeStyle();
    255     Color oldStrokeColor = painter->strokeColor();
    256     painter->setStrokeStyle(DashedStroke);
    257     painter->setStrokeColor(color);
     243    StrokeStyle oldStyle = m_data->strokeStyle();
     244    Color oldStrokeColor = m_data->strokeColor();
     245    m_data->setStrokeStyle(DashedStroke);
     246    m_data->setStrokeColor(color);
    258247    strokeRect(FloatRect(finalFocusRect), 1.f);
    259     painter->setStrokeStyle(oldStyle);
    260     painter->setStrokeColor(oldStrokeColor);
     248    m_data->setStrokeStyle(oldStyle);
     249    m_data->setStrokeColor(oldStrokeColor);
    261250}
    262251
     
    269258        return;
    270259
    271     notImplemented();
    272     UNUSED_PARAM(origin);
    273     UNUSED_PARAM(width);
     260    StrokeStyle oldStyle = m_data->strokeStyle();
     261    m_data->setStrokeStyle(SolidStroke);
     262    drawLine(origin, origin + IntSize(width, 0));
     263    m_data->setStrokeStyle(oldStyle);
     264
    274265    UNUSED_PARAM(printing);
    275266}
     
    336327        return;
    337328
    338     PainterOpenVG* painter = m_data;
    339 
    340     CompositeOperator op = painter->compositeOperation();
    341     painter->setCompositeOperation(CompositeClear);
    342     painter->drawRect(rect, VG_FILL_PATH);
    343     painter->setCompositeOperation(op);
     329    CompositeOperator op = m_data->compositeOperation();
     330    m_data->setCompositeOperation(CompositeClear);
     331    m_data->drawRect(rect, VG_FILL_PATH);
     332    m_data->setCompositeOperation(op);
    344333}
    345334
     
    357346        return;
    358347
    359     PainterOpenVG* painter = m_data;
    360 
    361     float oldThickness = painter->strokeThickness();
    362     painter->setStrokeThickness(lineWidth);
    363     painter->drawRect(rect, VG_STROKE_PATH);
    364     painter->setStrokeThickness(oldThickness);
     348    float oldThickness = m_data->strokeThickness();
     349    m_data->setStrokeThickness(lineWidth);
     350    m_data->drawRect(rect, VG_STROKE_PATH);
     351    m_data->setStrokeThickness(oldThickness);
    365352}
    366353
  • trunk/WebCore/platform/graphics/openvg/PainterOpenVG.cpp

    r54063 r54089  
    695695        5 /* expected number of segments */,
    696696        5 /* expected number of total coordinates */,
    697         VG_PATH_CAPABILITY_APPEND_TO
    698     );
     697        VG_PATH_CAPABILITY_APPEND_TO);
    699698    ASSERT_VG_NO_ERROR();
    700699
    701700    if (vguRect(path, rect.x(), rect.y(), rect.width(), rect.height()) == VGU_NO_ERROR) {
     701        vgDrawPath(path, paintModes);
     702        ASSERT_VG_NO_ERROR();
     703    }
     704
     705    vgDestroyPath(path);
     706    ASSERT_VG_NO_ERROR();
     707}
     708
     709void PainterOpenVG::drawRoundedRect(const FloatRect& rect, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight, VGbitfield specifiedPaintModes)
     710{
     711    ASSERT(m_state);
     712
     713    VGbitfield paintModes = 0;
     714    if (!m_state->strokeDisabled())
     715        paintModes |= VG_STROKE_PATH;
     716    if (!m_state->fillDisabled())
     717        paintModes |= VG_FILL_PATH;
     718
     719    paintModes &= specifiedPaintModes;
     720
     721    if (!paintModes)
     722        return;
     723
     724    m_surface->makeCurrent();
     725
     726    VGPath path = vgCreatePath(
     727        VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,
     728        1.0 /* scale */, 0.0 /* bias */,
     729        10 /* expected number of segments */,
     730        25 /* expected number of total coordinates */,
     731        VG_PATH_CAPABILITY_APPEND_TO);
     732    ASSERT_VG_NO_ERROR();
     733
     734    // clamp corner arc sizes
     735    FloatSize clampedTopLeft = FloatSize(topLeft).shrunkTo(rect.size()).expandedTo(FloatSize());
     736    FloatSize clampedTopRight = FloatSize(topRight).shrunkTo(rect.size()).expandedTo(FloatSize());
     737    FloatSize clampedBottomLeft = FloatSize(bottomLeft).shrunkTo(rect.size()).expandedTo(FloatSize());
     738    FloatSize clampedBottomRight = FloatSize(bottomRight).shrunkTo(rect.size()).expandedTo(FloatSize());
     739
     740    // As OpenVG's coordinate system is flipped in comparison to WebKit's,
     741    // we have to specify the opposite value for the "clockwise" value.
     742    static const VGubyte pathSegments[] = {
     743        VG_MOVE_TO_ABS,
     744        VG_HLINE_TO_REL,
     745        VG_SCCWARC_TO_REL,
     746        VG_VLINE_TO_REL,
     747        VG_SCCWARC_TO_REL,
     748        VG_HLINE_TO_REL,
     749        VG_SCCWARC_TO_REL,
     750        VG_VLINE_TO_REL,
     751        VG_SCCWARC_TO_REL,
     752        VG_CLOSE_PATH
     753    };
     754    // Also, the rounded rectangle path proceeds from the top to the bottom,
     755    // requiring height distances and clamped radius sizes to be flipped.
     756    const VGfloat pathData[] = {
     757        rect.x() + clampedTopLeft.width(), rect.y(),
     758        rect.width() - clampedTopLeft.width() - clampedTopRight.width(),
     759        clampedTopRight.width(), clampedTopRight.height(), 0, clampedTopRight.width(), clampedTopRight.height(),
     760        rect.height() - clampedTopRight.height() - clampedBottomRight.height(),
     761        clampedBottomRight.width(), clampedBottomRight.height(), 0, -clampedBottomRight.width(), clampedBottomRight.height(),
     762        -(rect.width() - clampedBottomLeft.width() - clampedBottomRight.width()),
     763        clampedBottomLeft.width(), clampedBottomLeft.height(), 0, -clampedBottomLeft.width(), -clampedBottomLeft.height(),
     764        -(rect.height() - clampedTopLeft.height() - clampedBottomLeft.height()),
     765        clampedTopLeft.width(), clampedTopLeft.height(), 0, clampedTopLeft.width(), -clampedTopLeft.height(),
     766    };
     767
     768    vgAppendPathData(path, 10, pathSegments, pathData);
     769    vgDrawPath(path, paintModes);
     770    vgDestroyPath(path);
     771    ASSERT_VG_NO_ERROR();
     772}
     773
     774void PainterOpenVG::drawLine(const IntPoint& from, const IntPoint& to)
     775{
     776    ASSERT(m_state);
     777
     778    if (m_state->strokeDisabled())
     779        return;
     780
     781    m_surface->makeCurrent();
     782
     783    VGPath path = vgCreatePath(
     784        VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,
     785        1.0 /* scale */, 0.0 /* bias */,
     786        2 /* expected number of segments */,
     787        4 /* expected number of total coordinates */,
     788        VG_PATH_CAPABILITY_APPEND_TO);
     789    ASSERT_VG_NO_ERROR();
     790
     791    VGUErrorCode errorCode;
     792
     793    // Try to align lines to pixels, centering them between pixels for odd thickness values.
     794    if (fmod(m_state->strokeThickness + 0.5, 2.0) < 1.0)
     795        errorCode = vguLine(path, from.x(), from.y(), to.x(), to.y());
     796    else if ((to.y() - from.y()) > (to.x() - from.x())) // more vertical than horizontal
     797        errorCode = vguLine(path, from.x() + 0.5, from.y(), to.x() + 0.5, to.y());
     798    else
     799        errorCode = vguLine(path, from.x(), from.y() + 0.5, to.x(), to.y() + 0.5);
     800
     801    if (errorCode == VGU_NO_ERROR) {
     802        vgDrawPath(path, VG_STROKE_PATH);
     803        ASSERT_VG_NO_ERROR();
     804    }
     805
     806    vgDestroyPath(path);
     807    ASSERT_VG_NO_ERROR();
     808}
     809
     810void PainterOpenVG::drawArc(const IntRect& rect, int startAngle, int angleSpan, VGbitfield specifiedPaintModes)
     811{
     812    ASSERT(m_state);
     813
     814    VGbitfield paintModes = 0;
     815    if (!m_state->strokeDisabled())
     816        paintModes |= VG_STROKE_PATH;
     817    if (!m_state->fillDisabled())
     818        paintModes |= VG_FILL_PATH;
     819
     820    paintModes &= specifiedPaintModes;
     821
     822    if (!paintModes)
     823        return;
     824
     825    m_surface->makeCurrent();
     826
     827    VGPath path = vgCreatePath(
     828        VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,
     829        1.0 /* scale */, 0.0 /* bias */,
     830        2 /* expected number of segments */,
     831        4 /* expected number of total coordinates */,
     832        VG_PATH_CAPABILITY_APPEND_TO);
     833    ASSERT_VG_NO_ERROR();
     834
     835    if (vguArc(path, rect.x() + rect.width() / 2.0, rect.y() + rect.height() / 2.0, rect.width(), rect.height(), -startAngle, -angleSpan, VGU_ARC_OPEN) == VGU_NO_ERROR) {
     836        vgDrawPath(path, VG_STROKE_PATH);
     837        ASSERT_VG_NO_ERROR();
     838    }
     839
     840    vgDestroyPath(path);
     841    ASSERT_VG_NO_ERROR();
     842}
     843
     844void PainterOpenVG::drawEllipse(const IntRect& rect, VGbitfield specifiedPaintModes)
     845{
     846    ASSERT(m_state);
     847
     848    VGbitfield paintModes = 0;
     849    if (!m_state->strokeDisabled())
     850        paintModes |= VG_STROKE_PATH;
     851    if (!m_state->fillDisabled())
     852        paintModes |= VG_FILL_PATH;
     853
     854    paintModes &= specifiedPaintModes;
     855
     856    if (!paintModes)
     857        return;
     858
     859    m_surface->makeCurrent();
     860
     861    VGPath path = vgCreatePath(
     862        VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,
     863        1.0 /* scale */, 0.0 /* bias */,
     864        4 /* expected number of segments */,
     865        12 /* expected number of total coordinates */,
     866        VG_PATH_CAPABILITY_APPEND_TO);
     867    ASSERT_VG_NO_ERROR();
     868
     869    if (vguEllipse(path, rect.x() + rect.width() / 2.0, rect.y() + rect.height() / 2.0, rect.width(), rect.height()) == VGU_NO_ERROR) {
     870        vgDrawPath(path, paintModes);
     871        ASSERT_VG_NO_ERROR();
     872    }
     873
     874    vgDestroyPath(path);
     875    ASSERT_VG_NO_ERROR();
     876}
     877
     878void PainterOpenVG::drawPolygon(size_t numPoints, const FloatPoint* points, VGbitfield specifiedPaintModes)
     879{
     880    ASSERT(m_state);
     881
     882    VGbitfield paintModes = 0;
     883    if (!m_state->strokeDisabled())
     884        paintModes |= VG_STROKE_PATH;
     885    if (!m_state->fillDisabled())
     886        paintModes |= VG_FILL_PATH;
     887
     888    paintModes &= specifiedPaintModes;
     889
     890    if (!paintModes)
     891        return;
     892
     893    m_surface->makeCurrent();
     894
     895    // Path segments: all points + "close path".
     896    const VGint numSegments = numPoints + 1;
     897    const VGint numCoordinates = numPoints * 2;
     898
     899    VGPath path = vgCreatePath(
     900        VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,
     901        1.0 /* scale */, 0.0 /* bias */,
     902        numSegments /* expected number of segments */,
     903        numCoordinates /* expected number of total coordinates */,
     904        VG_PATH_CAPABILITY_APPEND_TO);
     905    ASSERT_VG_NO_ERROR();
     906
     907    Vector<VGfloat> vgPoints(numCoordinates);
     908    for (int i = 0; i < numPoints; ++i) {
     909        vgPoints[i*2]     = points[i].x();
     910        vgPoints[i*2 + 1] = points[i].y();
     911    }
     912
     913    if (vguPolygon(path, vgPoints.data(), numPoints, VG_TRUE /* closed */) == VGU_NO_ERROR) {
    702914        vgDrawPath(path, paintModes);
    703915        ASSERT_VG_NO_ERROR();
  • trunk/WebCore/platform/graphics/openvg/PainterOpenVG.h

    r54063 r54089  
    8787
    8888    void drawRect(const FloatRect&, VGbitfield paintModes = (VG_STROKE_PATH | VG_FILL_PATH));
     89    void drawRoundedRect(const FloatRect&, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight, VGbitfield paintModes = (VG_STROKE_PATH | VG_FILL_PATH));
     90    void drawLine(const IntPoint& from, const IntPoint& to);
     91    void drawArc(const IntRect& ellipseBounds, int startAngle, int angleSpan, VGbitfield paintModes = (VG_STROKE_PATH | VG_FILL_PATH));
     92    void drawEllipse(const IntRect& bounds, VGbitfield paintModes = (VG_STROKE_PATH | VG_FILL_PATH));
     93    void drawPolygon(size_t numPoints, const FloatPoint* points, VGbitfield paintModes = (VG_STROKE_PATH | VG_FILL_PATH));
    8994
    9095    void scale(const FloatSize& scaleFactors);
Note: See TracChangeset for help on using the changeset viewer.