a MEMDEV issue

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • a MEMDEV issue

      I have created a emwin window, which has a jpg image as background. The code is as the following:

      C Source Code

      1. GUI_MEMDEV_Handle GH_LoadJPEG2MemDev(const char *filename, int x, int y)
      2. {
      3. HANDLE hFile;
      4. DWORD readBytes;
      5. DWORD fileSize;
      6. char *acBuffer;
      7. GUI_HMEM hMem;
      8. GUI_MEMDEV_Handle hMemJPEG;
      9. GUI_JPEG_INFO jpegInfo;
      10. hFile = CreateFile(filename, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
      11. fileSize = GetFileSize(hFile, NULL);
      12. hMem = GUI_ALLOC_AllocZero(fileSize);
      13. acBuffer = GUI_ALLOC_h2p(hMem);
      14. ReadFile(hFile, acBuffer, fileSize, &readBytes, NULL);
      15. GUI_JPEG_GetInfo(acBuffer, fileSize, &jpegInfo);
      16. hMemJPEG = GUI_MEMDEV_CreateEx(0, 0, jpegInfo.XSize, jpegInfo.YSize, GUI_MEMDEV_HASTRANS);
      17. GUI_MEMDEV_Select(hMemJPEG);
      18. GUI_JPEG_Draw(acBuffer, fileSize, x, y);
      19. GUI_MEMDEV_Select(0);
      20. GUI_ALLOC_Free(hMem);
      21. CloseHandle(hFile);
      22. return hMemJPEG;
      23. }
      24. /*********************************************************************
      25. * *
      26. * SEGGER Microcontroller GmbH *
      27. * Solutions for real time microcontroller applications *
      28. * *
      29. **********************************************************************
      30. * *
      31. * C-file generated by: *
      32. * *
      33. * GUI_Builder for emWin version 6.24 *
      34. * Compiled Jan 18 2022, 14:47:28 *
      35. * (c) 2022 SEGGER Microcontroller GmbH *
      36. * *
      37. **********************************************************************
      38. * *
      39. * Internet: www.segger.com Support: support@segger.com *
      40. * *
      41. **********************************************************************
      42. */
      43. // USER START (Optionally insert additional includes)
      44. // USER END
      45. #include "DIALOG.h"
      46. #include "GuiIncludes.h"
      47. /*********************************************************************
      48. *
      49. * Defines
      50. *
      51. **********************************************************************
      52. */
      53. enum {
      54. ID_WINDOW_0 = (GUI_ID_USER + 0x02),
      55. };
      56. static GUI_MEMDEV_Handle jpegHandle;
      57. /*********************************************************************
      58. *
      59. * _aDialogCreate
      60. */
      61. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
      62. { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 320, 240, 0, 0x0, 0 },
      63. };
      64. /*********************************************************************
      65. *
      66. * _cbDialog
      67. */
      68. static void _cbDialog(WM_MESSAGE * pMsg)
      69. {
      70. const void * pData;
      71. WM_HWIN hItem;
      72. U32 FileSize;
      73. WM_HWIN hWin = pMsg->hWin;
      74. switch (pMsg->MsgId) {
      75. case WM_INIT_DIALOG:
      76. #ifdef CREATE_MEMDEV_IN_INIT
      77. jpegHandle = GH_LoadJPEG2MemDev(GH_GetImageFilePath("home.jpg"), 0, 0);
      78. #endif
      79. break;
      80. case WM_PRE_PAINT:
      81. #ifdef CREATE_MEMDEV_IN_PREPAINT
      82. jpegHandle = GH_LoadJPEG2MemDev(GH_GetImageFilePath("home.jpg"), 0, 0);
      83. #endif
      84. break;
      85. case WM_PAINT:
      86. GUI_MEMDEV_WriteAt(jpegHandle, 0, 0);
      87. break;
      88. case WM_POST_PAINT:
      89. GUI_MEMDEV_Delete(jpegHandle);
      90. break;
      91. default:
      92. WM_DefaultProc(pMsg);
      93. break;
      94. }
      95. }
      96. /*********************************************************************
      97. *
      98. * CreateWindow
      99. */
      100. WM_HWIN CreateWindow_HomeDetect(void)
      101. {
      102. WM_HWIN hWin;
      103. hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
      104. WM__ahWinFocus[0] = hWin;
      105. return hWin;
      106. }
      Display All
      In order to speed up the PAINT process, I use MEMDEV to display the image.

      The strange thing is:

      1. When I enable macro CREATE_MEMDEV_IN_PREPAINT, the background image can not be displayed if I call 'WM_SetCreateFlags(WM_CF_MEMDEV);' before the window creation. Without this function call, everything looks fine.

      2. When I enable macro CREATE_MEMDEV_IN_INIT, both works with/without 'WM_SetCreateFlags(WM_CF_MEMDEV);' call.

      I don't understand, It looks the same. Any ideas?
    • Hi,

      WM_CF_MEMDEV enables automatic use of memory devices for the window manager. This means on each WM_PAINT the window will be drawn into a temporary memory device to avoid flickering. But generally this flag is not needed, if for example your hardware already supports multi-buffering.

      I don't understand why you would draw the image into your memory device on a WM_PRE_PAINT message. I am assuming the image that you load does not change?

      If so, it would make the most sense to create the memory device and render the image once only on WM_INIT_DIALOG. On WM_DELETE, the memory device should be deleted. This way, the memory device shares its lifetime with the window. And also, the image will only be loaded and drawn once which offers a much better performance than to do this on each paint event. Note that under most circumstances windows/widgets receive WM_PAINT messages (which includes WM_PRE_PAINT and POST_PAINT) very frequently.

      Best regards,
      Florian
      Please read the forum rules before posting.

      Keep in mind, this is *not* a support forum.
      Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
      Should you be entitled to support you can contact us via our support system: segger.com/ticket/

      Or you can contact us via e-mail.
    • Thanks a lot.

      1. My hardware (use 8080 parallel MCU interface) doesn't support multi-buffering (or the SW need change a lot to support that). So I try to use MEMDEV.
      2. I use WM_PRE_PAINT and WM_POST_PAINT so that I can create MEMDEV and then delete it share the lifetime with the dialog. Now I understand that WM_INIT_DIALOG and WM_DELETE is a better chooice.