Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 1f5bebde8f9e251b4f7b9f466c63c97f2cc92b59 Mon Sep 17 00:00:00 2001
- From: =?UTF-8?q?Samuel=20R=C3=B8dal?= <samuel.rodal@nokia.com>
- Date: Thu, 8 Sep 2011 13:10:47 +0200
- Subject: [PATCH] Allocate 16-byte aligned memory independent of platform for raster pool.
- ---
- src/gui/painting/qpaintengine_raster.cpp | 47 +++++++----------------------
- 1 files changed, 12 insertions(+), 35 deletions(-)
- diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp
- index 9826689..830f230 100644
- --- a/src/gui/painting/qpaintengine_raster.cpp
- +++ b/src/gui/painting/qpaintengine_raster.cpp
- @@ -3793,17 +3793,9 @@ void QRasterPaintEnginePrivate::rasterize(QT_FT_Outline *outline,
- // occur normally.
- const int rasterPoolInitialSize = MINIMUM_POOL_SIZE;
- int rasterPoolSize = rasterPoolInitialSize;
- - unsigned char *rasterPoolBase;
- -#if defined(Q_WS_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);
- + unsigned char rasterPoolOnStack[rasterPoolInitialSize + 0xf];
- + unsigned char *rasterPoolBase = (unsigned char *)((quintptr)rasterPoolOnStack & ~0xf);
- + unsigned char *rasterPoolOnHeap = 0;
- qt_ft_grays_raster.raster_reset(*grayRaster.data(), rasterPoolBase, rasterPoolSize);
- @@ -3839,31 +3831,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_WS_WIN64)
- - _aligned_free(rasterPoolBase);
- -#else
- - if (rasterPoolBase != rasterPoolOnStack) // initially on the stack
- - free(rasterPoolBase);
- -#endif
- + free(rasterPoolOnHeap);
- + rasterPoolOnHeap = (unsigned char *)malloc(rasterPoolSize + 0xf);
- - rasterPoolSize = new_size;
- - rasterPoolBase =
- -#if defined(Q_WS_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 = (unsigned char *)((quintptr)rasterPoolOnHeap & ~0xf);
- qt_ft_grays_raster.raster_done(*grayRaster.data());
- qt_ft_grays_raster.raster_new(grayRaster.data());
- @@ -3873,12 +3854,8 @@ void QRasterPaintEnginePrivate::rasterize(QT_FT_Outline *outline,
- }
- }
- -#if defined(Q_WS_WIN64)
- - _aligned_free(rasterPoolBase);
- -#else
- - if (rasterPoolBase != rasterPoolOnStack) // initially on the stack
- - free(rasterPoolBase);
- -#endif
- + if (rasterPoolOnHeap)
- + free(rasterPoolOnHeap);
- }
- void QRasterPaintEnginePrivate::recalculateFastImages()
- --
- 1.7.0.4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement