|
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 * This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef _MOZILLA_GFX_SOURCESURFACESKIA_H |
|
7 #define _MOZILLA_GFX_SOURCESURFACESKIA_H |
|
8 |
|
9 #ifdef USE_SKIA_GPU |
|
10 #include "skia/GrContext.h" |
|
11 #include "skia/GrGLInterface.h" |
|
12 #endif |
|
13 |
|
14 #include "skia/SkCanvas.h" |
|
15 |
|
16 #include "2D.h" |
|
17 #include "Rect.h" |
|
18 #include "PathSkia.h" |
|
19 #include <sstream> |
|
20 #include <vector> |
|
21 |
|
22 namespace mozilla { |
|
23 namespace gfx { |
|
24 |
|
25 class SourceSurfaceSkia; |
|
26 |
|
27 class DrawTargetSkia : public DrawTarget |
|
28 { |
|
29 public: |
|
30 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTargetSkia) |
|
31 DrawTargetSkia(); |
|
32 virtual ~DrawTargetSkia(); |
|
33 |
|
34 virtual BackendType GetType() const { return BackendType::SKIA; } |
|
35 virtual TemporaryRef<SourceSurface> Snapshot(); |
|
36 virtual IntSize GetSize() { return mSize; } |
|
37 virtual void Flush(); |
|
38 virtual void DrawSurface(SourceSurface *aSurface, |
|
39 const Rect &aDest, |
|
40 const Rect &aSource, |
|
41 const DrawSurfaceOptions &aSurfOptions = DrawSurfaceOptions(), |
|
42 const DrawOptions &aOptions = DrawOptions()); |
|
43 virtual void DrawFilter(FilterNode *aNode, |
|
44 const Rect &aSourceRect, |
|
45 const Point &aDestPoint, |
|
46 const DrawOptions &aOptions = DrawOptions()); |
|
47 virtual void DrawSurfaceWithShadow(SourceSurface *aSurface, |
|
48 const Point &aDest, |
|
49 const Color &aColor, |
|
50 const Point &aOffset, |
|
51 Float aSigma, |
|
52 CompositionOp aOperator); |
|
53 virtual void ClearRect(const Rect &aRect); |
|
54 virtual void CopySurface(SourceSurface *aSurface, |
|
55 const IntRect &aSourceRect, |
|
56 const IntPoint &aDestination); |
|
57 virtual void FillRect(const Rect &aRect, |
|
58 const Pattern &aPattern, |
|
59 const DrawOptions &aOptions = DrawOptions()); |
|
60 virtual void StrokeRect(const Rect &aRect, |
|
61 const Pattern &aPattern, |
|
62 const StrokeOptions &aStrokeOptions = StrokeOptions(), |
|
63 const DrawOptions &aOptions = DrawOptions()); |
|
64 virtual void StrokeLine(const Point &aStart, |
|
65 const Point &aEnd, |
|
66 const Pattern &aPattern, |
|
67 const StrokeOptions &aStrokeOptions = StrokeOptions(), |
|
68 const DrawOptions &aOptions = DrawOptions()); |
|
69 virtual void Stroke(const Path *aPath, |
|
70 const Pattern &aPattern, |
|
71 const StrokeOptions &aStrokeOptions = StrokeOptions(), |
|
72 const DrawOptions &aOptions = DrawOptions()); |
|
73 virtual void Fill(const Path *aPath, |
|
74 const Pattern &aPattern, |
|
75 const DrawOptions &aOptions = DrawOptions()); |
|
76 virtual void FillGlyphs(ScaledFont *aFont, |
|
77 const GlyphBuffer &aBuffer, |
|
78 const Pattern &aPattern, |
|
79 const DrawOptions &aOptions = DrawOptions(), |
|
80 const GlyphRenderingOptions *aRenderingOptions = nullptr); |
|
81 virtual void Mask(const Pattern &aSource, |
|
82 const Pattern &aMask, |
|
83 const DrawOptions &aOptions = DrawOptions()); |
|
84 virtual void MaskSurface(const Pattern &aSource, |
|
85 SourceSurface *aMask, |
|
86 Point aOffset, |
|
87 const DrawOptions &aOptions = DrawOptions()); |
|
88 virtual void PushClip(const Path *aPath); |
|
89 virtual void PushClipRect(const Rect& aRect); |
|
90 virtual void PopClip(); |
|
91 virtual TemporaryRef<SourceSurface> CreateSourceSurfaceFromData(unsigned char *aData, |
|
92 const IntSize &aSize, |
|
93 int32_t aStride, |
|
94 SurfaceFormat aFormat) const; |
|
95 virtual TemporaryRef<SourceSurface> OptimizeSourceSurface(SourceSurface *aSurface) const; |
|
96 virtual TemporaryRef<SourceSurface> |
|
97 CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const; |
|
98 virtual TemporaryRef<DrawTarget> |
|
99 CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const; |
|
100 virtual TemporaryRef<PathBuilder> CreatePathBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const; |
|
101 virtual TemporaryRef<GradientStops> CreateGradientStops(GradientStop *aStops, uint32_t aNumStops, ExtendMode aExtendMode = ExtendMode::CLAMP) const; |
|
102 virtual TemporaryRef<FilterNode> CreateFilter(FilterType aType); |
|
103 virtual void SetTransform(const Matrix &aTransform); |
|
104 virtual void *GetNativeSurface(NativeSurfaceType aType); |
|
105 |
|
106 bool Init(const IntSize &aSize, SurfaceFormat aFormat); |
|
107 void Init(unsigned char* aData, const IntSize &aSize, int32_t aStride, SurfaceFormat aFormat); |
|
108 |
|
109 #ifdef USE_SKIA_GPU |
|
110 bool InitWithGrContext(GrContext* aGrContext, |
|
111 const IntSize &aSize, |
|
112 SurfaceFormat aFormat) MOZ_OVERRIDE; |
|
113 #endif |
|
114 |
|
115 operator std::string() const { |
|
116 std::stringstream stream; |
|
117 stream << "DrawTargetSkia(" << this << ")"; |
|
118 return stream.str(); |
|
119 } |
|
120 |
|
121 private: |
|
122 friend class SourceSurfaceSkia; |
|
123 void SnapshotDestroyed(); |
|
124 |
|
125 void MarkChanged(); |
|
126 |
|
127 SkRect SkRectCoveringWholeSurface() const; |
|
128 |
|
129 #ifdef USE_SKIA_GPU |
|
130 SkRefPtr<GrContext> mGrContext; |
|
131 uint32_t mTexture; |
|
132 #endif |
|
133 |
|
134 IntSize mSize; |
|
135 SkRefPtr<SkCanvas> mCanvas; |
|
136 SourceSurfaceSkia* mSnapshot; |
|
137 }; |
|
138 |
|
139 } |
|
140 } |
|
141 |
|
142 #endif // _MOZILLA_GFX_SOURCESURFACESKIA_H |