Bug 1156742 Part 12: Record CreateSimilarDrawTarget separately for Moz2D. r=bas

This is so we can create the real print DrawTarget from our nsDeviceContext at the beginning of each page.
Default behaviour for other Translators is still to always use CreateSimilarDrawTarget.
This commit is contained in:
Bob Owen 2016-01-05 10:08:57 +00:00
parent ffbb94296a
commit e707786501
4 changed files with 100 additions and 6 deletions

View File

@ -297,6 +297,16 @@ DrawTargetRecording::DrawTargetRecording(DrawEventRecorder *aRecorder, DrawTarge
mFormat = mFinalDT->GetFormat();
}
DrawTargetRecording::DrawTargetRecording(const DrawTargetRecording *aDT,
const IntSize &aSize,
SurfaceFormat aFormat)
: mRecorder(aDT->mRecorder)
, mFinalDT(aDT->mFinalDT->CreateSimilarDrawTarget(aSize, aFormat))
{
mRecorder->RecordEvent(RecordedCreateSimilarDrawTarget(this, aSize, aFormat));
mFormat = mFinalDT->GetFormat();
}
DrawTargetRecording::~DrawTargetRecording()
{
mRecorder->RecordEvent(RecordedDrawTargetDestruction(this));
@ -589,8 +599,7 @@ DrawTargetRecording::CreateSourceSurfaceFromNativeSurface(const NativeSurface &a
already_AddRefed<DrawTarget>
DrawTargetRecording::CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const
{
RefPtr<DrawTarget> dt = mFinalDT->CreateSimilarDrawTarget(aSize, aFormat);
return MakeAndAddRef<DrawTargetRecording>(mRecorder.get(), dt);
return MakeAndAddRef<DrawTargetRecording>(this, aSize, aFormat);
}
already_AddRefed<PathBuilder>

View File

@ -18,6 +18,17 @@ class DrawTargetRecording : public DrawTarget
public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTargetRecording, override)
DrawTargetRecording(DrawEventRecorder *aRecorder, DrawTarget *aDT, bool aHasData = false);
/**
* Used for creating a DrawTargetRecording for a CreateSimilarDrawTarget call.
*
* @param aDT DrawTargetRecording on which CreateSimilarDrawTarget was called
* @param aSize size for the similar DrawTarget
* @param aFormat format for the similar DrawTarget
*/
DrawTargetRecording(const DrawTargetRecording *aDT, const IntSize &aSize,
SurfaceFormat aFormat);
~DrawTargetRecording();
virtual DrawTargetType GetType() const override { return mFinalDT->GetType(); }

View File

@ -28,6 +28,16 @@ static std::string NameFromBackend(BackendType aType)
}
}
already_AddRefed<DrawTarget>
Translator::CreateDrawTarget(ReferencePtr aRefPtr, const IntSize &aSize,
SurfaceFormat aFormat)
{
RefPtr<DrawTarget> newDT =
GetReferenceDrawTarget()->CreateSimilarDrawTarget(aSize, aFormat);
AddDrawTarget(aRefPtr, newDT);
return newDT.forget();
}
#define LOAD_EVENT_TYPE(_typeenum, _class) \
case _typeenum: return new _class(aStream)
@ -67,6 +77,7 @@ RecordedEvent::LoadEventFromStream(std::istream &aStream, EventType aType)
LOAD_EVENT_TYPE(MASKSURFACE, RecordedMaskSurface);
LOAD_EVENT_TYPE(FILTERNODESETATTRIBUTE, RecordedFilterNodeSetAttribute);
LOAD_EVENT_TYPE(FILTERNODESETINPUT, RecordedFilterNodeSetInput);
LOAD_EVENT_TYPE(CREATESIMILARDRAWTARGET, RecordedCreateSimilarDrawTarget);
default:
return nullptr;
}
@ -140,6 +151,8 @@ RecordedEvent::GetEventName(EventType aType)
return "SetAttribute";
case FILTERNODESETINPUT:
return "SetInput";
case CREATESIMILARDRAWTARGET:
return "CreateSimilarDrawTarget";
default:
return "Unknown";
}
@ -367,10 +380,9 @@ void
RecordedDrawTargetCreation::PlayEvent(Translator *aTranslator) const
{
RefPtr<DrawTarget> newDT =
aTranslator->GetReferenceDrawTarget()->CreateSimilarDrawTarget(mSize, mFormat);
aTranslator->AddDrawTarget(mRefPtr, newDT);
aTranslator->CreateDrawTarget(mRefPtr, mSize, mFormat);
if (mHasExistingData) {
if (newDT && mHasExistingData) {
Rect dataRect(0, 0, mExistingData->GetSize().width, mExistingData->GetSize().height);
newDT->DrawSurface(mExistingData, dataRect, dataRect);
}
@ -453,6 +465,36 @@ RecordedDrawTargetDestruction::OutputSimpleEventInfo(stringstream &aStringStream
aStringStream << "[" << mRefPtr << "] DrawTarget Destruction";
}
void
RecordedCreateSimilarDrawTarget::PlayEvent(Translator *aTranslator) const
{
RefPtr<DrawTarget> newDT =
aTranslator->GetReferenceDrawTarget()->CreateSimilarDrawTarget(mSize, mFormat);
aTranslator->AddDrawTarget(mRefPtr, newDT);
}
void
RecordedCreateSimilarDrawTarget::RecordToStream(ostream &aStream) const
{
WriteElement(aStream, mRefPtr);
WriteElement(aStream, mSize);
WriteElement(aStream, mFormat);
}
RecordedCreateSimilarDrawTarget::RecordedCreateSimilarDrawTarget(istream &aStream)
: RecordedEvent(CREATESIMILARDRAWTARGET)
{
ReadElement(aStream, mRefPtr);
ReadElement(aStream, mSize);
ReadElement(aStream, mFormat);
}
void
RecordedCreateSimilarDrawTarget::OutputSimpleEventInfo(stringstream &aStringStream) const
{
aStringStream << "[" << mRefPtr << "] CreateSimilarDrawTarget (Size: " << mSize.width << "x" << mSize.height << ")";
}
struct GenericPattern
{
GenericPattern(const PatternStorage &aStorage, Translator *aTranslator)

View File

@ -92,6 +92,9 @@ public:
virtual void AddScaledFont(ReferencePtr aRefPtr, ScaledFont *aScaledFont) = 0;
virtual void RemoveScaledFont(ReferencePtr aRefPtr) = 0;
virtual already_AddRefed<DrawTarget> CreateDrawTarget(ReferencePtr aRefPtr,
const IntSize &aSize,
SurfaceFormat aFormat);
virtual DrawTarget *GetReferenceDrawTarget() = 0;
virtual FontType GetDesiredFontType() = 0;
};
@ -173,7 +176,8 @@ public:
FILTERNODEDESTRUCTION,
DRAWFILTER,
FILTERNODESETATTRIBUTE,
FILTERNODESETINPUT
FILTERNODESETINPUT,
CREATESIMILARDRAWTARGET
};
static const uint32_t kTotalEventTypes = RecordedEvent::FILTERNODESETINPUT + 1;
@ -283,6 +287,34 @@ private:
MOZ_IMPLICIT RecordedDrawTargetDestruction(std::istream &aStream);
};
class RecordedCreateSimilarDrawTarget : public RecordedEvent
{
public:
RecordedCreateSimilarDrawTarget(ReferencePtr aRefPtr, const IntSize &aSize,
SurfaceFormat aFormat)
: RecordedEvent(CREATESIMILARDRAWTARGET)
, mRefPtr(aRefPtr) , mSize(aSize), mFormat(aFormat)
{
}
virtual void PlayEvent(Translator *aTranslator) const;
virtual void RecordToStream(std::ostream &aStream) const;
virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
virtual std::string GetName() const { return "CreateSimilarDrawTarget"; }
virtual ReferencePtr GetObjectRef() const { return mRefPtr; }
ReferencePtr mRefPtr;
IntSize mSize;
SurfaceFormat mFormat;
private:
friend class RecordedEvent;
MOZ_IMPLICIT RecordedCreateSimilarDrawTarget(std::istream &aStream);
};
class RecordedFillRect : public RecordedDrawingEvent {
public:
RecordedFillRect(DrawTarget *aDT, const Rect &aRect, const Pattern &aPattern, const DrawOptions &aOptions)