1. From 1f5bebde8f9e251b4f7b9f466c63c97f2cc92b59 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Samuel=20R=C3=B8dal?= <samuel.rodal@nokia.com>
  3. Date: Thu, 8 Sep 2011 13:10:47 +0200
  4. Subject: [PATCH] Allocate 16-byte aligned memory independent of platform for raster pool.
  5.  
  6. ---
  7. src/gui/painting/qpaintengine_raster.cpp |   47 +++++++----------------------
  8.  1 files changed, 12 insertions(+), 35 deletions(-)
  9.  
  10. diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp
  11. index 9826689..830f230 100644
  12. --- a/src/gui/painting/qpaintengine_raster.cpp
  13. +++ b/src/gui/painting/qpaintengine_raster.cpp
  14. @@ -3793,17 +3793,9 @@ void QRasterPaintEnginePrivate::rasterize(QT_FT_Outline *outline,
  15.      // occur normally.
  16.      const int rasterPoolInitialSize = MINIMUM_POOL_SIZE;
  17.      int rasterPoolSize = rasterPoolInitialSize;
  18. -    unsigned char *rasterPoolBase;
  19. -#if defined(Q_WS_WIN64)
  20. -    rasterPoolBase =
  21. -        // We make use of setjmp and longjmp in qgrayraster.c which requires
  22. -        // 16-byte alignment, hence we hardcode this requirement here..
  23. -        (unsigned char *) _aligned_malloc(rasterPoolSize, sizeof(void*) * 2);
  24. -#else
  25. -    unsigned char rasterPoolOnStack[rasterPoolInitialSize];
  26. -    rasterPoolBase = rasterPoolOnStack;
  27. -#endif
  28. -    Q_CHECK_PTR(rasterPoolBase);
  29. +    unsigned char rasterPoolOnStack[rasterPoolInitialSize + 0xf];
  30. +    unsigned char *rasterPoolBase = (unsigned char *)((quintptr)rasterPoolOnStack & ~0xf);
  31. +    unsigned char *rasterPoolOnHeap = 0;
  32.  
  33.      qt_ft_grays_raster.raster_reset(*grayRaster.data(), rasterPoolBase, rasterPoolSize);
  34.  
  35. @@ -3839,31 +3831,20 @@ void QRasterPaintEnginePrivate::rasterize(QT_FT_Outline *outline,
  36.  
  37.          // Out of memory, reallocate some more and try again...
  38.          if (error == -6) { // ErrRaster_OutOfMemory from qgrayraster.c
  39. -            int new_size = rasterPoolSize * 2;
  40. -            if (new_size > 1024 * 1024) {
  41. +            rasterPoolSize *= 2;
  42. +            if (rasterPoolSize > 1024 * 1024) {
  43.                  qWarning("QPainter: Rasterization of primitive failed");
  44.                  break;
  45.              }
  46.  
  47.              rendered_spans += q_gray_rendered_spans(*grayRaster.data());
  48.  
  49. -#if defined(Q_WS_WIN64)
  50. -            _aligned_free(rasterPoolBase);
  51. -#else
  52. -            if (rasterPoolBase != rasterPoolOnStack) // initially on the stack
  53. -                free(rasterPoolBase);
  54. -#endif
  55. +            free(rasterPoolOnHeap);
  56. +            rasterPoolOnHeap = (unsigned char *)malloc(rasterPoolSize + 0xf);
  57.  
  58. -            rasterPoolSize = new_size;
  59. -            rasterPoolBase =
  60. -#if defined(Q_WS_WIN64)
  61. -                // We make use of setjmp and longjmp in qgrayraster.c which requires
  62. -                // 16-byte alignment, hence we hardcode this requirement here..
  63. -                (unsigned char *) _aligned_malloc(rasterPoolSize, sizeof(void*) * 2);
  64. -#else
  65. -                (unsigned char *) malloc(rasterPoolSize);
  66. -#endif
  67. -            Q_CHECK_PTR(rasterPoolBase); // note: we just freed the old rasterPoolBase. I hope it's not fatal.
  68. +            Q_CHECK_PTR(rasterPoolOnHeap); // note: we just freed the old rasterPoolBase. I hope it's not fatal.
  69. +
  70. +            rasterPoolBase = (unsigned char *)((quintptr)rasterPoolOnHeap & ~0xf);
  71.  
  72.              qt_ft_grays_raster.raster_done(*grayRaster.data());
  73.              qt_ft_grays_raster.raster_new(grayRaster.data());
  74. @@ -3873,12 +3854,8 @@ void QRasterPaintEnginePrivate::rasterize(QT_FT_Outline *outline,
  75.          }
  76.      }
  77.  
  78. -#if defined(Q_WS_WIN64)
  79. -    _aligned_free(rasterPoolBase);
  80. -#else
  81. -    if (rasterPoolBase != rasterPoolOnStack) // initially on the stack
  82. -        free(rasterPoolBase);
  83. -#endif
  84. +    if (rasterPoolOnHeap)
  85. +        free(rasterPoolOnHeap);
  86.  }
  87.  
  88.  void QRasterPaintEnginePrivate::recalculateFastImages()
  89. --
  90. 1.7.0.4