RecordedEvent.h 38 KB

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