Changeset 55371 in webkit


Ignore:
Timestamp:
Mar 1, 2010 9:41:44 AM (14 years ago)
Author:
jpetsovits@rim.com
Message:

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

Reviewed by Dirk Schulze.

[OpenVG] Implement support for paths
https://bugs.webkit.org/show_bug.cgi?id=34366

Adds an implementation of the Path class -
*almost* complete, but not quite because OpenVG
does not provide access to the points in a VGPath
unless one keeps track of all the points by
themselves, which we decided not to do.

Also hooked up to PainterOpenVG and GraphicsContext.

Further introduced is SharedResourceOpenVG, which is
intended as base class for paths and other OpenVG
resources (images, fonts) that WebKit creates as
long-lived objects. We are at a slight disadvantage
here as WebKit doesn't have the concept of resources
belonging to a specific (hardware graphics) context,
which is the reason why EGLDisplayOpenVG had to
provide a current display singleton; this class is
what actually requires that functionality.

Path::addArcTo() uses code by Yong Li <yoli@rim.com>.

  • platform/graphics/Path.cpp:
  • platform/graphics/Path.h:
  • platform/graphics/openvg/GraphicsContextOpenVG.cpp: (WebCore::GraphicsContext::fillPath): (WebCore::GraphicsContext::strokePath): (WebCore::GraphicsContext::drawPath): (WebCore::GraphicsContext::beginPath): (WebCore::GraphicsContext::addPath):
  • platform/graphics/openvg/PainterOpenVG.cpp: (WebCore::PainterOpenVG::PainterOpenVG): (WebCore::PainterOpenVG::~PainterOpenVG): (WebCore::PainterOpenVG::transformPath): (WebCore::PainterOpenVG::beginPath): (WebCore::PainterOpenVG::addPath): (WebCore::PainterOpenVG::currentPath): (WebCore::PainterOpenVG::drawPath):
  • platform/graphics/openvg/PainterOpenVG.h:
  • platform/graphics/openvg/PathOpenVG.cpp: Added. (WebCore::PlatformPathOpenVG::PlatformPathOpenVG): (WebCore::PlatformPathOpenVG::operator=): (WebCore::PlatformPathOpenVG::~PlatformPathOpenVG): (WebCore::PlatformPathOpenVG::clear): (WebCore::PlatformPathOpenVG::createPath): (WebCore::Path::Path): (WebCore::Path::~Path): (WebCore::Path::operator=): (WebCore::Path::contains): (WebCore::Path::strokeContains): (WebCore::Path::translate): (WebCore::Path::boundingRect): (WebCore::Path::strokeBoundingRect): (WebCore::Path::moveTo): (WebCore::Path::addLineTo): (WebCore::Path::addQuadCurveTo): (WebCore::Path::addBezierCurveTo): (WebCore::Path::addArcTo): (WebCore::Path::closeSubpath): (WebCore::Path::addArc): (WebCore::Path::addRect): (WebCore::Path::addEllipse): (WebCore::Path::clear): (WebCore::Path::isEmpty): (WebCore::Path::hasCurrentPoint): (WebCore::Path::debugString): (WebCore::Path::apply): (WebCore::Path::transform): (WebCore::Path::length): (WebCore::Path::pointAtLength): (WebCore::Path::normalAngleAtLength):
  • platform/graphics/openvg/PlatformPathOpenVG.h: Added. (WebCore::PlatformPathOpenVG::vgPath):
  • platform/graphics/openvg/SharedResourceOpenVG.cpp: Added. (WebCore::SharedResourceOpenVG::makeSharedContextCurrent): (WebCore::SharedResourceOpenVG::makeCompatibleContextCurrent):
  • platform/graphics/openvg/SharedResourceOpenVG.h: Added.
Location:
trunk/WebCore
Files:
4 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r55370 r55371  
     12010-03-01  Jakob Petsovits  <jpetsovits@rim.com>
     2
     3        Reviewed by Dirk Schulze.
     4
     5        [OpenVG] Implement support for paths
     6        https://bugs.webkit.org/show_bug.cgi?id=34366
     7
     8        Adds an implementation of the Path class -
     9        *almost* complete, but not quite because OpenVG
     10        does not provide access to the points in a VGPath
     11        unless one keeps track of all the points by
     12        themselves, which we decided not to do.
     13
     14        Also hooked up to PainterOpenVG and GraphicsContext.
     15
     16        Further introduced is SharedResourceOpenVG, which is
     17        intended as base class for paths and other OpenVG
     18        resources (images, fonts) that WebKit creates as
     19        long-lived objects. We are at a slight disadvantage
     20        here as WebKit doesn't have the concept of resources
     21        belonging to a specific (hardware graphics) context,
     22        which is the reason why EGLDisplayOpenVG had to
     23        provide a current display singleton; this class is
     24        what actually requires that functionality.
     25
     26        Path::addArcTo() uses code by Yong Li <yoli@rim.com>.
     27
     28        * platform/graphics/Path.cpp:
     29        * platform/graphics/Path.h:
     30        * platform/graphics/openvg/GraphicsContextOpenVG.cpp:
     31        (WebCore::GraphicsContext::fillPath):
     32        (WebCore::GraphicsContext::strokePath):
     33        (WebCore::GraphicsContext::drawPath):
     34        (WebCore::GraphicsContext::beginPath):
     35        (WebCore::GraphicsContext::addPath):
     36        * platform/graphics/openvg/PainterOpenVG.cpp:
     37        (WebCore::PainterOpenVG::PainterOpenVG):
     38        (WebCore::PainterOpenVG::~PainterOpenVG):
     39        (WebCore::PainterOpenVG::transformPath):
     40        (WebCore::PainterOpenVG::beginPath):
     41        (WebCore::PainterOpenVG::addPath):
     42        (WebCore::PainterOpenVG::currentPath):
     43        (WebCore::PainterOpenVG::drawPath):
     44        * platform/graphics/openvg/PainterOpenVG.h:
     45        * platform/graphics/openvg/PathOpenVG.cpp: Added.
     46        (WebCore::PlatformPathOpenVG::PlatformPathOpenVG):
     47        (WebCore::PlatformPathOpenVG::operator=):
     48        (WebCore::PlatformPathOpenVG::~PlatformPathOpenVG):
     49        (WebCore::PlatformPathOpenVG::clear):
     50        (WebCore::PlatformPathOpenVG::createPath):
     51        (WebCore::Path::Path):
     52        (WebCore::Path::~Path):
     53        (WebCore::Path::operator=):
     54        (WebCore::Path::contains):
     55        (WebCore::Path::strokeContains):
     56        (WebCore::Path::translate):
     57        (WebCore::Path::boundingRect):
     58        (WebCore::Path::strokeBoundingRect):
     59        (WebCore::Path::moveTo):
     60        (WebCore::Path::addLineTo):
     61        (WebCore::Path::addQuadCurveTo):
     62        (WebCore::Path::addBezierCurveTo):
     63        (WebCore::Path::addArcTo):
     64        (WebCore::Path::closeSubpath):
     65        (WebCore::Path::addArc):
     66        (WebCore::Path::addRect):
     67        (WebCore::Path::addEllipse):
     68        (WebCore::Path::clear):
     69        (WebCore::Path::isEmpty):
     70        (WebCore::Path::hasCurrentPoint):
     71        (WebCore::Path::debugString):
     72        (WebCore::Path::apply):
     73        (WebCore::Path::transform):
     74        (WebCore::Path::length):
     75        (WebCore::Path::pointAtLength):
     76        (WebCore::Path::normalAngleAtLength):
     77        * platform/graphics/openvg/PlatformPathOpenVG.h: Added.
     78        (WebCore::PlatformPathOpenVG::vgPath):
     79        * platform/graphics/openvg/SharedResourceOpenVG.cpp: Added.
     80        (WebCore::SharedResourceOpenVG::makeSharedContextCurrent):
     81        (WebCore::SharedResourceOpenVG::makeCompatibleContextCurrent):
     82        * platform/graphics/openvg/SharedResourceOpenVG.h: Added.
     83
    1842010-03-01  Pavel Feldman  <pfeldman@chromium.org>
    285
  • trunk/WebCore/platform/graphics/Path.cpp

    r44235 r55371  
    4040namespace WebCore {
    4141
     42#if !PLATFORM(OPENVG)
    4243static void pathLengthApplierFunction(void* info, const PathElement* element)
    4344{
     
    108109    return traversalState.m_normalAngle;
    109110}
     111#endif
    110112
    111113Path Path::createRoundedRectangle(const FloatRect& rectangle, const FloatSize& roundingRadii)
  • trunk/WebCore/platform/graphics/Path.h

    r54503 r55371  
    3434#if PLATFORM(CG)
    3535typedef struct CGPath PlatformPath;
     36#elif PLATFORM(OPENVG)
     37namespace WebCore {
     38class PlatformPathOpenVG;
     39}
     40typedef WebCore::PlatformPathOpenVG PlatformPath;
    3641#elif PLATFORM(QT)
    3742#include <qpainterpath.h>
  • trunk/WebCore/platform/graphics/openvg/GraphicsContextOpenVG.cpp

    r55369 r55371  
    2323#include "AffineTransform.h"
    2424#include "GraphicsContextPrivate.h"
     25#include "KURL.h"
    2526#include "NotImplemented.h"
    2627#include "PainterOpenVG.h"
     
    144145        return;
    145146
    146     notImplemented();
     147    m_data->drawPath(VG_FILL_PATH, m_common->state.fillRule);
    147148}
    148149
     
    152153        return;
    153154
    154     notImplemented();
     155    m_data->drawPath(VG_STROKE_PATH, m_common->state.fillRule);
     156}
     157
     158void GraphicsContext::drawPath()
     159{
     160    if (paintingDisabled())
     161        return;
     162
     163    m_data->drawPath(VG_FILL_PATH | VG_STROKE_PATH, m_common->state.fillRule);
    155164}
    156165
     
    194203        return;
    195204
    196     notImplemented();
     205    m_data->beginPath();
    197206}
    198207
     
    202211        return;
    203212
    204     notImplemented();
     213    m_data->addPath(path);
    205214}
    206215
  • trunk/WebCore/platform/graphics/openvg/PainterOpenVG.cpp

    r55369 r55371  
    3030#include "IntSize.h"
    3131#include "NotImplemented.h"
     32#include "PlatformPathOpenVG.h"
    3233#include "SurfaceOpenVG.h"
    3334#include "VGUtils.h"
     
    341342    : m_state(0)
    342343    , m_surface(0)
     344    , m_currentPath(0)
    343345{
    344346}
     
    347349    : m_state(0)
    348350    , m_surface(0)
     351    , m_currentPath(0)
    349352{
    350353    ASSERT(surface);
     
    355358{
    356359    end();
     360    delete m_currentPath;
    357361}
    358362
     
    442446}
    443447
     448void PainterOpenVG::transformPath(VGPath dst, VGPath src, const AffineTransform& transformation)
     449{
     450    vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
     451
     452    // Save the transform state
     453    VGfloat currentMatrix[9];
     454    vgGetMatrix(currentMatrix);
     455    ASSERT_VG_NO_ERROR();
     456
     457    // Load the new transform
     458    vgLoadMatrix(VGMatrix(transformation).toVGfloat());
     459    ASSERT_VG_NO_ERROR();
     460
     461    // Apply the new transform
     462    vgTransformPath(dst, src);
     463    ASSERT_VG_NO_ERROR();
     464
     465    // Restore the transform state
     466    vgLoadMatrix(currentMatrix);
     467    ASSERT_VG_NO_ERROR();
     468}
     469
    444470CompositeOperator PainterOpenVG::compositeOperation() const
    445471{
     
    620646    transformation.translate(dx, dy);
    621647    setTransformation(transformation);
     648}
     649
     650void PainterOpenVG::beginPath()
     651{
     652    delete m_currentPath;
     653    m_currentPath = new Path();
     654}
     655
     656void PainterOpenVG::addPath(const Path& path)
     657{
     658    m_currentPath->platformPath()->makeCompatibleContextCurrent();
     659
     660    vgAppendPath(m_currentPath->platformPath()->vgPath(), path.platformPath()->vgPath());
     661    ASSERT_VG_NO_ERROR();
     662}
     663
     664Path* PainterOpenVG::currentPath() const
     665{
     666    return m_currentPath;
     667}
     668
     669void PainterOpenVG::drawPath(VGbitfield specifiedPaintModes, WindRule fillRule)
     670{
     671    ASSERT(m_state);
     672
     673    VGbitfield paintModes = 0;
     674    if (!m_state->strokeDisabled())
     675        paintModes |= VG_STROKE_PATH;
     676    if (!m_state->fillDisabled())
     677        paintModes |= VG_FILL_PATH;
     678
     679    paintModes &= specifiedPaintModes;
     680
     681    if (!paintModes)
     682        return;
     683
     684    m_surface->makeCurrent();
     685
     686    vgSeti(VG_FILL_RULE, toVGFillRule(fillRule));
     687    vgDrawPath(m_currentPath->platformPath()->vgPath(), paintModes);
     688    ASSERT_VG_NO_ERROR();
    622689}
    623690
  • trunk/WebCore/platform/graphics/openvg/PainterOpenVG.h

    r55369 r55371  
    3737class IntRect;
    3838class IntSize;
     39class Path;
    3940class SurfaceOpenVG;
    4041
     
    6162    void setTransformation(const AffineTransform&);
    6263    void concatTransformation(const AffineTransform&);
     64
     65    static void transformPath(VGPath dst, VGPath src, const AffineTransform&);
    6366
    6467    CompositeOperator compositeOperation() const;
     
    97100    void translate(float dx, float dy);
    98101
     102    void beginPath();
     103    void addPath(const Path&);
     104    Path* currentPath() const;
     105    void drawPath(VGbitfield paintModes = (VG_STROKE_PATH | VG_FILL_PATH), WindRule fillRule = RULE_NONZERO);
     106
    99107    void intersectClipRect(const FloatRect&);
    100108
     
    115123    PlatformPainterState* m_state;
    116124    SurfaceOpenVG* m_surface;
     125    Path* m_currentPath;
    117126};
    118127
Note: See TracChangeset for help on using the changeset viewer.