2012-09-24 19:02:50 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef MOZILLA_GFX_RECORDEDEVENT_H_
|
|
|
|
#define MOZILLA_GFX_RECORDEDEVENT_H_
|
|
|
|
|
|
|
|
#include "2D.h"
|
|
|
|
#include <ostream>
|
|
|
|
#include <sstream>
|
2012-10-07 00:59:01 +04:00
|
|
|
#include <cstring>
|
2016-01-05 13:08:57 +03:00
|
|
|
#include <vector>
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
2016-01-05 13:08:57 +03:00
|
|
|
struct PathOp;
|
|
|
|
class PathRecording;
|
|
|
|
|
2016-01-05 13:08:57 +03:00
|
|
|
const uint32_t kMagicInt = 0xc001feed;
|
|
|
|
|
2012-09-24 19:02:50 +04:00
|
|
|
// A change in major revision means a change in event binary format, causing
|
|
|
|
// loss of backwards compatibility. Old streams will not work in a player
|
|
|
|
// using a newer major revision. And new streams will not work in a player
|
|
|
|
// using an older major revision.
|
2017-06-30 21:09:05 +03:00
|
|
|
const uint16_t kMajorRevision = 10;
|
2012-09-24 19:02:50 +04:00
|
|
|
// A change in minor revision means additions of new events. New streams will
|
|
|
|
// not play in older players.
|
2016-11-15 14:09:51 +03:00
|
|
|
const uint16_t kMinorRevision = 0;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
struct ReferencePtr
|
|
|
|
{
|
|
|
|
ReferencePtr()
|
|
|
|
: mLongPtr(0)
|
|
|
|
{}
|
|
|
|
|
2014-08-08 05:17:30 +04:00
|
|
|
MOZ_IMPLICIT ReferencePtr(const void* aLongPtr)
|
2012-09-24 19:02:50 +04:00
|
|
|
: mLongPtr(uint64_t(aLongPtr))
|
|
|
|
{}
|
|
|
|
|
|
|
|
template <typename T>
|
2015-10-18 08:24:48 +03:00
|
|
|
MOZ_IMPLICIT ReferencePtr(const RefPtr<T>& aPtr)
|
2012-09-24 19:02:50 +04:00
|
|
|
: mLongPtr(uint64_t(aPtr.get()))
|
|
|
|
{}
|
|
|
|
|
|
|
|
ReferencePtr &operator =(const void* aLongPtr) {
|
|
|
|
mLongPtr = uint64_t(aLongPtr);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2015-10-18 08:24:48 +03:00
|
|
|
ReferencePtr &operator =(const RefPtr<T>& aPtr) {
|
2012-09-24 19:02:50 +04:00
|
|
|
mLongPtr = uint64_t(aPtr.get());
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator void*() const {
|
|
|
|
return (void*)mLongPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t mLongPtr;
|
|
|
|
};
|
|
|
|
|
2016-01-05 13:08:58 +03:00
|
|
|
struct RecordedFontDetails
|
|
|
|
{
|
|
|
|
uint64_t fontDataKey;
|
|
|
|
uint32_t size;
|
|
|
|
uint32_t index;
|
|
|
|
};
|
|
|
|
|
2012-10-30 03:15:31 +04:00
|
|
|
// Used by the Azure drawing debugger (player2d)
|
|
|
|
inline std::string StringFromPtr(ReferencePtr aPtr)
|
2012-09-24 19:02:50 +04:00
|
|
|
{
|
|
|
|
std::stringstream stream;
|
|
|
|
stream << aPtr;
|
|
|
|
return stream.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
class Translator
|
|
|
|
{
|
|
|
|
public:
|
2013-11-27 15:25:28 +04:00
|
|
|
virtual ~Translator() {}
|
|
|
|
|
2012-09-24 19:02:50 +04:00
|
|
|
virtual DrawTarget *LookupDrawTarget(ReferencePtr aRefPtr) = 0;
|
|
|
|
virtual Path *LookupPath(ReferencePtr aRefPtr) = 0;
|
|
|
|
virtual SourceSurface *LookupSourceSurface(ReferencePtr aRefPtr) = 0;
|
2013-11-27 15:25:28 +04:00
|
|
|
virtual FilterNode *LookupFilterNode(ReferencePtr aRefPtr) = 0;
|
2012-09-24 19:02:50 +04:00
|
|
|
virtual GradientStops *LookupGradientStops(ReferencePtr aRefPtr) = 0;
|
|
|
|
virtual ScaledFont *LookupScaledFont(ReferencePtr aRefPtr) = 0;
|
2017-04-14 21:11:00 +03:00
|
|
|
virtual UnscaledFont* LookupUnscaledFont(ReferencePtr aRefPtr) = 0;
|
2017-10-28 01:21:26 +03:00
|
|
|
virtual UnscaledFont* LookupUnscaledFontByIndex(size_t aIndex) { return nullptr; }
|
2016-01-05 13:08:58 +03:00
|
|
|
virtual NativeFontResource *LookupNativeFontResource(uint64_t aKey) = 0;
|
2012-09-24 19:02:50 +04:00
|
|
|
virtual void AddDrawTarget(ReferencePtr aRefPtr, DrawTarget *aDT) = 0;
|
|
|
|
virtual void RemoveDrawTarget(ReferencePtr aRefPtr) = 0;
|
|
|
|
virtual void AddPath(ReferencePtr aRefPtr, Path *aPath) = 0;
|
|
|
|
virtual void RemovePath(ReferencePtr aRefPtr) = 0;
|
|
|
|
virtual void AddSourceSurface(ReferencePtr aRefPtr, SourceSurface *aPath) = 0;
|
|
|
|
virtual void RemoveSourceSurface(ReferencePtr aRefPtr) = 0;
|
2013-11-27 15:25:28 +04:00
|
|
|
virtual void AddFilterNode(mozilla::gfx::ReferencePtr aRefPtr, FilterNode *aSurface) = 0;
|
|
|
|
virtual void RemoveFilterNode(mozilla::gfx::ReferencePtr aRefPtr) = 0;
|
2012-09-24 19:02:50 +04:00
|
|
|
virtual void AddGradientStops(ReferencePtr aRefPtr, GradientStops *aPath) = 0;
|
|
|
|
virtual void RemoveGradientStops(ReferencePtr aRefPtr) = 0;
|
|
|
|
virtual void AddScaledFont(ReferencePtr aRefPtr, ScaledFont *aScaledFont) = 0;
|
|
|
|
virtual void RemoveScaledFont(ReferencePtr aRefPtr) = 0;
|
2017-04-14 21:11:00 +03:00
|
|
|
virtual void AddUnscaledFont(ReferencePtr aRefPtr, UnscaledFont* aUnscaledFont) = 0;
|
|
|
|
virtual void RemoveUnscaledFont(ReferencePtr aRefPtr) = 0;
|
2016-01-05 13:08:58 +03:00
|
|
|
virtual void AddNativeFontResource(uint64_t aKey,
|
|
|
|
NativeFontResource *aNativeFontResource) = 0;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
2016-01-05 13:08:57 +03:00
|
|
|
virtual already_AddRefed<DrawTarget> CreateDrawTarget(ReferencePtr aRefPtr,
|
|
|
|
const IntSize &aSize,
|
|
|
|
SurfaceFormat aFormat);
|
2012-09-24 19:02:50 +04:00
|
|
|
virtual DrawTarget *GetReferenceDrawTarget() = 0;
|
2017-05-18 04:56:58 +03:00
|
|
|
virtual void* GetFontContext() { return nullptr; }
|
2012-09-24 19:02:50 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ColorPatternStorage
|
|
|
|
{
|
|
|
|
Color mColor;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LinearGradientPatternStorage
|
|
|
|
{
|
|
|
|
Point mBegin;
|
|
|
|
Point mEnd;
|
|
|
|
ReferencePtr mStops;
|
|
|
|
Matrix mMatrix;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RadialGradientPatternStorage
|
|
|
|
{
|
|
|
|
Point mCenter1;
|
|
|
|
Point mCenter2;
|
|
|
|
Float mRadius1;
|
|
|
|
Float mRadius2;
|
|
|
|
ReferencePtr mStops;
|
|
|
|
Matrix mMatrix;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SurfacePatternStorage
|
|
|
|
{
|
|
|
|
ExtendMode mExtend;
|
2016-05-25 19:01:18 +03:00
|
|
|
SamplingFilter mSamplingFilter;
|
2012-09-24 19:02:50 +04:00
|
|
|
ReferencePtr mSurface;
|
|
|
|
Matrix mMatrix;
|
2016-11-15 14:09:51 +03:00
|
|
|
IntRect mSamplingRect;
|
2012-09-24 19:02:50 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PatternStorage
|
|
|
|
{
|
|
|
|
PatternType mType;
|
|
|
|
union {
|
|
|
|
char *mStorage;
|
|
|
|
char mColor[sizeof(ColorPatternStorage)];
|
|
|
|
char mLinear[sizeof(LinearGradientPatternStorage)];
|
|
|
|
char mRadial[sizeof(RadialGradientPatternStorage)];
|
|
|
|
char mSurface[sizeof(SurfacePatternStorage)];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-06-22 20:39:27 +03:00
|
|
|
|
|
|
|
/* SizeCollector and MemWriter are used
|
|
|
|
* in a pair to first collect the size of the
|
|
|
|
* event that we're going to write and then
|
|
|
|
* to write it without checking each individual
|
|
|
|
* size. */
|
|
|
|
struct SizeCollector {
|
|
|
|
SizeCollector() : mTotalSize(0) {}
|
|
|
|
void write(const char*, size_t s) {
|
|
|
|
mTotalSize += s;
|
|
|
|
}
|
|
|
|
size_t mTotalSize;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MemWriter {
|
|
|
|
explicit MemWriter(char* aPtr) : mPtr(aPtr) {}
|
|
|
|
void write(const char* aData, size_t aSize) {
|
|
|
|
memcpy(mPtr, aData, aSize);
|
|
|
|
mPtr += aSize;
|
|
|
|
}
|
|
|
|
char* mPtr;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MemStream {
|
|
|
|
char *mData;
|
|
|
|
size_t mLength;
|
|
|
|
size_t mCapacity;
|
|
|
|
void Resize(size_t aSize) {
|
|
|
|
mLength = aSize;
|
|
|
|
if (mLength > mCapacity) {
|
|
|
|
mCapacity = mCapacity * 2;
|
|
|
|
// check if the doubled capacity is enough
|
|
|
|
// otherwise use mLength
|
|
|
|
if (mLength > mCapacity) {
|
|
|
|
mCapacity = mLength;
|
|
|
|
}
|
|
|
|
mData = (char*)realloc(mData, mCapacity * 2);
|
|
|
|
}
|
|
|
|
}
|
2017-06-22 20:39:28 +03:00
|
|
|
|
|
|
|
void write(const char* aData, size_t aSize) {
|
|
|
|
Resize(mLength + aSize);
|
|
|
|
memcpy(mData + mLength - aSize, aData, aSize);
|
|
|
|
}
|
|
|
|
|
2017-06-22 20:39:27 +03:00
|
|
|
MemStream() : mData(nullptr), mLength(0), mCapacity(0) {}
|
|
|
|
~MemStream() { free(mData); }
|
2017-06-22 20:39:27 +03:00
|
|
|
};
|
|
|
|
|
2017-10-03 19:29:15 +03:00
|
|
|
class EventStream {
|
|
|
|
public:
|
|
|
|
virtual void write(const char* aData, size_t aSize) = 0;
|
2017-10-03 20:23:57 +03:00
|
|
|
virtual void read(char* aOut, size_t aSize) = 0;
|
2017-10-03 19:29:15 +03:00
|
|
|
};
|
|
|
|
|
2012-09-24 19:02:50 +04:00
|
|
|
class RecordedEvent {
|
|
|
|
public:
|
|
|
|
enum EventType {
|
|
|
|
DRAWTARGETCREATION = 0,
|
|
|
|
DRAWTARGETDESTRUCTION,
|
|
|
|
FILLRECT,
|
|
|
|
STROKERECT,
|
|
|
|
STROKELINE,
|
|
|
|
CLEARRECT,
|
|
|
|
COPYSURFACE,
|
|
|
|
SETTRANSFORM,
|
|
|
|
PUSHCLIP,
|
|
|
|
PUSHCLIPRECT,
|
|
|
|
POPCLIP,
|
|
|
|
FILL,
|
|
|
|
FILLGLYPHS,
|
|
|
|
MASK,
|
|
|
|
STROKE,
|
|
|
|
DRAWSURFACE,
|
|
|
|
DRAWSURFACEWITHSHADOW,
|
|
|
|
PATHCREATION,
|
|
|
|
PATHDESTRUCTION,
|
|
|
|
SOURCESURFACECREATION,
|
|
|
|
SOURCESURFACEDESTRUCTION,
|
|
|
|
GRADIENTSTOPSCREATION,
|
|
|
|
GRADIENTSTOPSDESTRUCTION,
|
|
|
|
SNAPSHOT,
|
|
|
|
SCALEDFONTCREATION,
|
2017-10-28 01:21:26 +03:00
|
|
|
SCALEDFONTCREATIONBYINDEX,
|
2013-06-28 00:20:30 +04:00
|
|
|
SCALEDFONTDESTRUCTION,
|
2013-11-27 15:25:28 +04:00
|
|
|
MASKSURFACE,
|
|
|
|
FILTERNODECREATION,
|
|
|
|
FILTERNODEDESTRUCTION,
|
|
|
|
DRAWFILTER,
|
|
|
|
FILTERNODESETATTRIBUTE,
|
2016-01-05 13:08:57 +03:00
|
|
|
FILTERNODESETINPUT,
|
2016-01-05 13:08:58 +03:00
|
|
|
CREATESIMILARDRAWTARGET,
|
|
|
|
FONTDATA,
|
2016-04-22 15:23:25 +03:00
|
|
|
FONTDESC,
|
2016-01-26 13:03:07 +03:00
|
|
|
PUSHLAYER,
|
|
|
|
POPLAYER,
|
2017-04-14 21:11:00 +03:00
|
|
|
UNSCALEDFONTCREATION,
|
|
|
|
UNSCALEDFONTDESTRUCTION,
|
2012-09-24 19:02:50 +04:00
|
|
|
};
|
2013-11-27 15:25:28 +04:00
|
|
|
static const uint32_t kTotalEventTypes = RecordedEvent::FILTERNODESETINPUT + 1;
|
2013-11-27 15:21:49 +04:00
|
|
|
|
2016-01-05 13:08:57 +03:00
|
|
|
virtual ~RecordedEvent() {}
|
|
|
|
|
2013-11-27 15:21:49 +04:00
|
|
|
static std::string GetEventName(EventType aType);
|
|
|
|
|
2016-07-18 14:13:04 +03:00
|
|
|
/**
|
|
|
|
* Play back this event using the translator. Note that derived classes should
|
|
|
|
* only return false when there is a fatal error, as it will probably mean the
|
|
|
|
* translation will abort.
|
|
|
|
* @param aTranslator Translator to be used for retrieving other referenced
|
|
|
|
* objects and making playback decisions.
|
|
|
|
* @return true unless a fatal problem has occurred and playback should abort.
|
|
|
|
*/
|
|
|
|
virtual bool PlayEvent(Translator *aTranslator) const { return true; }
|
2012-09-24 19:02:50 +04:00
|
|
|
|
2017-10-03 19:29:15 +03:00
|
|
|
virtual void RecordToStream(std::ostream& aStream) const = 0;
|
|
|
|
virtual void RecordToStream(EventStream& aStream) const = 0;
|
|
|
|
virtual void RecordToStream(MemStream& aStream) const = 0;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const { }
|
|
|
|
|
2017-06-22 20:39:27 +03:00
|
|
|
template<class S>
|
|
|
|
void RecordPatternData(S &aStream, const PatternStorage &aPatternStorage) const;
|
2017-07-04 22:36:05 +03:00
|
|
|
template<class S>
|
|
|
|
void ReadPatternData(S &aStream, PatternStorage &aPatternStorage) const;
|
2012-09-24 19:02:50 +04:00
|
|
|
void StorePattern(PatternStorage &aDestination, const Pattern &aSource) const;
|
2017-06-22 20:39:27 +03:00
|
|
|
template<class S>
|
|
|
|
void RecordStrokeOptions(S &aStream, const StrokeOptions &aStrokeOptions) const;
|
2017-07-04 22:36:05 +03:00
|
|
|
template<class S>
|
|
|
|
void ReadStrokeOptions(S &aStream, StrokeOptions &aStrokeOptions);
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
virtual std::string GetName() const = 0;
|
|
|
|
|
2013-11-19 01:45:14 +04:00
|
|
|
virtual ReferencePtr GetObjectRef() const = 0;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
virtual ReferencePtr GetDestinedDT() { return nullptr; }
|
|
|
|
|
|
|
|
void OutputSimplePatternInfo(const PatternStorage &aStorage, std::stringstream &aOutput) const;
|
|
|
|
|
2017-07-04 18:53:35 +03:00
|
|
|
template<class S>
|
|
|
|
static RecordedEvent *LoadEvent(S &aStream, EventType aType);
|
2012-09-24 19:02:50 +04:00
|
|
|
static RecordedEvent *LoadEventFromStream(std::istream &aStream, EventType aType);
|
2017-10-03 20:23:57 +03:00
|
|
|
static RecordedEvent *LoadEventFromStream(EventStream& aStream, EventType aType);
|
2012-09-24 19:02:50 +04:00
|
|
|
|
2017-08-18 20:03:09 +03:00
|
|
|
// An alternative to LoadEvent that avoids a heap allocation for the event.
|
|
|
|
// This accepts a callable `f' that will take a RecordedEvent* as a single parameter
|
|
|
|
template<class S, class F>
|
|
|
|
static bool DoWithEvent(S &aStream, EventType aType, F f);
|
|
|
|
|
2017-10-03 19:29:15 +03:00
|
|
|
EventType GetType() const { return (EventType)mType; }
|
2012-09-24 19:02:50 +04:00
|
|
|
protected:
|
|
|
|
friend class DrawEventRecorderPrivate;
|
2017-06-22 20:39:28 +03:00
|
|
|
friend class DrawEventRecorderFile;
|
|
|
|
friend class DrawEventRecorderMemory;
|
2012-09-24 19:02:50 +04:00
|
|
|
|
2014-08-08 05:17:30 +04:00
|
|
|
MOZ_IMPLICIT RecordedEvent(int32_t aType) : mType(aType)
|
2012-09-24 19:02:50 +04:00
|
|
|
{}
|
|
|
|
|
|
|
|
int32_t mType;
|
|
|
|
std::vector<Float> mDashPatternStorage;
|
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
2012-09-24 19:02:50 +04:00
|
|
|
|
|
|
|
#endif
|