Skip to content
Permalink
Browse files
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.


Canonical link: https://commits.webkit.org/46672@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@55371 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Jakob Petsovits committed Mar 1, 2010
1 parent 2b5b12c commit 66ff92c86f26a22623cc3a8c36b0c7c8e958a1fe
Showing 10 changed files with 812 additions and 4 deletions.
@@ -1,3 +1,86 @@
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.

2010-03-01 Pavel Feldman <pfeldman@chromium.org>

Not reviewed, bring English.lproj/locallizedStrings.js back to binary (UTF) mode.
@@ -39,6 +39,7 @@ static const float QUARTER = 0.552f; // approximation of control point positions
// to simulate a quarter of a circle.
namespace WebCore {

#if !PLATFORM(OPENVG)
static void pathLengthApplierFunction(void* info, const PathElement* element)
{
PathTraversalState& traversalState = *static_cast<PathTraversalState*>(info);
@@ -107,6 +108,7 @@ float Path::normalAngleAtLength(float length, bool& ok)
ok = traversalState.m_success;
return traversalState.m_normalAngle;
}
#endif

Path Path::createRoundedRectangle(const FloatRect& rectangle, const FloatSize& roundingRadii)
{
@@ -33,6 +33,11 @@

#if PLATFORM(CG)
typedef struct CGPath PlatformPath;
#elif PLATFORM(OPENVG)
namespace WebCore {
class PlatformPathOpenVG;
}
typedef WebCore::PlatformPathOpenVG PlatformPath;
#elif PLATFORM(QT)
#include <qpainterpath.h>
typedef QPainterPath PlatformPath;
@@ -22,6 +22,7 @@

#include "AffineTransform.h"
#include "GraphicsContextPrivate.h"
#include "KURL.h"
#include "NotImplemented.h"
#include "PainterOpenVG.h"
#include "SurfaceOpenVG.h"
@@ -143,15 +144,23 @@ void GraphicsContext::fillPath()
if (paintingDisabled())
return;

notImplemented();
m_data->drawPath(VG_FILL_PATH, m_common->state.fillRule);
}

void GraphicsContext::strokePath()
{
if (paintingDisabled())
return;

notImplemented();
m_data->drawPath(VG_STROKE_PATH, m_common->state.fillRule);
}

void GraphicsContext::drawPath()
{
if (paintingDisabled())
return;

m_data->drawPath(VG_FILL_PATH | VG_STROKE_PATH, m_common->state.fillRule);
}

void GraphicsContext::fillRect(const FloatRect& rect)
@@ -193,15 +202,15 @@ void GraphicsContext::beginPath()
if (paintingDisabled())
return;

notImplemented();
m_data->beginPath();
}

void GraphicsContext::addPath(const Path& path)
{
if (paintingDisabled())
return;

notImplemented();
m_data->addPath(path);
}

void GraphicsContext::clip(const FloatRect& rect)
@@ -29,6 +29,7 @@
#include "IntRect.h"
#include "IntSize.h"
#include "NotImplemented.h"
#include "PlatformPathOpenVG.h"
#include "SurfaceOpenVG.h"
#include "VGUtils.h"

@@ -340,12 +341,14 @@ struct PlatformPainterState {
PainterOpenVG::PainterOpenVG()
: m_state(0)
, m_surface(0)
, m_currentPath(0)
{
}

PainterOpenVG::PainterOpenVG(SurfaceOpenVG* surface)
: m_state(0)
, m_surface(0)
, m_currentPath(0)
{
ASSERT(surface);
begin(surface);
@@ -354,6 +357,7 @@ PainterOpenVG::PainterOpenVG(SurfaceOpenVG* surface)
PainterOpenVG::~PainterOpenVG()
{
end();
delete m_currentPath;
}

void PainterOpenVG::begin(SurfaceOpenVG* surface)
@@ -441,6 +445,28 @@ void PainterOpenVG::setTransformation(const AffineTransform& transformation)
m_state->applyTransformation(this);
}

void PainterOpenVG::transformPath(VGPath dst, VGPath src, const AffineTransform& transformation)
{
vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);

// Save the transform state
VGfloat currentMatrix[9];
vgGetMatrix(currentMatrix);
ASSERT_VG_NO_ERROR();

// Load the new transform
vgLoadMatrix(VGMatrix(transformation).toVGfloat());
ASSERT_VG_NO_ERROR();

// Apply the new transform
vgTransformPath(dst, src);
ASSERT_VG_NO_ERROR();

// Restore the transform state
vgLoadMatrix(currentMatrix);
ASSERT_VG_NO_ERROR();
}

CompositeOperator PainterOpenVG::compositeOperation() const
{
ASSERT(m_state);
@@ -621,6 +647,47 @@ void PainterOpenVG::translate(float dx, float dy)
setTransformation(transformation);
}

void PainterOpenVG::beginPath()
{
delete m_currentPath;
m_currentPath = new Path();
}

void PainterOpenVG::addPath(const Path& path)
{
m_currentPath->platformPath()->makeCompatibleContextCurrent();

vgAppendPath(m_currentPath->platformPath()->vgPath(), path.platformPath()->vgPath());
ASSERT_VG_NO_ERROR();
}

Path* PainterOpenVG::currentPath() const
{
return m_currentPath;
}

void PainterOpenVG::drawPath(VGbitfield specifiedPaintModes, WindRule fillRule)
{
ASSERT(m_state);

VGbitfield paintModes = 0;
if (!m_state->strokeDisabled())
paintModes |= VG_STROKE_PATH;
if (!m_state->fillDisabled())
paintModes |= VG_FILL_PATH;

paintModes &= specifiedPaintModes;

if (!paintModes)
return;

m_surface->makeCurrent();

vgSeti(VG_FILL_RULE, toVGFillRule(fillRule));
vgDrawPath(m_currentPath->platformPath()->vgPath(), paintModes);
ASSERT_VG_NO_ERROR();
}

void PainterOpenVG::intersectScissorRect(const FloatRect& rect)
{
// Scissor rectangles are defined by float values, but e.g. painting
@@ -36,6 +36,7 @@ class FloatPoint;
class FloatRect;
class IntRect;
class IntSize;
class Path;
class SurfaceOpenVG;

struct PlatformPainterState;
@@ -61,6 +62,8 @@ class PainterOpenVG : public Noncopyable {
void setTransformation(const AffineTransform&);
void concatTransformation(const AffineTransform&);

static void transformPath(VGPath dst, VGPath src, const AffineTransform&);

CompositeOperator compositeOperation() const;
void setCompositeOperation(CompositeOperator);
float opacity() const;
@@ -96,6 +99,11 @@ class PainterOpenVG : public Noncopyable {
void rotate(float radians);
void translate(float dx, float dy);

void beginPath();
void addPath(const Path&);
Path* currentPath() const;
void drawPath(VGbitfield paintModes = (VG_STROKE_PATH | VG_FILL_PATH), WindRule fillRule = RULE_NONZERO);

void intersectClipRect(const FloatRect&);

void save(PainterOpenVG::SaveMode saveMode = CreateNewState);
@@ -114,6 +122,7 @@ class PainterOpenVG : public Noncopyable {
Vector<PlatformPainterState*> m_stateStack;
PlatformPainterState* m_state;
SurfaceOpenVG* m_surface;
Path* m_currentPath;
};

}

0 comments on commit 66ff92c

Please sign in to comment.