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/. */
6
7 #include "RecordedEventImpl.h"
8
9 #include "PathRecording.h"
10 #include "RecordingTypes.h"
11 #include "Tools.h"
12 #include "Filters.h"
13 #include "Logging.h"
14 #include "ScaledFontBase.h"
15 #include "SFNTData.h"
16
17 namespace mozilla {
18 namespace gfx {
19
20 using namespace std;
21
LoadEventFromStream(std::istream & aStream,EventType aType)22 RecordedEvent *RecordedEvent::LoadEventFromStream(std::istream &aStream,
23 EventType aType) {
24 return LoadEvent(aStream, aType);
25 }
26
LoadEventFromStream(EventStream & aStream,EventType aType)27 RecordedEvent *RecordedEvent::LoadEventFromStream(EventStream &aStream,
28 EventType aType) {
29 return LoadEvent(aStream, aType);
30 }
31
GetEventName(EventType aType)32 string RecordedEvent::GetEventName(EventType aType) {
33 switch (aType) {
34 case DRAWTARGETCREATION:
35 return "DrawTarget Creation";
36 case DRAWTARGETDESTRUCTION:
37 return "DrawTarget Destruction";
38 case FILLRECT:
39 return "FillRect";
40 case STROKERECT:
41 return "StrokeRect";
42 case STROKELINE:
43 return "StrokeLine";
44 case CLEARRECT:
45 return "ClearRect";
46 case COPYSURFACE:
47 return "CopySurface";
48 case SETTRANSFORM:
49 return "SetTransform";
50 case PUSHCLIP:
51 return "PushClip";
52 case PUSHCLIPRECT:
53 return "PushClipRect";
54 case POPCLIP:
55 return "PopClip";
56 case FILL:
57 return "Fill";
58 case FILLGLYPHS:
59 return "FillGlyphs";
60 case MASK:
61 return "Mask";
62 case STROKE:
63 return "Stroke";
64 case DRAWSURFACE:
65 return "DrawSurface";
66 case DRAWSURFACEWITHSHADOW:
67 return "DrawSurfaceWithShadow";
68 case DRAWFILTER:
69 return "DrawFilter";
70 case PATHCREATION:
71 return "PathCreation";
72 case PATHDESTRUCTION:
73 return "PathDestruction";
74 case SOURCESURFACECREATION:
75 return "SourceSurfaceCreation";
76 case SOURCESURFACEDESTRUCTION:
77 return "SourceSurfaceDestruction";
78 case FILTERNODECREATION:
79 return "FilterNodeCreation";
80 case FILTERNODEDESTRUCTION:
81 return "FilterNodeDestruction";
82 case GRADIENTSTOPSCREATION:
83 return "GradientStopsCreation";
84 case GRADIENTSTOPSDESTRUCTION:
85 return "GradientStopsDestruction";
86 case SNAPSHOT:
87 return "Snapshot";
88 case SCALEDFONTCREATION:
89 return "ScaledFontCreation";
90 case SCALEDFONTCREATIONBYINDEX:
91 return "ScaledFontCreationByIndex";
92 case SCALEDFONTDESTRUCTION:
93 return "ScaledFontDestruction";
94 case MASKSURFACE:
95 return "MaskSurface";
96 case FILTERNODESETATTRIBUTE:
97 return "SetAttribute";
98 case FILTERNODESETINPUT:
99 return "SetInput";
100 case CREATESIMILARDRAWTARGET:
101 return "CreateSimilarDrawTarget";
102 case FONTDATA:
103 return "FontData";
104 case FONTDESC:
105 return "FontDescriptor";
106 case PUSHLAYER:
107 return "PushLayer";
108 case POPLAYER:
109 return "PopLayer";
110 case UNSCALEDFONTCREATION:
111 return "UnscaledFontCreation";
112 case UNSCALEDFONTDESTRUCTION:
113 return "UnscaledFontDestruction";
114 default:
115 return "Unknown";
116 }
117 }
118
119 template <class S>
RecordUnscaledFontImpl(UnscaledFont * aUnscaledFont,S & aOutput)120 void RecordedEvent::RecordUnscaledFontImpl(UnscaledFont *aUnscaledFont,
121 S &aOutput) {
122 RecordedFontData fontData(aUnscaledFont);
123 RecordedFontDetails fontDetails;
124 if (fontData.GetFontDetails(fontDetails)) {
125 // Try to serialise the whole font, just in case this is a web font that
126 // is not present on the system.
127 WriteElement(aOutput, fontData.mType);
128 fontData.RecordToStream(aOutput);
129
130 auto r = RecordedUnscaledFontCreation(aUnscaledFont, fontDetails);
131 WriteElement(aOutput, r.mType);
132 r.RecordToStream(aOutput);
133 } else {
134 // If that fails, record just the font description and try to load it from
135 // the system on the other side.
136 RecordedFontDescriptor fontDesc(aUnscaledFont);
137 if (fontDesc.IsValid()) {
138 WriteElement(aOutput, fontDesc.RecordedEvent::mType);
139 fontDesc.RecordToStream(aOutput);
140 } else {
141 gfxWarning()
142 << "DrawTargetRecording::FillGlyphs failed to serialise UnscaledFont";
143 }
144 }
145 }
146
RecordUnscaledFont(UnscaledFont * aUnscaledFont,std::ostream * aOutput)147 void RecordedEvent::RecordUnscaledFont(UnscaledFont *aUnscaledFont,
148 std::ostream *aOutput) {
149 RecordUnscaledFontImpl(aUnscaledFont, *aOutput);
150 }
151
RecordUnscaledFont(UnscaledFont * aUnscaledFont,MemStream & aOutput)152 void RecordedEvent::RecordUnscaledFont(UnscaledFont *aUnscaledFont,
153 MemStream &aOutput) {
154 RecordUnscaledFontImpl(aUnscaledFont, aOutput);
155 }
156
CreateDrawTarget(ReferencePtr aRefPtr,const IntSize & aSize,SurfaceFormat aFormat)157 already_AddRefed<DrawTarget> Translator::CreateDrawTarget(
158 ReferencePtr aRefPtr, const IntSize &aSize, SurfaceFormat aFormat) {
159 RefPtr<DrawTarget> newDT =
160 GetReferenceDrawTarget()->CreateSimilarDrawTarget(aSize, aFormat);
161 AddDrawTarget(aRefPtr, newDT);
162 return newDT.forget();
163 }
164
165 } // namespace gfx
166 } // namespace mozilla
167