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 #ifndef mozilla_layout_PrintTranslator_h
8 #define mozilla_layout_PrintTranslator_h
12 #include "DrawEventRecorder.h"
13 #include "mozilla/gfx/2D.h"
14 #include "mozilla/gfx/Filters.h"
15 #include "mozilla/gfx/RecordedEvent.h"
17 class nsDeviceContext
;
22 using gfx::DrawTarget
;
23 using gfx::FilterNode
;
24 using gfx::GradientStops
;
25 using gfx::NativeFontResource
;
27 using gfx::RecordedDependentSurface
;
28 using gfx::ReferencePtr
;
29 using gfx::ScaledFont
;
30 using gfx::SourceSurface
;
31 using gfx::Translator
;
32 using gfx::UnscaledFont
;
34 class PrintTranslator final
: public Translator
{
36 explicit PrintTranslator(nsDeviceContext
* aDeviceContext
);
38 bool TranslateRecording(PRFileDescStream
& aRecording
);
40 DrawTarget
* LookupDrawTarget(ReferencePtr aRefPtr
) final
{
41 DrawTarget
* result
= mDrawTargets
.GetWeak(aRefPtr
);
46 Path
* LookupPath(ReferencePtr aRefPtr
) final
{
47 Path
* result
= mPaths
.GetWeak(aRefPtr
);
52 SourceSurface
* LookupSourceSurface(ReferencePtr aRefPtr
) final
{
53 SourceSurface
* result
= mSourceSurfaces
.GetWeak(aRefPtr
);
58 FilterNode
* LookupFilterNode(ReferencePtr aRefPtr
) final
{
59 FilterNode
* result
= mFilterNodes
.GetWeak(aRefPtr
);
64 already_AddRefed
<GradientStops
> LookupGradientStops(
65 ReferencePtr aRefPtr
) final
{
66 return mGradientStops
.Get(aRefPtr
);
69 ScaledFont
* LookupScaledFont(ReferencePtr aRefPtr
) final
{
70 ScaledFont
* result
= mScaledFonts
.GetWeak(aRefPtr
);
75 UnscaledFont
* LookupUnscaledFont(ReferencePtr aRefPtr
) final
{
76 UnscaledFont
* result
= mUnscaledFonts
.GetWeak(aRefPtr
);
81 NativeFontResource
* LookupNativeFontResource(uint64_t aKey
) final
{
82 NativeFontResource
* result
= mNativeFontResources
.GetWeak(aKey
);
87 void AddDrawTarget(ReferencePtr aRefPtr
, DrawTarget
* aDT
) final
{
88 mDrawTargets
.InsertOrUpdate(aRefPtr
, RefPtr
{aDT
});
91 void AddPath(ReferencePtr aRefPtr
, Path
* aPath
) final
{
92 mPaths
.InsertOrUpdate(aRefPtr
, RefPtr
{aPath
});
95 void AddSourceSurface(ReferencePtr aRefPtr
, SourceSurface
* aSurface
) final
{
96 mSourceSurfaces
.InsertOrUpdate(aRefPtr
, RefPtr
{aSurface
});
99 void AddFilterNode(ReferencePtr aRefPtr
, FilterNode
* aFilter
) final
{
100 mFilterNodes
.InsertOrUpdate(aRefPtr
, RefPtr
{aFilter
});
103 void AddGradientStops(ReferencePtr aRefPtr
, GradientStops
* aStops
) final
{
104 mGradientStops
.InsertOrUpdate(aRefPtr
, RefPtr
{aStops
});
107 void AddScaledFont(ReferencePtr aRefPtr
, ScaledFont
* aScaledFont
) final
{
108 mScaledFonts
.InsertOrUpdate(aRefPtr
, RefPtr
{aScaledFont
});
111 void AddUnscaledFont(ReferencePtr aRefPtr
,
112 UnscaledFont
* aUnscaledFont
) final
{
113 mUnscaledFonts
.InsertOrUpdate(aRefPtr
, RefPtr
{aUnscaledFont
});
116 void AddNativeFontResource(uint64_t aKey
,
117 NativeFontResource
* aScaledFontResouce
) final
{
118 mNativeFontResources
.InsertOrUpdate(aKey
, RefPtr
{aScaledFontResouce
});
121 void RemoveDrawTarget(ReferencePtr aRefPtr
) final
{
122 ReferencePtr currentDT
= mCurrentDT
;
123 if (currentDT
== aRefPtr
) {
124 mCurrentDT
= nullptr;
126 mDrawTargets
.Remove(aRefPtr
);
129 bool SetCurrentDrawTarget(ReferencePtr aRefPtr
) final
{
130 mCurrentDT
= mDrawTargets
.GetWeak(aRefPtr
);
134 void RemovePath(ReferencePtr aRefPtr
) final
{ mPaths
.Remove(aRefPtr
); }
136 void RemoveSourceSurface(ReferencePtr aRefPtr
) final
{
137 mSourceSurfaces
.Remove(aRefPtr
);
140 void RemoveFilterNode(ReferencePtr aRefPtr
) final
{
141 mFilterNodes
.Remove(aRefPtr
);
144 void RemoveGradientStops(ReferencePtr aRefPtr
) final
{
145 mGradientStops
.Remove(aRefPtr
);
148 void RemoveScaledFont(ReferencePtr aRefPtr
) final
{
149 mScaledFonts
.Remove(aRefPtr
);
152 void RemoveUnscaledFont(ReferencePtr aRefPtr
) final
{
153 mUnscaledFonts
.Remove(aRefPtr
);
156 already_AddRefed
<DrawTarget
> CreateDrawTarget(
157 ReferencePtr aRefPtr
, const gfx::IntSize
& aSize
,
158 gfx::SurfaceFormat aFormat
) final
;
160 mozilla::gfx::DrawTarget
* GetReferenceDrawTarget() final
{ return mBaseDT
; }
163 RefPtr
<nsDeviceContext
> mDeviceContext
;
164 RefPtr
<DrawTarget
> mBaseDT
;
166 nsRefPtrHashtable
<nsPtrHashKey
<void>, DrawTarget
> mDrawTargets
;
167 nsRefPtrHashtable
<nsPtrHashKey
<void>, Path
> mPaths
;
168 nsRefPtrHashtable
<nsPtrHashKey
<void>, SourceSurface
> mSourceSurfaces
;
169 nsRefPtrHashtable
<nsPtrHashKey
<void>, FilterNode
> mFilterNodes
;
170 nsRefPtrHashtable
<nsPtrHashKey
<void>, GradientStops
> mGradientStops
;
171 nsRefPtrHashtable
<nsPtrHashKey
<void>, ScaledFont
> mScaledFonts
;
172 nsRefPtrHashtable
<nsPtrHashKey
<void>, UnscaledFont
> mUnscaledFonts
;
173 nsRefPtrHashtable
<nsUint64HashKey
, NativeFontResource
> mNativeFontResources
;
176 } // namespace layout
177 } // namespace mozilla
179 #endif // mozilla_layout_PrintTranslator_h