gfx/2d/RecordedEvent.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:773b0bdb8903
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_RECORDEDEVENT_H_
7 #define MOZILLA_GFX_RECORDEDEVENT_H_
8
9 #include "2D.h"
10 #include <ostream>
11 #include <sstream>
12 #include <cstring>
13 #include "RecordingTypes.h"
14 #include "PathRecording.h"
15
16 namespace mozilla {
17 namespace gfx {
18
19 // A change in major revision means a change in event binary format, causing
20 // loss of backwards compatibility. Old streams will not work in a player
21 // using a newer major revision. And new streams will not work in a player
22 // using an older major revision.
23 const uint16_t kMajorRevision = 3;
24 // A change in minor revision means additions of new events. New streams will
25 // not play in older players.
26 const uint16_t kMinorRevision = 2;
27
28 struct ReferencePtr
29 {
30 ReferencePtr()
31 : mLongPtr(0)
32 {}
33
34 ReferencePtr(const void* aLongPtr)
35 : mLongPtr(uint64_t(aLongPtr))
36 {}
37
38 template <typename T>
39 ReferencePtr(const RefPtr<T>& aPtr)
40 : mLongPtr(uint64_t(aPtr.get()))
41 {}
42
43 ReferencePtr &operator =(const void* aLongPtr) {
44 mLongPtr = uint64_t(aLongPtr);
45 return *this;
46 }
47
48 template <typename T>
49 ReferencePtr &operator =(const RefPtr<T>& aPtr) {
50 mLongPtr = uint64_t(aPtr.get());
51 return *this;
52 }
53
54 operator void*() const {
55 return (void*)mLongPtr;
56 }
57
58 uint64_t mLongPtr;
59 };
60
61 // Used by the Azure drawing debugger (player2d)
62 inline std::string StringFromPtr(ReferencePtr aPtr)
63 {
64 std::stringstream stream;
65 stream << aPtr;
66 return stream.str();
67 }
68
69 class Translator
70 {
71 public:
72 virtual ~Translator() {}
73
74 virtual DrawTarget *LookupDrawTarget(ReferencePtr aRefPtr) = 0;
75 virtual Path *LookupPath(ReferencePtr aRefPtr) = 0;
76 virtual SourceSurface *LookupSourceSurface(ReferencePtr aRefPtr) = 0;
77 virtual FilterNode *LookupFilterNode(ReferencePtr aRefPtr) = 0;
78 virtual GradientStops *LookupGradientStops(ReferencePtr aRefPtr) = 0;
79 virtual ScaledFont *LookupScaledFont(ReferencePtr aRefPtr) = 0;
80 virtual void AddDrawTarget(ReferencePtr aRefPtr, DrawTarget *aDT) = 0;
81 virtual void RemoveDrawTarget(ReferencePtr aRefPtr) = 0;
82 virtual void AddPath(ReferencePtr aRefPtr, Path *aPath) = 0;
83 virtual void RemovePath(ReferencePtr aRefPtr) = 0;
84 virtual void AddSourceSurface(ReferencePtr aRefPtr, SourceSurface *aPath) = 0;
85 virtual void RemoveSourceSurface(ReferencePtr aRefPtr) = 0;
86 virtual void AddFilterNode(mozilla::gfx::ReferencePtr aRefPtr, FilterNode *aSurface) = 0;
87 virtual void RemoveFilterNode(mozilla::gfx::ReferencePtr aRefPtr) = 0;
88 virtual void AddGradientStops(ReferencePtr aRefPtr, GradientStops *aPath) = 0;
89 virtual void RemoveGradientStops(ReferencePtr aRefPtr) = 0;
90 virtual void AddScaledFont(ReferencePtr aRefPtr, ScaledFont *aScaledFont) = 0;
91 virtual void RemoveScaledFont(ReferencePtr aRefPtr) = 0;
92
93 virtual DrawTarget *GetReferenceDrawTarget() = 0;
94 virtual FontType GetDesiredFontType() = 0;
95 };
96
97 struct ColorPatternStorage
98 {
99 Color mColor;
100 };
101
102 struct LinearGradientPatternStorage
103 {
104 Point mBegin;
105 Point mEnd;
106 ReferencePtr mStops;
107 Matrix mMatrix;
108 };
109
110 struct RadialGradientPatternStorage
111 {
112 Point mCenter1;
113 Point mCenter2;
114 Float mRadius1;
115 Float mRadius2;
116 ReferencePtr mStops;
117 Matrix mMatrix;
118 };
119
120 struct SurfacePatternStorage
121 {
122 ExtendMode mExtend;
123 Filter mFilter;
124 ReferencePtr mSurface;
125 Matrix mMatrix;
126 };
127
128 struct PatternStorage
129 {
130 PatternType mType;
131 union {
132 char *mStorage;
133 char mColor[sizeof(ColorPatternStorage)];
134 char mLinear[sizeof(LinearGradientPatternStorage)];
135 char mRadial[sizeof(RadialGradientPatternStorage)];
136 char mSurface[sizeof(SurfacePatternStorage)];
137 };
138 };
139
140 class RecordedEvent {
141 public:
142 enum EventType {
143 DRAWTARGETCREATION = 0,
144 DRAWTARGETDESTRUCTION,
145 FILLRECT,
146 STROKERECT,
147 STROKELINE,
148 CLEARRECT,
149 COPYSURFACE,
150 SETTRANSFORM,
151 PUSHCLIP,
152 PUSHCLIPRECT,
153 POPCLIP,
154 FILL,
155 FILLGLYPHS,
156 MASK,
157 STROKE,
158 DRAWSURFACE,
159 DRAWSURFACEWITHSHADOW,
160 PATHCREATION,
161 PATHDESTRUCTION,
162 SOURCESURFACECREATION,
163 SOURCESURFACEDESTRUCTION,
164 GRADIENTSTOPSCREATION,
165 GRADIENTSTOPSDESTRUCTION,
166 SNAPSHOT,
167 SCALEDFONTCREATION,
168 SCALEDFONTDESTRUCTION,
169 MASKSURFACE,
170 FILTERNODECREATION,
171 FILTERNODEDESTRUCTION,
172 DRAWFILTER,
173 FILTERNODESETATTRIBUTE,
174 FILTERNODESETINPUT
175 };
176 static const uint32_t kTotalEventTypes = RecordedEvent::FILTERNODESETINPUT + 1;
177
178 static std::string GetEventName(EventType aType);
179
180 virtual void PlayEvent(Translator *aTranslator) const {}
181
182 virtual void RecordToStream(std::ostream &aStream) const {}
183
184 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const { }
185
186 void RecordPatternData(std::ostream &aStream, const PatternStorage &aPatternStorage) const;
187 void ReadPatternData(std::istream &aStream, PatternStorage &aPatternStorage) const;
188 void StorePattern(PatternStorage &aDestination, const Pattern &aSource) const;
189 void RecordStrokeOptions(std::ostream &aStream, const StrokeOptions &aStrokeOptions) const;
190 void ReadStrokeOptions(std::istream &aStream, StrokeOptions &aStrokeOptions);
191
192 virtual std::string GetName() const = 0;
193
194 virtual ReferencePtr GetObjectRef() const = 0;
195
196 virtual ReferencePtr GetDestinedDT() { return nullptr; }
197
198 void OutputSimplePatternInfo(const PatternStorage &aStorage, std::stringstream &aOutput) const;
199
200 static RecordedEvent *LoadEventFromStream(std::istream &aStream, EventType aType);
201
202 EventType GetType() { return (EventType)mType; }
203 protected:
204 friend class DrawEventRecorderPrivate;
205
206 RecordedEvent(int32_t aType) : mType(aType)
207 {}
208
209 int32_t mType;
210 std::vector<Float> mDashPatternStorage;
211 };
212
213 class RecordedDrawingEvent : public RecordedEvent
214 {
215 public:
216 virtual ReferencePtr GetDestinedDT() { return mDT; }
217
218 protected:
219 RecordedDrawingEvent(EventType aType, DrawTarget *aTarget)
220 : RecordedEvent(aType), mDT(aTarget)
221 {
222 }
223
224 RecordedDrawingEvent(EventType aType, std::istream &aStream);
225 virtual void RecordToStream(std::ostream &aStream) const;
226
227 virtual ReferencePtr GetObjectRef() const;
228
229 ReferencePtr mDT;
230 };
231
232 class RecordedDrawTargetCreation : public RecordedEvent {
233 public:
234 RecordedDrawTargetCreation(ReferencePtr aRefPtr, BackendType aType, const IntSize &aSize, SurfaceFormat aFormat,
235 bool aHasExistingData = false, SourceSurface *aExistingData = nullptr)
236 : RecordedEvent(DRAWTARGETCREATION), mRefPtr(aRefPtr), mBackendType(aType), mSize(aSize), mFormat(aFormat)
237 , mHasExistingData(aHasExistingData), mExistingData(aExistingData)
238 {}
239
240 virtual void PlayEvent(Translator *aTranslator) const;
241
242 virtual void RecordToStream(std::ostream &aStream) const;
243 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
244
245 virtual std::string GetName() const { return "DrawTarget Creation"; }
246 virtual ReferencePtr GetObjectRef() const { return mRefPtr; }
247
248 ReferencePtr mRefPtr;
249 BackendType mBackendType;
250 IntSize mSize;
251 SurfaceFormat mFormat;
252 bool mHasExistingData;
253 RefPtr<SourceSurface> mExistingData;
254
255 private:
256 friend class RecordedEvent;
257
258 RecordedDrawTargetCreation(std::istream &aStream);
259 };
260
261 class RecordedDrawTargetDestruction : public RecordedEvent {
262 public:
263 RecordedDrawTargetDestruction(ReferencePtr aRefPtr)
264 : RecordedEvent(DRAWTARGETDESTRUCTION), mRefPtr(aRefPtr)
265 {}
266
267 virtual void PlayEvent(Translator *aTranslator) const;
268
269 virtual void RecordToStream(std::ostream &aStream) const;
270 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
271
272 virtual std::string GetName() const { return "DrawTarget Destruction"; }
273 virtual ReferencePtr GetObjectRef() const { return mRefPtr; }
274
275 ReferencePtr mRefPtr;
276
277 BackendType mBackendType;
278 private:
279 friend class RecordedEvent;
280
281 RecordedDrawTargetDestruction(std::istream &aStream);
282 };
283
284 class RecordedFillRect : public RecordedDrawingEvent {
285 public:
286 RecordedFillRect(DrawTarget *aDT, const Rect &aRect, const Pattern &aPattern, const DrawOptions &aOptions)
287 : RecordedDrawingEvent(FILLRECT, aDT), mRect(aRect), mOptions(aOptions)
288 {
289 StorePattern(mPattern, aPattern);
290 }
291
292 virtual void PlayEvent(Translator *aTranslator) const;
293
294 virtual void RecordToStream(std::ostream &aStream) const;
295 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
296
297 virtual std::string GetName() const { return "FillRect"; }
298 private:
299 friend class RecordedEvent;
300
301 RecordedFillRect(std::istream &aStream);
302
303 Rect mRect;
304 PatternStorage mPattern;
305 DrawOptions mOptions;
306 };
307
308 class RecordedStrokeRect : public RecordedDrawingEvent {
309 public:
310 RecordedStrokeRect(DrawTarget *aDT, const Rect &aRect, const Pattern &aPattern,
311 const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions)
312 : RecordedDrawingEvent(STROKERECT, aDT), mRect(aRect),
313 mStrokeOptions(aStrokeOptions), mOptions(aOptions)
314 {
315 StorePattern(mPattern, aPattern);
316 }
317
318 virtual void PlayEvent(Translator *aTranslator) const;
319
320 virtual void RecordToStream(std::ostream &aStream) const;
321 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
322
323 virtual std::string GetName() const { return "StrokeRect"; }
324 private:
325 friend class RecordedEvent;
326
327 RecordedStrokeRect(std::istream &aStream);
328
329 Rect mRect;
330 PatternStorage mPattern;
331 StrokeOptions mStrokeOptions;
332 DrawOptions mOptions;
333 };
334
335 class RecordedStrokeLine : public RecordedDrawingEvent {
336 public:
337 RecordedStrokeLine(DrawTarget *aDT, const Point &aBegin, const Point &aEnd,
338 const Pattern &aPattern, const StrokeOptions &aStrokeOptions,
339 const DrawOptions &aOptions)
340 : RecordedDrawingEvent(STROKELINE, aDT), mBegin(aBegin), mEnd(aEnd),
341 mStrokeOptions(aStrokeOptions), mOptions(aOptions)
342 {
343 StorePattern(mPattern, aPattern);
344 }
345
346 virtual void PlayEvent(Translator *aTranslator) const;
347
348 virtual void RecordToStream(std::ostream &aStream) const;
349 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
350
351 virtual std::string GetName() const { return "StrokeLine"; }
352 private:
353 friend class RecordedEvent;
354
355 RecordedStrokeLine(std::istream &aStream);
356
357 Point mBegin;
358 Point mEnd;
359 PatternStorage mPattern;
360 StrokeOptions mStrokeOptions;
361 DrawOptions mOptions;
362 };
363
364 class RecordedFill : public RecordedDrawingEvent {
365 public:
366 RecordedFill(DrawTarget *aDT, ReferencePtr aPath, const Pattern &aPattern, const DrawOptions &aOptions)
367 : RecordedDrawingEvent(FILL, aDT), mPath(aPath), mOptions(aOptions)
368 {
369 StorePattern(mPattern, aPattern);
370 }
371
372 virtual void PlayEvent(Translator *aTranslator) const;
373
374 virtual void RecordToStream(std::ostream &aStream) const;
375 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
376
377 virtual std::string GetName() const { return "Fill"; }
378 private:
379 friend class RecordedEvent;
380
381 RecordedFill(std::istream &aStream);
382
383 ReferencePtr mPath;
384 PatternStorage mPattern;
385 DrawOptions mOptions;
386 };
387
388 class RecordedFillGlyphs : public RecordedDrawingEvent {
389 public:
390 RecordedFillGlyphs(DrawTarget *aDT, ReferencePtr aScaledFont, const Pattern &aPattern, const DrawOptions &aOptions,
391 const Glyph *aGlyphs, uint32_t aNumGlyphs)
392 : RecordedDrawingEvent(FILLGLYPHS, aDT), mScaledFont(aScaledFont), mOptions(aOptions)
393 {
394 StorePattern(mPattern, aPattern);
395 mNumGlyphs = aNumGlyphs;
396 mGlyphs = new Glyph[aNumGlyphs];
397 memcpy(mGlyphs, aGlyphs, sizeof(Glyph) * aNumGlyphs);
398 }
399 virtual ~RecordedFillGlyphs();
400
401 virtual void PlayEvent(Translator *aTranslator) const;
402
403 virtual void RecordToStream(std::ostream &aStream) const;
404 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
405
406 virtual std::string GetName() const { return "FillGlyphs"; }
407 private:
408 friend class RecordedEvent;
409
410 RecordedFillGlyphs(std::istream &aStream);
411
412 ReferencePtr mScaledFont;
413 PatternStorage mPattern;
414 DrawOptions mOptions;
415 Glyph *mGlyphs;
416 uint32_t mNumGlyphs;
417 };
418
419 class RecordedMask : public RecordedDrawingEvent {
420 public:
421 RecordedMask(DrawTarget *aDT, const Pattern &aSource, const Pattern &aMask, const DrawOptions &aOptions)
422 : RecordedDrawingEvent(MASK, aDT), mOptions(aOptions)
423 {
424 StorePattern(mSource, aSource);
425 StorePattern(mMask, aMask);
426 }
427
428 virtual void PlayEvent(Translator *aTranslator) const;
429
430 virtual void RecordToStream(std::ostream &aStream) const;
431 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
432
433 virtual std::string GetName() const { return "Mask"; }
434 private:
435 friend class RecordedEvent;
436
437 RecordedMask(std::istream &aStream);
438
439 PatternStorage mSource;
440 PatternStorage mMask;
441 DrawOptions mOptions;
442 };
443
444 class RecordedStroke : public RecordedDrawingEvent {
445 public:
446 RecordedStroke(DrawTarget *aDT, ReferencePtr aPath, const Pattern &aPattern,
447 const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions)
448 : RecordedDrawingEvent(STROKE, aDT), mPath(aPath),
449 mStrokeOptions(aStrokeOptions), mOptions(aOptions)
450 {
451 StorePattern(mPattern, aPattern);
452 }
453
454 virtual void PlayEvent(Translator *aTranslator) const;
455
456 virtual void RecordToStream(std::ostream &aStream) const;
457 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
458
459 virtual std::string GetName() const { return "Stroke"; }
460 private:
461 friend class RecordedEvent;
462
463 RecordedStroke(std::istream &aStream);
464
465 ReferencePtr mPath;
466 PatternStorage mPattern;
467 StrokeOptions mStrokeOptions;
468 DrawOptions mOptions;
469 };
470
471 class RecordedClearRect : public RecordedDrawingEvent {
472 public:
473 RecordedClearRect(DrawTarget *aDT, const Rect &aRect)
474 : RecordedDrawingEvent(CLEARRECT, aDT), mRect(aRect)
475 {
476 }
477
478 virtual void PlayEvent(Translator *aTranslator) const;
479
480 virtual void RecordToStream(std::ostream &aStream) const;
481 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
482
483 virtual std::string GetName() const { return "ClearRect"; }
484 private:
485 friend class RecordedEvent;
486
487 RecordedClearRect(std::istream &aStream);
488
489 Rect mRect;
490 };
491
492 class RecordedCopySurface : public RecordedDrawingEvent {
493 public:
494 RecordedCopySurface(DrawTarget *aDT, ReferencePtr aSourceSurface,
495 const IntRect &aSourceRect, const IntPoint &aDest)
496 : RecordedDrawingEvent(COPYSURFACE, aDT), mSourceSurface(aSourceSurface),
497 mSourceRect(aSourceRect), mDest(aDest)
498 {
499 }
500
501 virtual void PlayEvent(Translator *aTranslator) const;
502
503 virtual void RecordToStream(std::ostream &aStream) const;
504 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
505
506 virtual std::string GetName() const { return "CopySurface"; }
507 private:
508 friend class RecordedEvent;
509
510 RecordedCopySurface(std::istream &aStream);
511
512 ReferencePtr mSourceSurface;
513 IntRect mSourceRect;
514 IntPoint mDest;
515 };
516
517 class RecordedPushClip : public RecordedDrawingEvent {
518 public:
519 RecordedPushClip(DrawTarget *aDT, ReferencePtr aPath)
520 : RecordedDrawingEvent(PUSHCLIP, aDT), mPath(aPath)
521 {
522 }
523
524 virtual void PlayEvent(Translator *aTranslator) const;
525
526 virtual void RecordToStream(std::ostream &aStream) const;
527 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
528
529 virtual std::string GetName() const { return "PushClip"; }
530 private:
531 friend class RecordedEvent;
532
533 RecordedPushClip(std::istream &aStream);
534
535 ReferencePtr mPath;
536 };
537
538 class RecordedPushClipRect : public RecordedDrawingEvent {
539 public:
540 RecordedPushClipRect(DrawTarget *aDT, const Rect &aRect)
541 : RecordedDrawingEvent(PUSHCLIPRECT, aDT), mRect(aRect)
542 {
543 }
544
545 virtual void PlayEvent(Translator *aTranslator) const;
546
547 virtual void RecordToStream(std::ostream &aStream) const;
548 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
549
550 virtual std::string GetName() const { return "PushClipRect"; }
551 private:
552 friend class RecordedEvent;
553
554 RecordedPushClipRect(std::istream &aStream);
555
556 Rect mRect;
557 };
558
559 class RecordedPopClip : public RecordedDrawingEvent {
560 public:
561 RecordedPopClip(DrawTarget *aDT)
562 : RecordedDrawingEvent(POPCLIP, aDT)
563 {}
564
565 virtual void PlayEvent(Translator *aTranslator) const;
566
567 virtual void RecordToStream(std::ostream &aStream) const;
568 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
569
570 virtual std::string GetName() const { return "PopClip"; }
571 private:
572 friend class RecordedEvent;
573
574 RecordedPopClip(std::istream &aStream);
575 };
576
577 class RecordedSetTransform : public RecordedDrawingEvent {
578 public:
579 RecordedSetTransform(DrawTarget *aDT, const Matrix &aTransform)
580 : RecordedDrawingEvent(SETTRANSFORM, aDT), mTransform(aTransform)
581 {
582 }
583
584 virtual void PlayEvent(Translator *aTranslator) const;
585
586 virtual void RecordToStream(std::ostream &aStream) const;
587 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
588
589 virtual std::string GetName() const { return "SetTransform"; }
590 private:
591 friend class RecordedEvent;
592
593 RecordedSetTransform(std::istream &aStream);
594
595 Matrix mTransform;
596 };
597
598 class RecordedDrawSurface : public RecordedDrawingEvent {
599 public:
600 RecordedDrawSurface(DrawTarget *aDT, ReferencePtr aRefSource, const Rect &aDest,
601 const Rect &aSource, const DrawSurfaceOptions &aDSOptions,
602 const DrawOptions &aOptions)
603 : RecordedDrawingEvent(DRAWSURFACE, aDT), mRefSource(aRefSource), mDest(aDest)
604 , mSource(aSource), mDSOptions(aDSOptions), mOptions(aOptions)
605 {
606 }
607
608 virtual void PlayEvent(Translator *aTranslator) const;
609
610 virtual void RecordToStream(std::ostream &aStream) const;
611 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
612
613 virtual std::string GetName() const { return "DrawSurface"; }
614 private:
615 friend class RecordedEvent;
616
617 RecordedDrawSurface(std::istream &aStream);
618
619 ReferencePtr mRefSource;
620 Rect mDest;
621 Rect mSource;
622 DrawSurfaceOptions mDSOptions;
623 DrawOptions mOptions;
624 };
625
626 class RecordedDrawSurfaceWithShadow : public RecordedDrawingEvent {
627 public:
628 RecordedDrawSurfaceWithShadow(DrawTarget *aDT, ReferencePtr aRefSource, const Point &aDest,
629 const Color &aColor, const Point &aOffset,
630 Float aSigma, CompositionOp aOp)
631 : RecordedDrawingEvent(DRAWSURFACEWITHSHADOW, aDT), mRefSource(aRefSource), mDest(aDest)
632 , mColor(aColor), mOffset(aOffset), mSigma(aSigma), mOp(aOp)
633 {
634 }
635
636 virtual void PlayEvent(Translator *aTranslator) const;
637
638 virtual void RecordToStream(std::ostream &aStream) const;
639 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
640
641 virtual std::string GetName() const { return "DrawSurfaceWithShadow"; }
642 private:
643 friend class RecordedEvent;
644
645 RecordedDrawSurfaceWithShadow(std::istream &aStream);
646
647 ReferencePtr mRefSource;
648 Point mDest;
649 Color mColor;
650 Point mOffset;
651 Float mSigma;
652 CompositionOp mOp;
653 };
654
655 class RecordedDrawFilter : public RecordedDrawingEvent {
656 public:
657 RecordedDrawFilter(DrawTarget *aDT, ReferencePtr aNode,
658 const Rect &aSourceRect,
659 const Point &aDestPoint,
660 const DrawOptions &aOptions)
661 : RecordedDrawingEvent(DRAWFILTER, aDT), mNode(aNode), mSourceRect(aSourceRect)
662 , mDestPoint(aDestPoint), mOptions(aOptions)
663 {
664 }
665
666 virtual void PlayEvent(Translator *aTranslator) const;
667
668 virtual void RecordToStream(std::ostream &aStream) const;
669 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
670
671 virtual std::string GetName() const { return "DrawFilter"; }
672 private:
673 friend class RecordedEvent;
674
675 RecordedDrawFilter(std::istream &aStream);
676
677 ReferencePtr mNode;
678 Rect mSourceRect;
679 Point mDestPoint;
680 DrawOptions mOptions;
681 };
682
683 class RecordedPathCreation : public RecordedEvent {
684 public:
685 RecordedPathCreation(PathRecording *aPath);
686 ~RecordedPathCreation();
687
688 virtual void PlayEvent(Translator *aTranslator) const;
689
690 virtual void RecordToStream(std::ostream &aStream) const;
691 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
692
693 virtual std::string GetName() const { return "Path Creation"; }
694 virtual ReferencePtr GetObjectRef() const { return mRefPtr; }
695 private:
696 friend class RecordedEvent;
697
698 ReferencePtr mRefPtr;
699 FillRule mFillRule;
700 std::vector<PathOp> mPathOps;
701
702 RecordedPathCreation(std::istream &aStream);
703 };
704
705 class RecordedPathDestruction : public RecordedEvent {
706 public:
707 RecordedPathDestruction(PathRecording *aPath)
708 : RecordedEvent(PATHDESTRUCTION), mRefPtr(aPath)
709 {
710 }
711
712 virtual void PlayEvent(Translator *aTranslator) const;
713
714 virtual void RecordToStream(std::ostream &aStream) const;
715 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
716
717 virtual std::string GetName() const { return "Path Destruction"; }
718 virtual ReferencePtr GetObjectRef() const { return mRefPtr; }
719 private:
720 friend class RecordedEvent;
721
722 ReferencePtr mRefPtr;
723
724 RecordedPathDestruction(std::istream &aStream);
725 };
726
727 class RecordedSourceSurfaceCreation : public RecordedEvent {
728 public:
729 RecordedSourceSurfaceCreation(ReferencePtr aRefPtr, uint8_t *aData, int32_t aStride,
730 const IntSize &aSize, SurfaceFormat aFormat)
731 : RecordedEvent(SOURCESURFACECREATION), mRefPtr(aRefPtr), mData(aData)
732 , mStride(aStride), mSize(aSize), mFormat(aFormat), mDataOwned(false)
733 {
734 }
735
736 ~RecordedSourceSurfaceCreation();
737
738 virtual void PlayEvent(Translator *aTranslator) const;
739
740 virtual void RecordToStream(std::ostream &aStream) const;
741 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
742
743 virtual std::string GetName() const { return "SourceSurface Creation"; }
744 virtual ReferencePtr GetObjectRef() const { return mRefPtr; }
745 private:
746 friend class RecordedEvent;
747
748 ReferencePtr mRefPtr;
749 uint8_t *mData;
750 int32_t mStride;
751 IntSize mSize;
752 SurfaceFormat mFormat;
753 bool mDataOwned;
754
755 RecordedSourceSurfaceCreation(std::istream &aStream);
756 };
757
758 class RecordedSourceSurfaceDestruction : public RecordedEvent {
759 public:
760 RecordedSourceSurfaceDestruction(ReferencePtr aRefPtr)
761 : RecordedEvent(SOURCESURFACEDESTRUCTION), mRefPtr(aRefPtr)
762 {
763 }
764
765 virtual void PlayEvent(Translator *aTranslator) const;
766
767 virtual void RecordToStream(std::ostream &aStream) const;
768 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
769
770 virtual std::string GetName() const { return "SourceSurface Destruction"; }
771 virtual ReferencePtr GetObjectRef() const { return mRefPtr; }
772 private:
773 friend class RecordedEvent;
774
775 ReferencePtr mRefPtr;
776
777 RecordedSourceSurfaceDestruction(std::istream &aStream);
778 };
779
780 class RecordedFilterNodeCreation : public RecordedEvent {
781 public:
782 RecordedFilterNodeCreation(ReferencePtr aRefPtr, FilterType aType)
783 : RecordedEvent(FILTERNODECREATION), mRefPtr(aRefPtr), mType(aType)
784 {
785 }
786
787 ~RecordedFilterNodeCreation();
788
789 virtual void PlayEvent(Translator *aTranslator) const;
790
791 virtual void RecordToStream(std::ostream &aStream) const;
792 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
793
794 virtual std::string GetName() const { return "FilterNode Creation"; }
795 virtual ReferencePtr GetObjectRef() const { return mRefPtr; }
796 private:
797 friend class RecordedEvent;
798
799 ReferencePtr mRefPtr;
800 FilterType mType;
801
802 RecordedFilterNodeCreation(std::istream &aStream);
803 };
804
805 class RecordedFilterNodeDestruction : public RecordedEvent {
806 public:
807 RecordedFilterNodeDestruction(ReferencePtr aRefPtr)
808 : RecordedEvent(FILTERNODEDESTRUCTION), mRefPtr(aRefPtr)
809 {
810 }
811
812 virtual void PlayEvent(Translator *aTranslator) const;
813
814 virtual void RecordToStream(std::ostream &aStream) const;
815 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
816
817 virtual std::string GetName() const { return "FilterNode Destruction"; }
818 virtual ReferencePtr GetObjectRef() const { return mRefPtr; }
819 private:
820 friend class RecordedEvent;
821
822 ReferencePtr mRefPtr;
823
824 RecordedFilterNodeDestruction(std::istream &aStream);
825 };
826
827 class RecordedGradientStopsCreation : public RecordedEvent {
828 public:
829 RecordedGradientStopsCreation(ReferencePtr aRefPtr, GradientStop *aStops,
830 uint32_t aNumStops, ExtendMode aExtendMode)
831 : RecordedEvent(GRADIENTSTOPSCREATION), mRefPtr(aRefPtr), mStops(aStops)
832 , mNumStops(aNumStops), mExtendMode(aExtendMode), mDataOwned(false)
833 {
834 }
835
836 ~RecordedGradientStopsCreation();
837
838 virtual void PlayEvent(Translator *aTranslator) const;
839
840 virtual void RecordToStream(std::ostream &aStream) const;
841 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
842
843 virtual std::string GetName() const { return "GradientStops Creation"; }
844 virtual ReferencePtr GetObjectRef() const { return mRefPtr; }
845 private:
846 friend class RecordedEvent;
847
848 ReferencePtr mRefPtr;
849 GradientStop *mStops;
850 uint32_t mNumStops;
851 ExtendMode mExtendMode;
852 bool mDataOwned;
853
854 RecordedGradientStopsCreation(std::istream &aStream);
855 };
856
857 class RecordedGradientStopsDestruction : public RecordedEvent {
858 public:
859 RecordedGradientStopsDestruction(ReferencePtr aRefPtr)
860 : RecordedEvent(GRADIENTSTOPSDESTRUCTION), mRefPtr(aRefPtr)
861 {
862 }
863
864 virtual void PlayEvent(Translator *aTranslator) const;
865
866 virtual void RecordToStream(std::ostream &aStream) const;
867 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
868
869 virtual std::string GetName() const { return "GradientStops Destruction"; }
870 virtual ReferencePtr GetObjectRef() const { return mRefPtr; }
871 private:
872 friend class RecordedEvent;
873
874 ReferencePtr mRefPtr;
875
876 RecordedGradientStopsDestruction(std::istream &aStream);
877 };
878
879 class RecordedSnapshot : public RecordedEvent {
880 public:
881 RecordedSnapshot(ReferencePtr aRefPtr, DrawTarget *aDT)
882 : RecordedEvent(SNAPSHOT), mRefPtr(aRefPtr), mDT(aDT)
883 {
884 }
885
886 virtual void PlayEvent(Translator *aTranslator) const;
887
888 virtual void RecordToStream(std::ostream &aStream) const;
889 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
890
891 virtual std::string GetName() const { return "Snapshot"; }
892 virtual ReferencePtr GetObjectRef() const { return mRefPtr; }
893 private:
894 friend class RecordedEvent;
895
896 ReferencePtr mRefPtr;
897 ReferencePtr mDT;
898
899 RecordedSnapshot(std::istream &aStream);
900 };
901
902 class RecordedScaledFontCreation : public RecordedEvent {
903 public:
904 static void FontDataProc(const uint8_t *aData, uint32_t aSize, uint32_t aIndex, Float aGlyphSize, void* aBaton)
905 {
906 static_cast<RecordedScaledFontCreation*>(aBaton)->SetFontData(aData, aSize, aIndex, aGlyphSize);
907 }
908
909 RecordedScaledFontCreation(ReferencePtr aRefPtr, ScaledFont *aScaledFont)
910 : RecordedEvent(SCALEDFONTCREATION), mRefPtr(aRefPtr), mData(nullptr)
911 {
912 aScaledFont->GetFontFileData(&FontDataProc, this);
913 }
914
915 ~RecordedScaledFontCreation();
916
917 virtual void PlayEvent(Translator *aTranslator) const;
918
919 virtual void RecordToStream(std::ostream &aStream) const;
920 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
921
922 virtual std::string GetName() const { return "ScaledFont Creation"; }
923 virtual ReferencePtr GetObjectRef() const { return mRefPtr; }
924
925 void SetFontData(const uint8_t *aData, uint32_t aSize, uint32_t aIndex, Float aGlyphSize);
926
927 private:
928 friend class RecordedEvent;
929
930 ReferencePtr mRefPtr;
931 uint8_t *mData;
932 uint32_t mSize;
933 Float mGlyphSize;
934 uint32_t mIndex;
935
936 RecordedScaledFontCreation(std::istream &aStream);
937 };
938
939 class RecordedScaledFontDestruction : public RecordedEvent {
940 public:
941 RecordedScaledFontDestruction(ReferencePtr aRefPtr)
942 : RecordedEvent(SCALEDFONTDESTRUCTION), mRefPtr(aRefPtr)
943 {
944 }
945
946 virtual void PlayEvent(Translator *aTranslator) const;
947
948 virtual void RecordToStream(std::ostream &aStream) const;
949 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
950
951 virtual std::string GetName() const { return "ScaledFont Destruction"; }
952 virtual ReferencePtr GetObjectRef() const { return mRefPtr; }
953 private:
954 friend class RecordedEvent;
955
956 ReferencePtr mRefPtr;
957
958 RecordedScaledFontDestruction(std::istream &aStream);
959 };
960
961 class RecordedMaskSurface : public RecordedDrawingEvent {
962 public:
963 RecordedMaskSurface(DrawTarget *aDT, const Pattern &aPattern, ReferencePtr aRefMask,
964 const Point &aOffset, const DrawOptions &aOptions)
965 : RecordedDrawingEvent(MASKSURFACE, aDT), mRefMask(aRefMask), mOffset(aOffset)
966 , mOptions(aOptions)
967 {
968 StorePattern(mPattern, aPattern);
969 }
970
971 virtual void PlayEvent(Translator *aTranslator) const;
972
973 virtual void RecordToStream(std::ostream &aStream) const;
974 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
975
976 virtual std::string GetName() const { return "MaskSurface"; }
977 private:
978 friend class RecordedEvent;
979
980 RecordedMaskSurface(std::istream &aStream);
981
982 PatternStorage mPattern;
983 ReferencePtr mRefMask;
984 Point mOffset;
985 DrawOptions mOptions;
986 };
987
988 class RecordedFilterNodeSetAttribute : public RecordedEvent
989 {
990 public:
991 enum ArgType {
992 ARGTYPE_UINT32,
993 ARGTYPE_BOOL,
994 ARGTYPE_FLOAT,
995 ARGTYPE_SIZE,
996 ARGTYPE_INTSIZE,
997 ARGTYPE_INTPOINT,
998 ARGTYPE_RECT,
999 ARGTYPE_INTRECT,
1000 ARGTYPE_POINT,
1001 ARGTYPE_MATRIX5X4,
1002 ARGTYPE_POINT3D,
1003 ARGTYPE_COLOR,
1004 ARGTYPE_FLOAT_ARRAY
1005 };
1006
1007 template<typename T>
1008 RecordedFilterNodeSetAttribute(FilterNode *aNode, uint32_t aIndex, T aArgument, ArgType aArgType)
1009 : RecordedEvent(FILTERNODESETATTRIBUTE), mNode(aNode), mIndex(aIndex), mArgType(aArgType)
1010 {
1011 mPayload.resize(sizeof(T));
1012 memcpy(&mPayload.front(), &aArgument, sizeof(T));
1013 }
1014
1015 RecordedFilterNodeSetAttribute(FilterNode *aNode, uint32_t aIndex, const Float *aFloat, uint32_t aSize)
1016 : RecordedEvent(FILTERNODESETATTRIBUTE), mNode(aNode), mIndex(aIndex), mArgType(ARGTYPE_FLOAT_ARRAY)
1017 {
1018 mPayload.resize(sizeof(Float) * aSize);
1019 memcpy(&mPayload.front(), aFloat, sizeof(Float) * aSize);
1020 }
1021
1022 virtual void PlayEvent(Translator *aTranslator) const;
1023 virtual void RecordToStream(std::ostream &aStream) const;
1024 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
1025
1026 virtual std::string GetName() const { return "SetAttribute"; }
1027
1028 virtual ReferencePtr GetObjectRef() const { return mNode; }
1029
1030 private:
1031 friend class RecordedEvent;
1032
1033 ReferencePtr mNode;
1034
1035 uint32_t mIndex;
1036 ArgType mArgType;
1037 std::vector<uint8_t> mPayload;
1038
1039 RecordedFilterNodeSetAttribute(std::istream &aStream);
1040 };
1041
1042 class RecordedFilterNodeSetInput : public RecordedEvent
1043 {
1044 public:
1045 RecordedFilterNodeSetInput(FilterNode* aNode, uint32_t aIndex, FilterNode* aInputNode)
1046 : RecordedEvent(FILTERNODESETINPUT), mNode(aNode), mIndex(aIndex)
1047 , mInputFilter(aInputNode), mInputSurface(nullptr)
1048 {
1049 }
1050
1051 RecordedFilterNodeSetInput(FilterNode *aNode, uint32_t aIndex, SourceSurface *aInputSurface)
1052 : RecordedEvent(FILTERNODESETINPUT), mNode(aNode), mIndex(aIndex)
1053 , mInputFilter(nullptr), mInputSurface(aInputSurface)
1054 {
1055 }
1056
1057 virtual void PlayEvent(Translator *aTranslator) const;
1058 virtual void RecordToStream(std::ostream &aStream) const;
1059 virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
1060
1061 virtual std::string GetName() const { return "SetInput"; }
1062
1063 virtual ReferencePtr GetObjectRef() const { return mNode; }
1064
1065 private:
1066 friend class RecordedEvent;
1067
1068 ReferencePtr mNode;
1069 uint32_t mIndex;
1070 ReferencePtr mInputFilter;
1071 ReferencePtr mInputSurface;
1072
1073 RecordedFilterNodeSetInput(std::istream &aStream);
1074 };
1075
1076 }
1077 }
1078
1079 #endif

mercurial