• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012, The Android Open Source Project
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *  * Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  *  * Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef platform_graphics_context_skia_h
27 #define platform_graphics_context_skia_h
28 
29 #include "PlatformGraphicsContext.h"
30 
31 namespace WebCore {
32 
33 class PlatformGraphicsContextSkia : public PlatformGraphicsContext {
34 public:
35     PlatformGraphicsContextSkia(SkCanvas* canvas, bool takeCanvasOwnership = false);
36     virtual ~PlatformGraphicsContextSkia();
37     virtual bool isPaintingDisabled();
canvas()38     SkCanvas* canvas() { return mCanvas; }
39 
type()40     virtual ContextType type() { return PaintingContext; }
recordingCanvas()41     virtual SkCanvas* recordingCanvas() { return mCanvas; }
setTextOffset(FloatSize offset)42     virtual void setTextOffset(FloatSize offset) {}
43 
44     // FIXME: This is used by ImageBufferAndroid, which should really be
45     //        managing the canvas lifecycle itself
46 
deleteUs()47     virtual bool deleteUs() const { return m_deleteCanvas; }
48 
49     // State management
50     virtual void beginTransparencyLayer(float opacity);
51     virtual void endTransparencyLayer();
52     virtual void save();
53     virtual void restore();
54 
55     // Matrix operations
56     virtual void concatCTM(const AffineTransform& affine);
57     virtual void rotate(float angleInRadians);
58     virtual void scale(const FloatSize& size);
59     virtual void translate(float x, float y);
60     virtual const SkMatrix& getTotalMatrix();
61 
62     // Clipping
63     virtual void addInnerRoundedRectClip(const IntRect& rect, int thickness);
64     virtual void canvasClip(const Path& path);
65     virtual bool clip(const FloatRect& rect);
66     virtual bool clip(const Path& path);
67     virtual bool clipConvexPolygon(size_t numPoints, const FloatPoint*, bool antialias);
68     virtual bool clipOut(const IntRect& r);
69     virtual bool clipOut(const Path& p);
70     virtual bool clipPath(const Path& pathToClip, WindRule clipRule);
getTotalClipBounds()71     virtual SkIRect getTotalClipBounds() { return mCanvas->getTotalClip().getBounds(); }
72 
73     // Drawing
74     virtual void clearRect(const FloatRect& rect);
75     virtual void drawBitmapPattern(const SkBitmap& bitmap, const SkMatrix& matrix,
76                            CompositeOperator compositeOp, const FloatRect& destRect);
77     virtual void drawBitmapRect(const SkBitmap& bitmap, const SkIRect* src,
78                         const SkRect& dst, CompositeOperator op = CompositeSourceOver);
79     virtual void drawConvexPolygon(size_t numPoints, const FloatPoint* points,
80                            bool shouldAntialias);
81     virtual void drawEllipse(const IntRect& rect);
82     virtual void drawFocusRing(const Vector<IntRect>& rects, int /* width */,
83                        int /* offset */, const Color& color);
84     virtual void drawHighlightForText(const Font& font, const TextRun& run,
85                               const FloatPoint& point, int h,
86                               const Color& backgroundColor, ColorSpace colorSpace,
87                               int from, int to, bool isActive);
88     virtual void drawLine(const IntPoint& point1, const IntPoint& point2);
89     virtual void drawLineForText(const FloatPoint& pt, float width);
90     virtual void drawLineForTextChecking(const FloatPoint& pt, float width,
91                                          GraphicsContext::TextCheckingLineStyle);
92     virtual void drawRect(const IntRect& rect);
93     virtual void fillPath(const Path& pathToFill, WindRule fillRule);
94     virtual void fillRect(const FloatRect& rect);
95     virtual void fillRect(const FloatRect& rect, const Color& color);
96     virtual void fillRoundedRect(const IntRect& rect, const IntSize& topLeft,
97                          const IntSize& topRight, const IntSize& bottomLeft,
98                          const IntSize& bottomRight, const Color& color);
99     virtual void strokeArc(const IntRect& r, int startAngle, int angleSpan);
100     virtual void strokePath(const Path& pathToStroke);
101     virtual void strokeRect(const FloatRect& rect, float lineWidth);
102     virtual void drawPosText(const void* text, size_t byteLength,
103                              const SkPoint pos[], const SkPaint& paint);
104     virtual void drawMediaButton(const IntRect& rect, RenderSkinMediaButton::MediaButton buttonType,
105                                  bool translucent = false, bool drawBackground = true,
106                                  const IntRect& thumb = IntRect());
107 
108 private:
109 
110     // shadowsIgnoreTransforms is only true for canvas's ImageBuffer, which will
111     // have a GraphicsContext
shadowsIgnoreTransforms()112     virtual bool shadowsIgnoreTransforms() const {
113         return m_gc && m_gc->shadowsIgnoreTransforms();
114     }
115 
116     SkCanvas* mCanvas;
117     bool m_deleteCanvas;
118 };
119 
120 }
121 #endif
122