summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gui/painting/qpaintengine_raster.cpp54
1 files changed, 17 insertions, 37 deletions
diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp
index e2e4ed6b0a..233bc04924 100644
--- a/src/gui/painting/qpaintengine_raster.cpp
+++ b/src/gui/painting/qpaintengine_raster.cpp
@@ -3450,6 +3450,11 @@ extern "C" {
int q_gray_rendered_spans(QT_FT_Raster raster);
}
+static inline uchar *alignAddress(uchar *address, quintptr alignmentMask)
+{
+ return (uchar *)(((quintptr)address + alignmentMask) & ~alignmentMask);
+}
+
void QRasterPaintEnginePrivate::rasterize(QT_FT_Outline *outline,
ProcessSpans callback,
void *userData, QRasterBuffer *)
@@ -3477,19 +3482,10 @@ void QRasterPaintEnginePrivate::rasterize(QT_FT_Outline *outline,
// minimize memory reallocations. However if initial size for
// raster pool is changed for lower value, reallocations will
// occur normally.
- const int rasterPoolInitialSize = MINIMUM_POOL_SIZE;
- int rasterPoolSize = rasterPoolInitialSize;
- unsigned char *rasterPoolBase;
-#if defined(Q_OS_WIN64)
- rasterPoolBase =
- // We make use of setjmp and longjmp in qgrayraster.c which requires
- // 16-byte alignment, hence we hardcode this requirement here..
- (unsigned char *) _aligned_malloc(rasterPoolSize, sizeof(void*) * 2);
-#else
- unsigned char rasterPoolOnStack[rasterPoolInitialSize];
- rasterPoolBase = rasterPoolOnStack;
-#endif
- Q_CHECK_PTR(rasterPoolBase);
+ int rasterPoolSize = MINIMUM_POOL_SIZE;
+ uchar rasterPoolOnStack[MINIMUM_POOL_SIZE + 0xf];
+ uchar *rasterPoolBase = alignAddress(rasterPoolOnStack, 0xf);
+ uchar *rasterPoolOnHeap = 0;
qt_ft_grays_raster.raster_reset(*grayRaster.data(), rasterPoolBase, rasterPoolSize);
@@ -3525,31 +3521,20 @@ void QRasterPaintEnginePrivate::rasterize(QT_FT_Outline *outline,
// Out of memory, reallocate some more and try again...
if (error == -6) { // ErrRaster_OutOfMemory from qgrayraster.c
- int new_size = rasterPoolSize * 2;
- if (new_size > 1024 * 1024) {
+ rasterPoolSize *= 2;
+ if (rasterPoolSize > 1024 * 1024) {
qWarning("QPainter: Rasterization of primitive failed");
break;
}
rendered_spans += q_gray_rendered_spans(*grayRaster.data());
-#if defined(Q_OS_WIN64)
- _aligned_free(rasterPoolBase);
-#else
- if (rasterPoolBase != rasterPoolOnStack) // initially on the stack
- free(rasterPoolBase);
-#endif
+ free(rasterPoolOnHeap);
+ rasterPoolOnHeap = (uchar *)malloc(rasterPoolSize + 0xf);
- rasterPoolSize = new_size;
- rasterPoolBase =
-#if defined(Q_OS_WIN64)
- // We make use of setjmp and longjmp in qgrayraster.c which requires
- // 16-byte alignment, hence we hardcode this requirement here..
- (unsigned char *) _aligned_malloc(rasterPoolSize, sizeof(void*) * 2);
-#else
- (unsigned char *) malloc(rasterPoolSize);
-#endif
- Q_CHECK_PTR(rasterPoolBase); // note: we just freed the old rasterPoolBase. I hope it's not fatal.
+ Q_CHECK_PTR(rasterPoolOnHeap); // note: we just freed the old rasterPoolBase. I hope it's not fatal.
+
+ rasterPoolBase = alignAddress(rasterPoolOnHeap, 0xf);
qt_ft_grays_raster.raster_done(*grayRaster.data());
qt_ft_grays_raster.raster_new(grayRaster.data());
@@ -3559,12 +3544,7 @@ void QRasterPaintEnginePrivate::rasterize(QT_FT_Outline *outline,
}
}
-#if defined(Q_OS_WIN64)
- _aligned_free(rasterPoolBase);
-#else
- if (rasterPoolBase != rasterPoolOnStack) // initially on the stack
- free(rasterPoolBase);
-#endif
+ free(rasterPoolOnHeap);
}
void QRasterPaintEnginePrivate::recalculateFastImages()