no bug - Import translations from android-l10n r=release a=l10n CLOSED TREE
[gecko.git] / gfx / 2d / RecordedEvent.cpp
blob265ee1904b9e8d8e39579913e05a997cac202935
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"
11 #include "Tools.h"
12 #include "Filters.h"
13 #include "Logging.h"
14 #include "ScaledFontBase.h"
15 #include "SFNTData.h"
16 #include "InlineTranslator.h"
18 namespace mozilla {
19 namespace gfx {
21 /* static */
22 bool RecordedEvent::DoWithEventFromStream(
23 EventStream& aStream, EventType aType,
24 const std::function<bool(RecordedEvent*)>& aAction) {
25 return DoWithEvent(aStream, aType, aAction);
28 /* static */
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) {
36 switch (aType) {
37 case DRAWTARGETCREATION:
38 return "DrawTarget Creation";
39 case DRAWTARGETDESTRUCTION:
40 return "DrawTarget Destruction";
41 case FILLRECT:
42 return "FillRect";
43 case STROKERECT:
44 return "StrokeRect";
45 case STROKELINE:
46 return "StrokeLine";
47 case CLEARRECT:
48 return "ClearRect";
49 case COPYSURFACE:
50 return "CopySurface";
51 case SETPERMITSUBPIXELAA:
52 return "SetPermitSubpixelAA";
53 case SETTRANSFORM:
54 return "SetTransform";
55 case PUSHCLIP:
56 return "PushClip";
57 case PUSHCLIPRECT:
58 return "PushClipRect";
59 case POPCLIP:
60 return "PopClip";
61 case FILL:
62 return "Fill";
63 case FILLGLYPHS:
64 return "FillGlyphs";
65 case STROKEGLYPHS:
66 return "StrokeGlyphs";
67 case MASK:
68 return "Mask";
69 case STROKE:
70 return "Stroke";
71 case DRAWSURFACE:
72 return "DrawSurface";
73 case DRAWDEPENDENTSURFACE:
74 return "DrawDependentSurface";
75 case DRAWSURFACEWITHSHADOW:
76 return "DrawSurfaceWithShadow";
77 case DRAWFILTER:
78 return "DrawFilter";
79 case PATHCREATION:
80 return "PathCreation";
81 case PATHDESTRUCTION:
82 return "PathDestruction";
83 case SOURCESURFACECREATION:
84 return "SourceSurfaceCreation";
85 case SOURCESURFACEDESTRUCTION:
86 return "SourceSurfaceDestruction";
87 case FILTERNODECREATION:
88 return "FilterNodeCreation";
89 case FILTERNODEDESTRUCTION:
90 return "FilterNodeDestruction";
91 case GRADIENTSTOPSCREATION:
92 return "GradientStopsCreation";
93 case GRADIENTSTOPSDESTRUCTION:
94 return "GradientStopsDestruction";
95 case SNAPSHOT:
96 return "Snapshot";
97 case SCALEDFONTCREATION:
98 return "ScaledFontCreation";
99 case SCALEDFONTDESTRUCTION:
100 return "ScaledFontDestruction";
101 case MASKSURFACE:
102 return "MaskSurface";
103 case FILTERNODESETATTRIBUTE:
104 return "SetAttribute";
105 case FILTERNODESETINPUT:
106 return "SetInput";
107 case CREATESIMILARDRAWTARGET:
108 return "CreateSimilarDrawTarget";
109 case FONTDATA:
110 return "FontData";
111 case FONTDESC:
112 return "FontDescriptor";
113 case PUSHLAYER:
114 return "PushLayer";
115 case POPLAYER:
116 return "PopLayer";
117 case UNSCALEDFONTCREATION:
118 return "UnscaledFontCreation";
119 case UNSCALEDFONTDESTRUCTION:
120 return "UnscaledFontDestruction";
121 case EXTERNALSURFACECREATION:
122 return "ExternalSourceSurfaceCreation";
123 case LINK:
124 return "Link";
125 case DESTINATION:
126 return "Destination";
127 default:
128 return "Unknown";
132 template <class S>
133 void RecordedEvent::RecordUnscaledFontImpl(UnscaledFont* aUnscaledFont,
134 S& aOutput) {
135 RecordedFontData fontData(aUnscaledFont);
136 RecordedFontDetails fontDetails;
137 if (fontData.GetFontDetails(fontDetails)) {
138 // Try to serialise the whole font, just in case this is a web font that
139 // is not present on the system.
140 WriteElement(aOutput, fontData.mType);
141 fontData.RecordToStream(aOutput);
143 auto r = RecordedUnscaledFontCreation(aUnscaledFont, fontDetails);
144 WriteElement(aOutput, r.mType);
145 r.RecordToStream(aOutput);
146 } else {
147 // If that fails, record just the font description and try to load it from
148 // the system on the other side.
149 RecordedFontDescriptor fontDesc(aUnscaledFont);
150 if (fontDesc.IsValid()) {
151 WriteElement(aOutput, fontDesc.RecordedEvent::mType);
152 fontDesc.RecordToStream(aOutput);
153 } else {
154 gfxWarning()
155 << "DrawTargetRecording::FillGlyphs failed to serialise UnscaledFont";
160 void RecordedEvent::RecordUnscaledFont(UnscaledFont* aUnscaledFont,
161 std::ostream* aOutput) {
162 RecordUnscaledFontImpl(aUnscaledFont, *aOutput);
165 void RecordedEvent::RecordUnscaledFont(UnscaledFont* aUnscaledFont,
166 MemStream& aOutput) {
167 RecordUnscaledFontImpl(aUnscaledFont, aOutput);
170 already_AddRefed<DrawTarget> Translator::CreateDrawTarget(
171 ReferencePtr aRefPtr, const IntSize& aSize, SurfaceFormat aFormat) {
172 RefPtr<DrawTarget> newDT =
173 GetReferenceDrawTarget()->CreateSimilarDrawTarget(aSize, aFormat);
174 AddDrawTarget(aRefPtr, newDT);
175 return newDT.forget();
178 void Translator::DrawDependentSurface(uint64_t aKey, const Rect& aRect) {
179 if (!mDependentSurfaces || !mCurrentDT) {
180 return;
183 RefPtr<RecordedDependentSurface> recordedSurface =
184 mDependentSurfaces->Get(aKey);
185 if (!recordedSurface) {
186 return;
189 // Construct a new translator, so we can recurse into translating this
190 // sub-recording into the same DT. Set an initial transform for the
191 // translator, so that all commands get moved into the rect we want to draw.
193 // Because the recording may have filtered out SetTransform calls with the
194 // same value, we need to call SetTransform here to ensure it gets called at
195 // least once with the translated matrix.
196 const Matrix oldTransform = mCurrentDT->GetTransform();
198 Matrix dependentTransform = oldTransform;
199 dependentTransform.PreTranslate(aRect.TopLeft());
201 mCurrentDT->PushClipRect(aRect);
202 mCurrentDT->SetTransform(dependentTransform);
205 InlineTranslator translator(mCurrentDT, nullptr);
206 translator.SetReferenceDrawTargetTransform(dependentTransform);
207 translator.SetDependentSurfaces(mDependentSurfaces);
208 translator.TranslateRecording((char*)recordedSurface->mRecording.mData,
209 recordedSurface->mRecording.mLen);
212 mCurrentDT->SetTransform(oldTransform);
213 mCurrentDT->PopClip();
216 } // namespace gfx
217 } // namespace mozilla