|
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #include <QPixmap> |
|
7 #include <QWindow> |
|
8 #ifdef MOZ_X11 |
|
9 #include <qpa/qplatformnativeinterface.h> |
|
10 #include <qpa/qplatformintegration.h> |
|
11 #endif |
|
12 #include <QGuiApplication> |
|
13 #include <QScreen> |
|
14 |
|
15 #include "gfxQtPlatform.h" |
|
16 |
|
17 #include "gfxFontconfigUtils.h" |
|
18 |
|
19 #include "mozilla/gfx/2D.h" |
|
20 |
|
21 #include "cairo.h" |
|
22 |
|
23 #include "gfxImageSurface.h" |
|
24 #include "gfxQPainterSurface.h" |
|
25 #include "nsUnicodeProperties.h" |
|
26 |
|
27 #include "gfxPangoFonts.h" |
|
28 #include "gfxContext.h" |
|
29 #include "gfxUserFontSet.h" |
|
30 |
|
31 #include "nsUnicharUtils.h" |
|
32 |
|
33 #include "nsMathUtils.h" |
|
34 #include "nsTArray.h" |
|
35 #ifdef MOZ_X11 |
|
36 #include "gfxXlibSurface.h" |
|
37 #include "prenv.h" |
|
38 #endif |
|
39 |
|
40 #include "qcms.h" |
|
41 |
|
42 #include "mozilla/Preferences.h" |
|
43 |
|
44 using namespace mozilla; |
|
45 using namespace mozilla::unicode; |
|
46 using namespace mozilla::gfx; |
|
47 |
|
48 gfxFontconfigUtils *gfxQtPlatform::sFontconfigUtils = nullptr; |
|
49 #ifdef MOZ_X11 |
|
50 bool gfxQtPlatform::sUseXRender = true; |
|
51 #endif |
|
52 |
|
53 static gfxImageFormat sOffscreenFormat = gfxImageFormat::RGB24; |
|
54 |
|
55 gfxQtPlatform::gfxQtPlatform() |
|
56 { |
|
57 #ifdef MOZ_X11 |
|
58 sUseXRender = mozilla::Preferences::GetBool("gfx.xrender.enabled"); |
|
59 #endif |
|
60 if (!sFontconfigUtils) |
|
61 sFontconfigUtils = gfxFontconfigUtils::GetFontconfigUtils(); |
|
62 |
|
63 mScreenDepth = qApp->primaryScreen()->depth(); |
|
64 if (mScreenDepth == 16) { |
|
65 sOffscreenFormat = gfxImageFormat::RGB16_565; |
|
66 } |
|
67 uint32_t canvasMask = BackendTypeBit(BackendType::CAIRO) | BackendTypeBit(BackendType::SKIA); |
|
68 uint32_t contentMask = BackendTypeBit(BackendType::CAIRO) | BackendTypeBit(BackendType::SKIA); |
|
69 InitBackendPrefs(canvasMask, BackendType::CAIRO, |
|
70 contentMask, BackendType::CAIRO); |
|
71 } |
|
72 |
|
73 gfxQtPlatform::~gfxQtPlatform() |
|
74 { |
|
75 gfxFontconfigUtils::Shutdown(); |
|
76 sFontconfigUtils = nullptr; |
|
77 |
|
78 gfxPangoFontGroup::Shutdown(); |
|
79 } |
|
80 |
|
81 #ifdef MOZ_X11 |
|
82 Display* |
|
83 gfxQtPlatform::GetXDisplay(QWindow* aWindow) |
|
84 { |
|
85 return (Display*)(qApp->platformNativeInterface()-> |
|
86 nativeResourceForScreen("display", aWindow ? aWindow->screen() : qApp->primaryScreen())); |
|
87 } |
|
88 |
|
89 Screen* |
|
90 gfxQtPlatform::GetXScreen(QWindow* aWindow) |
|
91 { |
|
92 return ScreenOfDisplay(GetXDisplay(aWindow), |
|
93 (int)(intptr_t)qApp->platformNativeInterface()-> |
|
94 nativeResourceForScreen("screen", aWindow ? aWindow->screen() : qApp->primaryScreen())); |
|
95 } |
|
96 #endif |
|
97 |
|
98 already_AddRefed<gfxASurface> |
|
99 gfxQtPlatform::CreateOffscreenSurface(const IntSize& size, |
|
100 gfxContentType contentType) |
|
101 { |
|
102 gfxImageFormat imageFormat = OptimalFormatForContent(contentType); |
|
103 |
|
104 nsRefPtr<gfxASurface> newSurface = |
|
105 new gfxImageSurface(gfxIntSize(size.width, size.height), imageFormat); |
|
106 |
|
107 return newSurface.forget(); |
|
108 } |
|
109 |
|
110 already_AddRefed<gfxASurface> |
|
111 gfxQtPlatform::OptimizeImage(gfxImageSurface *aSurface, |
|
112 gfxImageFormat format) |
|
113 { |
|
114 /* Qt have no special offscreen surfaces so we can avoid a copy */ |
|
115 if (OptimalFormatForContent(gfxASurface::ContentFromFormat(format)) == |
|
116 format) { |
|
117 return nullptr; |
|
118 } |
|
119 |
|
120 return gfxPlatform::OptimizeImage(aSurface, format); |
|
121 } |
|
122 |
|
123 |
|
124 nsresult |
|
125 gfxQtPlatform::GetFontList(nsIAtom *aLangGroup, |
|
126 const nsACString& aGenericFamily, |
|
127 nsTArray<nsString>& aListOfFonts) |
|
128 { |
|
129 return sFontconfigUtils->GetFontList(aLangGroup, aGenericFamily, |
|
130 aListOfFonts); |
|
131 } |
|
132 |
|
133 nsresult |
|
134 gfxQtPlatform::UpdateFontList() |
|
135 { |
|
136 return sFontconfigUtils->UpdateFontList(); |
|
137 } |
|
138 |
|
139 nsresult |
|
140 gfxQtPlatform::ResolveFontName(const nsAString& aFontName, |
|
141 FontResolverCallback aCallback, |
|
142 void *aClosure, |
|
143 bool& aAborted) |
|
144 { |
|
145 return sFontconfigUtils->ResolveFontName(aFontName, aCallback, |
|
146 aClosure, aAborted); |
|
147 } |
|
148 |
|
149 nsresult |
|
150 gfxQtPlatform::GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName) |
|
151 { |
|
152 return sFontconfigUtils->GetStandardFamilyName(aFontName, aFamilyName); |
|
153 } |
|
154 |
|
155 gfxFontGroup * |
|
156 gfxQtPlatform::CreateFontGroup(const nsAString &aFamilies, |
|
157 const gfxFontStyle *aStyle, |
|
158 gfxUserFontSet* aUserFontSet) |
|
159 { |
|
160 return new gfxPangoFontGroup(aFamilies, aStyle, aUserFontSet); |
|
161 } |
|
162 |
|
163 gfxFontEntry* |
|
164 gfxQtPlatform::LookupLocalFont(const gfxProxyFontEntry *aProxyEntry, |
|
165 const nsAString& aFontName) |
|
166 { |
|
167 return gfxPangoFontGroup::NewFontEntry(*aProxyEntry, aFontName); |
|
168 } |
|
169 |
|
170 gfxFontEntry* |
|
171 gfxQtPlatform::MakePlatformFont(const gfxProxyFontEntry *aProxyEntry, |
|
172 const uint8_t *aFontData, uint32_t aLength) |
|
173 { |
|
174 // passing ownership of the font data to the new font entry |
|
175 return gfxPangoFontGroup::NewFontEntry(*aProxyEntry, |
|
176 aFontData, aLength); |
|
177 } |
|
178 |
|
179 bool |
|
180 gfxQtPlatform::SupportsOffMainThreadCompositing() |
|
181 { |
|
182 #if defined(MOZ_X11) && !defined(NIGHTLY_BUILD) |
|
183 return (PR_GetEnv("MOZ_USE_OMTC") != nullptr) || |
|
184 (PR_GetEnv("MOZ_OMTC_ENABLED") != nullptr); |
|
185 #else |
|
186 return true; |
|
187 #endif |
|
188 } |
|
189 |
|
190 bool |
|
191 gfxQtPlatform::IsFontFormatSupported(nsIURI *aFontURI, uint32_t aFormatFlags) |
|
192 { |
|
193 // check for strange format flags |
|
194 NS_ASSERTION(!(aFormatFlags & gfxUserFontSet::FLAG_FORMAT_NOT_USED), |
|
195 "strange font format hint set"); |
|
196 |
|
197 // accept supported formats |
|
198 // Pango doesn't apply features from AAT TrueType extensions. |
|
199 // Assume that if this is the only SFNT format specified, |
|
200 // then AAT extensions are required for complex script support. |
|
201 if (aFormatFlags & (gfxUserFontSet::FLAG_FORMAT_WOFF | |
|
202 gfxUserFontSet::FLAG_FORMAT_OPENTYPE | |
|
203 gfxUserFontSet::FLAG_FORMAT_TRUETYPE)) { |
|
204 return true; |
|
205 } |
|
206 |
|
207 // reject all other formats, known and unknown |
|
208 if (aFormatFlags != 0) { |
|
209 return false; |
|
210 } |
|
211 |
|
212 // no format hint set, need to look at data |
|
213 return true; |
|
214 } |
|
215 |
|
216 void |
|
217 gfxQtPlatform::GetPlatformCMSOutputProfile(void *&mem, size_t &size) |
|
218 { |
|
219 mem = nullptr; |
|
220 size = 0; |
|
221 } |
|
222 |
|
223 int32_t |
|
224 gfxQtPlatform::GetDPI() |
|
225 { |
|
226 return qApp->primaryScreen()->logicalDotsPerInch(); |
|
227 } |
|
228 |
|
229 gfxImageFormat |
|
230 gfxQtPlatform::GetOffscreenFormat() |
|
231 { |
|
232 return sOffscreenFormat; |
|
233 } |
|
234 |
|
235 int |
|
236 gfxQtPlatform::GetScreenDepth() const |
|
237 { |
|
238 return mScreenDepth; |
|
239 } |
|
240 |
|
241 TemporaryRef<ScaledFont> |
|
242 gfxQtPlatform::GetScaledFontForFont(DrawTarget* aTarget, gfxFont* aFont) |
|
243 { |
|
244 return GetScaledFontForFontWithCairoSkia(aTarget, aFont); |
|
245 } |