Home | History | Annotate | Download | only in openvg
      1 /*
      2  * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
      3  *
      4  * This library is free software; you can redistribute it and/or
      5  * modify it under the terms of the GNU Library General Public
      6  * License as published by the Free Software Foundation; either
      7  * version 2 of the License, or (at your option) any later version.
      8  *
      9  * This library is distributed in the hope that it will be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12  * Library General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU Library General Public License
     15  * along with this library; see the file COPYING.LIB.  If not, write to
     16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     17  * Boston, MA 02110-1301, USA.
     18  */
     19 
     20 #ifndef PainterOpenVG_h
     21 #define PainterOpenVG_h
     22 
     23 #include "Color.h"
     24 #include "GraphicsContext.h"
     25 
     26 #include <openvg.h>
     27 
     28 #include <wtf/Noncopyable.h>
     29 #include <wtf/Platform.h>
     30 #include <wtf/Vector.h>
     31 
     32 namespace WebCore {
     33 
     34 class FloatPoint;
     35 class FloatRect;
     36 class IntRect;
     37 class IntSize;
     38 class SurfaceOpenVG;
     39 class TransformationMatrix;
     40 
     41 struct PlatformPainterState;
     42 
     43 class PainterOpenVG : public Noncopyable {
     44 public:
     45     friend class SurfaceOpenVG;
     46     friend struct PlatformPainterState;
     47 
     48     enum SaveMode {
     49         CreateNewState,
     50         CreateNewStateWithPaintStateOnly // internal usage only, do not use outside PainterOpenVG
     51     };
     52 
     53     PainterOpenVG();
     54     PainterOpenVG(SurfaceOpenVG*);
     55     ~PainterOpenVG();
     56 
     57     void begin(SurfaceOpenVG*);
     58     void end();
     59 
     60     TransformationMatrix transformationMatrix() const;
     61     void setTransformationMatrix(const TransformationMatrix&);
     62     void concatTransformationMatrix(const TransformationMatrix&);
     63 
     64     CompositeOperator compositeOperation() const;
     65     void setCompositeOperation(CompositeOperator);
     66     float opacity() const;
     67     void setOpacity(float);
     68 
     69     float strokeThickness() const;
     70     void setStrokeThickness(float);
     71     StrokeStyle strokeStyle() const;
     72     void setStrokeStyle(const StrokeStyle&);
     73 
     74     void setLineDash(const DashArray&, float dashOffset);
     75     void setLineCap(LineCap);
     76     void setLineJoin(LineJoin);
     77     void setMiterLimit(float);
     78 
     79     Color strokeColor() const;
     80     void setStrokeColor(const Color&);
     81 
     82     Color fillColor() const;
     83     void setFillColor(const Color&);
     84 
     85     bool antialiasingEnabled() const;
     86     void setAntialiasingEnabled(bool);
     87 
     88     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));
     94 
     95     void scale(const FloatSize& scaleFactors);
     96     void rotate(float radians);
     97     void translate(float dx, float dy);
     98 
     99     void intersectClipRect(const FloatRect&);
    100 
    101     void save(PainterOpenVG::SaveMode saveMode = CreateNewState);
    102     void restore();
    103 
    104     SurfaceOpenVG* surface() { return m_surface; }
    105     void blitToSurface();
    106 
    107 private:
    108     void destroyPainterStates();
    109     void applyState();
    110 
    111     void intersectScissorRect(const FloatRect&);
    112 
    113 private:
    114     Vector<PlatformPainterState*> m_stateStack;
    115     PlatformPainterState* m_state;
    116     SurfaceOpenVG* m_surface;
    117 };
    118 
    119 }
    120 
    121 #endif
    122