1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "RecordedEventImpl.h"
9 #include "PathRecording.h"
10 #include "RecordingTypes.h"
14 #include "ScaledFontBase.h"
16 #include "InlineTranslator.h"
22 bool RecordedEvent::DoWithEventFromStream(
23 EventStream
& aStream
, EventType aType
,
24 const std::function
<bool(RecordedEvent
*)>& aAction
) {
25 return DoWithEvent(aStream
, aType
, aAction
);
29 bool RecordedEvent::DoWithEventFromReader(
30 MemReader
& aReader
, EventType aType
,
31 const std::function
<bool(RecordedEvent
*)>& aAction
) {
32 return DoWithEvent(aReader
, aType
, aAction
);
35 std::string
RecordedEvent::GetEventName(EventType aType
) {
37 case DRAWTARGETCREATION
:
38 return "DrawTarget Creation";
39 case DRAWTARGETDESTRUCTION
:
40 return "DrawTarget Destruction";
51 case SETPERMITSUBPIXELAA
:
52 return "SetPermitSubpixelAA";
54 return "SetTransform";
58 return "PushClipRect";
66 return "StrokeGlyphs";
73 case DRAWSURFACEDESCRIPTOR
:
74 return "DrawSurfaceDescriptor";
75 case DRAWDEPENDENTSURFACE
:
76 return "DrawDependentSurface";
77 case DRAWSURFACEWITHSHADOW
:
78 return "DrawSurfaceWithShadow";
82 return "PathCreation";
84 return "PathDestruction";
85 case SOURCESURFACECREATION
:
86 return "SourceSurfaceCreation";
87 case SOURCESURFACEDESTRUCTION
:
88 return "SourceSurfaceDestruction";
89 case FILTERNODECREATION
:
90 return "FilterNodeCreation";
91 case FILTERNODEDESTRUCTION
:
92 return "FilterNodeDestruction";
93 case GRADIENTSTOPSCREATION
:
94 return "GradientStopsCreation";
95 case GRADIENTSTOPSDESTRUCTION
:
96 return "GradientStopsDestruction";
99 case SCALEDFONTCREATION
:
100 return "ScaledFontCreation";
101 case SCALEDFONTDESTRUCTION
:
102 return "ScaledFontDestruction";
104 return "MaskSurface";
105 case FILTERNODESETATTRIBUTE
:
106 return "SetAttribute";
107 case FILTERNODESETINPUT
:
109 case CREATESIMILARDRAWTARGET
:
110 return "CreateSimilarDrawTarget";
114 return "FontDescriptor";
119 case UNSCALEDFONTCREATION
:
120 return "UnscaledFontCreation";
121 case UNSCALEDFONTDESTRUCTION
:
122 return "UnscaledFontDestruction";
123 case EXTERNALSURFACECREATION
:
124 return "ExternalSourceSurfaceCreation";
128 return "Destination";
135 void RecordedEvent::RecordUnscaledFontImpl(UnscaledFont
* aUnscaledFont
,
137 RecordedFontData
fontData(aUnscaledFont
);
138 RecordedFontDetails fontDetails
;
139 if (fontData
.GetFontDetails(fontDetails
)) {
140 // Try to serialise the whole font, just in case this is a web font that
141 // is not present on the system.
142 WriteElement(aOutput
, fontData
.mType
);
143 fontData
.RecordToStream(aOutput
);
145 auto r
= RecordedUnscaledFontCreation(aUnscaledFont
, fontDetails
);
146 WriteElement(aOutput
, r
.mType
);
147 r
.RecordToStream(aOutput
);
149 // If that fails, record just the font description and try to load it from
150 // the system on the other side.
151 RecordedFontDescriptor
fontDesc(aUnscaledFont
);
152 if (fontDesc
.IsValid()) {
153 WriteElement(aOutput
, fontDesc
.RecordedEvent::mType
);
154 fontDesc
.RecordToStream(aOutput
);
157 << "DrawTargetRecording::FillGlyphs failed to serialise UnscaledFont";
162 void RecordedEvent::RecordUnscaledFont(UnscaledFont
* aUnscaledFont
,
163 std::ostream
* aOutput
) {
164 RecordUnscaledFontImpl(aUnscaledFont
, *aOutput
);
167 void RecordedEvent::RecordUnscaledFont(UnscaledFont
* aUnscaledFont
,
168 MemStream
& aOutput
) {
169 RecordUnscaledFontImpl(aUnscaledFont
, aOutput
);
172 already_AddRefed
<DrawTarget
> Translator::CreateDrawTarget(
173 ReferencePtr aRefPtr
, const IntSize
& aSize
, SurfaceFormat aFormat
) {
174 RefPtr
<DrawTarget
> newDT
=
175 GetReferenceDrawTarget()->CreateSimilarDrawTarget(aSize
, aFormat
);
176 AddDrawTarget(aRefPtr
, newDT
);
177 return newDT
.forget();
180 void Translator::DrawDependentSurface(uint64_t aKey
, const Rect
& aRect
) {
181 if (!mDependentSurfaces
|| !mCurrentDT
) {
185 RefPtr
<RecordedDependentSurface
> recordedSurface
=
186 mDependentSurfaces
->Get(aKey
);
187 if (!recordedSurface
) {
191 // Construct a new translator, so we can recurse into translating this
192 // sub-recording into the same DT. Set an initial transform for the
193 // translator, so that all commands get moved into the rect we want to draw.
195 // Because the recording may have filtered out SetTransform calls with the
196 // same value, we need to call SetTransform here to ensure it gets called at
197 // least once with the translated matrix.
198 const Matrix oldTransform
= mCurrentDT
->GetTransform();
200 Matrix dependentTransform
= oldTransform
;
201 dependentTransform
.PreTranslate(aRect
.TopLeft());
203 mCurrentDT
->PushClipRect(aRect
);
204 mCurrentDT
->SetTransform(dependentTransform
);
207 InlineTranslator
translator(mCurrentDT
, nullptr);
208 translator
.SetReferenceDrawTargetTransform(dependentTransform
);
209 translator
.SetDependentSurfaces(mDependentSurfaces
);
210 translator
.TranslateRecording((char*)recordedSurface
->mRecording
.mData
,
211 recordedSurface
->mRecording
.mLen
);
214 mCurrentDT
->SetTransform(oldTransform
);
215 mCurrentDT
->PopClip();
219 } // namespace mozilla