michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef MOZILLA_GFX_RECORDEDEVENT_H_ michael@0: #define MOZILLA_GFX_RECORDEDEVENT_H_ michael@0: michael@0: #include "2D.h" michael@0: #include michael@0: #include michael@0: #include michael@0: #include "RecordingTypes.h" michael@0: #include "PathRecording.h" michael@0: michael@0: namespace mozilla { michael@0: namespace gfx { michael@0: michael@0: // A change in major revision means a change in event binary format, causing michael@0: // loss of backwards compatibility. Old streams will not work in a player michael@0: // using a newer major revision. And new streams will not work in a player michael@0: // using an older major revision. michael@0: const uint16_t kMajorRevision = 3; michael@0: // A change in minor revision means additions of new events. New streams will michael@0: // not play in older players. michael@0: const uint16_t kMinorRevision = 2; michael@0: michael@0: struct ReferencePtr michael@0: { michael@0: ReferencePtr() michael@0: : mLongPtr(0) michael@0: {} michael@0: michael@0: ReferencePtr(const void* aLongPtr) michael@0: : mLongPtr(uint64_t(aLongPtr)) michael@0: {} michael@0: michael@0: template michael@0: ReferencePtr(const RefPtr& aPtr) michael@0: : mLongPtr(uint64_t(aPtr.get())) michael@0: {} michael@0: michael@0: ReferencePtr &operator =(const void* aLongPtr) { michael@0: mLongPtr = uint64_t(aLongPtr); michael@0: return *this; michael@0: } michael@0: michael@0: template michael@0: ReferencePtr &operator =(const RefPtr& aPtr) { michael@0: mLongPtr = uint64_t(aPtr.get()); michael@0: return *this; michael@0: } michael@0: michael@0: operator void*() const { michael@0: return (void*)mLongPtr; michael@0: } michael@0: michael@0: uint64_t mLongPtr; michael@0: }; michael@0: michael@0: // Used by the Azure drawing debugger (player2d) michael@0: inline std::string StringFromPtr(ReferencePtr aPtr) michael@0: { michael@0: std::stringstream stream; michael@0: stream << aPtr; michael@0: return stream.str(); michael@0: } michael@0: michael@0: class Translator michael@0: { michael@0: public: michael@0: virtual ~Translator() {} michael@0: michael@0: virtual DrawTarget *LookupDrawTarget(ReferencePtr aRefPtr) = 0; michael@0: virtual Path *LookupPath(ReferencePtr aRefPtr) = 0; michael@0: virtual SourceSurface *LookupSourceSurface(ReferencePtr aRefPtr) = 0; michael@0: virtual FilterNode *LookupFilterNode(ReferencePtr aRefPtr) = 0; michael@0: virtual GradientStops *LookupGradientStops(ReferencePtr aRefPtr) = 0; michael@0: virtual ScaledFont *LookupScaledFont(ReferencePtr aRefPtr) = 0; michael@0: virtual void AddDrawTarget(ReferencePtr aRefPtr, DrawTarget *aDT) = 0; michael@0: virtual void RemoveDrawTarget(ReferencePtr aRefPtr) = 0; michael@0: virtual void AddPath(ReferencePtr aRefPtr, Path *aPath) = 0; michael@0: virtual void RemovePath(ReferencePtr aRefPtr) = 0; michael@0: virtual void AddSourceSurface(ReferencePtr aRefPtr, SourceSurface *aPath) = 0; michael@0: virtual void RemoveSourceSurface(ReferencePtr aRefPtr) = 0; michael@0: virtual void AddFilterNode(mozilla::gfx::ReferencePtr aRefPtr, FilterNode *aSurface) = 0; michael@0: virtual void RemoveFilterNode(mozilla::gfx::ReferencePtr aRefPtr) = 0; michael@0: virtual void AddGradientStops(ReferencePtr aRefPtr, GradientStops *aPath) = 0; michael@0: virtual void RemoveGradientStops(ReferencePtr aRefPtr) = 0; michael@0: virtual void AddScaledFont(ReferencePtr aRefPtr, ScaledFont *aScaledFont) = 0; michael@0: virtual void RemoveScaledFont(ReferencePtr aRefPtr) = 0; michael@0: michael@0: virtual DrawTarget *GetReferenceDrawTarget() = 0; michael@0: virtual FontType GetDesiredFontType() = 0; michael@0: }; michael@0: michael@0: struct ColorPatternStorage michael@0: { michael@0: Color mColor; michael@0: }; michael@0: michael@0: struct LinearGradientPatternStorage michael@0: { michael@0: Point mBegin; michael@0: Point mEnd; michael@0: ReferencePtr mStops; michael@0: Matrix mMatrix; michael@0: }; michael@0: michael@0: struct RadialGradientPatternStorage michael@0: { michael@0: Point mCenter1; michael@0: Point mCenter2; michael@0: Float mRadius1; michael@0: Float mRadius2; michael@0: ReferencePtr mStops; michael@0: Matrix mMatrix; michael@0: }; michael@0: michael@0: struct SurfacePatternStorage michael@0: { michael@0: ExtendMode mExtend; michael@0: Filter mFilter; michael@0: ReferencePtr mSurface; michael@0: Matrix mMatrix; michael@0: }; michael@0: michael@0: struct PatternStorage michael@0: { michael@0: PatternType mType; michael@0: union { michael@0: char *mStorage; michael@0: char mColor[sizeof(ColorPatternStorage)]; michael@0: char mLinear[sizeof(LinearGradientPatternStorage)]; michael@0: char mRadial[sizeof(RadialGradientPatternStorage)]; michael@0: char mSurface[sizeof(SurfacePatternStorage)]; michael@0: }; michael@0: }; michael@0: michael@0: class RecordedEvent { michael@0: public: michael@0: enum EventType { michael@0: DRAWTARGETCREATION = 0, michael@0: DRAWTARGETDESTRUCTION, michael@0: FILLRECT, michael@0: STROKERECT, michael@0: STROKELINE, michael@0: CLEARRECT, michael@0: COPYSURFACE, michael@0: SETTRANSFORM, michael@0: PUSHCLIP, michael@0: PUSHCLIPRECT, michael@0: POPCLIP, michael@0: FILL, michael@0: FILLGLYPHS, michael@0: MASK, michael@0: STROKE, michael@0: DRAWSURFACE, michael@0: DRAWSURFACEWITHSHADOW, michael@0: PATHCREATION, michael@0: PATHDESTRUCTION, michael@0: SOURCESURFACECREATION, michael@0: SOURCESURFACEDESTRUCTION, michael@0: GRADIENTSTOPSCREATION, michael@0: GRADIENTSTOPSDESTRUCTION, michael@0: SNAPSHOT, michael@0: SCALEDFONTCREATION, michael@0: SCALEDFONTDESTRUCTION, michael@0: MASKSURFACE, michael@0: FILTERNODECREATION, michael@0: FILTERNODEDESTRUCTION, michael@0: DRAWFILTER, michael@0: FILTERNODESETATTRIBUTE, michael@0: FILTERNODESETINPUT michael@0: }; michael@0: static const uint32_t kTotalEventTypes = RecordedEvent::FILTERNODESETINPUT + 1; michael@0: michael@0: static std::string GetEventName(EventType aType); michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const {} michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const {} michael@0: michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const { } michael@0: michael@0: void RecordPatternData(std::ostream &aStream, const PatternStorage &aPatternStorage) const; michael@0: void ReadPatternData(std::istream &aStream, PatternStorage &aPatternStorage) const; michael@0: void StorePattern(PatternStorage &aDestination, const Pattern &aSource) const; michael@0: void RecordStrokeOptions(std::ostream &aStream, const StrokeOptions &aStrokeOptions) const; michael@0: void ReadStrokeOptions(std::istream &aStream, StrokeOptions &aStrokeOptions); michael@0: michael@0: virtual std::string GetName() const = 0; michael@0: michael@0: virtual ReferencePtr GetObjectRef() const = 0; michael@0: michael@0: virtual ReferencePtr GetDestinedDT() { return nullptr; } michael@0: michael@0: void OutputSimplePatternInfo(const PatternStorage &aStorage, std::stringstream &aOutput) const; michael@0: michael@0: static RecordedEvent *LoadEventFromStream(std::istream &aStream, EventType aType); michael@0: michael@0: EventType GetType() { return (EventType)mType; } michael@0: protected: michael@0: friend class DrawEventRecorderPrivate; michael@0: michael@0: RecordedEvent(int32_t aType) : mType(aType) michael@0: {} michael@0: michael@0: int32_t mType; michael@0: std::vector mDashPatternStorage; michael@0: }; michael@0: michael@0: class RecordedDrawingEvent : public RecordedEvent michael@0: { michael@0: public: michael@0: virtual ReferencePtr GetDestinedDT() { return mDT; } michael@0: michael@0: protected: michael@0: RecordedDrawingEvent(EventType aType, DrawTarget *aTarget) michael@0: : RecordedEvent(aType), mDT(aTarget) michael@0: { michael@0: } michael@0: michael@0: RecordedDrawingEvent(EventType aType, std::istream &aStream); michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: michael@0: virtual ReferencePtr GetObjectRef() const; michael@0: michael@0: ReferencePtr mDT; michael@0: }; michael@0: michael@0: class RecordedDrawTargetCreation : public RecordedEvent { michael@0: public: michael@0: RecordedDrawTargetCreation(ReferencePtr aRefPtr, BackendType aType, const IntSize &aSize, SurfaceFormat aFormat, michael@0: bool aHasExistingData = false, SourceSurface *aExistingData = nullptr) michael@0: : RecordedEvent(DRAWTARGETCREATION), mRefPtr(aRefPtr), mBackendType(aType), mSize(aSize), mFormat(aFormat) michael@0: , mHasExistingData(aHasExistingData), mExistingData(aExistingData) michael@0: {} michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "DrawTarget Creation"; } michael@0: virtual ReferencePtr GetObjectRef() const { return mRefPtr; } michael@0: michael@0: ReferencePtr mRefPtr; michael@0: BackendType mBackendType; michael@0: IntSize mSize; michael@0: SurfaceFormat mFormat; michael@0: bool mHasExistingData; michael@0: RefPtr mExistingData; michael@0: michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: RecordedDrawTargetCreation(std::istream &aStream); michael@0: }; michael@0: michael@0: class RecordedDrawTargetDestruction : public RecordedEvent { michael@0: public: michael@0: RecordedDrawTargetDestruction(ReferencePtr aRefPtr) michael@0: : RecordedEvent(DRAWTARGETDESTRUCTION), mRefPtr(aRefPtr) michael@0: {} michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "DrawTarget Destruction"; } michael@0: virtual ReferencePtr GetObjectRef() const { return mRefPtr; } michael@0: michael@0: ReferencePtr mRefPtr; michael@0: michael@0: BackendType mBackendType; michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: RecordedDrawTargetDestruction(std::istream &aStream); michael@0: }; michael@0: michael@0: class RecordedFillRect : public RecordedDrawingEvent { michael@0: public: michael@0: RecordedFillRect(DrawTarget *aDT, const Rect &aRect, const Pattern &aPattern, const DrawOptions &aOptions) michael@0: : RecordedDrawingEvent(FILLRECT, aDT), mRect(aRect), mOptions(aOptions) michael@0: { michael@0: StorePattern(mPattern, aPattern); michael@0: } michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "FillRect"; } michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: RecordedFillRect(std::istream &aStream); michael@0: michael@0: Rect mRect; michael@0: PatternStorage mPattern; michael@0: DrawOptions mOptions; michael@0: }; michael@0: michael@0: class RecordedStrokeRect : public RecordedDrawingEvent { michael@0: public: michael@0: RecordedStrokeRect(DrawTarget *aDT, const Rect &aRect, const Pattern &aPattern, michael@0: const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions) michael@0: : RecordedDrawingEvent(STROKERECT, aDT), mRect(aRect), michael@0: mStrokeOptions(aStrokeOptions), mOptions(aOptions) michael@0: { michael@0: StorePattern(mPattern, aPattern); michael@0: } michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "StrokeRect"; } michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: RecordedStrokeRect(std::istream &aStream); michael@0: michael@0: Rect mRect; michael@0: PatternStorage mPattern; michael@0: StrokeOptions mStrokeOptions; michael@0: DrawOptions mOptions; michael@0: }; michael@0: michael@0: class RecordedStrokeLine : public RecordedDrawingEvent { michael@0: public: michael@0: RecordedStrokeLine(DrawTarget *aDT, const Point &aBegin, const Point &aEnd, michael@0: const Pattern &aPattern, const StrokeOptions &aStrokeOptions, michael@0: const DrawOptions &aOptions) michael@0: : RecordedDrawingEvent(STROKELINE, aDT), mBegin(aBegin), mEnd(aEnd), michael@0: mStrokeOptions(aStrokeOptions), mOptions(aOptions) michael@0: { michael@0: StorePattern(mPattern, aPattern); michael@0: } michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "StrokeLine"; } michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: RecordedStrokeLine(std::istream &aStream); michael@0: michael@0: Point mBegin; michael@0: Point mEnd; michael@0: PatternStorage mPattern; michael@0: StrokeOptions mStrokeOptions; michael@0: DrawOptions mOptions; michael@0: }; michael@0: michael@0: class RecordedFill : public RecordedDrawingEvent { michael@0: public: michael@0: RecordedFill(DrawTarget *aDT, ReferencePtr aPath, const Pattern &aPattern, const DrawOptions &aOptions) michael@0: : RecordedDrawingEvent(FILL, aDT), mPath(aPath), mOptions(aOptions) michael@0: { michael@0: StorePattern(mPattern, aPattern); michael@0: } michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "Fill"; } michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: RecordedFill(std::istream &aStream); michael@0: michael@0: ReferencePtr mPath; michael@0: PatternStorage mPattern; michael@0: DrawOptions mOptions; michael@0: }; michael@0: michael@0: class RecordedFillGlyphs : public RecordedDrawingEvent { michael@0: public: michael@0: RecordedFillGlyphs(DrawTarget *aDT, ReferencePtr aScaledFont, const Pattern &aPattern, const DrawOptions &aOptions, michael@0: const Glyph *aGlyphs, uint32_t aNumGlyphs) michael@0: : RecordedDrawingEvent(FILLGLYPHS, aDT), mScaledFont(aScaledFont), mOptions(aOptions) michael@0: { michael@0: StorePattern(mPattern, aPattern); michael@0: mNumGlyphs = aNumGlyphs; michael@0: mGlyphs = new Glyph[aNumGlyphs]; michael@0: memcpy(mGlyphs, aGlyphs, sizeof(Glyph) * aNumGlyphs); michael@0: } michael@0: virtual ~RecordedFillGlyphs(); michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "FillGlyphs"; } michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: RecordedFillGlyphs(std::istream &aStream); michael@0: michael@0: ReferencePtr mScaledFont; michael@0: PatternStorage mPattern; michael@0: DrawOptions mOptions; michael@0: Glyph *mGlyphs; michael@0: uint32_t mNumGlyphs; michael@0: }; michael@0: michael@0: class RecordedMask : public RecordedDrawingEvent { michael@0: public: michael@0: RecordedMask(DrawTarget *aDT, const Pattern &aSource, const Pattern &aMask, const DrawOptions &aOptions) michael@0: : RecordedDrawingEvent(MASK, aDT), mOptions(aOptions) michael@0: { michael@0: StorePattern(mSource, aSource); michael@0: StorePattern(mMask, aMask); michael@0: } michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "Mask"; } michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: RecordedMask(std::istream &aStream); michael@0: michael@0: PatternStorage mSource; michael@0: PatternStorage mMask; michael@0: DrawOptions mOptions; michael@0: }; michael@0: michael@0: class RecordedStroke : public RecordedDrawingEvent { michael@0: public: michael@0: RecordedStroke(DrawTarget *aDT, ReferencePtr aPath, const Pattern &aPattern, michael@0: const StrokeOptions &aStrokeOptions, const DrawOptions &aOptions) michael@0: : RecordedDrawingEvent(STROKE, aDT), mPath(aPath), michael@0: mStrokeOptions(aStrokeOptions), mOptions(aOptions) michael@0: { michael@0: StorePattern(mPattern, aPattern); michael@0: } michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "Stroke"; } michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: RecordedStroke(std::istream &aStream); michael@0: michael@0: ReferencePtr mPath; michael@0: PatternStorage mPattern; michael@0: StrokeOptions mStrokeOptions; michael@0: DrawOptions mOptions; michael@0: }; michael@0: michael@0: class RecordedClearRect : public RecordedDrawingEvent { michael@0: public: michael@0: RecordedClearRect(DrawTarget *aDT, const Rect &aRect) michael@0: : RecordedDrawingEvent(CLEARRECT, aDT), mRect(aRect) michael@0: { michael@0: } michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "ClearRect"; } michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: RecordedClearRect(std::istream &aStream); michael@0: michael@0: Rect mRect; michael@0: }; michael@0: michael@0: class RecordedCopySurface : public RecordedDrawingEvent { michael@0: public: michael@0: RecordedCopySurface(DrawTarget *aDT, ReferencePtr aSourceSurface, michael@0: const IntRect &aSourceRect, const IntPoint &aDest) michael@0: : RecordedDrawingEvent(COPYSURFACE, aDT), mSourceSurface(aSourceSurface), michael@0: mSourceRect(aSourceRect), mDest(aDest) michael@0: { michael@0: } michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "CopySurface"; } michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: RecordedCopySurface(std::istream &aStream); michael@0: michael@0: ReferencePtr mSourceSurface; michael@0: IntRect mSourceRect; michael@0: IntPoint mDest; michael@0: }; michael@0: michael@0: class RecordedPushClip : public RecordedDrawingEvent { michael@0: public: michael@0: RecordedPushClip(DrawTarget *aDT, ReferencePtr aPath) michael@0: : RecordedDrawingEvent(PUSHCLIP, aDT), mPath(aPath) michael@0: { michael@0: } michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "PushClip"; } michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: RecordedPushClip(std::istream &aStream); michael@0: michael@0: ReferencePtr mPath; michael@0: }; michael@0: michael@0: class RecordedPushClipRect : public RecordedDrawingEvent { michael@0: public: michael@0: RecordedPushClipRect(DrawTarget *aDT, const Rect &aRect) michael@0: : RecordedDrawingEvent(PUSHCLIPRECT, aDT), mRect(aRect) michael@0: { michael@0: } michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "PushClipRect"; } michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: RecordedPushClipRect(std::istream &aStream); michael@0: michael@0: Rect mRect; michael@0: }; michael@0: michael@0: class RecordedPopClip : public RecordedDrawingEvent { michael@0: public: michael@0: RecordedPopClip(DrawTarget *aDT) michael@0: : RecordedDrawingEvent(POPCLIP, aDT) michael@0: {} michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "PopClip"; } michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: RecordedPopClip(std::istream &aStream); michael@0: }; michael@0: michael@0: class RecordedSetTransform : public RecordedDrawingEvent { michael@0: public: michael@0: RecordedSetTransform(DrawTarget *aDT, const Matrix &aTransform) michael@0: : RecordedDrawingEvent(SETTRANSFORM, aDT), mTransform(aTransform) michael@0: { michael@0: } michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "SetTransform"; } michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: RecordedSetTransform(std::istream &aStream); michael@0: michael@0: Matrix mTransform; michael@0: }; michael@0: michael@0: class RecordedDrawSurface : public RecordedDrawingEvent { michael@0: public: michael@0: RecordedDrawSurface(DrawTarget *aDT, ReferencePtr aRefSource, const Rect &aDest, michael@0: const Rect &aSource, const DrawSurfaceOptions &aDSOptions, michael@0: const DrawOptions &aOptions) michael@0: : RecordedDrawingEvent(DRAWSURFACE, aDT), mRefSource(aRefSource), mDest(aDest) michael@0: , mSource(aSource), mDSOptions(aDSOptions), mOptions(aOptions) michael@0: { michael@0: } michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "DrawSurface"; } michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: RecordedDrawSurface(std::istream &aStream); michael@0: michael@0: ReferencePtr mRefSource; michael@0: Rect mDest; michael@0: Rect mSource; michael@0: DrawSurfaceOptions mDSOptions; michael@0: DrawOptions mOptions; michael@0: }; michael@0: michael@0: class RecordedDrawSurfaceWithShadow : public RecordedDrawingEvent { michael@0: public: michael@0: RecordedDrawSurfaceWithShadow(DrawTarget *aDT, ReferencePtr aRefSource, const Point &aDest, michael@0: const Color &aColor, const Point &aOffset, michael@0: Float aSigma, CompositionOp aOp) michael@0: : RecordedDrawingEvent(DRAWSURFACEWITHSHADOW, aDT), mRefSource(aRefSource), mDest(aDest) michael@0: , mColor(aColor), mOffset(aOffset), mSigma(aSigma), mOp(aOp) michael@0: { michael@0: } michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "DrawSurfaceWithShadow"; } michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: RecordedDrawSurfaceWithShadow(std::istream &aStream); michael@0: michael@0: ReferencePtr mRefSource; michael@0: Point mDest; michael@0: Color mColor; michael@0: Point mOffset; michael@0: Float mSigma; michael@0: CompositionOp mOp; michael@0: }; michael@0: michael@0: class RecordedDrawFilter : public RecordedDrawingEvent { michael@0: public: michael@0: RecordedDrawFilter(DrawTarget *aDT, ReferencePtr aNode, michael@0: const Rect &aSourceRect, michael@0: const Point &aDestPoint, michael@0: const DrawOptions &aOptions) michael@0: : RecordedDrawingEvent(DRAWFILTER, aDT), mNode(aNode), mSourceRect(aSourceRect) michael@0: , mDestPoint(aDestPoint), mOptions(aOptions) michael@0: { michael@0: } michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "DrawFilter"; } michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: RecordedDrawFilter(std::istream &aStream); michael@0: michael@0: ReferencePtr mNode; michael@0: Rect mSourceRect; michael@0: Point mDestPoint; michael@0: DrawOptions mOptions; michael@0: }; michael@0: michael@0: class RecordedPathCreation : public RecordedEvent { michael@0: public: michael@0: RecordedPathCreation(PathRecording *aPath); michael@0: ~RecordedPathCreation(); michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "Path Creation"; } michael@0: virtual ReferencePtr GetObjectRef() const { return mRefPtr; } michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: ReferencePtr mRefPtr; michael@0: FillRule mFillRule; michael@0: std::vector mPathOps; michael@0: michael@0: RecordedPathCreation(std::istream &aStream); michael@0: }; michael@0: michael@0: class RecordedPathDestruction : public RecordedEvent { michael@0: public: michael@0: RecordedPathDestruction(PathRecording *aPath) michael@0: : RecordedEvent(PATHDESTRUCTION), mRefPtr(aPath) michael@0: { michael@0: } michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "Path Destruction"; } michael@0: virtual ReferencePtr GetObjectRef() const { return mRefPtr; } michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: ReferencePtr mRefPtr; michael@0: michael@0: RecordedPathDestruction(std::istream &aStream); michael@0: }; michael@0: michael@0: class RecordedSourceSurfaceCreation : public RecordedEvent { michael@0: public: michael@0: RecordedSourceSurfaceCreation(ReferencePtr aRefPtr, uint8_t *aData, int32_t aStride, michael@0: const IntSize &aSize, SurfaceFormat aFormat) michael@0: : RecordedEvent(SOURCESURFACECREATION), mRefPtr(aRefPtr), mData(aData) michael@0: , mStride(aStride), mSize(aSize), mFormat(aFormat), mDataOwned(false) michael@0: { michael@0: } michael@0: michael@0: ~RecordedSourceSurfaceCreation(); michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "SourceSurface Creation"; } michael@0: virtual ReferencePtr GetObjectRef() const { return mRefPtr; } michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: ReferencePtr mRefPtr; michael@0: uint8_t *mData; michael@0: int32_t mStride; michael@0: IntSize mSize; michael@0: SurfaceFormat mFormat; michael@0: bool mDataOwned; michael@0: michael@0: RecordedSourceSurfaceCreation(std::istream &aStream); michael@0: }; michael@0: michael@0: class RecordedSourceSurfaceDestruction : public RecordedEvent { michael@0: public: michael@0: RecordedSourceSurfaceDestruction(ReferencePtr aRefPtr) michael@0: : RecordedEvent(SOURCESURFACEDESTRUCTION), mRefPtr(aRefPtr) michael@0: { michael@0: } michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "SourceSurface Destruction"; } michael@0: virtual ReferencePtr GetObjectRef() const { return mRefPtr; } michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: ReferencePtr mRefPtr; michael@0: michael@0: RecordedSourceSurfaceDestruction(std::istream &aStream); michael@0: }; michael@0: michael@0: class RecordedFilterNodeCreation : public RecordedEvent { michael@0: public: michael@0: RecordedFilterNodeCreation(ReferencePtr aRefPtr, FilterType aType) michael@0: : RecordedEvent(FILTERNODECREATION), mRefPtr(aRefPtr), mType(aType) michael@0: { michael@0: } michael@0: michael@0: ~RecordedFilterNodeCreation(); michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "FilterNode Creation"; } michael@0: virtual ReferencePtr GetObjectRef() const { return mRefPtr; } michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: ReferencePtr mRefPtr; michael@0: FilterType mType; michael@0: michael@0: RecordedFilterNodeCreation(std::istream &aStream); michael@0: }; michael@0: michael@0: class RecordedFilterNodeDestruction : public RecordedEvent { michael@0: public: michael@0: RecordedFilterNodeDestruction(ReferencePtr aRefPtr) michael@0: : RecordedEvent(FILTERNODEDESTRUCTION), mRefPtr(aRefPtr) michael@0: { michael@0: } michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "FilterNode Destruction"; } michael@0: virtual ReferencePtr GetObjectRef() const { return mRefPtr; } michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: ReferencePtr mRefPtr; michael@0: michael@0: RecordedFilterNodeDestruction(std::istream &aStream); michael@0: }; michael@0: michael@0: class RecordedGradientStopsCreation : public RecordedEvent { michael@0: public: michael@0: RecordedGradientStopsCreation(ReferencePtr aRefPtr, GradientStop *aStops, michael@0: uint32_t aNumStops, ExtendMode aExtendMode) michael@0: : RecordedEvent(GRADIENTSTOPSCREATION), mRefPtr(aRefPtr), mStops(aStops) michael@0: , mNumStops(aNumStops), mExtendMode(aExtendMode), mDataOwned(false) michael@0: { michael@0: } michael@0: michael@0: ~RecordedGradientStopsCreation(); michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "GradientStops Creation"; } michael@0: virtual ReferencePtr GetObjectRef() const { return mRefPtr; } michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: ReferencePtr mRefPtr; michael@0: GradientStop *mStops; michael@0: uint32_t mNumStops; michael@0: ExtendMode mExtendMode; michael@0: bool mDataOwned; michael@0: michael@0: RecordedGradientStopsCreation(std::istream &aStream); michael@0: }; michael@0: michael@0: class RecordedGradientStopsDestruction : public RecordedEvent { michael@0: public: michael@0: RecordedGradientStopsDestruction(ReferencePtr aRefPtr) michael@0: : RecordedEvent(GRADIENTSTOPSDESTRUCTION), mRefPtr(aRefPtr) michael@0: { michael@0: } michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "GradientStops Destruction"; } michael@0: virtual ReferencePtr GetObjectRef() const { return mRefPtr; } michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: ReferencePtr mRefPtr; michael@0: michael@0: RecordedGradientStopsDestruction(std::istream &aStream); michael@0: }; michael@0: michael@0: class RecordedSnapshot : public RecordedEvent { michael@0: public: michael@0: RecordedSnapshot(ReferencePtr aRefPtr, DrawTarget *aDT) michael@0: : RecordedEvent(SNAPSHOT), mRefPtr(aRefPtr), mDT(aDT) michael@0: { michael@0: } michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "Snapshot"; } michael@0: virtual ReferencePtr GetObjectRef() const { return mRefPtr; } michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: ReferencePtr mRefPtr; michael@0: ReferencePtr mDT; michael@0: michael@0: RecordedSnapshot(std::istream &aStream); michael@0: }; michael@0: michael@0: class RecordedScaledFontCreation : public RecordedEvent { michael@0: public: michael@0: static void FontDataProc(const uint8_t *aData, uint32_t aSize, uint32_t aIndex, Float aGlyphSize, void* aBaton) michael@0: { michael@0: static_cast(aBaton)->SetFontData(aData, aSize, aIndex, aGlyphSize); michael@0: } michael@0: michael@0: RecordedScaledFontCreation(ReferencePtr aRefPtr, ScaledFont *aScaledFont) michael@0: : RecordedEvent(SCALEDFONTCREATION), mRefPtr(aRefPtr), mData(nullptr) michael@0: { michael@0: aScaledFont->GetFontFileData(&FontDataProc, this); michael@0: } michael@0: michael@0: ~RecordedScaledFontCreation(); michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "ScaledFont Creation"; } michael@0: virtual ReferencePtr GetObjectRef() const { return mRefPtr; } michael@0: michael@0: void SetFontData(const uint8_t *aData, uint32_t aSize, uint32_t aIndex, Float aGlyphSize); michael@0: michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: ReferencePtr mRefPtr; michael@0: uint8_t *mData; michael@0: uint32_t mSize; michael@0: Float mGlyphSize; michael@0: uint32_t mIndex; michael@0: michael@0: RecordedScaledFontCreation(std::istream &aStream); michael@0: }; michael@0: michael@0: class RecordedScaledFontDestruction : public RecordedEvent { michael@0: public: michael@0: RecordedScaledFontDestruction(ReferencePtr aRefPtr) michael@0: : RecordedEvent(SCALEDFONTDESTRUCTION), mRefPtr(aRefPtr) michael@0: { michael@0: } michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "ScaledFont Destruction"; } michael@0: virtual ReferencePtr GetObjectRef() const { return mRefPtr; } michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: ReferencePtr mRefPtr; michael@0: michael@0: RecordedScaledFontDestruction(std::istream &aStream); michael@0: }; michael@0: michael@0: class RecordedMaskSurface : public RecordedDrawingEvent { michael@0: public: michael@0: RecordedMaskSurface(DrawTarget *aDT, const Pattern &aPattern, ReferencePtr aRefMask, michael@0: const Point &aOffset, const DrawOptions &aOptions) michael@0: : RecordedDrawingEvent(MASKSURFACE, aDT), mRefMask(aRefMask), mOffset(aOffset) michael@0: , mOptions(aOptions) michael@0: { michael@0: StorePattern(mPattern, aPattern); michael@0: } michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "MaskSurface"; } michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: RecordedMaskSurface(std::istream &aStream); michael@0: michael@0: PatternStorage mPattern; michael@0: ReferencePtr mRefMask; michael@0: Point mOffset; michael@0: DrawOptions mOptions; michael@0: }; michael@0: michael@0: class RecordedFilterNodeSetAttribute : public RecordedEvent michael@0: { michael@0: public: michael@0: enum ArgType { michael@0: ARGTYPE_UINT32, michael@0: ARGTYPE_BOOL, michael@0: ARGTYPE_FLOAT, michael@0: ARGTYPE_SIZE, michael@0: ARGTYPE_INTSIZE, michael@0: ARGTYPE_INTPOINT, michael@0: ARGTYPE_RECT, michael@0: ARGTYPE_INTRECT, michael@0: ARGTYPE_POINT, michael@0: ARGTYPE_MATRIX5X4, michael@0: ARGTYPE_POINT3D, michael@0: ARGTYPE_COLOR, michael@0: ARGTYPE_FLOAT_ARRAY michael@0: }; michael@0: michael@0: template michael@0: RecordedFilterNodeSetAttribute(FilterNode *aNode, uint32_t aIndex, T aArgument, ArgType aArgType) michael@0: : RecordedEvent(FILTERNODESETATTRIBUTE), mNode(aNode), mIndex(aIndex), mArgType(aArgType) michael@0: { michael@0: mPayload.resize(sizeof(T)); michael@0: memcpy(&mPayload.front(), &aArgument, sizeof(T)); michael@0: } michael@0: michael@0: RecordedFilterNodeSetAttribute(FilterNode *aNode, uint32_t aIndex, const Float *aFloat, uint32_t aSize) michael@0: : RecordedEvent(FILTERNODESETATTRIBUTE), mNode(aNode), mIndex(aIndex), mArgType(ARGTYPE_FLOAT_ARRAY) michael@0: { michael@0: mPayload.resize(sizeof(Float) * aSize); michael@0: memcpy(&mPayload.front(), aFloat, sizeof(Float) * aSize); michael@0: } michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "SetAttribute"; } michael@0: michael@0: virtual ReferencePtr GetObjectRef() const { return mNode; } michael@0: michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: ReferencePtr mNode; michael@0: michael@0: uint32_t mIndex; michael@0: ArgType mArgType; michael@0: std::vector mPayload; michael@0: michael@0: RecordedFilterNodeSetAttribute(std::istream &aStream); michael@0: }; michael@0: michael@0: class RecordedFilterNodeSetInput : public RecordedEvent michael@0: { michael@0: public: michael@0: RecordedFilterNodeSetInput(FilterNode* aNode, uint32_t aIndex, FilterNode* aInputNode) michael@0: : RecordedEvent(FILTERNODESETINPUT), mNode(aNode), mIndex(aIndex) michael@0: , mInputFilter(aInputNode), mInputSurface(nullptr) michael@0: { michael@0: } michael@0: michael@0: RecordedFilterNodeSetInput(FilterNode *aNode, uint32_t aIndex, SourceSurface *aInputSurface) michael@0: : RecordedEvent(FILTERNODESETINPUT), mNode(aNode), mIndex(aIndex) michael@0: , mInputFilter(nullptr), mInputSurface(aInputSurface) michael@0: { michael@0: } michael@0: michael@0: virtual void PlayEvent(Translator *aTranslator) const; michael@0: virtual void RecordToStream(std::ostream &aStream) const; michael@0: virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const; michael@0: michael@0: virtual std::string GetName() const { return "SetInput"; } michael@0: michael@0: virtual ReferencePtr GetObjectRef() const { return mNode; } michael@0: michael@0: private: michael@0: friend class RecordedEvent; michael@0: michael@0: ReferencePtr mNode; michael@0: uint32_t mIndex; michael@0: ReferencePtr mInputFilter; michael@0: ReferencePtr mInputSurface; michael@0: michael@0: RecordedFilterNodeSetInput(std::istream &aStream); michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif