Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/2d/DrawCommands.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_DRAWCOMMANDS_H_
8
#define MOZILLA_GFX_DRAWCOMMANDS_H_
9
10
#include <math.h>
11
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
21
namespace mozilla {
22
namespace gfx {
23
24
0
#define CLONE_INTO(Type) new (aList->Append<Type>()) Type
25
26
class StrokeOptionsCommand : public DrawingCommand
27
{
28
public:
29
  StrokeOptionsCommand(const StrokeOptions& aStrokeOptions)
30
    : mStrokeOptions(aStrokeOptions)
31
0
  {
32
0
    // Stroke Options dashes are owned by the caller.
33
0
    // Have to copy them here so they don't get freed
34
0
    // between now and replay.
35
0
    if (aStrokeOptions.mDashLength) {
36
0
      mDashes.resize(aStrokeOptions.mDashLength);
37
0
      mStrokeOptions.mDashPattern = &mDashes.front();
38
0
      PodCopy(&mDashes.front(), aStrokeOptions.mDashPattern, mStrokeOptions.mDashLength);
39
0
    }
40
0
  }
41
42
0
  virtual ~StrokeOptionsCommand() {}
43
44
protected:
45
  StrokeOptions mStrokeOptions;
46
  std::vector<Float> mDashes;
47
};
48
49
class StoredPattern
50
{
51
public:
52
  explicit StoredPattern(const Pattern& aPattern)
53
0
  {
54
0
    Assign(aPattern);
55
0
  }
56
57
  void Assign(const Pattern& aPattern)
58
  {
59
    switch (aPattern.GetType()) {
60
    case PatternType::COLOR:
61
      new (mColor)ColorPattern(*static_cast<const ColorPattern*>(&aPattern));
62
      return;
63
    case PatternType::SURFACE:
64
    {
65
      SurfacePattern* surfPat = new (mSurface)SurfacePattern(*static_cast<const SurfacePattern*>(&aPattern));
66
      surfPat->mSurface->GuaranteePersistance();
67
      return;
68
    }
69
    case PatternType::LINEAR_GRADIENT:
70
      new (mLinear)LinearGradientPattern(*static_cast<const LinearGradientPattern*>(&aPattern));
71
      return;
72
    case PatternType::RADIAL_GRADIENT:
73
      new (mRadial)RadialGradientPattern(*static_cast<const RadialGradientPattern*>(&aPattern));
74
      return;
75
    }
76
  }
77
78
  ~StoredPattern()
79
0
  {
80
0
    reinterpret_cast<Pattern*>(mPattern)->~Pattern();
81
0
  }
82
83
  Pattern* Get()
84
0
  {
85
0
    return reinterpret_cast<Pattern*>(mPattern);
86
0
  }
87
88
  const Pattern* Get() const
89
0
  {
90
0
    return reinterpret_cast<const Pattern*>(mPattern);
91
0
  }
92
93
  operator Pattern&()
94
0
  {
95
0
    return *reinterpret_cast<Pattern*>(mPattern);
96
0
  }
97
98
  operator const Pattern&() const
99
0
  {
100
0
    return *reinterpret_cast<const Pattern*>(mPattern);
101
0
  }
102
103
  StoredPattern(const StoredPattern& aPattern)
104
0
  {
105
0
    Assign(aPattern);
106
0
  }
107
108
private:
109
  StoredPattern operator=(const StoredPattern& aOther)
110
0
  {
111
0
    // Block this so that we notice if someone's doing excessive assigning.
112
0
    return *this;
113
0
  }
114
115
  union {
116
    char mPattern[sizeof(Pattern)];
117
    char mColor[sizeof(ColorPattern)];
118
    char mLinear[sizeof(LinearGradientPattern)];
119
    char mRadial[sizeof(RadialGradientPattern)];
120
    char mSurface[sizeof(SurfacePattern)];
121
  };
122
};
123
124
class DrawSurfaceCommand : public DrawingCommand
125
{
126
public:
127
  DrawSurfaceCommand(SourceSurface *aSurface, const Rect& aDest,
128
                     const Rect& aSource, const DrawSurfaceOptions& aSurfOptions,
129
                     const DrawOptions& aOptions)
130
    : mSurface(aSurface), mDest(aDest)
131
    , mSource(aSource), mSurfOptions(aSurfOptions)
132
    , mOptions(aOptions)
133
0
  {
134
0
  }
135
136
  CommandType GetType() const override
137
0
  {
138
0
    return DrawSurfaceCommand::Type;
139
0
  }
140
141
  void CloneInto(CaptureCommandList* aList) override
142
0
  {
143
0
    CLONE_INTO(DrawSurfaceCommand)(mSurface, mDest, mSource, mSurfOptions, mOptions);
144
0
  }
145
146
  void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override
147
0
  {
148
0
    aDT->DrawSurface(mSurface, mDest, mSource, mSurfOptions, mOptions);
149
0
  }
150
151
  void Log(TreeLog& aStream) const override
152
0
  {
153
0
    aStream << "[DrawSurface surf=" << mSurface;
154
0
    aStream << " dest=" << mDest;
155
0
    aStream << " src=" << mSource;
156
0
    aStream << " surfOpt=" << mSurfOptions;
157
0
    aStream << " opt=" << mOptions;
158
0
    aStream << "]";
159
0
  }
160
161
  static const bool AffectsSnapshot = true;
162
  static const CommandType Type = CommandType::DRAWSURFACE;
163
164
private:
165
  RefPtr<SourceSurface> mSurface;
166
  Rect mDest;
167
  Rect mSource;
168
  DrawSurfaceOptions mSurfOptions;
169
  DrawOptions mOptions;
170
};
171
172
class DrawSurfaceWithShadowCommand : public DrawingCommand
173
{
174
public:
175
  DrawSurfaceWithShadowCommand(SourceSurface *aSurface,
176
                               const Point &aDest,
177
                               const Color &aColor,
178
                               const Point &aOffset,
179
                               Float aSigma,
180
                               CompositionOp aOperator)
181
    : mSurface(aSurface),
182
      mDest(aDest),
183
      mColor(aColor),
184
      mOffset(aOffset),
185
      mSigma(aSigma),
186
      mOperator(aOperator)
187
0
  {
188
0
  }
189
190
  CommandType GetType() const override
191
0
  {
192
0
    return DrawSurfaceWithShadowCommand::Type;
193
0
  }
194
195
  void CloneInto(CaptureCommandList* aList) override
196
0
  {
197
0
    CLONE_INTO(DrawSurfaceWithShadowCommand)(mSurface, mDest, mColor, mOffset, mSigma, mOperator);
198
0
  }
199
200
  void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override
201
0
  {
202
0
    aDT->DrawSurfaceWithShadow(mSurface, mDest, mColor, mOffset, mSigma, mOperator);
203
0
  }
204
205
  void Log(TreeLog& aStream) const override
206
0
  {
207
0
    aStream << "[DrawSurfaceWithShadow surf=" << mSurface;
208
0
    aStream << " dest=" << mDest;
209
0
    aStream << " color=" << mColor;
210
0
    aStream << " offset=" << mOffset;
211
0
    aStream << " sigma=" << mSigma;
212
0
    aStream << " op=" << mOperator;
213
0
    aStream << "]";
214
0
  }
215
216
  static const bool AffectsSnapshot = true;
217
  static const CommandType Type = CommandType::DRAWSURFACEWITHSHADOW;
218
219
private:
220
  RefPtr<SourceSurface> mSurface;
221
  Point mDest;
222
  Color mColor;
223
  Point mOffset;
224
  Float mSigma;
225
  CompositionOp mOperator;
226
};
227
228
class DrawFilterCommand : public DrawingCommand
229
{
230
public:
231
  DrawFilterCommand(FilterNode* aFilter, const Rect& aSourceRect,
232
                    const Point& aDestPoint, const DrawOptions& aOptions)
233
    : mFilter(aFilter), mSourceRect(aSourceRect)
234
    , mDestPoint(aDestPoint), mOptions(aOptions)
235
0
  {
236
0
  }
237
238
  CommandType GetType() const override
239
0
  {
240
0
    return DrawFilterCommand::Type;
241
0
  }
242
243
  void CloneInto(CaptureCommandList* aList) override
244
0
  {
245
0
    CLONE_INTO(DrawFilterCommand)(mFilter, mSourceRect, mDestPoint, mOptions);
246
0
  }
247
248
  void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override
249
0
  {
250
0
    RefPtr<FilterNode> filter = mFilter;
251
0
    if (mFilter->GetBackendType() == FilterBackend::FILTER_BACKEND_CAPTURE) {
252
0
      filter = static_cast<FilterNodeCapture*>(filter.get())->Validate(aDT);
253
0
254
0
      // This can happen if the FilterNodeCapture is unable to create a
255
0
      // backing FilterNode on the target backend. Normally this would be
256
0
      // handled by the painting code, but here there's not much we can do.
257
0
      if (!filter) {
258
0
        return;
259
0
      }
260
0
    }
261
0
    aDT->DrawFilter(filter, mSourceRect, mDestPoint, mOptions);
262
0
  }
263
264
  void Log(TreeLog& aStream) const override
265
0
  {
266
0
    aStream << "[DrawFilter surf=" << mFilter;
267
0
    aStream << " src=" << mSourceRect;
268
0
    aStream << " dest=" << mDestPoint;
269
0
    aStream << " opt=" << mOptions;
270
0
    aStream << "]";
271
0
  }
272
273
  static const bool AffectsSnapshot = true;
274
  static const CommandType Type = CommandType::DRAWFILTER;
275
276
private:
277
  RefPtr<FilterNode> mFilter;
278
  Rect mSourceRect;
279
  Point mDestPoint;
280
  DrawOptions mOptions;
281
};
282
283
class ClearRectCommand : public DrawingCommand
284
{
285
public:
286
  explicit ClearRectCommand(const Rect& aRect)
287
    : mRect(aRect)
288
0
  {
289
0
  }
290
291
  CommandType GetType() const override
292
0
  {
293
0
    return ClearRectCommand::Type;
294
0
  }
295
296
  void CloneInto(CaptureCommandList* aList) override
297
0
  {
298
0
    CLONE_INTO(ClearRectCommand)(mRect);
299
0
  }
300
301
  void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override
302
0
  {
303
0
    aDT->ClearRect(mRect);
304
0
  }
305
306
  void Log(TreeLog& aStream) const override
307
0
  {
308
0
    aStream << "[ClearRect rect=" << mRect << "]";
309
0
  }
310
311
  static const bool AffectsSnapshot = true;
312
  static const CommandType Type = CommandType::CLEARRECT;
313
314
private:
315
  Rect mRect;
316
};
317
318
class CopySurfaceCommand : public DrawingCommand
319
{
320
public:
321
  CopySurfaceCommand(SourceSurface* aSurface,
322
                     const IntRect& aSourceRect,
323
                     const IntPoint& aDestination)
324
    : mSurface(aSurface)
325
    , mSourceRect(aSourceRect)
326
    , mDestination(aDestination)
327
0
  {
328
0
  }
329
330
  CommandType GetType() const override
331
0
  {
332
0
    return CopySurfaceCommand::Type;
333
0
  }
334
335
  void CloneInto(CaptureCommandList* aList) override
336
0
  {
337
0
    CLONE_INTO(CopySurfaceCommand)(mSurface, mSourceRect, mDestination);
338
0
  }
339
340
  virtual void ExecuteOnDT(DrawTarget* aDT, const Matrix* aTransform) const override
341
0
  {
342
0
    MOZ_ASSERT(!aTransform || !aTransform->HasNonIntegerTranslation());
343
0
    Point dest(Float(mDestination.x), Float(mDestination.y));
344
0
    if (aTransform) {
345
0
      dest = aTransform->TransformPoint(dest);
346
0
    }
347
0
    aDT->CopySurface(mSurface, mSourceRect, IntPoint(uint32_t(dest.x), uint32_t(dest.y)));
348
0
  }
349
350
  void Log(TreeLog& aStream) const override
351
0
  {
352
0
    aStream << "[CopySurface surf=" << mSurface;
353
0
    aStream << " src=" << mSourceRect;
354
0
    aStream << " dest=" << mDestination;
355
0
    aStream << "]";
356
0
  }
357
358
  static const bool AffectsSnapshot = true;
359
  static const CommandType Type = CommandType::COPYSURFACE;
360
361
private:
362
  RefPtr<SourceSurface> mSurface;
363
  IntRect mSourceRect;
364
  IntPoint mDestination;
365
};
366
367
class CopyRectCommand : public DrawingCommand
368
{
369
public:
370
  CopyRectCommand(const IntRect& aSourceRect,
371
                  const IntPoint& aDestination)
372
    : mSourceRect(aSourceRect)
373
    , mDestination(aDestination)
374
0
  {
375
0
  }
376
377
  CommandType GetType() const override
378
0
  {
379
0
    return CopyRectCommand::Type;
380
0
  }
381
382
  void CloneInto(CaptureCommandList* aList) override
383
0
  {
384
0
    CLONE_INTO(CopyRectCommand)(mSourceRect, mDestination);
385
0
  }
386
387
  virtual void ExecuteOnDT(DrawTarget* aDT, const Matrix* aTransform) const override
388
0
  {
389
0
    aDT->CopyRect(mSourceRect, mDestination);
390
0
  }
391
392
  void Log(TreeLog& aStream) const override
393
0
  {
394
0
    aStream << "[CopyRect src=" << mSourceRect;
395
0
    aStream << " dest=" << mDestination;
396
0
    aStream << "]";
397
0
  }
398
399
  static const bool AffectsSnapshot = true;
400
  static const CommandType Type = CommandType::COPYRECT;
401
402
private:
403
  IntRect mSourceRect;
404
  IntPoint mDestination;
405
};
406
407
class FillRectCommand : public DrawingCommand
408
{
409
public:
410
  FillRectCommand(const Rect& aRect,
411
                  const Pattern& aPattern,
412
                  const DrawOptions& aOptions)
413
    : mRect(aRect)
414
    , mPattern(aPattern)
415
    , mOptions(aOptions)
416
0
  {
417
0
  }
418
419
  CommandType GetType() const override
420
0
  {
421
0
    return FillRectCommand::Type;
422
0
  }
423
424
  void CloneInto(CaptureCommandList* aList) override
425
0
  {
426
0
    CLONE_INTO(FillRectCommand)(mRect, mPattern, mOptions);
427
0
  }
428
429
  void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override
430
0
  {
431
0
    aDT->FillRect(mRect, mPattern, mOptions);
432
0
  }
433
434
  void Log(TreeLog& aStream) const override
435
0
  {
436
0
    aStream << "[FillRect rect=" << mRect;
437
0
    aStream << " pattern=" << mPattern.Get();
438
0
    aStream << " opt=" << mOptions;
439
0
    aStream << "]";
440
0
  }
441
442
  static const bool AffectsSnapshot = true;
443
  static const CommandType Type = CommandType::FILLRECT;
444
445
private:
446
  Rect mRect;
447
  StoredPattern mPattern;
448
  DrawOptions mOptions;
449
};
450
451
class StrokeRectCommand : public StrokeOptionsCommand
452
{
453
public:
454
  StrokeRectCommand(const Rect& aRect,
455
                    const Pattern& aPattern,
456
                    const StrokeOptions& aStrokeOptions,
457
                    const DrawOptions& aOptions)
458
    : StrokeOptionsCommand(aStrokeOptions)
459
    , mRect(aRect)
460
    , mPattern(aPattern)
461
    , mOptions(aOptions)
462
0
  {
463
0
  }
464
465
  CommandType GetType() const override
466
0
  {
467
0
    return StrokeRectCommand::Type;
468
0
  }
469
470
  void CloneInto(CaptureCommandList* aList) override
471
0
  {
472
0
    CLONE_INTO(StrokeRectCommand)(mRect, mPattern, mStrokeOptions, mOptions);
473
0
  }
474
475
  void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override
476
0
  {
477
0
    aDT->StrokeRect(mRect, mPattern, mStrokeOptions, mOptions);
478
0
  }
479
480
  void Log(TreeLog& aStream) const override
481
0
  {
482
0
    aStream << "[StrokeRect rect=" << mRect;
483
0
    aStream << " pattern=" << mPattern.Get();
484
0
    aStream << " opt=" << mOptions;
485
0
    aStream << "]";
486
0
  }
487
488
  static const bool AffectsSnapshot = true;
489
  static const CommandType Type = CommandType::STROKERECT;
490
491
private:
492
  Rect mRect;
493
  StoredPattern mPattern;
494
  DrawOptions mOptions;
495
};
496
497
class StrokeLineCommand : public StrokeOptionsCommand
498
{
499
public:
500
  StrokeLineCommand(const Point& aStart,
501
                    const Point& aEnd,
502
                    const Pattern& aPattern,
503
                    const StrokeOptions& aStrokeOptions,
504
                    const DrawOptions& aOptions)
505
    : StrokeOptionsCommand(aStrokeOptions)
506
    , mStart(aStart)
507
    , mEnd(aEnd)
508
    , mPattern(aPattern)
509
    , mOptions(aOptions)
510
0
  {
511
0
  }
512
513
  CommandType GetType() const override
514
0
  {
515
0
    return StrokeLineCommand::Type;
516
0
  }
517
518
  void CloneInto(CaptureCommandList* aList) override
519
0
  {
520
0
    CLONE_INTO(StrokeLineCommand)(mStart, mEnd, mPattern, mStrokeOptions, mOptions);
521
0
  }
522
523
  void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override
524
0
  {
525
0
    aDT->StrokeLine(mStart, mEnd, mPattern, mStrokeOptions, mOptions);
526
0
  }
527
528
  void Log(TreeLog& aStream) const override
529
0
  {
530
0
    aStream << "[StrokeLine start=" << mStart;
531
0
    aStream << " end=" << mEnd;
532
0
    aStream << " pattern=" << mPattern.Get();
533
0
    aStream << " opt=" << mOptions;
534
0
    aStream << "]";
535
0
  }
536
537
  static const bool AffectsSnapshot = true;
538
  static const CommandType Type = CommandType::STROKELINE;
539
540
private:
541
  Point mStart;
542
  Point mEnd;
543
  StoredPattern mPattern;
544
  DrawOptions mOptions;
545
};
546
547
class FillCommand : public DrawingCommand
548
{
549
public:
550
  FillCommand(const Path* aPath,
551
              const Pattern& aPattern,
552
              const DrawOptions& aOptions)
553
    : mPath(const_cast<Path*>(aPath))
554
    , mPattern(aPattern)
555
    , mOptions(aOptions)
556
0
  {
557
0
  }
558
559
  CommandType GetType() const override
560
0
  {
561
0
    return FillCommand::Type;
562
0
  }
563
564
  void CloneInto(CaptureCommandList* aList) override
565
0
  {
566
0
    CLONE_INTO(FillCommand)(mPath, mPattern, mOptions);
567
0
  }
568
569
  void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override
570
0
  {
571
0
    aDT->Fill(mPath, mPattern, mOptions);
572
0
  }
573
574
  void Log(TreeLog& aStream) const override
575
0
  {
576
0
    aStream << "[FillCommand path=" << mPath;
577
0
    aStream << " pattern=" << mPattern.Get();
578
0
    aStream << " opt=" << mOptions;
579
0
    aStream << "]";
580
0
  }
581
582
  static const bool AffectsSnapshot = true;
583
  static const CommandType Type = CommandType::FILL;
584
585
private:
586
  RefPtr<Path> mPath;
587
  StoredPattern mPattern;
588
  DrawOptions mOptions;
589
};
590
591
class StrokeCommand : public StrokeOptionsCommand
592
{
593
public:
594
  StrokeCommand(const Path* aPath,
595
                const Pattern& aPattern,
596
                const StrokeOptions& aStrokeOptions,
597
                const DrawOptions& aOptions)
598
    : StrokeOptionsCommand(aStrokeOptions)
599
    , mPath(const_cast<Path*>(aPath))
600
    , mPattern(aPattern)
601
    , mOptions(aOptions)
602
0
  {
603
0
  }
604
605
  CommandType GetType() const override
606
0
  {
607
0
    return StrokeCommand::Type;
608
0
  }
609
610
  void CloneInto(CaptureCommandList* aList) override
611
0
  {
612
0
    CLONE_INTO(StrokeCommand)(mPath, mPattern, mStrokeOptions, mOptions);
613
0
  }
614
615
  void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override
616
0
  {
617
0
    aDT->Stroke(mPath, mPattern, mStrokeOptions, mOptions);
618
0
  }
619
620
  void Log(TreeLog& aStream) const override
621
0
  {
622
0
    aStream << "[Stroke path=" << mPath;
623
0
    aStream << " pattern=" << mPattern.Get();
624
0
    aStream << " opt=" << mOptions;
625
0
    aStream << "]";
626
0
  }
627
628
  static const bool AffectsSnapshot = true;
629
  static const CommandType Type = CommandType::STROKE;
630
631
private:
632
  RefPtr<Path> mPath;
633
  StoredPattern mPattern;
634
  DrawOptions mOptions;
635
};
636
637
class FillGlyphsCommand : public DrawingCommand
638
{
639
  friend class DrawTargetCaptureImpl;
640
public:
641
  FillGlyphsCommand(ScaledFont* aFont,
642
                    const GlyphBuffer& aBuffer,
643
                    const Pattern& aPattern,
644
                    const DrawOptions& aOptions)
645
    : mFont(aFont)
646
    , mPattern(aPattern)
647
    , mOptions(aOptions)
648
0
  {
649
0
    mGlyphs.resize(aBuffer.mNumGlyphs);
650
0
    memcpy(&mGlyphs.front(), aBuffer.mGlyphs, sizeof(Glyph) * aBuffer.mNumGlyphs);
651
0
  }
652
653
  CommandType GetType() const override
654
0
  {
655
0
    return FillGlyphsCommand::Type;
656
0
  }
657
658
  void CloneInto(CaptureCommandList* aList) override
659
0
  {
660
0
    GlyphBuffer glyphs = {
661
0
      mGlyphs.data(),
662
0
      (uint32_t)mGlyphs.size(),
663
0
    };
664
0
    CLONE_INTO(FillGlyphsCommand)(mFont, glyphs, mPattern, mOptions);
665
0
  }
666
667
  void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override
668
0
  {
669
0
    GlyphBuffer buf;
670
0
    buf.mNumGlyphs = mGlyphs.size();
671
0
    buf.mGlyphs = &mGlyphs.front();
672
0
    aDT->FillGlyphs(mFont, buf, mPattern, mOptions);
673
0
  }
674
675
  void Log(TreeLog& aStream) const override
676
0
  {
677
0
    aStream << "[FillGlyphs font=" << mFont;
678
0
    aStream << " glyphCount=" << mGlyphs.size();
679
0
    aStream << " pattern=" << mPattern.Get();
680
0
    aStream << " opt=" << mOptions;
681
0
    aStream << "]";
682
0
  }
683
684
  static const bool AffectsSnapshot = true;
685
  static const CommandType Type = CommandType::FILLGLYPHS;
686
687
private:
688
  RefPtr<ScaledFont> mFont;
689
  std::vector<Glyph> mGlyphs;
690
  StoredPattern mPattern;
691
  DrawOptions mOptions;
692
};
693
694
class StrokeGlyphsCommand : public StrokeOptionsCommand
695
{
696
  friend class DrawTargetCaptureImpl;
697
public:
698
  StrokeGlyphsCommand(ScaledFont* aFont,
699
                      const GlyphBuffer& aBuffer,
700
                      const Pattern& aPattern,
701
                      const StrokeOptions& aStrokeOptions,
702
                      const DrawOptions& aOptions)
703
    : StrokeOptionsCommand(aStrokeOptions)
704
    , mFont(aFont)
705
    , mPattern(aPattern)
706
    , mOptions(aOptions)
707
0
  {
708
0
    mGlyphs.resize(aBuffer.mNumGlyphs);
709
0
    memcpy(&mGlyphs.front(), aBuffer.mGlyphs, sizeof(Glyph) * aBuffer.mNumGlyphs);
710
0
  }
711
712
  CommandType GetType() const override
713
0
  {
714
0
    return StrokeGlyphsCommand::Type;
715
0
  }
716
717
  void CloneInto(CaptureCommandList* aList) override
718
0
  {
719
0
    GlyphBuffer glyphs = {
720
0
      mGlyphs.data(),
721
0
      (uint32_t)mGlyphs.size(),
722
0
    };
723
0
    CLONE_INTO(StrokeGlyphsCommand)(mFont, glyphs, mPattern, mStrokeOptions, mOptions);
724
0
  }
725
726
  void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override
727
0
  {
728
0
    GlyphBuffer buf;
729
0
    buf.mNumGlyphs = mGlyphs.size();
730
0
    buf.mGlyphs = &mGlyphs.front();
731
0
    aDT->StrokeGlyphs(mFont, buf, mPattern, mStrokeOptions, mOptions);
732
0
  }
733
734
  void Log(TreeLog& aStream) const override
735
0
  {
736
0
    aStream << "[StrokeGlyphs font=" << mFont;
737
0
    aStream << " glyphCount=" << mGlyphs.size();
738
0
    aStream << " pattern=" << mPattern.Get();
739
0
    aStream << " opt=" << mOptions;
740
0
    aStream << "]";
741
0
  }
742
743
  static const bool AffectsSnapshot = true;
744
  static const CommandType Type = CommandType::STROKEGLYPHS;
745
746
private:
747
  RefPtr<ScaledFont> mFont;
748
  std::vector<Glyph> mGlyphs;
749
  StoredPattern mPattern;
750
  DrawOptions mOptions;
751
};
752
753
class MaskCommand : public DrawingCommand
754
{
755
public:
756
  MaskCommand(const Pattern& aSource,
757
              const Pattern& aMask,
758
              const DrawOptions& aOptions)
759
    : mSource(aSource)
760
    , mMask(aMask)
761
    , mOptions(aOptions)
762
0
  {
763
0
  }
764
765
  CommandType GetType() const override
766
0
  {
767
0
    return MaskCommand::Type;
768
0
  }
769
770
  void CloneInto(CaptureCommandList* aList) override
771
0
  {
772
0
    CLONE_INTO(MaskCommand)(mSource, mMask, mOptions);
773
0
  }
774
775
  void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override
776
0
  {
777
0
    aDT->Mask(mSource, mMask, mOptions);
778
0
  }
779
780
  void Log(TreeLog& aStream) const override
781
0
  {
782
0
    aStream << "[Mask source=" << mSource.Get();
783
0
    aStream << " mask=" << mMask.Get();
784
0
    aStream << " opt=" << mOptions;
785
0
    aStream << "]";
786
0
  }
787
788
  static const bool AffectsSnapshot = true;
789
  static const CommandType Type = CommandType::MASK;
790
791
private:
792
  StoredPattern mSource;
793
  StoredPattern mMask;
794
  DrawOptions mOptions;
795
};
796
797
class MaskSurfaceCommand : public DrawingCommand
798
{
799
public:
800
  MaskSurfaceCommand(const Pattern& aSource,
801
                     const SourceSurface* aMask,
802
                     const Point& aOffset,
803
                     const DrawOptions& aOptions)
804
    : mSource(aSource)
805
    , mMask(const_cast<SourceSurface*>(aMask))
806
    , mOffset(aOffset)
807
    , mOptions(aOptions)
808
0
  {
809
0
  }
810
811
  CommandType GetType() const override
812
0
  {
813
0
    return MaskSurfaceCommand::Type;
814
0
  }
815
816
  void CloneInto(CaptureCommandList* aList) override
817
0
  {
818
0
    CLONE_INTO(MaskSurfaceCommand)(mSource, mMask, mOffset, mOptions);
819
0
  }
820
821
  void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override
822
0
  {
823
0
    aDT->MaskSurface(mSource, mMask, mOffset, mOptions);
824
0
  }
825
826
  void Log(TreeLog& aStream) const override
827
0
  {
828
0
    aStream << "[Mask source=" << mSource.Get();
829
0
    aStream << " mask=" << mMask;
830
0
    aStream << " offset=" << &mOffset;
831
0
    aStream << " opt=" << mOptions;
832
0
    aStream << "]";
833
0
  }
834
835
  static const bool AffectsSnapshot = true;
836
  static const CommandType Type = CommandType::MASKSURFACE;
837
838
private:
839
  StoredPattern mSource;
840
  RefPtr<SourceSurface> mMask;
841
  Point mOffset;
842
  DrawOptions mOptions;
843
};
844
845
class PushClipCommand : public DrawingCommand
846
{
847
public:
848
  explicit PushClipCommand(const Path* aPath)
849
    : mPath(const_cast<Path*>(aPath))
850
0
  {
851
0
  }
852
853
  CommandType GetType() const override
854
0
  {
855
0
    return PushClipCommand::Type;
856
0
  }
857
858
  void CloneInto(CaptureCommandList* aList) override
859
0
  {
860
0
    CLONE_INTO(PushClipCommand)(mPath);
861
0
  }
862
863
  void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override
864
0
  {
865
0
    aDT->PushClip(mPath);
866
0
  }
867
868
  void Log(TreeLog& aStream) const override
869
0
  {
870
0
    aStream << "[PushClip path=" << mPath << "]";
871
0
  }
872
873
  static const bool AffectsSnapshot = false;
874
  static const CommandType Type = CommandType::PUSHCLIP;
875
876
private:
877
  RefPtr<Path> mPath;
878
};
879
880
class PushClipRectCommand : public DrawingCommand
881
{
882
public:
883
  explicit PushClipRectCommand(const Rect& aRect)
884
    : mRect(aRect)
885
0
  {
886
0
  }
887
888
  CommandType GetType() const override
889
0
  {
890
0
    return PushClipRectCommand::Type;
891
0
  }
892
893
  void CloneInto(CaptureCommandList* aList) override
894
0
  {
895
0
    CLONE_INTO(PushClipRectCommand)(mRect);
896
0
  }
897
898
  void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override
899
0
  {
900
0
    aDT->PushClipRect(mRect);
901
0
  }
902
903
  void Log(TreeLog& aStream) const override
904
0
  {
905
0
    aStream << "[PushClipRect rect=" << mRect << "]";
906
0
  }
907
908
  static const bool AffectsSnapshot = false;
909
  static const CommandType Type = CommandType::PUSHCLIPRECT;
910
911
private:
912
  Rect mRect;
913
};
914
915
class PushLayerCommand : public DrawingCommand
916
{
917
public:
918
  PushLayerCommand(const bool aOpaque,
919
                   const Float aOpacity,
920
                   SourceSurface* aMask,
921
                   const Matrix& aMaskTransform,
922
                   const IntRect& aBounds,
923
                   bool aCopyBackground)
924
    : mOpaque(aOpaque)
925
    , mOpacity(aOpacity)
926
    , mMask(aMask)
927
    , mMaskTransform(aMaskTransform)
928
    , mBounds(aBounds)
929
    , mCopyBackground(aCopyBackground)
930
0
  {
931
0
  }
932
933
  CommandType GetType() const override
934
0
  {
935
0
    return PushLayerCommand::Type;
936
0
  }
937
938
  void CloneInto(CaptureCommandList* aList) override
939
0
  {
940
0
    CLONE_INTO(PushLayerCommand)(mOpaque, mOpacity, mMask, mMaskTransform, mBounds, mCopyBackground);
941
0
  }
942
943
  void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override
944
0
  {
945
0
    aDT->PushLayer(mOpaque, mOpacity, mMask,
946
0
                   mMaskTransform, mBounds, mCopyBackground);
947
0
  }
948
949
  void Log(TreeLog& aStream) const override
950
0
  {
951
0
    aStream << "[PushLayer opaque=" << mOpaque;
952
0
    aStream << " opacity=" << mOpacity;
953
0
    aStream << " mask=" << mMask;
954
0
    aStream << " maskTransform=" << mMaskTransform;
955
0
    aStream << " bounds=" << mBounds;
956
0
    aStream << " copyBackground=" << mCopyBackground;
957
0
    aStream << "]";
958
0
  }
959
960
  static const bool AffectsSnapshot = false;
961
  static const CommandType Type = CommandType::PUSHLAYER;
962
963
private:
964
  bool mOpaque;
965
  float mOpacity;
966
  RefPtr<SourceSurface> mMask;
967
  Matrix mMaskTransform;
968
  IntRect mBounds;
969
  bool mCopyBackground;
970
};
971
972
class PopClipCommand : public DrawingCommand
973
{
974
public:
975
0
  PopClipCommand() {}
976
977
  CommandType GetType() const override
978
0
  {
979
0
    return PopClipCommand::Type;
980
0
  }
981
982
  void CloneInto(CaptureCommandList* aList) override
983
0
  {
984
0
    CLONE_INTO(PopClipCommand)();
985
0
  }
986
987
  void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override
988
0
  {
989
0
    aDT->PopClip();
990
0
  }
991
992
  void Log(TreeLog& aStream) const override
993
0
  {
994
0
    aStream << "[PopClip]";
995
0
  }
996
997
  static const bool AffectsSnapshot = false;
998
  static const CommandType Type = CommandType::POPCLIP;
999
};
1000
1001
class PopLayerCommand : public DrawingCommand
1002
{
1003
public:
1004
0
  PopLayerCommand() {}
1005
1006
  CommandType GetType() const override
1007
0
  {
1008
0
    return PopLayerCommand::Type;
1009
0
  }
1010
1011
  void CloneInto(CaptureCommandList* aList) override
1012
0
  {
1013
0
    CLONE_INTO(PopLayerCommand)();
1014
0
  }
1015
1016
  void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override
1017
0
  {
1018
0
    aDT->PopLayer();
1019
0
  }
1020
1021
  void Log(TreeLog& aStream) const override
1022
0
  {
1023
0
    aStream << "[PopLayer]";
1024
0
  }
1025
1026
  static const bool AffectsSnapshot = true;
1027
  static const CommandType Type = CommandType::POPLAYER;
1028
};
1029
1030
class SetTransformCommand : public DrawingCommand
1031
{
1032
  friend class DrawTargetCaptureImpl;
1033
public:
1034
  explicit SetTransformCommand(const Matrix& aTransform)
1035
    : mTransform(aTransform)
1036
0
  {
1037
0
  }
1038
1039
  CommandType GetType() const override
1040
0
  {
1041
0
    return SetTransformCommand::Type;
1042
0
  }
1043
1044
  void CloneInto(CaptureCommandList* aList) override
1045
0
  {
1046
0
    CLONE_INTO(SetTransformCommand)(mTransform);
1047
0
  }
1048
1049
  virtual void ExecuteOnDT(DrawTarget* aDT, const Matrix* aMatrix) const override
1050
0
  {
1051
0
    if (aMatrix) {
1052
0
      aDT->SetTransform(mTransform * (*aMatrix));
1053
0
    } else {
1054
0
      aDT->SetTransform(mTransform);
1055
0
    }
1056
0
  }
1057
1058
  void Log(TreeLog& aStream) const override
1059
0
  {
1060
0
    aStream << "[SetTransform transform=" << mTransform << "]";
1061
0
  }
1062
1063
  static const bool AffectsSnapshot = false;
1064
  static const CommandType Type = CommandType::SETTRANSFORM;
1065
1066
private:
1067
  Matrix mTransform;
1068
};
1069
1070
class SetPermitSubpixelAACommand : public DrawingCommand
1071
{
1072
  friend class DrawTargetCaptureImpl;
1073
public:
1074
  explicit SetPermitSubpixelAACommand(bool aPermitSubpixelAA)
1075
    : mPermitSubpixelAA(aPermitSubpixelAA)
1076
0
  {
1077
0
  }
1078
1079
  CommandType GetType() const override
1080
0
  {
1081
0
    return SetPermitSubpixelAACommand::Type;
1082
0
  }
1083
1084
  void CloneInto(CaptureCommandList* aList) override
1085
0
  {
1086
0
    CLONE_INTO(SetPermitSubpixelAACommand)(mPermitSubpixelAA);
1087
0
  }
1088
1089
  virtual void ExecuteOnDT(DrawTarget* aDT, const Matrix* aMatrix) const override
1090
0
  {
1091
0
    aDT->SetPermitSubpixelAA(mPermitSubpixelAA);
1092
0
  }
1093
1094
  void Log(TreeLog& aStream) const override
1095
0
  {
1096
0
    aStream << "[SetPermitSubpixelAA permitSubpixelAA=" << mPermitSubpixelAA << "]";
1097
0
  }
1098
1099
  static const bool AffectsSnapshot = false;
1100
  static const CommandType Type = CommandType::SETPERMITSUBPIXELAA;
1101
1102
private:
1103
  bool mPermitSubpixelAA;
1104
};
1105
1106
class FlushCommand : public DrawingCommand
1107
{
1108
public:
1109
0
  explicit FlushCommand() {}
1110
1111
  CommandType GetType() const override
1112
0
  {
1113
0
    return FlushCommand::Type;
1114
0
  }
1115
1116
  void CloneInto(CaptureCommandList* aList) override
1117
0
  {
1118
0
    CLONE_INTO(FlushCommand)();
1119
0
  }
1120
1121
  void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override
1122
0
  {
1123
0
    aDT->Flush();
1124
0
  }
1125
1126
  void Log(TreeLog& aStream) const override
1127
0
  {
1128
0
    aStream << "[Flush]";
1129
0
  }
1130
1131
  static const bool AffectsSnapshot = false;
1132
  static const CommandType Type = CommandType::FLUSH;
1133
};
1134
1135
class BlurCommand : public DrawingCommand
1136
{
1137
public:
1138
  explicit BlurCommand(const AlphaBoxBlur& aBlur)
1139
   : mBlur(aBlur)
1140
0
  {}
1141
1142
  CommandType GetType() const override
1143
0
  {
1144
0
    return BlurCommand::Type;
1145
0
  }
1146
1147
  void CloneInto(CaptureCommandList* aList) override
1148
0
  {
1149
0
    CLONE_INTO(BlurCommand)(mBlur);
1150
0
  }
1151
1152
  void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override
1153
0
  {
1154
0
    aDT->Blur(mBlur);
1155
0
  }
1156
1157
  void Log(TreeLog& aStream) const override
1158
0
  {
1159
0
    aStream << "[Blur]";
1160
0
  }
1161
1162
  static const bool AffectsSnapshot = true;
1163
  static const CommandType Type = CommandType::BLUR;
1164
1165
private:
1166
  AlphaBoxBlur mBlur;
1167
};
1168
1169
class PadEdgesCommand : public DrawingCommand
1170
{
1171
public:
1172
  explicit PadEdgesCommand(const IntRegion& aRegion)
1173
   : mRegion(aRegion)
1174
0
  {}
1175
1176
  CommandType GetType() const override
1177
0
  {
1178
0
    return PadEdgesCommand::Type;
1179
0
  }
1180
1181
  void CloneInto(CaptureCommandList* aList) override
1182
0
  {
1183
0
    CLONE_INTO(PadEdgesCommand)(IntRegion(mRegion));
1184
0
  }
1185
1186
  void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const override
1187
0
  {
1188
0
    aDT->PadEdges(mRegion);
1189
0
  }
1190
1191
  void Log(TreeLog& aStream) const override
1192
0
  {
1193
0
    aStream << "[PADEDGES]";
1194
0
  }
1195
1196
  static const bool AffectsSnapshot = true;
1197
  static const CommandType Type = CommandType::PADEDGES;
1198
1199
private:
1200
  IntRegion mRegion;
1201
};
1202
1203
#undef CLONE_INTO
1204
1205
} // namespace gfx
1206
} // namespace mozilla
1207
1208
#endif /* MOZILLA_GFX_DRAWCOMMANDS_H_ */