1 From a8ab3ec3542469c1d4e0741121eb1be17cc0acb0 Mon Sep 17 00:00:00 2001 |
|
2 From: Mike Hommey <mh@glandium.org> |
|
3 Date: Mon, 9 Mar 2015 08:42:19 +0900 |
|
4 Subject: [PATCH] Bug 1136958 - Reintroduce pixman code path removed in bug |
|
5 1097776 for --disable-skia builds |
|
6 |
|
7 --- |
|
8 gfx/layers/basic/BasicCompositor.cpp | 94 +++++++++++++++++++++++++++++++--- |
|
9 gfx/layers/basic/BasicLayerManager.cpp | 88 +++++++++++++++++++++++++++++-- |
|
10 2 files changed, 171 insertions(+), 11 deletions(-) |
|
11 |
|
12 diff --git a/gfx/layers/basic/BasicCompositor.cpp b/gfx/layers/basic/BasicCompositor.cpp |
|
13 index 0bef076..000b591 100644 |
|
14 --- a/gfx/layers/basic/BasicCompositor.cpp |
|
15 +++ b/gfx/layers/basic/BasicCompositor.cpp |
|
16 @@ -17,8 +17,13 @@ |
|
17 #include <algorithm> |
|
18 #include "ImageContainer.h" |
|
19 #include "gfxPrefs.h" |
|
20 +#ifdef MOZ_ENABLE_SKIA |
|
21 #include "skia/SkCanvas.h" // for SkCanvas |
|
22 #include "skia/SkBitmapDevice.h" // for SkBitmapDevice |
|
23 +#else |
|
24 +#define PIXMAN_DONT_DEFINE_STDINT |
|
25 +#include "pixman.h" // for pixman_f_transform, etc |
|
26 +#endif |
|
27 |
|
28 namespace mozilla { |
|
29 using namespace mozilla::gfx; |
|
30 @@ -168,6 +173,7 @@ DrawSurfaceWithTextureCoords(DrawTarget *aDest, |
|
31 mode, aMask, aMaskTransform, &matrix); |
|
32 } |
|
33 |
|
34 +#ifdef MOZ_ENABLE_SKIA |
|
35 static SkMatrix |
|
36 Matrix3DToSkia(const gfx3DMatrix& aMatrix) |
|
37 { |
|
38 @@ -186,10 +192,10 @@ Matrix3DToSkia(const gfx3DMatrix& aMatrix) |
|
39 } |
|
40 |
|
41 static void |
|
42 -SkiaTransform(DataSourceSurface* aDest, |
|
43 - DataSourceSurface* aSource, |
|
44 - const gfx3DMatrix& aTransform, |
|
45 - const Point& aDestOffset) |
|
46 +Transform(DataSourceSurface* aDest, |
|
47 + DataSourceSurface* aSource, |
|
48 + const gfx3DMatrix& aTransform, |
|
49 + const Point& aDestOffset) |
|
50 { |
|
51 if (aTransform.IsSingular()) { |
|
52 return; |
|
53 @@ -225,6 +231,78 @@ SkiaTransform(DataSourceSurface* aDest, |
|
54 SkRect destRect = SkRect::MakeXYWH(0, 0, srcSize.width, srcSize.height); |
|
55 destCanvas.drawBitmapRectToRect(src, nullptr, destRect, &paint); |
|
56 } |
|
57 +#else |
|
58 +static pixman_transform |
|
59 +Matrix3DToPixman(const gfx3DMatrix& aMatrix) |
|
60 +{ |
|
61 + pixman_f_transform transform; |
|
62 + |
|
63 + transform.m[0][0] = aMatrix._11; |
|
64 + transform.m[0][1] = aMatrix._21; |
|
65 + transform.m[0][2] = aMatrix._41; |
|
66 + transform.m[1][0] = aMatrix._12; |
|
67 + transform.m[1][1] = aMatrix._22; |
|
68 + transform.m[1][2] = aMatrix._42; |
|
69 + transform.m[2][0] = aMatrix._14; |
|
70 + transform.m[2][1] = aMatrix._24; |
|
71 + transform.m[2][2] = aMatrix._44; |
|
72 + |
|
73 + pixman_transform result; |
|
74 + pixman_transform_from_pixman_f_transform(&result, &transform); |
|
75 + |
|
76 + return result; |
|
77 +} |
|
78 + |
|
79 +static void |
|
80 +Transform(DataSourceSurface* aDest, |
|
81 + DataSourceSurface* aSource, |
|
82 + const gfx3DMatrix& aTransform, |
|
83 + const Point& aDestOffset) |
|
84 +{ |
|
85 + IntSize destSize = aDest->GetSize(); |
|
86 + pixman_image_t* dest = pixman_image_create_bits(PIXMAN_a8r8g8b8, |
|
87 + destSize.width, |
|
88 + destSize.height, |
|
89 + (uint32_t*)aDest->GetData(), |
|
90 + aDest->Stride()); |
|
91 + |
|
92 + IntSize srcSize = aSource->GetSize(); |
|
93 + pixman_image_t* src = pixman_image_create_bits(PIXMAN_a8r8g8b8, |
|
94 + srcSize.width, |
|
95 + srcSize.height, |
|
96 + (uint32_t*)aSource->GetData(), |
|
97 + aSource->Stride()); |
|
98 + |
|
99 + NS_ABORT_IF_FALSE(src && dest, "Failed to create pixman images?"); |
|
100 + |
|
101 + pixman_transform pixTransform = Matrix3DToPixman(aTransform); |
|
102 + pixman_transform pixTransformInverted; |
|
103 + |
|
104 + // If the transform is singular then nothing would be drawn anyway, return here |
|
105 + if (!pixman_transform_invert(&pixTransformInverted, &pixTransform)) { |
|
106 + pixman_image_unref(dest); |
|
107 + pixman_image_unref(src); |
|
108 + return; |
|
109 + } |
|
110 + pixman_image_set_transform(src, &pixTransformInverted); |
|
111 + |
|
112 + pixman_image_composite32(PIXMAN_OP_SRC, |
|
113 + src, |
|
114 + nullptr, |
|
115 + dest, |
|
116 + aDestOffset.x, |
|
117 + aDestOffset.y, |
|
118 + 0, |
|
119 + 0, |
|
120 + 0, |
|
121 + 0, |
|
122 + destSize.width, |
|
123 + destSize.height); |
|
124 + |
|
125 + pixman_image_unref(dest); |
|
126 + pixman_image_unref(src); |
|
127 +} |
|
128 +#endif |
|
129 |
|
130 static inline IntRect |
|
131 RoundOut(Rect r) |
|
132 @@ -364,12 +442,16 @@ BasicCompositor::DrawQuad(const gfx::Rect& aRect, |
|
133 RefPtr<SourceSurface> snapshot = dest->Snapshot(); |
|
134 RefPtr<DataSourceSurface> source = snapshot->GetDataSurface(); |
|
135 RefPtr<DataSourceSurface> temp = |
|
136 - Factory::CreateDataSourceSurface(RoundOut(transformBounds).Size(), SurfaceFormat::B8G8R8A8, true); |
|
137 + Factory::CreateDataSourceSurface(RoundOut(transformBounds).Size(), SurfaceFormat::B8G8R8A8 |
|
138 +#ifdef MOZ_ENABLE_SKIA |
|
139 + , true |
|
140 +#endif |
|
141 + ); |
|
142 if (NS_WARN_IF(!temp)) { |
|
143 return; |
|
144 } |
|
145 |
|
146 - SkiaTransform(temp, source, new3DTransform, transformBounds.TopLeft()); |
|
147 + Transform(temp, source, new3DTransform, transformBounds.TopLeft()); |
|
148 |
|
149 transformBounds.MoveTo(0, 0); |
|
150 buffer->DrawSurface(temp, transformBounds, transformBounds); |
|
151 diff --git a/gfx/layers/basic/BasicLayerManager.cpp b/gfx/layers/basic/BasicLayerManager.cpp |
|
152 index f4ec9e4..c849c27 100644 |
|
153 --- a/gfx/layers/basic/BasicLayerManager.cpp |
|
154 +++ b/gfx/layers/basic/BasicLayerManager.cpp |
|
155 @@ -46,8 +46,13 @@ |
|
156 #include "nsRect.h" // for nsIntRect |
|
157 #include "nsRegion.h" // for nsIntRegion, etc |
|
158 #include "nsTArray.h" // for nsAutoTArray |
|
159 +#ifdef MOZ_ENABLE_SKIA |
|
160 #include "skia/SkCanvas.h" // for SkCanvas |
|
161 #include "skia/SkBitmapDevice.h" // for SkBitmapDevice |
|
162 +#else |
|
163 +#define PIXMAN_DONT_DEFINE_STDINT |
|
164 +#include "pixman.h" // for pixman_f_transform, etc |
|
165 +#endif |
|
166 class nsIWidget; |
|
167 |
|
168 namespace mozilla { |
|
169 @@ -601,6 +606,7 @@ BasicLayerManager::SetRoot(Layer* aLayer) |
|
170 mRoot = aLayer; |
|
171 } |
|
172 |
|
173 +#ifdef MOZ_ENABLE_SKIA |
|
174 static SkMatrix |
|
175 BasicLayerManager_Matrix3DToSkia(const gfx3DMatrix& aMatrix) |
|
176 { |
|
177 @@ -619,10 +625,10 @@ BasicLayerManager_Matrix3DToSkia(const gfx3DMatrix& aMatrix) |
|
178 } |
|
179 |
|
180 static void |
|
181 -SkiaTransform(const gfxImageSurface* aDest, |
|
182 - RefPtr<DataSourceSurface> aSrc, |
|
183 - const gfx3DMatrix& aTransform, |
|
184 - gfxPoint aDestOffset) |
|
185 +Transform(const gfxImageSurface* aDest, |
|
186 + RefPtr<DataSourceSurface> aSrc, |
|
187 + const gfx3DMatrix& aTransform, |
|
188 + gfxPoint aDestOffset) |
|
189 { |
|
190 if (aTransform.IsSingular()) { |
|
191 return; |
|
192 @@ -658,6 +664,78 @@ SkiaTransform(const gfxImageSurface* aDest, |
|
193 SkRect destRect = SkRect::MakeXYWH(0, 0, srcSize.width, srcSize.height); |
|
194 destCanvas.drawBitmapRectToRect(src, nullptr, destRect, &paint); |
|
195 } |
|
196 +#else |
|
197 +static pixman_transform |
|
198 +BasicLayerManager_Matrix3DToPixman(const gfx3DMatrix& aMatrix) |
|
199 +{ |
|
200 + pixman_f_transform transform; |
|
201 + |
|
202 + transform.m[0][0] = aMatrix._11; |
|
203 + transform.m[0][1] = aMatrix._21; |
|
204 + transform.m[0][2] = aMatrix._41; |
|
205 + transform.m[1][0] = aMatrix._12; |
|
206 + transform.m[1][1] = aMatrix._22; |
|
207 + transform.m[1][2] = aMatrix._42; |
|
208 + transform.m[2][0] = aMatrix._14; |
|
209 + transform.m[2][1] = aMatrix._24; |
|
210 + transform.m[2][2] = aMatrix._44; |
|
211 + |
|
212 + pixman_transform result; |
|
213 + pixman_transform_from_pixman_f_transform(&result, &transform); |
|
214 + |
|
215 + return result; |
|
216 +} |
|
217 + |
|
218 +static void |
|
219 +Transform(const gfxImageSurface* aDest, |
|
220 + RefPtr<DataSourceSurface> aSrc, |
|
221 + const gfx3DMatrix& aTransform, |
|
222 + gfxPoint aDestOffset) |
|
223 +{ |
|
224 + IntSize destSize = ToIntSize(aDest->GetSize()); |
|
225 + pixman_image_t* dest = pixman_image_create_bits(aDest->Format() == gfxImageFormat::ARGB32 ? PIXMAN_a8r8g8b8 : PIXMAN_x8r8g8b8, |
|
226 + destSize.width, |
|
227 + destSize.height, |
|
228 + (uint32_t*)aDest->Data(), |
|
229 + aDest->Stride()); |
|
230 + |
|
231 + IntSize srcSize = aSrc->GetSize(); |
|
232 + pixman_image_t* src = pixman_image_create_bits(aSrc->GetFormat() == SurfaceFormat::B8G8R8A8 ? PIXMAN_a8r8g8b8 : PIXMAN_x8r8g8b8, |
|
233 + srcSize.width, |
|
234 + srcSize.height, |
|
235 + (uint32_t*)aSrc->GetData(), |
|
236 + aSrc->Stride()); |
|
237 + |
|
238 + NS_ABORT_IF_FALSE(src && dest, "Failed to create pixman images?"); |
|
239 + |
|
240 + pixman_transform pixTransform = BasicLayerManager_Matrix3DToPixman(aTransform); |
|
241 + pixman_transform pixTransformInverted; |
|
242 + |
|
243 + // If the transform is singular then nothing would be drawn anyway, return here |
|
244 + if (!pixman_transform_invert(&pixTransformInverted, &pixTransform)) { |
|
245 + pixman_image_unref(dest); |
|
246 + pixman_image_unref(src); |
|
247 + return; |
|
248 + } |
|
249 + pixman_image_set_transform(src, &pixTransformInverted); |
|
250 + |
|
251 + pixman_image_composite32(PIXMAN_OP_SRC, |
|
252 + src, |
|
253 + nullptr, |
|
254 + dest, |
|
255 + aDestOffset.x, |
|
256 + aDestOffset.y, |
|
257 + 0, |
|
258 + 0, |
|
259 + 0, |
|
260 + 0, |
|
261 + destSize.width, |
|
262 + destSize.height); |
|
263 + |
|
264 + pixman_image_unref(dest); |
|
265 + pixman_image_unref(src); |
|
266 +} |
|
267 +#endif |
|
268 |
|
269 /** |
|
270 * Transform a surface using a gfx3DMatrix and blit to the destination if |
|
271 @@ -699,7 +777,7 @@ Transform3D(RefPtr<SourceSurface> aSource, |
|
272 gfx3DMatrix translation = gfx3DMatrix::Translation(aBounds.x, aBounds.y, 0); |
|
273 |
|
274 // Transform the content and offset it such that the content begins at the origin. |
|
275 - SkiaTransform(destImage, aSource->GetDataSurface(), translation * aTransform, offset); |
|
276 + Transform(destImage, aSource->GetDataSurface(), translation * aTransform, offset); |
|
277 |
|
278 // If we haven't actually drawn to aDest then return our temporary image so |
|
279 // that the caller can do this. |
|
280 -- |
|
281 2.3.0.4.g34b1174 |
|
282 |
|