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