Bug 1890689 accumulate input in LargerReceiverBlockSizeThanDesiredBuffering GTest...
[gecko.git] / gfx / 2d / RecordedEvent.cpp
blobc89bd99d4c2b2f13f13b3c77c6c010a963d6f4c5
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 DRAWSURFACEDESCRIPTOR:
74 return "DrawSurfaceDescriptor";
75 case DRAWDEPENDENTSURFACE:
76 return "DrawDependentSurface";
77 case DRAWSURFACEWITHSHADOW:
78 return "DrawSurfaceWithShadow";
79 case DRAWFILTER:
80 return "DrawFilter";
81 case PATHCREATION:
82 return "PathCreation";
83 case PATHDESTRUCTION:
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";
97 case SNAPSHOT:
98 return "Snapshot";
99 case SCALEDFONTCREATION:
100 return "ScaledFontCreation";
101 case SCALEDFONTDESTRUCTION:
102 return "ScaledFontDestruction";
103 case MASKSURFACE:
104 return "MaskSurface";
105 case FILTERNODESETATTRIBUTE:
106 return "SetAttribute";
107 case FILTERNODESETINPUT:
108 return "SetInput";
109 case CREATESIMILARDRAWTARGET:
110 return "CreateSimilarDrawTarget";
111 case FONTDATA:
112 return "FontData";
113 case FONTDESC:
114 return "FontDescriptor";
115 case PUSHLAYER:
116 return "PushLayer";
117 case POPLAYER:
118 return "PopLayer";
119 case UNSCALEDFONTCREATION:
120 return "UnscaledFontCreation";
121 case UNSCALEDFONTDESTRUCTION:
122 return "UnscaledFontDestruction";
123 case EXTERNALSURFACECREATION:
124 return "ExternalSourceSurfaceCreation";
125 case LINK:
126 return "Link";
127 case DESTINATION:
128 return "Destination";
129 default:
130 return "Unknown";
134 template <class S>
135 void RecordedEvent::RecordUnscaledFontImpl(UnscaledFont* aUnscaledFont,
136 S& aOutput) {
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);
148 } else {
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);
155 } else {
156 gfxWarning()
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) {
182 return;
185 RefPtr<RecordedDependentSurface> recordedSurface =
186 mDependentSurfaces->Get(aKey);
187 if (!recordedSurface) {
188 return;
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();
218 } // namespace gfx
219 } // namespace mozilla