Bug 1641886 [wpt PR 23851] - Support interpolating contain-intrinsic-size, a=testonly
[gecko.git] / gfx / 2d / DrawCommands.h
blob23db4c9be1ba97cb0e5b54e8032d83b2e531e139
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/. */
7 #ifndef MOZILLA_GFX_DRAWCOMMANDS_H_
8 #define MOZILLA_GFX_DRAWCOMMANDS_H_
10 #include <math.h>
12 #include "2D.h"
13 #include "Blur.h"
14 #include "Filters.h"
15 #include <vector>
16 #include "CaptureCommandList.h"
17 #include "DrawCommand.h"
18 #include "FilterNodeCapture.h"
19 #include "Logging.h"
20 #include "nsRegion.h"
22 namespace mozilla {
23 namespace gfx {
25 #define CLONE_INTO(Type) new (aList->Append<Type>()) Type
27 class StrokeOptionsCommand : public DrawingCommand {
28 public:
29 StrokeOptionsCommand(const StrokeOptions& aStrokeOptions)
30 : mStrokeOptions(aStrokeOptions) {
31 // Stroke Options dashes are owned by the caller.
32 // Have to copy them here so they don't get freed
33 // between now and replay.
34 if (aStrokeOptions.mDashLength) {
35 mDashes.resize(aStrokeOptions.mDashLength);
36 mStrokeOptions.mDashPattern = &mDashes.front();
37 PodCopy(&mDashes.front(), aStrokeOptions.mDashPattern,
38 mStrokeOptions.mDashLength);
42 virtual ~StrokeOptionsCommand() = default;
44 protected:
45 StrokeOptions mStrokeOptions;
46 std::vector<Float> mDashes;
49 class StoredPattern {
50 public:
51 explicit StoredPattern(const Pattern& aPattern) { Assign(aPattern); }
53 void Assign(const Pattern& aPattern) {
54 switch (aPattern.GetType()) {
55 case PatternType::COLOR:
56 new (mColor) ColorPattern(*static_cast<const ColorPattern*>(&aPattern));
57 return;
58 case PatternType::SURFACE: {
59 SurfacePattern* surfPat = new (mSurface)
60 SurfacePattern(*static_cast<const SurfacePattern*>(&aPattern));
61 surfPat->mSurface->GuaranteePersistance();
62 return;
64 case PatternType::LINEAR_GRADIENT:
65 new (mLinear) LinearGradientPattern(
66 *static_cast<const LinearGradientPattern*>(&aPattern));
67 return;
68 case PatternType::RADIAL_GRADIENT:
69 new (mRadial) RadialGradientPattern(
70 *static_cast<const RadialGradientPattern*>(&aPattern));
71 return;
72 case PatternType::CONIC_GRADIENT:
73 new (mConic) ConicGradientPattern(
74 *static_cast<const ConicGradientPattern*>(&aPattern));
75 return;
79 ~StoredPattern() { reinterpret_cast<Pattern*>(mPattern)->~Pattern(); }
81 Pattern* Get() { return reinterpret_cast<Pattern*>(mPattern); }
83 const Pattern* Get() const {
84 return reinterpret_cast<const Pattern*>(mPattern);
87 operator Pattern&() { return *reinterpret_cast<Pattern*>(mPattern); }
89 operator const Pattern&() const {
90 return *reinterpret_cast<const Pattern*>(mPattern);
93 StoredPattern(const StoredPattern& aPattern) { Assign(aPattern); }
95 private:
96 StoredPattern operator=(const StoredPattern& aOther) {
97 // Block this so that we notice if someone's doing excessive assigning.
98 return *this;
101 union {
102 char mPattern[sizeof(Pattern)];
103 char mColor[sizeof(ColorPattern)];
104 char mLinear[sizeof(LinearGradientPattern)];
105 char mRadial[sizeof(RadialGradientPattern)];
106 char mConic[sizeof(ConicGradientPattern)];
107 char mSurface[sizeof(SurfacePattern)];
111 class DrawSurfaceCommand : public DrawingCommand {
112 public:
113 DrawSurfaceCommand(SourceSurface* aSurface, const Rect& aDest,
114 const Rect& aSource,
115 const DrawSurfaceOptions& aSurfOptions,
116 const DrawOptions& aOptions)
117 : mSurface(aSurface),
118 mDest(aDest),
119 mSource(aSource),
120 mSurfOptions(aSurfOptions),
121 mOptions(aOptions) {}
123 CommandType GetType() const override { return DrawSurfaceCommand::Type; }
125 void CloneInto(CaptureCommandList* aList) override {
126 CLONE_INTO(DrawSurfaceCommand)
127 (mSurface, mDest, mSource, mSurfOptions, mOptions);
130 void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override {
131 aDT->DrawSurface(mSurface, mDest, mSource, mSurfOptions, mOptions);
134 void Log(TreeLog<>& aStream) const override {
135 aStream << "[DrawSurface surf=" << mSurface;
136 aStream << " dest=" << mDest;
137 aStream << " src=" << mSource;
138 aStream << " surfOpt=" << mSurfOptions;
139 aStream << " opt=" << mOptions;
140 aStream << "]";
143 static const bool AffectsSnapshot = true;
144 static const CommandType Type = CommandType::DRAWSURFACE;
146 private:
147 RefPtr<SourceSurface> mSurface;
148 Rect mDest;
149 Rect mSource;
150 DrawSurfaceOptions mSurfOptions;
151 DrawOptions mOptions;
154 class DrawSurfaceWithShadowCommand : public DrawingCommand {
155 public:
156 DrawSurfaceWithShadowCommand(SourceSurface* aSurface, const Point& aDest,
157 const DeviceColor& aColor, const Point& aOffset,
158 Float aSigma, CompositionOp aOperator)
159 : mSurface(aSurface),
160 mDest(aDest),
161 mColor(aColor),
162 mOffset(aOffset),
163 mSigma(aSigma),
164 mOperator(aOperator) {}
166 CommandType GetType() const override {
167 return DrawSurfaceWithShadowCommand::Type;
170 void CloneInto(CaptureCommandList* aList) override {
171 CLONE_INTO(DrawSurfaceWithShadowCommand)
172 (mSurface, mDest, mColor, mOffset, mSigma, mOperator);
175 void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override {
176 aDT->DrawSurfaceWithShadow(mSurface, mDest, mColor, mOffset, mSigma,
177 mOperator);
180 void Log(TreeLog<>& aStream) const override {
181 aStream << "[DrawSurfaceWithShadow surf=" << mSurface;
182 aStream << " dest=" << mDest;
183 aStream << " color=" << mColor;
184 aStream << " offset=" << mOffset;
185 aStream << " sigma=" << mSigma;
186 aStream << " op=" << mOperator;
187 aStream << "]";
190 static const bool AffectsSnapshot = true;
191 static const CommandType Type = CommandType::DRAWSURFACEWITHSHADOW;
193 private:
194 RefPtr<SourceSurface> mSurface;
195 Point mDest;
196 DeviceColor mColor;
197 Point mOffset;
198 Float mSigma;
199 CompositionOp mOperator;
202 class DrawFilterCommand : public DrawingCommand {
203 public:
204 DrawFilterCommand(FilterNode* aFilter, const Rect& aSourceRect,
205 const Point& aDestPoint, const DrawOptions& aOptions)
206 : mFilter(aFilter),
207 mSourceRect(aSourceRect),
208 mDestPoint(aDestPoint),
209 mOptions(aOptions) {}
211 CommandType GetType() const override { return DrawFilterCommand::Type; }
213 void CloneInto(CaptureCommandList* aList) override {
214 CLONE_INTO(DrawFilterCommand)(mFilter, mSourceRect, mDestPoint, mOptions);
217 void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override {
218 RefPtr<FilterNode> filter = mFilter;
219 if (mFilter->GetBackendType() == FilterBackend::FILTER_BACKEND_CAPTURE) {
220 filter = static_cast<FilterNodeCapture*>(filter.get())->Validate(aDT);
222 // This can happen if the FilterNodeCapture is unable to create a
223 // backing FilterNode on the target backend. Normally this would be
224 // handled by the painting code, but here there's not much we can do.
225 if (!filter) {
226 return;
229 aDT->DrawFilter(filter, mSourceRect, mDestPoint, mOptions);
232 void Log(TreeLog<>& aStream) const override {
233 aStream << "[DrawFilter surf=" << mFilter;
234 aStream << " src=" << mSourceRect;
235 aStream << " dest=" << mDestPoint;
236 aStream << " opt=" << mOptions;
237 aStream << "]";
240 static const bool AffectsSnapshot = true;
241 static const CommandType Type = CommandType::DRAWFILTER;
243 private:
244 RefPtr<FilterNode> mFilter;
245 Rect mSourceRect;
246 Point mDestPoint;
247 DrawOptions mOptions;
250 class ClearRectCommand : public DrawingCommand {
251 public:
252 explicit ClearRectCommand(const Rect& aRect) : mRect(aRect) {}
254 CommandType GetType() const override { return ClearRectCommand::Type; }
256 void CloneInto(CaptureCommandList* aList) override {
257 CLONE_INTO(ClearRectCommand)(mRect);
260 void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override {
261 aDT->ClearRect(mRect);
264 void Log(TreeLog<>& aStream) const override {
265 aStream << "[ClearRect rect=" << mRect << "]";
268 static const bool AffectsSnapshot = true;
269 static const CommandType Type = CommandType::CLEARRECT;
271 private:
272 Rect mRect;
275 class CopySurfaceCommand : public DrawingCommand {
276 public:
277 CopySurfaceCommand(SourceSurface* aSurface, const IntRect& aSourceRect,
278 const IntPoint& aDestination)
279 : mSurface(aSurface),
280 mSourceRect(aSourceRect),
281 mDestination(aDestination) {}
283 CommandType GetType() const override { return CopySurfaceCommand::Type; }
285 void CloneInto(CaptureCommandList* aList) override {
286 CLONE_INTO(CopySurfaceCommand)(mSurface, mSourceRect, mDestination);
289 virtual void ExecuteOnDT(DrawTarget* aDT,
290 const Matrix* aTransform) const override {
291 MOZ_ASSERT(!aTransform || !aTransform->HasNonIntegerTranslation());
292 Point dest(Float(mDestination.x), Float(mDestination.y));
293 if (aTransform) {
294 dest = aTransform->TransformPoint(dest);
296 aDT->CopySurface(mSurface, mSourceRect,
297 IntPoint(uint32_t(dest.x), uint32_t(dest.y)));
300 void Log(TreeLog<>& aStream) const override {
301 aStream << "[CopySurface surf=" << mSurface;
302 aStream << " src=" << mSourceRect;
303 aStream << " dest=" << mDestination;
304 aStream << "]";
307 static const bool AffectsSnapshot = true;
308 static const CommandType Type = CommandType::COPYSURFACE;
310 private:
311 RefPtr<SourceSurface> mSurface;
312 IntRect mSourceRect;
313 IntPoint mDestination;
316 class CopyRectCommand : public DrawingCommand {
317 public:
318 CopyRectCommand(const IntRect& aSourceRect, const IntPoint& aDestination)
319 : mSourceRect(aSourceRect), mDestination(aDestination) {}
321 CommandType GetType() const override { return CopyRectCommand::Type; }
323 void CloneInto(CaptureCommandList* aList) override {
324 CLONE_INTO(CopyRectCommand)(mSourceRect, mDestination);
327 virtual void ExecuteOnDT(DrawTarget* aDT,
328 const Matrix* aTransform) const override {
329 aDT->CopyRect(mSourceRect, mDestination);
332 void Log(TreeLog<>& aStream) const override {
333 aStream << "[CopyRect src=" << mSourceRect;
334 aStream << " dest=" << mDestination;
335 aStream << "]";
338 static const bool AffectsSnapshot = true;
339 static const CommandType Type = CommandType::COPYRECT;
341 private:
342 IntRect mSourceRect;
343 IntPoint mDestination;
346 class FillRectCommand : public DrawingCommand {
347 public:
348 FillRectCommand(const Rect& aRect, const Pattern& aPattern,
349 const DrawOptions& aOptions)
350 : mRect(aRect), mPattern(aPattern), mOptions(aOptions) {}
352 CommandType GetType() const override { return FillRectCommand::Type; }
354 void CloneInto(CaptureCommandList* aList) override {
355 CLONE_INTO(FillRectCommand)(mRect, mPattern, mOptions);
358 void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override {
359 aDT->FillRect(mRect, mPattern, mOptions);
362 void Log(TreeLog<>& aStream) const override {
363 aStream << "[FillRect rect=" << mRect;
364 aStream << " pattern=" << mPattern.Get();
365 aStream << " opt=" << mOptions;
366 aStream << "]";
369 static const bool AffectsSnapshot = true;
370 static const CommandType Type = CommandType::FILLRECT;
372 private:
373 Rect mRect;
374 StoredPattern mPattern;
375 DrawOptions mOptions;
378 class FillRoundedRectCommand : public DrawingCommand {
379 public:
380 FillRoundedRectCommand(const RoundedRect& aRect, const Pattern& aPattern,
381 const DrawOptions& aOptions)
382 : mRect(aRect), mPattern(aPattern), mOptions(aOptions) {}
384 CommandType GetType() const override { return FillRoundedRectCommand::Type; }
386 void CloneInto(CaptureCommandList* aList) override {
387 CLONE_INTO(FillRoundedRectCommand)(mRect, mPattern, mOptions);
390 void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override {
391 aDT->FillRoundedRect(mRect, mPattern, mOptions);
394 void Log(TreeLog<>& aStream) const override {
395 aStream << "[FillRoundedRect rect=" << mRect.rect;
396 aStream << " pattern=" << mPattern.Get();
397 aStream << " opt=" << mOptions;
398 aStream << "]";
401 static const bool AffectsSnapshot = true;
402 static const CommandType Type = CommandType::FILLROUNDEDRECT;
404 private:
405 RoundedRect mRect;
406 StoredPattern mPattern;
407 DrawOptions mOptions;
410 class StrokeRectCommand : public StrokeOptionsCommand {
411 public:
412 StrokeRectCommand(const Rect& aRect, const Pattern& aPattern,
413 const StrokeOptions& aStrokeOptions,
414 const DrawOptions& aOptions)
415 : StrokeOptionsCommand(aStrokeOptions),
416 mRect(aRect),
417 mPattern(aPattern),
418 mOptions(aOptions) {}
420 CommandType GetType() const override { return StrokeRectCommand::Type; }
422 void CloneInto(CaptureCommandList* aList) override {
423 CLONE_INTO(StrokeRectCommand)(mRect, mPattern, mStrokeOptions, mOptions);
426 void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override {
427 aDT->StrokeRect(mRect, mPattern, mStrokeOptions, mOptions);
430 void Log(TreeLog<>& aStream) const override {
431 aStream << "[StrokeRect rect=" << mRect;
432 aStream << " pattern=" << mPattern.Get();
433 aStream << " opt=" << mOptions;
434 aStream << "]";
437 static const bool AffectsSnapshot = true;
438 static const CommandType Type = CommandType::STROKERECT;
440 private:
441 Rect mRect;
442 StoredPattern mPattern;
443 DrawOptions mOptions;
446 class StrokeLineCommand : public StrokeOptionsCommand {
447 public:
448 StrokeLineCommand(const Point& aStart, const Point& aEnd,
449 const Pattern& aPattern,
450 const StrokeOptions& aStrokeOptions,
451 const DrawOptions& aOptions)
452 : StrokeOptionsCommand(aStrokeOptions),
453 mStart(aStart),
454 mEnd(aEnd),
455 mPattern(aPattern),
456 mOptions(aOptions) {}
458 CommandType GetType() const override { return StrokeLineCommand::Type; }
460 void CloneInto(CaptureCommandList* aList) override {
461 CLONE_INTO(StrokeLineCommand)
462 (mStart, mEnd, mPattern, mStrokeOptions, mOptions);
465 void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override {
466 aDT->StrokeLine(mStart, mEnd, mPattern, mStrokeOptions, mOptions);
469 void Log(TreeLog<>& aStream) const override {
470 aStream << "[StrokeLine start=" << mStart;
471 aStream << " end=" << mEnd;
472 aStream << " pattern=" << mPattern.Get();
473 aStream << " opt=" << mOptions;
474 aStream << "]";
477 static const bool AffectsSnapshot = true;
478 static const CommandType Type = CommandType::STROKELINE;
480 private:
481 Point mStart;
482 Point mEnd;
483 StoredPattern mPattern;
484 DrawOptions mOptions;
487 class FillCommand : public DrawingCommand {
488 public:
489 FillCommand(const Path* aPath, const Pattern& aPattern,
490 const DrawOptions& aOptions)
491 : mPath(const_cast<Path*>(aPath)),
492 mPattern(aPattern),
493 mOptions(aOptions) {}
495 CommandType GetType() const override { return FillCommand::Type; }
497 void CloneInto(CaptureCommandList* aList) override {
498 CLONE_INTO(FillCommand)(mPath, mPattern, mOptions);
501 void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override {
502 aDT->Fill(mPath, mPattern, mOptions);
505 void Log(TreeLog<>& aStream) const override {
506 aStream << "[FillCommand path=" << mPath;
507 aStream << " pattern=" << mPattern.Get();
508 aStream << " opt=" << mOptions;
509 aStream << "]";
512 static const bool AffectsSnapshot = true;
513 static const CommandType Type = CommandType::FILL;
515 private:
516 RefPtr<Path> mPath;
517 StoredPattern mPattern;
518 DrawOptions mOptions;
521 class StrokeCommand : public StrokeOptionsCommand {
522 public:
523 StrokeCommand(const Path* aPath, const Pattern& aPattern,
524 const StrokeOptions& aStrokeOptions,
525 const DrawOptions& aOptions)
526 : StrokeOptionsCommand(aStrokeOptions),
527 mPath(const_cast<Path*>(aPath)),
528 mPattern(aPattern),
529 mOptions(aOptions) {}
531 CommandType GetType() const override { return StrokeCommand::Type; }
533 void CloneInto(CaptureCommandList* aList) override {
534 CLONE_INTO(StrokeCommand)(mPath, mPattern, mStrokeOptions, mOptions);
537 void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override {
538 aDT->Stroke(mPath, mPattern, mStrokeOptions, mOptions);
541 void Log(TreeLog<>& aStream) const override {
542 aStream << "[Stroke path=" << mPath;
543 aStream << " pattern=" << mPattern.Get();
544 aStream << " opt=" << mOptions;
545 aStream << "]";
548 static const bool AffectsSnapshot = true;
549 static const CommandType Type = CommandType::STROKE;
551 private:
552 RefPtr<Path> mPath;
553 StoredPattern mPattern;
554 DrawOptions mOptions;
557 class FillGlyphsCommand : public DrawingCommand {
558 friend class DrawTargetCaptureImpl;
560 public:
561 FillGlyphsCommand(ScaledFont* aFont, const GlyphBuffer& aBuffer,
562 const Pattern& aPattern, const DrawOptions& aOptions)
563 : mFont(aFont), mPattern(aPattern), mOptions(aOptions) {
564 mGlyphs.resize(aBuffer.mNumGlyphs);
565 memcpy(&mGlyphs.front(), aBuffer.mGlyphs,
566 sizeof(Glyph) * aBuffer.mNumGlyphs);
569 CommandType GetType() const override { return FillGlyphsCommand::Type; }
571 void CloneInto(CaptureCommandList* aList) override {
572 GlyphBuffer glyphs = {
573 mGlyphs.data(),
574 (uint32_t)mGlyphs.size(),
576 CLONE_INTO(FillGlyphsCommand)(mFont, glyphs, mPattern, mOptions);
579 void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override {
580 GlyphBuffer buf;
581 buf.mNumGlyphs = mGlyphs.size();
582 buf.mGlyphs = &mGlyphs.front();
583 aDT->FillGlyphs(mFont, buf, mPattern, mOptions);
586 void Log(TreeLog<>& aStream) const override {
587 aStream << "[FillGlyphs font=" << mFont;
588 aStream << " glyphCount=" << mGlyphs.size();
589 aStream << " pattern=" << mPattern.Get();
590 aStream << " opt=" << mOptions;
591 aStream << "]";
594 static const bool AffectsSnapshot = true;
595 static const CommandType Type = CommandType::FILLGLYPHS;
597 private:
598 RefPtr<ScaledFont> mFont;
599 std::vector<Glyph> mGlyphs;
600 StoredPattern mPattern;
601 DrawOptions mOptions;
604 class StrokeGlyphsCommand : public StrokeOptionsCommand {
605 friend class DrawTargetCaptureImpl;
607 public:
608 StrokeGlyphsCommand(ScaledFont* aFont, const GlyphBuffer& aBuffer,
609 const Pattern& aPattern,
610 const StrokeOptions& aStrokeOptions,
611 const DrawOptions& aOptions)
612 : StrokeOptionsCommand(aStrokeOptions),
613 mFont(aFont),
614 mPattern(aPattern),
615 mOptions(aOptions) {
616 mGlyphs.resize(aBuffer.mNumGlyphs);
617 memcpy(&mGlyphs.front(), aBuffer.mGlyphs,
618 sizeof(Glyph) * aBuffer.mNumGlyphs);
621 CommandType GetType() const override { return StrokeGlyphsCommand::Type; }
623 void CloneInto(CaptureCommandList* aList) override {
624 GlyphBuffer glyphs = {
625 mGlyphs.data(),
626 (uint32_t)mGlyphs.size(),
628 CLONE_INTO(StrokeGlyphsCommand)
629 (mFont, glyphs, mPattern, mStrokeOptions, mOptions);
632 void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override {
633 GlyphBuffer buf;
634 buf.mNumGlyphs = mGlyphs.size();
635 buf.mGlyphs = &mGlyphs.front();
636 aDT->StrokeGlyphs(mFont, buf, mPattern, mStrokeOptions, mOptions);
639 void Log(TreeLog<>& aStream) const override {
640 aStream << "[StrokeGlyphs font=" << mFont;
641 aStream << " glyphCount=" << mGlyphs.size();
642 aStream << " pattern=" << mPattern.Get();
643 aStream << " opt=" << mOptions;
644 aStream << "]";
647 static const bool AffectsSnapshot = true;
648 static const CommandType Type = CommandType::STROKEGLYPHS;
650 private:
651 RefPtr<ScaledFont> mFont;
652 std::vector<Glyph> mGlyphs;
653 StoredPattern mPattern;
654 DrawOptions mOptions;
657 class MaskCommand : public DrawingCommand {
658 public:
659 MaskCommand(const Pattern& aSource, const Pattern& aMask,
660 const DrawOptions& aOptions)
661 : mSource(aSource), mMask(aMask), mOptions(aOptions) {}
663 CommandType GetType() const override { return MaskCommand::Type; }
665 void CloneInto(CaptureCommandList* aList) override {
666 CLONE_INTO(MaskCommand)(mSource, mMask, mOptions);
669 void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override {
670 aDT->Mask(mSource, mMask, mOptions);
673 void Log(TreeLog<>& aStream) const override {
674 aStream << "[Mask source=" << mSource.Get();
675 aStream << " mask=" << mMask.Get();
676 aStream << " opt=" << mOptions;
677 aStream << "]";
680 static const bool AffectsSnapshot = true;
681 static const CommandType Type = CommandType::MASK;
683 private:
684 StoredPattern mSource;
685 StoredPattern mMask;
686 DrawOptions mOptions;
689 class MaskSurfaceCommand : public DrawingCommand {
690 public:
691 MaskSurfaceCommand(const Pattern& aSource, const SourceSurface* aMask,
692 const Point& aOffset, const DrawOptions& aOptions)
693 : mSource(aSource),
694 mMask(const_cast<SourceSurface*>(aMask)),
695 mOffset(aOffset),
696 mOptions(aOptions) {}
698 CommandType GetType() const override { return MaskSurfaceCommand::Type; }
700 void CloneInto(CaptureCommandList* aList) override {
701 CLONE_INTO(MaskSurfaceCommand)(mSource, mMask, mOffset, mOptions);
704 void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override {
705 aDT->MaskSurface(mSource, mMask, mOffset, mOptions);
708 void Log(TreeLog<>& aStream) const override {
709 aStream << "[Mask source=" << mSource.Get();
710 aStream << " mask=" << mMask;
711 aStream << " offset=" << &mOffset;
712 aStream << " opt=" << mOptions;
713 aStream << "]";
716 static const bool AffectsSnapshot = true;
717 static const CommandType Type = CommandType::MASKSURFACE;
719 private:
720 StoredPattern mSource;
721 RefPtr<SourceSurface> mMask;
722 Point mOffset;
723 DrawOptions mOptions;
726 class PushClipCommand : public DrawingCommand {
727 public:
728 explicit PushClipCommand(const Path* aPath)
729 : mPath(const_cast<Path*>(aPath)) {}
731 CommandType GetType() const override { return PushClipCommand::Type; }
733 void CloneInto(CaptureCommandList* aList) override {
734 CLONE_INTO(PushClipCommand)(mPath);
737 void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override {
738 aDT->PushClip(mPath);
741 void Log(TreeLog<>& aStream) const override {
742 aStream << "[PushClip path=" << mPath << "]";
745 static const bool AffectsSnapshot = false;
746 static const CommandType Type = CommandType::PUSHCLIP;
748 private:
749 RefPtr<Path> mPath;
752 class PushClipRectCommand : public DrawingCommand {
753 public:
754 explicit PushClipRectCommand(const Rect& aRect) : mRect(aRect) {}
756 CommandType GetType() const override { return PushClipRectCommand::Type; }
758 void CloneInto(CaptureCommandList* aList) override {
759 CLONE_INTO(PushClipRectCommand)(mRect);
762 void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override {
763 aDT->PushClipRect(mRect);
766 void Log(TreeLog<>& aStream) const override {
767 aStream << "[PushClipRect rect=" << mRect << "]";
770 static const bool AffectsSnapshot = false;
771 static const CommandType Type = CommandType::PUSHCLIPRECT;
773 private:
774 Rect mRect;
777 class PushLayerCommand : public DrawingCommand {
778 public:
779 PushLayerCommand(const bool aOpaque, const Float aOpacity,
780 SourceSurface* aMask, const Matrix& aMaskTransform,
781 const IntRect& aBounds, bool aCopyBackground)
782 : mOpaque(aOpaque),
783 mOpacity(aOpacity),
784 mMask(aMask),
785 mMaskTransform(aMaskTransform),
786 mBounds(aBounds),
787 mCopyBackground(aCopyBackground) {}
789 CommandType GetType() const override { return PushLayerCommand::Type; }
791 void CloneInto(CaptureCommandList* aList) override {
792 CLONE_INTO(PushLayerCommand)
793 (mOpaque, mOpacity, mMask, mMaskTransform, mBounds, mCopyBackground);
796 void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override {
797 aDT->PushLayer(mOpaque, mOpacity, mMask, mMaskTransform, mBounds,
798 mCopyBackground);
801 void Log(TreeLog<>& aStream) const override {
802 aStream << "[PushLayer opaque=" << mOpaque;
803 aStream << " opacity=" << mOpacity;
804 aStream << " mask=" << mMask;
805 aStream << " maskTransform=" << mMaskTransform;
806 aStream << " bounds=" << mBounds;
807 aStream << " copyBackground=" << mCopyBackground;
808 aStream << "]";
811 static const bool AffectsSnapshot = false;
812 static const CommandType Type = CommandType::PUSHLAYER;
814 private:
815 bool mOpaque;
816 float mOpacity;
817 RefPtr<SourceSurface> mMask;
818 Matrix mMaskTransform;
819 IntRect mBounds;
820 bool mCopyBackground;
823 class PopClipCommand : public DrawingCommand {
824 public:
825 PopClipCommand() = default;
827 CommandType GetType() const override { return PopClipCommand::Type; }
829 void CloneInto(CaptureCommandList* aList) override {
830 CLONE_INTO(PopClipCommand)();
833 void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override {
834 aDT->PopClip();
837 void Log(TreeLog<>& aStream) const override { aStream << "[PopClip]"; }
839 static const bool AffectsSnapshot = false;
840 static const CommandType Type = CommandType::POPCLIP;
843 class PopLayerCommand : public DrawingCommand {
844 public:
845 PopLayerCommand() = default;
847 CommandType GetType() const override { return PopLayerCommand::Type; }
849 void CloneInto(CaptureCommandList* aList) override {
850 CLONE_INTO(PopLayerCommand)();
853 void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override {
854 aDT->PopLayer();
857 void Log(TreeLog<>& aStream) const override { aStream << "[PopLayer]"; }
859 static const bool AffectsSnapshot = true;
860 static const CommandType Type = CommandType::POPLAYER;
863 class SetTransformCommand : public DrawingCommand {
864 friend class DrawTargetCaptureImpl;
866 public:
867 explicit SetTransformCommand(const Matrix& aTransform)
868 : mTransform(aTransform) {}
870 CommandType GetType() const override { return SetTransformCommand::Type; }
872 void CloneInto(CaptureCommandList* aList) override {
873 CLONE_INTO(SetTransformCommand)(mTransform);
876 void ExecuteOnDT(DrawTarget* aDT, const Matrix* aMatrix) const override {
877 if (aMatrix) {
878 aDT->SetTransform(mTransform * (*aMatrix));
879 } else {
880 aDT->SetTransform(mTransform);
884 void Log(TreeLog<>& aStream) const override {
885 aStream << "[SetTransform transform=" << mTransform << "]";
888 static const bool AffectsSnapshot = false;
889 static const CommandType Type = CommandType::SETTRANSFORM;
891 private:
892 Matrix mTransform;
895 class SetPermitSubpixelAACommand : public DrawingCommand {
896 friend class DrawTargetCaptureImpl;
898 public:
899 explicit SetPermitSubpixelAACommand(bool aPermitSubpixelAA)
900 : mPermitSubpixelAA(aPermitSubpixelAA) {}
902 CommandType GetType() const override {
903 return SetPermitSubpixelAACommand::Type;
906 void CloneInto(CaptureCommandList* aList) override {
907 CLONE_INTO(SetPermitSubpixelAACommand)(mPermitSubpixelAA);
910 void ExecuteOnDT(DrawTarget* aDT, const Matrix* aMatrix) const override {
911 aDT->SetPermitSubpixelAA(mPermitSubpixelAA);
914 void Log(TreeLog<>& aStream) const override {
915 aStream << "[SetPermitSubpixelAA permitSubpixelAA=" << mPermitSubpixelAA
916 << "]";
919 static const bool AffectsSnapshot = false;
920 static const CommandType Type = CommandType::SETPERMITSUBPIXELAA;
922 private:
923 bool mPermitSubpixelAA;
926 class FlushCommand : public DrawingCommand {
927 public:
928 FlushCommand() = default;
930 CommandType GetType() const override { return FlushCommand::Type; }
932 void CloneInto(CaptureCommandList* aList) override {
933 CLONE_INTO(FlushCommand)();
936 void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override {
937 aDT->Flush();
940 void Log(TreeLog<>& aStream) const override { aStream << "[Flush]"; }
942 static const bool AffectsSnapshot = false;
943 static const CommandType Type = CommandType::FLUSH;
946 class BlurCommand : public DrawingCommand {
947 public:
948 explicit BlurCommand(const AlphaBoxBlur& aBlur) : mBlur(aBlur) {}
950 CommandType GetType() const override { return BlurCommand::Type; }
952 void CloneInto(CaptureCommandList* aList) override {
953 CLONE_INTO(BlurCommand)(mBlur);
956 void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override {
957 aDT->Blur(mBlur);
960 void Log(TreeLog<>& aStream) const override { aStream << "[Blur]"; }
962 static const bool AffectsSnapshot = true;
963 static const CommandType Type = CommandType::BLUR;
965 private:
966 AlphaBoxBlur mBlur;
969 class PadEdgesCommand : public DrawingCommand {
970 public:
971 explicit PadEdgesCommand(const IntRegion& aRegion) : mRegion(aRegion) {}
973 CommandType GetType() const override { return PadEdgesCommand::Type; }
975 void CloneInto(CaptureCommandList* aList) override {
976 CLONE_INTO(PadEdgesCommand)(IntRegion(mRegion));
979 void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override {
980 aDT->PadEdges(mRegion);
983 void Log(TreeLog<>& aStream) const override { aStream << "[PADEDGES]"; }
985 static const bool AffectsSnapshot = true;
986 static const CommandType Type = CommandType::PADEDGES;
988 private:
989 IntRegion mRegion;
992 #undef CLONE_INTO
994 } // namespace gfx
995 } // namespace mozilla
997 #endif /* MOZILLA_GFX_DRAWCOMMANDS_H_ */