/src/mozilla-central/gfx/2d/DrawTargetCapture.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef MOZILLA_GFX_DRAWTARGETCAPTURE_H_ |
8 | | #define MOZILLA_GFX_DRAWTARGETCAPTURE_H_ |
9 | | |
10 | | #include "2D.h" |
11 | | #include "CaptureCommandList.h" |
12 | | |
13 | | #include "Filters.h" |
14 | | |
15 | | namespace mozilla { |
16 | | namespace gfx { |
17 | | |
18 | | class DrawingCommand; |
19 | | class SourceSurfaceCapture; |
20 | | class AlphaBoxBlur; |
21 | | |
22 | | class DrawTargetCaptureImpl : public DrawTargetCapture |
23 | | { |
24 | | friend class SourceSurfaceCapture; |
25 | | |
26 | | public: |
27 | | DrawTargetCaptureImpl(gfx::DrawTarget* aTarget, size_t aFlushBytes); |
28 | | DrawTargetCaptureImpl(BackendType aBackend, const IntSize& aSize, SurfaceFormat aFormat); |
29 | | |
30 | | bool Init(const IntSize& aSize, DrawTarget* aRefDT); |
31 | | void InitForData(int32_t aStride, size_t aSurfaceAllocationSize); |
32 | | |
33 | 0 | virtual BackendType GetBackendType() const override { return mRefDT->GetBackendType(); } |
34 | 0 | virtual DrawTargetType GetType() const override { return mRefDT->GetType(); } |
35 | 0 | virtual bool IsCaptureDT() const override { return true; } |
36 | | virtual already_AddRefed<SourceSurface> Snapshot() override; |
37 | | virtual already_AddRefed<SourceSurface> IntoLuminanceSource(LuminanceType aLuminanceType, |
38 | | float aOpacity) override; |
39 | | virtual void SetPermitSubpixelAA(bool aPermitSubpixelAA) override; |
40 | | virtual void DetachAllSnapshots() override; |
41 | 0 | virtual IntSize GetSize() const override { return mSize; } |
42 | 0 | virtual void Flush() override {} |
43 | | virtual void DrawSurface(SourceSurface *aSurface, |
44 | | const Rect &aDest, |
45 | | const Rect &aSource, |
46 | | const DrawSurfaceOptions &aSurfOptions, |
47 | | const DrawOptions &aOptions) override; |
48 | | virtual void DrawFilter(FilterNode *aNode, |
49 | | const Rect &aSourceRect, |
50 | | const Point &aDestPoint, |
51 | | const DrawOptions &aOptions = DrawOptions()) override; |
52 | | virtual void DrawSurfaceWithShadow(SourceSurface *aSurface, |
53 | | const Point &aDest, |
54 | | const Color &aColor, |
55 | | const Point &aOffset, |
56 | | Float aSigma, |
57 | | CompositionOp aOperator) override; |
58 | | |
59 | | virtual void ClearRect(const Rect &aRect) override; |
60 | | virtual void MaskSurface(const Pattern &aSource, |
61 | | SourceSurface *aMask, |
62 | | Point aOffset, |
63 | | const DrawOptions &aOptions = DrawOptions()) override; |
64 | | virtual void CopySurface(SourceSurface *aSurface, |
65 | | const IntRect &aSourceRect, |
66 | | const IntPoint &aDestination) override; |
67 | | virtual void CopyRect(const IntRect &aSourceRect, |
68 | | const IntPoint &aDestination) override; |
69 | | |
70 | | virtual void FillRect(const Rect &aRect, |
71 | | const Pattern &aPattern, |
72 | | const DrawOptions &aOptions = DrawOptions()) override; |
73 | | virtual void StrokeRect(const Rect &aRect, |
74 | | const Pattern &aPattern, |
75 | | const StrokeOptions &aStrokeOptions = StrokeOptions(), |
76 | | const DrawOptions &aOptions = DrawOptions()) override; |
77 | | virtual void StrokeLine(const Point &aStart, |
78 | | const Point &aEnd, |
79 | | const Pattern &aPattern, |
80 | | const StrokeOptions &aStrokeOptions = StrokeOptions(), |
81 | | const DrawOptions &aOptions = DrawOptions()) override; |
82 | | virtual void Stroke(const Path *aPath, |
83 | | const Pattern &aPattern, |
84 | | const StrokeOptions &aStrokeOptions = StrokeOptions(), |
85 | | const DrawOptions &aOptions = DrawOptions()) override; |
86 | | virtual void Fill(const Path *aPath, |
87 | | const Pattern &aPattern, |
88 | | const DrawOptions &aOptions = DrawOptions()) override; |
89 | | virtual void FillGlyphs(ScaledFont *aFont, |
90 | | const GlyphBuffer &aBuffer, |
91 | | const Pattern &aPattern, |
92 | | const DrawOptions &aOptions = DrawOptions()) override; |
93 | | virtual void StrokeGlyphs(ScaledFont* aFont, |
94 | | const GlyphBuffer& aBuffer, |
95 | | const Pattern& aPattern, |
96 | | const StrokeOptions& aStrokeOptions = StrokeOptions(), |
97 | | const DrawOptions& aOptions = DrawOptions()) override; |
98 | | virtual void Mask(const Pattern &aSource, |
99 | | const Pattern &aMask, |
100 | | const DrawOptions &aOptions = DrawOptions()) override; |
101 | | virtual void PushClip(const Path *aPath) override; |
102 | | virtual void PushClipRect(const Rect &aRect) override; |
103 | | virtual void PopClip() override; |
104 | | virtual void PushLayer(bool aOpaque, |
105 | | Float aOpacity, |
106 | | SourceSurface* aMask, |
107 | | const Matrix& aMaskTransform, |
108 | | const IntRect& aBounds, |
109 | | bool aCopyBackground) override; |
110 | | virtual void PopLayer() override; |
111 | | virtual void Blur(const AlphaBoxBlur& aBlur) override; |
112 | | virtual void PadEdges(const IntRegion& aRegion) override; |
113 | | |
114 | | virtual void SetTransform(const Matrix &aTransform) override; |
115 | | |
116 | 0 | virtual bool SupportsRegionClipping() const override { return mRefDT->SupportsRegionClipping(); } |
117 | | |
118 | | virtual already_AddRefed<SourceSurface> CreateSourceSurfaceFromData(unsigned char *aData, |
119 | | const IntSize &aSize, |
120 | | int32_t aStride, |
121 | | SurfaceFormat aFormat) const override |
122 | 0 | { |
123 | 0 | return mRefDT->CreateSourceSurfaceFromData(aData, aSize, aStride, aFormat); |
124 | 0 | } |
125 | | virtual already_AddRefed<SourceSurface> OptimizeSourceSurface(SourceSurface *aSurface) const override; |
126 | | |
127 | | virtual already_AddRefed<SourceSurface> |
128 | | CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const override |
129 | 0 | { |
130 | 0 | return mRefDT->CreateSourceSurfaceFromNativeSurface(aSurface); |
131 | 0 | } |
132 | | |
133 | | virtual already_AddRefed<DrawTarget> |
134 | | CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const override; |
135 | | virtual RefPtr<DrawTarget> |
136 | | CreateSimilarRasterTarget(const IntSize& aSize, SurfaceFormat aFormat) const override; |
137 | | |
138 | | virtual already_AddRefed<PathBuilder> CreatePathBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const override |
139 | 0 | { |
140 | 0 | return mRefDT->CreatePathBuilder(aFillRule); |
141 | 0 | } |
142 | | |
143 | | virtual already_AddRefed<GradientStops> |
144 | | CreateGradientStops(GradientStop *aStops, |
145 | | uint32_t aNumStops, |
146 | | ExtendMode aExtendMode = ExtendMode::CLAMP) const override |
147 | 0 | { |
148 | 0 | return mRefDT->CreateGradientStops(aStops, aNumStops, aExtendMode); |
149 | 0 | } |
150 | | virtual already_AddRefed<FilterNode> CreateFilter(FilterType aType) override; |
151 | | |
152 | | void ReplayToDrawTarget(DrawTarget* aDT, const Matrix& aTransform); |
153 | | |
154 | | bool IsEmpty() const override; |
155 | | void Dump() override; |
156 | | |
157 | | protected: |
158 | | virtual ~DrawTargetCaptureImpl(); |
159 | | |
160 | | void MarkChanged(); |
161 | | |
162 | | private: |
163 | | void FlushCommandBuffer() |
164 | 0 | { |
165 | 0 | ReplayToDrawTarget(mRefDT, Matrix()); |
166 | 0 | mCommands.Clear(); |
167 | 0 | } |
168 | | |
169 | | // This storage system was used to minimize the amount of heap allocations |
170 | | // that are required while recording. It should be noted there's no |
171 | | // guarantees on the alignments of DrawingCommands allocated in this array. |
172 | | template<typename T> |
173 | 0 | T* AppendToCommandList() { |
174 | 0 | if (T::AffectsSnapshot) { |
175 | 0 | MarkChanged(); |
176 | 0 | } |
177 | 0 | if (mFlushBytes && |
178 | 0 | mCommands.BufferWillAlloc<T>() && |
179 | 0 | mCommands.BufferCapacity() > mFlushBytes) { |
180 | 0 | FlushCommandBuffer(); |
181 | 0 | } |
182 | 0 | return mCommands.Append<T>(); |
183 | 0 | } Unexecuted instantiation: mozilla::gfx::DrawSurfaceCommand* mozilla::gfx::DrawTargetCaptureImpl::AppendToCommandList<mozilla::gfx::DrawSurfaceCommand>() Unexecuted instantiation: mozilla::gfx::DrawSurfaceWithShadowCommand* mozilla::gfx::DrawTargetCaptureImpl::AppendToCommandList<mozilla::gfx::DrawSurfaceWithShadowCommand>() Unexecuted instantiation: mozilla::gfx::DrawFilterCommand* mozilla::gfx::DrawTargetCaptureImpl::AppendToCommandList<mozilla::gfx::DrawFilterCommand>() Unexecuted instantiation: mozilla::gfx::ClearRectCommand* mozilla::gfx::DrawTargetCaptureImpl::AppendToCommandList<mozilla::gfx::ClearRectCommand>() Unexecuted instantiation: mozilla::gfx::MaskSurfaceCommand* mozilla::gfx::DrawTargetCaptureImpl::AppendToCommandList<mozilla::gfx::MaskSurfaceCommand>() Unexecuted instantiation: mozilla::gfx::CopySurfaceCommand* mozilla::gfx::DrawTargetCaptureImpl::AppendToCommandList<mozilla::gfx::CopySurfaceCommand>() Unexecuted instantiation: mozilla::gfx::CopyRectCommand* mozilla::gfx::DrawTargetCaptureImpl::AppendToCommandList<mozilla::gfx::CopyRectCommand>() Unexecuted instantiation: mozilla::gfx::FillRectCommand* mozilla::gfx::DrawTargetCaptureImpl::AppendToCommandList<mozilla::gfx::FillRectCommand>() Unexecuted instantiation: mozilla::gfx::StrokeRectCommand* mozilla::gfx::DrawTargetCaptureImpl::AppendToCommandList<mozilla::gfx::StrokeRectCommand>() Unexecuted instantiation: mozilla::gfx::StrokeLineCommand* mozilla::gfx::DrawTargetCaptureImpl::AppendToCommandList<mozilla::gfx::StrokeLineCommand>() Unexecuted instantiation: mozilla::gfx::StrokeCommand* mozilla::gfx::DrawTargetCaptureImpl::AppendToCommandList<mozilla::gfx::StrokeCommand>() Unexecuted instantiation: mozilla::gfx::FillCommand* mozilla::gfx::DrawTargetCaptureImpl::AppendToCommandList<mozilla::gfx::FillCommand>() Unexecuted instantiation: mozilla::gfx::FillGlyphsCommand* mozilla::gfx::DrawTargetCaptureImpl::AppendToCommandList<mozilla::gfx::FillGlyphsCommand>() Unexecuted instantiation: mozilla::gfx::StrokeGlyphsCommand* mozilla::gfx::DrawTargetCaptureImpl::AppendToCommandList<mozilla::gfx::StrokeGlyphsCommand>() Unexecuted instantiation: mozilla::gfx::MaskCommand* mozilla::gfx::DrawTargetCaptureImpl::AppendToCommandList<mozilla::gfx::MaskCommand>() Unexecuted instantiation: mozilla::gfx::PushClipCommand* mozilla::gfx::DrawTargetCaptureImpl::AppendToCommandList<mozilla::gfx::PushClipCommand>() Unexecuted instantiation: mozilla::gfx::PushClipRectCommand* mozilla::gfx::DrawTargetCaptureImpl::AppendToCommandList<mozilla::gfx::PushClipRectCommand>() Unexecuted instantiation: mozilla::gfx::PushLayerCommand* mozilla::gfx::DrawTargetCaptureImpl::AppendToCommandList<mozilla::gfx::PushLayerCommand>() Unexecuted instantiation: mozilla::gfx::PopLayerCommand* mozilla::gfx::DrawTargetCaptureImpl::AppendToCommandList<mozilla::gfx::PopLayerCommand>() Unexecuted instantiation: mozilla::gfx::PopClipCommand* mozilla::gfx::DrawTargetCaptureImpl::AppendToCommandList<mozilla::gfx::PopClipCommand>() Unexecuted instantiation: mozilla::gfx::BlurCommand* mozilla::gfx::DrawTargetCaptureImpl::AppendToCommandList<mozilla::gfx::BlurCommand>() Unexecuted instantiation: mozilla::gfx::PadEdgesCommand* mozilla::gfx::DrawTargetCaptureImpl::AppendToCommandList<mozilla::gfx::PadEdgesCommand>() |
184 | | template<typename T> |
185 | 0 | T* ReuseOrAppendToCommandList() { |
186 | 0 | if (T::AffectsSnapshot) { |
187 | 0 | MarkChanged(); |
188 | 0 | } |
189 | 0 | if (mFlushBytes && |
190 | 0 | mCommands.BufferWillAlloc<T>() && |
191 | 0 | mCommands.BufferCapacity() > mFlushBytes) { |
192 | 0 | FlushCommandBuffer(); |
193 | 0 | } |
194 | 0 | return mCommands.ReuseOrAppend<T>(); |
195 | 0 | } Unexecuted instantiation: mozilla::gfx::SetPermitSubpixelAACommand* mozilla::gfx::DrawTargetCaptureImpl::ReuseOrAppendToCommandList<mozilla::gfx::SetPermitSubpixelAACommand>() Unexecuted instantiation: mozilla::gfx::SetTransformCommand* mozilla::gfx::DrawTargetCaptureImpl::ReuseOrAppendToCommandList<mozilla::gfx::SetTransformCommand>() |
196 | | |
197 | | RefPtr<DrawTarget> mRefDT; |
198 | | IntSize mSize; |
199 | | RefPtr<SourceSurfaceCapture> mSnapshot; |
200 | | |
201 | | // These are set if the draw target must be explicitly backed by data. |
202 | | int32_t mStride; |
203 | | size_t mSurfaceAllocationSize; |
204 | | |
205 | | struct PushedLayer |
206 | | { |
207 | | explicit PushedLayer(bool aOldPermitSubpixelAA) |
208 | | : mOldPermitSubpixelAA(aOldPermitSubpixelAA) |
209 | 0 | {} |
210 | | bool mOldPermitSubpixelAA; |
211 | | }; |
212 | | std::vector<PushedLayer> mPushedLayers; |
213 | | |
214 | | CaptureCommandList mCommands; |
215 | | size_t mFlushBytes; |
216 | | }; |
217 | | |
218 | | } // namespace gfx |
219 | | } // namespace mozilla |
220 | | |
221 | | #endif /* MOZILLA_GFX_DRAWTARGETCAPTURE_H_ */ |