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_InlineTranslator_h
8 #define mozilla_layout_InlineTranslator_h
13 #include "mozilla/gfx/2D.h"
14 #include "mozilla/gfx/Filters.h"
15 #include "mozilla/gfx/RecordedEvent.h"
20 using gfx::DrawTarget
;
21 using gfx::FilterNode
;
22 using gfx::GradientStops
;
23 using gfx::NativeFontResource
;
25 using gfx::ReferencePtr
;
26 using gfx::ScaledFont
;
27 using gfx::SourceSurface
;
28 using gfx::Translator
;
30 class InlineTranslator
: public Translator
{
34 explicit InlineTranslator(DrawTarget
* aDT
, void* aFontContext
= nullptr);
36 bool TranslateRecording(char*, size_t len
);
38 void SetExternalSurfaces(
39 nsRefPtrHashtable
<nsUint64HashKey
, SourceSurface
>* aExternalSurfaces
) {
40 mExternalSurfaces
= aExternalSurfaces
;
42 void SetReferenceDrawTargetTransform(const Matrix
& aTransform
) {
43 mBaseDTTransform
= aTransform
;
46 DrawTarget
* LookupDrawTarget(ReferencePtr aRefPtr
) final
{
47 DrawTarget
* result
= mDrawTargets
.GetWeak(aRefPtr
);
52 Path
* LookupPath(ReferencePtr aRefPtr
) final
{
53 Path
* result
= mPaths
.GetWeak(aRefPtr
);
58 SourceSurface
* LookupSourceSurface(ReferencePtr aRefPtr
) final
{
59 SourceSurface
* result
= mSourceSurfaces
.GetWeak(aRefPtr
);
64 FilterNode
* LookupFilterNode(ReferencePtr aRefPtr
) final
{
65 FilterNode
* result
= mFilterNodes
.GetWeak(aRefPtr
);
70 already_AddRefed
<GradientStops
> LookupGradientStops(
71 ReferencePtr aRefPtr
) final
{
72 return mGradientStops
.Get(aRefPtr
);
75 ScaledFont
* LookupScaledFont(ReferencePtr aRefPtr
) final
{
76 ScaledFont
* result
= mScaledFonts
.GetWeak(aRefPtr
);
81 UnscaledFont
* LookupUnscaledFont(ReferencePtr aRefPtr
) final
{
82 UnscaledFont
* result
= mUnscaledFonts
.GetWeak(aRefPtr
);
87 NativeFontResource
* LookupNativeFontResource(uint64_t aKey
) final
{
88 NativeFontResource
* result
= mNativeFontResources
.GetWeak(aKey
);
93 already_AddRefed
<SourceSurface
> LookupExternalSurface(uint64_t aKey
) override
;
95 void AddDrawTarget(ReferencePtr aRefPtr
, DrawTarget
* aDT
) final
{
96 mDrawTargets
.InsertOrUpdate(aRefPtr
, RefPtr
{aDT
});
99 void AddPath(ReferencePtr aRefPtr
, Path
* aPath
) final
{
100 mPaths
.InsertOrUpdate(aRefPtr
, RefPtr
{aPath
});
103 void AddSourceSurface(ReferencePtr aRefPtr
, SourceSurface
* aSurface
) final
{
104 mSourceSurfaces
.InsertOrUpdate(aRefPtr
, RefPtr
{aSurface
});
107 void AddFilterNode(ReferencePtr aRefPtr
, FilterNode
* aFilter
) final
{
108 mFilterNodes
.InsertOrUpdate(aRefPtr
, RefPtr
{aFilter
});
111 void AddGradientStops(ReferencePtr aRefPtr
, GradientStops
* aStops
) final
{
112 mGradientStops
.InsertOrUpdate(aRefPtr
, RefPtr
{aStops
});
115 void AddScaledFont(ReferencePtr aRefPtr
, ScaledFont
* aScaledFont
) final
{
116 mScaledFonts
.InsertOrUpdate(aRefPtr
, RefPtr
{aScaledFont
});
119 void AddUnscaledFont(ReferencePtr aRefPtr
,
120 UnscaledFont
* aUnscaledFont
) final
{
121 mUnscaledFonts
.InsertOrUpdate(aRefPtr
, RefPtr
{aUnscaledFont
});
124 void AddNativeFontResource(uint64_t aKey
,
125 NativeFontResource
* aScaledFontResouce
) final
{
126 mNativeFontResources
.InsertOrUpdate(aKey
, RefPtr
{aScaledFontResouce
});
129 void RemoveDrawTarget(ReferencePtr aRefPtr
) override
{
130 mDrawTargets
.Remove(aRefPtr
);
133 void RemovePath(ReferencePtr aRefPtr
) final
{ mPaths
.Remove(aRefPtr
); }
135 void RemoveSourceSurface(ReferencePtr aRefPtr
) override
{
136 mSourceSurfaces
.Remove(aRefPtr
);
139 void RemoveFilterNode(ReferencePtr aRefPtr
) final
{
140 mFilterNodes
.Remove(aRefPtr
);
143 void RemoveGradientStops(ReferencePtr aRefPtr
) final
{
144 mGradientStops
.Remove(aRefPtr
);
147 void RemoveScaledFont(ReferencePtr aRefPtr
) final
{
148 mScaledFonts
.Remove(aRefPtr
);
151 void RemoveUnscaledFont(ReferencePtr aRefPtr
) final
{
152 mUnscaledFonts
.Remove(aRefPtr
);
155 already_AddRefed
<DrawTarget
> CreateDrawTarget(
156 ReferencePtr aRefPtr
, const gfx::IntSize
& aSize
,
157 gfx::SurfaceFormat aFormat
) override
;
159 mozilla::gfx::DrawTarget
* GetReferenceDrawTarget() final
{
160 MOZ_ASSERT(mBaseDT
, "mBaseDT has not been initialized.");
163 Matrix
GetReferenceDrawTargetTransform() final
{ return mBaseDTTransform
; }
165 void* GetFontContext() final
{ return mFontContext
; }
166 std::string
GetError() { return mError
; }
169 RefPtr
<DrawTarget
> mBaseDT
;
170 Matrix mBaseDTTransform
;
171 nsRefPtrHashtable
<nsPtrHashKey
<void>, DrawTarget
> mDrawTargets
;
177 nsRefPtrHashtable
<nsPtrHashKey
<void>, Path
> mPaths
;
178 nsRefPtrHashtable
<nsPtrHashKey
<void>, SourceSurface
> mSourceSurfaces
;
179 nsRefPtrHashtable
<nsPtrHashKey
<void>, FilterNode
> mFilterNodes
;
180 nsRefPtrHashtable
<nsPtrHashKey
<void>, GradientStops
> mGradientStops
;
181 nsRefPtrHashtable
<nsPtrHashKey
<void>, ScaledFont
> mScaledFonts
;
182 nsRefPtrHashtable
<nsPtrHashKey
<void>, UnscaledFont
> mUnscaledFonts
;
183 nsRefPtrHashtable
<nsUint64HashKey
, NativeFontResource
> mNativeFontResources
;
184 nsRefPtrHashtable
<nsUint64HashKey
, SourceSurface
>* mExternalSurfaces
=
189 } // namespace mozilla
191 #endif // mozilla_layout_InlineTranslator_h