Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; 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_DRAWTARGETCAPTURE_H_
7 : #define MOZILLA_GFX_DRAWTARGETCAPTURE_H_
8 :
9 : #include "2D.h"
10 : #include <vector>
11 :
12 : #include "Filters.h"
13 :
14 : namespace mozilla {
15 : namespace gfx {
16 :
17 : class DrawingCommand;
18 :
19 : class DrawTargetCaptureImpl : public DrawTargetCapture
20 : {
21 : public:
22 0 : DrawTargetCaptureImpl()
23 0 : {}
24 :
25 : bool Init(const IntSize& aSize, DrawTarget* aRefDT);
26 :
27 0 : virtual BackendType GetBackendType() const override { return mRefDT->GetBackendType(); }
28 0 : virtual DrawTargetType GetType() const override { return mRefDT->GetType(); }
29 0 : virtual bool IsCaptureDT() const override { return true; }
30 : virtual already_AddRefed<SourceSurface> Snapshot() override;
31 : virtual void DetachAllSnapshots() override;
32 0 : virtual IntSize GetSize() override { return mSize; }
33 0 : virtual void Flush() override {}
34 : virtual void DrawSurface(SourceSurface *aSurface,
35 : const Rect &aDest,
36 : const Rect &aSource,
37 : const DrawSurfaceOptions &aSurfOptions,
38 : const DrawOptions &aOptions) override;
39 : virtual void DrawFilter(FilterNode *aNode,
40 : const Rect &aSourceRect,
41 : const Point &aDestPoint,
42 : const DrawOptions &aOptions = DrawOptions()) override;
43 0 : virtual void DrawSurfaceWithShadow(SourceSurface *aSurface,
44 : const Point &aDest,
45 : const Color &aColor,
46 : const Point &aOffset,
47 : Float aSigma,
48 0 : CompositionOp aOperator) override { /* Not implemented */ }
49 :
50 : virtual void ClearRect(const Rect &aRect) override;
51 : virtual void MaskSurface(const Pattern &aSource,
52 : SourceSurface *aMask,
53 : Point aOffset,
54 : const DrawOptions &aOptions = DrawOptions()) override;
55 : virtual void CopySurface(SourceSurface *aSurface,
56 : const IntRect &aSourceRect,
57 : const IntPoint &aDestination) override;
58 :
59 : virtual void FillRect(const Rect &aRect,
60 : const Pattern &aPattern,
61 : const DrawOptions &aOptions = DrawOptions()) override;
62 : virtual void StrokeRect(const Rect &aRect,
63 : const Pattern &aPattern,
64 : const StrokeOptions &aStrokeOptions = StrokeOptions(),
65 : const DrawOptions &aOptions = DrawOptions()) override;
66 : virtual void StrokeLine(const Point &aStart,
67 : const Point &aEnd,
68 : const Pattern &aPattern,
69 : const StrokeOptions &aStrokeOptions = StrokeOptions(),
70 : const DrawOptions &aOptions = DrawOptions()) override;
71 : virtual void Stroke(const Path *aPath,
72 : const Pattern &aPattern,
73 : const StrokeOptions &aStrokeOptions = StrokeOptions(),
74 : const DrawOptions &aOptions = DrawOptions()) override;
75 : virtual void Fill(const Path *aPath,
76 : const Pattern &aPattern,
77 : const DrawOptions &aOptions = DrawOptions()) override;
78 : virtual void FillGlyphs(ScaledFont *aFont,
79 : const GlyphBuffer &aBuffer,
80 : const Pattern &aPattern,
81 : const DrawOptions &aOptions = DrawOptions(),
82 : const GlyphRenderingOptions *aRenderingOptions = nullptr) override;
83 : virtual void Mask(const Pattern &aSource,
84 : const Pattern &aMask,
85 : const DrawOptions &aOptions = DrawOptions()) override;
86 : virtual void PushClip(const Path *aPath) override;
87 : virtual void PushClipRect(const Rect &aRect) override;
88 : virtual void PopClip() override;
89 : virtual void PushLayer(bool aOpaque,
90 : Float aOpacity,
91 : SourceSurface* aMask,
92 : const Matrix& aMaskTransform,
93 : const IntRect& aBounds,
94 : bool aCopyBackground) override;
95 : virtual void PopLayer() override;
96 :
97 :
98 : virtual void SetTransform(const Matrix &aTransform) override;
99 :
100 0 : virtual already_AddRefed<SourceSurface> CreateSourceSurfaceFromData(unsigned char *aData,
101 : const IntSize &aSize,
102 : int32_t aStride,
103 : SurfaceFormat aFormat) const override
104 : {
105 0 : return mRefDT->CreateSourceSurfaceFromData(aData, aSize, aStride, aFormat);
106 : }
107 0 : virtual already_AddRefed<SourceSurface> OptimizeSourceSurface(SourceSurface *aSurface) const override
108 : {
109 0 : return mRefDT->OptimizeSourceSurface(aSurface);
110 : }
111 :
112 : virtual already_AddRefed<SourceSurface>
113 0 : CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const override
114 : {
115 0 : return mRefDT->CreateSourceSurfaceFromNativeSurface(aSurface);
116 : }
117 :
118 : virtual already_AddRefed<DrawTarget>
119 0 : CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const override
120 : {
121 0 : return mRefDT->CreateSimilarDrawTarget(aSize, aFormat);
122 : }
123 :
124 0 : virtual already_AddRefed<PathBuilder> CreatePathBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const override
125 : {
126 0 : return mRefDT->CreatePathBuilder(aFillRule);
127 : }
128 :
129 : virtual already_AddRefed<GradientStops>
130 0 : CreateGradientStops(GradientStop *aStops,
131 : uint32_t aNumStops,
132 : ExtendMode aExtendMode = ExtendMode::CLAMP) const override
133 : {
134 0 : return mRefDT->CreateGradientStops(aStops, aNumStops, aExtendMode);
135 : }
136 0 : virtual already_AddRefed<FilterNode> CreateFilter(FilterType aType) override
137 : {
138 0 : return mRefDT->CreateFilter(aType);
139 : }
140 :
141 : void ReplayToDrawTarget(DrawTarget* aDT, const Matrix& aTransform);
142 :
143 : bool ContainsOnlyColoredGlyphs(RefPtr<ScaledFont>& aScaledFont, Color& aColor, std::vector<Glyph>& aGlyphs) override;
144 :
145 : protected:
146 : ~DrawTargetCaptureImpl();
147 :
148 : private:
149 :
150 : // This storage system was used to minimize the amount of heap allocations
151 : // that are required while recording. It should be noted there's no
152 : // guarantees on the alignments of DrawingCommands allocated in this array.
153 : template<typename T>
154 0 : T* AppendToCommandList()
155 : {
156 0 : size_t oldSize = mDrawCommandStorage.size();
157 0 : mDrawCommandStorage.resize(mDrawCommandStorage.size() + sizeof(T) + sizeof(uint32_t));
158 0 : uint8_t* nextDrawLocation = &mDrawCommandStorage.front() + oldSize;
159 0 : *(uint32_t*)(nextDrawLocation) = sizeof(T) + sizeof(uint32_t);
160 0 : return reinterpret_cast<T*>(nextDrawLocation + sizeof(uint32_t));
161 : }
162 : RefPtr<DrawTarget> mRefDT;
163 :
164 : IntSize mSize;
165 :
166 : std::vector<uint8_t> mDrawCommandStorage;
167 : };
168 :
169 : } // namespace gfx
170 :
171 : } // namespace mozilla
172 :
173 :
174 : #endif /* MOZILLA_GFX_DRAWTARGETCAPTURE_H_ */
|