Bug 1890689 accumulate input in LargerReceiverBlockSizeThanDesiredBuffering GTest...
[gecko.git] / gfx / 2d / InlineTranslator.h
blobf29e28113a91e7c4c42ea29f1575fad61013e945
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
10 #include <string>
12 #include "mozilla/gfx/2D.h"
13 #include "mozilla/gfx/Filters.h"
14 #include "mozilla/gfx/RecordedEvent.h"
16 namespace mozilla {
17 namespace gfx {
19 using gfx::DrawTarget;
20 using gfx::FilterNode;
21 using gfx::GradientStops;
22 using gfx::NativeFontResource;
23 using gfx::Path;
24 using gfx::ReferencePtr;
25 using gfx::ScaledFont;
26 using gfx::SourceSurface;
27 using gfx::Translator;
29 class InlineTranslator : public Translator {
30 public:
31 InlineTranslator();
33 explicit InlineTranslator(DrawTarget* aDT, void* aFontContext = nullptr);
35 bool TranslateRecording(char*, size_t len);
37 void SetExternalSurfaces(
38 nsRefPtrHashtable<nsUint64HashKey, SourceSurface>* aExternalSurfaces) {
39 mExternalSurfaces = aExternalSurfaces;
41 void SetReferenceDrawTargetTransform(const Matrix& aTransform) {
42 mBaseDTTransform = aTransform;
45 DrawTarget* LookupDrawTarget(ReferencePtr aRefPtr) final {
46 DrawTarget* result = mDrawTargets.GetWeak(aRefPtr);
47 MOZ_ASSERT(result);
48 return result;
51 Path* LookupPath(ReferencePtr aRefPtr) final {
52 Path* result = mPaths.GetWeak(aRefPtr);
53 MOZ_ASSERT(result);
54 return result;
57 SourceSurface* LookupSourceSurface(ReferencePtr aRefPtr) final {
58 SourceSurface* result = mSourceSurfaces.GetWeak(aRefPtr);
59 MOZ_ASSERT(result);
60 return result;
63 FilterNode* LookupFilterNode(ReferencePtr aRefPtr) final {
64 FilterNode* result = mFilterNodes.GetWeak(aRefPtr);
65 MOZ_ASSERT(result);
66 return result;
69 already_AddRefed<GradientStops> LookupGradientStops(
70 ReferencePtr aRefPtr) final {
71 return mGradientStops.Get(aRefPtr);
74 ScaledFont* LookupScaledFont(ReferencePtr aRefPtr) final {
75 ScaledFont* result = mScaledFonts.GetWeak(aRefPtr);
76 MOZ_ASSERT(result);
77 return result;
80 UnscaledFont* LookupUnscaledFont(ReferencePtr aRefPtr) final {
81 UnscaledFont* result = mUnscaledFonts.GetWeak(aRefPtr);
82 MOZ_ASSERT(result);
83 return result;
86 NativeFontResource* LookupNativeFontResource(uint64_t aKey) final {
87 NativeFontResource* result = mNativeFontResources.GetWeak(aKey);
88 MOZ_ASSERT(result);
89 return result;
92 already_AddRefed<SourceSurface> LookupExternalSurface(uint64_t aKey) override;
94 void AddDrawTarget(ReferencePtr aRefPtr, DrawTarget* aDT) final {
95 mDrawTargets.InsertOrUpdate(aRefPtr, RefPtr{aDT});
98 void AddPath(ReferencePtr aRefPtr, Path* aPath) final {
99 mPaths.InsertOrUpdate(aRefPtr, RefPtr{aPath});
102 void AddSourceSurface(ReferencePtr aRefPtr,
103 SourceSurface* aSurface) override {
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 ReferencePtr currentDT = mCurrentDT;
131 if (currentDT == aRefPtr) {
132 mCurrentDT = nullptr;
134 mDrawTargets.Remove(aRefPtr);
137 bool SetCurrentDrawTarget(ReferencePtr aRefPtr) override {
138 mCurrentDT = mDrawTargets.GetWeak(aRefPtr);
139 return !!mCurrentDT;
142 void RemovePath(ReferencePtr aRefPtr) final { mPaths.Remove(aRefPtr); }
144 void RemoveSourceSurface(ReferencePtr aRefPtr) override {
145 mSourceSurfaces.Remove(aRefPtr);
148 void RemoveFilterNode(ReferencePtr aRefPtr) final {
149 mFilterNodes.Remove(aRefPtr);
152 void RemoveGradientStops(ReferencePtr aRefPtr) final {
153 mGradientStops.Remove(aRefPtr);
156 void RemoveScaledFont(ReferencePtr aRefPtr) final {
157 mScaledFonts.Remove(aRefPtr);
160 void RemoveUnscaledFont(ReferencePtr aRefPtr) final {
161 mUnscaledFonts.Remove(aRefPtr);
164 already_AddRefed<DrawTarget> CreateDrawTarget(
165 ReferencePtr aRefPtr, const gfx::IntSize& aSize,
166 gfx::SurfaceFormat aFormat) override;
168 mozilla::gfx::DrawTarget* GetReferenceDrawTarget() final {
169 MOZ_ASSERT(mBaseDT, "mBaseDT has not been initialized.");
170 return mBaseDT;
172 Matrix GetReferenceDrawTargetTransform() final { return mBaseDTTransform; }
174 void* GetFontContext() final { return mFontContext; }
175 std::string GetError() { return mError; }
177 protected:
178 RefPtr<DrawTarget> mBaseDT;
179 Matrix mBaseDTTransform;
180 nsRefPtrHashtable<nsPtrHashKey<void>, DrawTarget> mDrawTargets;
182 private:
183 void* mFontContext;
184 std::string mError;
186 nsRefPtrHashtable<nsPtrHashKey<void>, Path> mPaths;
187 nsRefPtrHashtable<nsPtrHashKey<void>, SourceSurface> mSourceSurfaces;
188 nsRefPtrHashtable<nsPtrHashKey<void>, FilterNode> mFilterNodes;
189 nsRefPtrHashtable<nsPtrHashKey<void>, GradientStops> mGradientStops;
190 nsRefPtrHashtable<nsPtrHashKey<void>, ScaledFont> mScaledFonts;
191 nsRefPtrHashtable<nsPtrHashKey<void>, UnscaledFont> mUnscaledFonts;
192 nsRefPtrHashtable<nsUint64HashKey, NativeFontResource> mNativeFontResources;
193 nsRefPtrHashtable<nsUint64HashKey, SourceSurface>* mExternalSurfaces =
194 nullptr;
197 } // namespace gfx
198 } // namespace mozilla
200 #endif // mozilla_layout_InlineTranslator_h