Bug 1924993 - [devtools] Debugger tests wait before typing in conditional panel r...
[gecko.git] / gfx / 2d / InlineTranslator.h
blob3e52568b4cc1a61212eaa599dc33a9c01a3cd33f
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 bool HasSourceSurface(ReferencePtr aRefPtr) const {
58 return mSourceSurfaces.GetWeak(aRefPtr) != nullptr;
61 SourceSurface* LookupSourceSurface(ReferencePtr aRefPtr) final {
62 SourceSurface* result = mSourceSurfaces.GetWeak(aRefPtr);
63 MOZ_ASSERT(result);
64 return result;
67 FilterNode* LookupFilterNode(ReferencePtr aRefPtr) final {
68 FilterNode* result = mFilterNodes.GetWeak(aRefPtr);
69 MOZ_ASSERT(result);
70 return result;
73 already_AddRefed<GradientStops> LookupGradientStops(
74 ReferencePtr aRefPtr) final {
75 return mGradientStops.Get(aRefPtr);
78 ScaledFont* LookupScaledFont(ReferencePtr aRefPtr) final {
79 ScaledFont* result = mScaledFonts.GetWeak(aRefPtr);
80 MOZ_ASSERT(result);
81 return result;
84 UnscaledFont* LookupUnscaledFont(ReferencePtr aRefPtr) final {
85 UnscaledFont* result = mUnscaledFonts.GetWeak(aRefPtr);
86 MOZ_ASSERT(result);
87 return result;
90 NativeFontResource* LookupNativeFontResource(uint64_t aKey) final {
91 NativeFontResource* result = mNativeFontResources.GetWeak(aKey);
92 MOZ_ASSERT(result);
93 return result;
96 already_AddRefed<SourceSurface> LookupExternalSurface(uint64_t aKey) override;
98 void AddDrawTarget(ReferencePtr aRefPtr, DrawTarget* aDT) final {
99 mDrawTargets.InsertOrUpdate(aRefPtr, RefPtr{aDT});
102 void AddPath(ReferencePtr aRefPtr, Path* aPath) final {
103 mPaths.InsertOrUpdate(aRefPtr, RefPtr{aPath});
106 void AddSourceSurface(ReferencePtr aRefPtr,
107 SourceSurface* aSurface) override {
108 mSourceSurfaces.InsertOrUpdate(aRefPtr, RefPtr{aSurface});
111 void AddFilterNode(ReferencePtr aRefPtr, FilterNode* aFilter) final {
112 mFilterNodes.InsertOrUpdate(aRefPtr, RefPtr{aFilter});
115 void AddGradientStops(ReferencePtr aRefPtr, GradientStops* aStops) final {
116 mGradientStops.InsertOrUpdate(aRefPtr, RefPtr{aStops});
119 void AddScaledFont(ReferencePtr aRefPtr, ScaledFont* aScaledFont) final {
120 mScaledFonts.InsertOrUpdate(aRefPtr, RefPtr{aScaledFont});
123 void AddUnscaledFont(ReferencePtr aRefPtr,
124 UnscaledFont* aUnscaledFont) final {
125 mUnscaledFonts.InsertOrUpdate(aRefPtr, RefPtr{aUnscaledFont});
128 void AddNativeFontResource(uint64_t aKey,
129 NativeFontResource* aScaledFontResouce) final {
130 mNativeFontResources.InsertOrUpdate(aKey, RefPtr{aScaledFontResouce});
133 void RemoveDrawTarget(ReferencePtr aRefPtr) override {
134 RefPtr<DrawTarget> removedDT;
135 if (mDrawTargets.Remove(aRefPtr, getter_AddRefs(removedDT)) &&
136 mCurrentDT == removedDT) {
137 mCurrentDT = nullptr;
141 bool SetCurrentDrawTarget(ReferencePtr aRefPtr) override {
142 mCurrentDT = mDrawTargets.GetWeak(aRefPtr);
143 return !!mCurrentDT;
146 void RemovePath(ReferencePtr aRefPtr) final { mPaths.Remove(aRefPtr); }
148 void RemoveSourceSurface(ReferencePtr aRefPtr) override {
149 mSourceSurfaces.Remove(aRefPtr);
152 void RemoveFilterNode(ReferencePtr aRefPtr) final {
153 mFilterNodes.Remove(aRefPtr);
156 void RemoveGradientStops(ReferencePtr aRefPtr) final {
157 mGradientStops.Remove(aRefPtr);
160 void RemoveScaledFont(ReferencePtr aRefPtr) final {
161 mScaledFonts.Remove(aRefPtr);
164 void RemoveUnscaledFont(ReferencePtr aRefPtr) final {
165 mUnscaledFonts.Remove(aRefPtr);
168 already_AddRefed<DrawTarget> CreateDrawTarget(
169 ReferencePtr aRefPtr, const gfx::IntSize& aSize,
170 gfx::SurfaceFormat aFormat) override;
172 mozilla::gfx::DrawTarget* GetReferenceDrawTarget() final {
173 MOZ_ASSERT(mBaseDT, "mBaseDT has not been initialized.");
174 return mBaseDT;
176 Matrix GetReferenceDrawTargetTransform() final { return mBaseDTTransform; }
178 void* GetFontContext() final { return mFontContext; }
179 std::string GetError() { return mError; }
181 protected:
182 RefPtr<DrawTarget> mBaseDT;
183 Matrix mBaseDTTransform;
184 nsRefPtrHashtable<nsPtrHashKey<void>, DrawTarget> mDrawTargets;
186 private:
187 void* mFontContext;
188 std::string mError;
190 nsRefPtrHashtable<nsPtrHashKey<void>, Path> mPaths;
191 nsRefPtrHashtable<nsPtrHashKey<void>, SourceSurface> mSourceSurfaces;
192 nsRefPtrHashtable<nsPtrHashKey<void>, FilterNode> mFilterNodes;
193 nsRefPtrHashtable<nsPtrHashKey<void>, GradientStops> mGradientStops;
194 nsRefPtrHashtable<nsPtrHashKey<void>, ScaledFont> mScaledFonts;
195 nsRefPtrHashtable<nsPtrHashKey<void>, UnscaledFont> mUnscaledFonts;
196 nsRefPtrHashtable<nsUint64HashKey, NativeFontResource> mNativeFontResources;
197 nsRefPtrHashtable<nsUint64HashKey, SourceSurface>* mExternalSurfaces =
198 nullptr;
201 } // namespace gfx
202 } // namespace mozilla
204 #endif // mozilla_layout_InlineTranslator_h