/src/mozilla-central/gfx/2d/InlineTranslator.h
Line | Count | Source (jump to first uncovered line) |
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 | | #ifndef mozilla_layout_InlineTranslator_h |
8 | | #define mozilla_layout_InlineTranslator_h |
9 | | |
10 | | #include <istream> |
11 | | |
12 | | #include "mozilla/gfx/2D.h" |
13 | | #include "mozilla/gfx/Filters.h" |
14 | | #include "mozilla/gfx/RecordedEvent.h" |
15 | | #include "nsRefPtrHashtable.h" |
16 | | |
17 | | namespace mozilla { |
18 | | namespace gfx { |
19 | | |
20 | | using gfx::Translator; |
21 | | using gfx::ReferencePtr; |
22 | | using gfx::DrawTarget; |
23 | | using gfx::Path; |
24 | | using gfx::SourceSurface; |
25 | | using gfx::FilterNode; |
26 | | using gfx::GradientStops; |
27 | | using gfx::ScaledFont; |
28 | | using gfx::NativeFontResource; |
29 | | |
30 | | class InlineTranslator : public Translator |
31 | | { |
32 | | public: |
33 | | explicit InlineTranslator(DrawTarget* aDT, void* aFontContext = nullptr); |
34 | | |
35 | | bool TranslateRecording(char *, size_t len); |
36 | | |
37 | | DrawTarget* LookupDrawTarget(ReferencePtr aRefPtr) final |
38 | 0 | { |
39 | 0 | DrawTarget* result = mDrawTargets.GetWeak(aRefPtr); |
40 | 0 | MOZ_ASSERT(result); |
41 | 0 | return result; |
42 | 0 | } |
43 | | |
44 | | Path* LookupPath(ReferencePtr aRefPtr) final |
45 | 0 | { |
46 | 0 | Path* result = mPaths.GetWeak(aRefPtr); |
47 | 0 | MOZ_ASSERT(result); |
48 | 0 | return result; |
49 | 0 | } |
50 | | |
51 | | SourceSurface* LookupSourceSurface(ReferencePtr aRefPtr) final |
52 | 0 | { |
53 | 0 | SourceSurface* result = mSourceSurfaces.GetWeak(aRefPtr); |
54 | 0 | MOZ_ASSERT(result); |
55 | 0 | return result; |
56 | 0 | } |
57 | | |
58 | | FilterNode* LookupFilterNode(ReferencePtr aRefPtr) final |
59 | 0 | { |
60 | 0 | FilterNode* result = mFilterNodes.GetWeak(aRefPtr); |
61 | 0 | MOZ_ASSERT(result); |
62 | 0 | return result; |
63 | 0 | } |
64 | | |
65 | | GradientStops* LookupGradientStops(ReferencePtr aRefPtr) final |
66 | 0 | { |
67 | 0 | GradientStops* result = mGradientStops.GetWeak(aRefPtr); |
68 | 0 | MOZ_ASSERT(result); |
69 | 0 | return result; |
70 | 0 | } |
71 | | |
72 | | ScaledFont* LookupScaledFont(ReferencePtr aRefPtr) final |
73 | 0 | { |
74 | 0 | ScaledFont* result = mScaledFonts.GetWeak(aRefPtr); |
75 | 0 | MOZ_ASSERT(result); |
76 | 0 | return result; |
77 | 0 | } |
78 | | |
79 | | UnscaledFont* LookupUnscaledFont(ReferencePtr aRefPtr) final |
80 | 0 | { |
81 | 0 | UnscaledFont* result = mUnscaledFonts.GetWeak(aRefPtr); |
82 | 0 | MOZ_ASSERT(result); |
83 | 0 | return result; |
84 | 0 | } |
85 | | |
86 | | NativeFontResource* LookupNativeFontResource(uint64_t aKey) final |
87 | 0 | { |
88 | 0 | NativeFontResource* result = mNativeFontResources.GetWeak(aKey); |
89 | 0 | MOZ_ASSERT(result); |
90 | 0 | return result; |
91 | 0 | } |
92 | | |
93 | | void AddDrawTarget(ReferencePtr aRefPtr, DrawTarget *aDT) final |
94 | 0 | { |
95 | 0 | mDrawTargets.Put(aRefPtr, aDT); |
96 | 0 | } |
97 | | |
98 | | void AddPath(ReferencePtr aRefPtr, Path *aPath) final |
99 | 0 | { |
100 | 0 | mPaths.Put(aRefPtr, aPath); |
101 | 0 | } |
102 | | |
103 | | void AddSourceSurface(ReferencePtr aRefPtr, SourceSurface *aSurface) final |
104 | 0 | { |
105 | 0 | mSourceSurfaces.Put(aRefPtr, aSurface); |
106 | 0 | } |
107 | | |
108 | | void AddFilterNode(ReferencePtr aRefPtr, FilterNode *aFilter) final |
109 | 0 | { |
110 | 0 | mFilterNodes.Put(aRefPtr, aFilter); |
111 | 0 | } |
112 | | |
113 | | void AddGradientStops(ReferencePtr aRefPtr, GradientStops *aStops) final |
114 | 0 | { |
115 | 0 | mGradientStops.Put(aRefPtr, aStops); |
116 | 0 | } |
117 | | |
118 | | void AddScaledFont(ReferencePtr aRefPtr, ScaledFont *aScaledFont) final |
119 | 0 | { |
120 | 0 | mScaledFonts.Put(aRefPtr, aScaledFont); |
121 | 0 | } |
122 | | |
123 | | void AddUnscaledFont(ReferencePtr aRefPtr, UnscaledFont *aUnscaledFont) final |
124 | 0 | { |
125 | 0 | mUnscaledFonts.Put(aRefPtr, aUnscaledFont); |
126 | 0 | } |
127 | | |
128 | | void AddNativeFontResource(uint64_t aKey, |
129 | | NativeFontResource *aScaledFontResouce) final |
130 | 0 | { |
131 | 0 | mNativeFontResources.Put(aKey, aScaledFontResouce); |
132 | 0 | } |
133 | | |
134 | | void RemoveDrawTarget(ReferencePtr aRefPtr) final |
135 | 0 | { |
136 | 0 | mDrawTargets.Remove(aRefPtr); |
137 | 0 | } |
138 | | |
139 | | void RemovePath(ReferencePtr aRefPtr) final |
140 | 0 | { |
141 | 0 | mPaths.Remove(aRefPtr); |
142 | 0 | } |
143 | | |
144 | | void RemoveSourceSurface(ReferencePtr aRefPtr) final |
145 | 0 | { |
146 | 0 | mSourceSurfaces.Remove(aRefPtr); |
147 | 0 | } |
148 | | |
149 | | void RemoveFilterNode(ReferencePtr aRefPtr) final |
150 | 0 | { |
151 | 0 | mFilterNodes.Remove(aRefPtr); |
152 | 0 | } |
153 | | |
154 | | void RemoveGradientStops(ReferencePtr aRefPtr) final |
155 | 0 | { |
156 | 0 | mGradientStops.Remove(aRefPtr); |
157 | 0 | } |
158 | | |
159 | | void RemoveScaledFont(ReferencePtr aRefPtr) final |
160 | 0 | { |
161 | 0 | mScaledFonts.Remove(aRefPtr); |
162 | 0 | } |
163 | | |
164 | | void RemoveUnscaledFont(ReferencePtr aRefPtr) final |
165 | 0 | { |
166 | 0 | mUnscaledFonts.Remove(aRefPtr); |
167 | 0 | } |
168 | | |
169 | | |
170 | | already_AddRefed<DrawTarget> CreateDrawTarget(ReferencePtr aRefPtr, |
171 | | const gfx::IntSize &aSize, |
172 | | gfx::SurfaceFormat aFormat) final; |
173 | | |
174 | 0 | mozilla::gfx::DrawTarget* GetReferenceDrawTarget() final { return mBaseDT; } |
175 | | |
176 | 0 | void* GetFontContext() final { return mFontContext; } |
177 | | |
178 | | private: |
179 | | RefPtr<DrawTarget> mBaseDT; |
180 | | void* mFontContext; |
181 | | |
182 | | nsRefPtrHashtable<nsPtrHashKey<void>, DrawTarget> mDrawTargets; |
183 | | nsRefPtrHashtable<nsPtrHashKey<void>, Path> mPaths; |
184 | | nsRefPtrHashtable<nsPtrHashKey<void>, SourceSurface> mSourceSurfaces; |
185 | | nsRefPtrHashtable<nsPtrHashKey<void>, FilterNode> mFilterNodes; |
186 | | nsRefPtrHashtable<nsPtrHashKey<void>, GradientStops> mGradientStops; |
187 | | nsRefPtrHashtable<nsPtrHashKey<void>, ScaledFont> mScaledFonts; |
188 | | nsRefPtrHashtable<nsPtrHashKey<void>, UnscaledFont> mUnscaledFonts; |
189 | | nsRefPtrHashtable<nsUint64HashKey, NativeFontResource> mNativeFontResources; |
190 | | }; |
191 | | |
192 | | } // namespace gfx |
193 | | } // namespace mozilla |
194 | | |
195 | | #endif // mozilla_layout_InlineTranslator_h |