WINCE's graphics display efficiency comparison

WINCE's graphics display efficiency comparison

Article source: blog.csdn.net/zjh824/arti...

[cpp]   view plain copy

  1. #include <pkfuncs.h>  

  2. #define rgb565(r,g,b) (WORD)((((WORD)r&0xf8)<<8)|(((WORD)g&0xfc)<<3)|(((WORD)b&0xf8)>>3))  

  3.   

  4. void CTestDisplayDlg::OnBnClickedButton1()  

  5. {  

  6.     //TODO: Add control notification handler code here  

  7.     //char *gpLCDBuf;  

  8.     //gpLCDBuf = (char*)VirtualAlloc(NULL,0x100000,MEM_RESERVE,PAGE_NOACCESS);  

  9.     //VirtualCopy(gpLCDBuf, (void *)(0x30100000/256), 0x100000, PAGE_READWRITE | PAGE_PHYSICAL | PAGE_NOCACHE);  

  10. //memset(gpLCDBuf,0xFF,0x100000);      

  11.   

  12.   

  13. //HDC m_hdcBuffer = CreateDC(TEXT("DISPLAY"),NULL,NULL,NULL);  

  14.   

  15. //HDC hDisplayDC = ::CreateDC(_T("DISPLAY"), NULL, NULL, NULL);  

  16.     HDC hDisplayDC = ::GetDC(m_hWnd);  

  17.     HDC m_hdcBuffer = ::CreateCompatibleDC(hDisplayDC);  

  18.     //int a = ::GetDeviceCaps(hDisplayDC,BITSPIXEL);  

  19.     //int b = ::GetDeviceCaps(hdcTmp, BITSPIXEL);  

  20.     //int c = ::GetDeviceCaps(m_hdcBuffer, BITSPIXEL);  

  21.     HBITMAP m_hbmpBuffer;  

  22.   

  23.     m_hbmpBuffer = ::CreateCompatibleBitmap(hDisplayDC, 800, 480);  

  24.     HBITMAP hbmp = (HBITMAP)::SelectObject(m_hdcBuffer, m_hbmpBuffer);  

  25.     ::SetBkMode(m_hdcBuffer, TRANSPARENT);  

  26.     ::SetStretchBltMode(m_hdcBuffer, COLORONCOLOR);  

  27.     ::PatBlt(m_hdcBuffer, 0, 0, 800, 480,BLACKNESS);  

  28. //::Set  

  29.     for(int i=0; i<255; ++i)  

  30.     {  

  31.         HPEN hpen = ::CreatePen(PS_SOLID, 1, RGB(i,0, 0));  

  32.         HPEN hOldPen = (HPEN)::SelectObject(m_hdcBuffer, hpen);  

  33.   

  34.         ::MoveToEx(m_hdcBuffer,i,0, NULL);  

  35.         ::LineTo(m_hdcBuffer, i,480 );  

  36.         ::DeleteObject(::SelectObject(m_hdcBuffer, hOldPen));  

  37.           

  38.     }  

  39.   

  40.     for(int i=0; i<=255; ++i)  

  41.     {  

  42.         HPEN hpen = ::CreatePen(0, 1, RGB(0,i, 0));  

  43.         HPEN hOldPen = (HPEN)::SelectObject(m_hdcBuffer, hpen);  

  44.   

  45.         ::MoveToEx(m_hdcBuffer, i+256,0, NULL);  

  46.         ::LineTo(m_hdcBuffer, i+256,480 );  

  47.         ::DeleteObject(::SelectObject(m_hdcBuffer, hOldPen));  

  48.     }  

  49.   

  50.     for(int i=0; i<=255; ++i)  

  51.     {  

  52.         HPEN hpen = ::CreatePen(0, 1, RGB(0,0, i));  

  53.         HPEN hOldPen = (HPEN)::SelectObject(m_hdcBuffer, hpen);  

  54.   

  55.         ::MoveToEx(m_hdcBuffer,i+512, 0, NULL);  

  56.         ::LineTo(m_hdcBuffer, i+512, 480);  

  57.         ::DeleteObject(::SelectObject(m_hdcBuffer, hOldPen));  

  58.     }  

  59.     //::SetPixel(m_hdcBuffer, 0, 0, RGB(200, 0, 0));  

  60.     //*((WORD*)m_lpBitmapBits + 1) = rgb565(200, 0, 0);  

  61.     //*((WORD*)m_lpBitmapBits + 2) = rgb565(200, 0, 0);  

  62.     //*((WORD*)m_lpBitmapBits + 3) = rgb565(200, 0, 0);  

  63.     DWORD dwTime = ::GetTickCount();  

  64.     BitBlt(hDisplayDC, 0, 0,800 ,480, m_hdcBuffer, 0, 0, SRCCOPY);  

  65.     RETAILMSG(1, (TEXT("BitBlt use tickcount is %d/r/n"), ::GetTickCount()-dwTime));  

  66.   

  67.     DeleteObject(::SelectObject(m_hdcBuffer, hbmp));  

  68.     DeleteDC(m_hdcBuffer);  

  69. //::DeleteDC(hDisplayDC);  

  70.     ::ReleaseDC(m_hWnd, hDisplayDC);  

  71. }  

  72.   

  73. void CTestDisplayDlg::OnBnClickedButton2()  

  74. {  

  75.     //TODO: Add control notification handler code here  

  76.   

  77.     //HDC hDisplayDC = ::CreateDC(_T("DISPLAY"), NULL, NULL, NULL);  

  78.     HDC hDisplayDC = ::GetDC(m_hWnd);  

  79.     HDC m_hdcBuffer = ::CreateCompatibleDC(hDisplayDC);  

  80.     HBITMAP m_hbmpBuffer;  

  81.     LPBYTE m_lpBitmapBits;  

  82.     BITMAPINFO bmpInfo;  

  83.     ZeroMemory(&bmpInfo, sizeof(bmpInfo));  

  84.     bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);  

  85.     bmpInfo.bmiHeader.biBitCount = 16;  

  86.     bmpInfo.bmiHeader.biWidth = 800;  

  87.     bmpInfo.bmiHeader.biHeight = -480;  

  88.     bmpInfo.bmiHeader.biPlanes = 1;  

  89.     //bmpInfo.bmiHeader.biCompression = BI_BITFIELDS;  

  90.     //*(DWORD *)(&bmpInfo.bmiColors[0]) = 0xF800;  

  91.     //*(DWORD *)(&bmpInfo.bmiColors[1]) = 0x07E0;  

  92.     //*(DWORD *)(&bmpInfo.bmiColors[2]) = 0x001F;  

  93.   

  94.     bmpInfo.bmiHeader.biSizeImage = 0;  

  95.     bmpInfo.bmiHeader.biXPelsPerMeter = 0;  

  96.     bmpInfo.bmiHeader.biYPelsPerMeter = 0;  

  97.     bmpInfo.bmiHeader.biClrUsed = 0;  

  98.     bmpInfo.bmiHeader.biClrImportant = 0;  

  99.   

  100.     m_hbmpBuffer = ::CreateDIBSection(m_hdcBuffer, (BITMAPINFO *)&bmpInfo,   

  101.         DIB_RGB_COLORS, (void **)&m_lpBitmapBits, NULL, 0);  

  102.   

  103.     HBITMAP hbmp = (HBITMAP)::SelectObject(m_hdcBuffer, m_hbmpBuffer);  

  104.     ::SetBkMode(m_hdcBuffer, TRANSPARENT);  

  105.     ::SetStretchBltMode(m_hdcBuffer, COLORONCOLOR);  

  106.   

  107.     ::PatBlt(hDisplayDC, 0, 0, 800, 480,BLACKNESS);  

  108. //::BitBlt(hDisplayDC, 0, 0, 800, 480, m_hdcBuffer, 0, 0, SRCCOPY);  

  109.   

  110.   

  111.     for(int i=0; i<=255; ++i)  

  112.     {  

  113.         HPEN hpen = ::CreatePen(0, 1, RGB(i,0, 0));  

  114.         HPEN hOldPen = (HPEN)::SelectObject(m_hdcBuffer, hpen);  

  115.   

  116.         ::MoveToEx(m_hdcBuffer,i, 0, NULL);  

  117.         ::LineTo(m_hdcBuffer, i,480 );  

  118.         ::DeleteObject(::SelectObject(m_hdcBuffer, hOldPen));  

  119.     }  

  120.   

  121.     for(int i=0; i<=255; ++i)  

  122.     {  

  123.         HPEN hpen = ::CreatePen(0, 1, RGB(0,i, 0));  

  124.         HPEN hOldPen = (HPEN)::SelectObject(m_hdcBuffer, hpen);  

  125.   

  126.         ::MoveToEx(m_hdcBuffer, i+256,0, NULL);  

  127.         ::LineTo(m_hdcBuffer, i+256,480 );  

  128.         ::DeleteObject(::SelectObject(m_hdcBuffer, hOldPen));  

  129.     }  

  130.   

  131.     for(int i=0; i<=255; ++i)  

  132.     {  

  133.         HPEN hpen = ::CreatePen(0, 1, RGB(0,0, i));  

  134.         HPEN hOldPen = (HPEN)::SelectObject(m_hdcBuffer, hpen);  

  135.   

  136.         ::MoveToEx(m_hdcBuffer,i+512, 0, NULL);  

  137.         ::LineTo(m_hdcBuffer, i+512, 480);  

  138.         ::DeleteObject(::SelectObject(m_hdcBuffer, hOldPen));  

  139.     }  

  140.     //::SetPixel(m_hdcBuffer, 0, 0, RGB(200, 0, 0));  

  141.     //*((WORD*)m_lpBitmapBits + 1) = rgb565(200, 0, 0);  

  142.     //*((WORD*)m_lpBitmapBits + 2) = rgb565(200, 0, 0);  

  143.     //*((WORD*)m_lpBitmapBits + 3) = rgb565(200, 0, 0);  

  144.   

  145.     //::BitBlt(hDisplayDC, 0, 0, 800, 480, m_hdcBuffer, 0, 0, SRCCOPY);  

  146.     DWORD dwTime = ::GetTickCount();  

  147.   

  148.     ::StretchDIBits(hDisplayDC, 0, 0, 800, 480, 0, 0, 800, 480, m_lpBitmapBits, &bmpInfo, DIB_RGB_COLORS, SRCCOPY);  

  149.     RETAILMSG(1, (TEXT("StretchDIBits use tickcount is %d/r/n"), ::GetTickCount()-dwTime));  

  150.   

  151.     DeleteObject(::SelectObject(m_hdcBuffer, hbmp));  

  152.     DeleteDC(m_hdcBuffer);  

  153.     //::DeleteDC(hDisplayDC);  

  154.     ::ReleaseDC(m_hWnd, hDisplayDC);  

  155.   

  156.   

  157. }  

  158.   

  159. void CTestDisplayDlg::OnBnClickedButton4()  

  160. {  

  161.   

  162.   

  163.     //HDC hDisplayDC = ::CreateDC(_T("DISPLAY"), NULL, NULL, NULL);  

  164.     HDC hDisplayDC = ::GetDC(m_hWnd);  

  165.     HDC m_hdcBuffer = ::CreateCompatibleDC(hDisplayDC);  

  166.     HBITMAP m_hbmpBuffer;  

  167.     LPBYTE m_lpBitmapBits;  

  168.     BITMAPINFO* lpNewBmpInfo = (BITMAPINFO *) new BYTE[ (sizeof(BITMAPINFOHEADER) + 3*sizeof(RGBQUAD)) ];      

  169.   

  170.     ZeroMemory(lpNewBmpInfo, sizeof(BITMAPINFO));  

  171.     lpNewBmpInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);  

  172.     lpNewBmpInfo->bmiHeader.biBitCount = 16;  

  173.     lpNewBmpInfo->bmiHeader.biWidth = 800;  

  174.     lpNewBmpInfo->bmiHeader.biHeight = -480;  

  175.     lpNewBmpInfo->bmiHeader.biPlanes = 1;  

  176.   

  177.   

  178.     lpNewBmpInfo->bmiHeader.biSizeImage = 0;  

  179.     lpNewBmpInfo->bmiHeader.biXPelsPerMeter = 0;  

  180.     lpNewBmpInfo->bmiHeader.biYPelsPerMeter = 0;  

  181.     lpNewBmpInfo->bmiHeader.biClrUsed = 0;  

  182.     lpNewBmpInfo->bmiHeader.biClrImportant = 0;  

  183.   

  184.     lpNewBmpInfo->bmiHeader.biCompression = BI_BITFIELDS;  

  185.     *(DWORD *)(&(lpNewBmpInfo->bmiColors[0])) = 0xF800;  

  186.     *(DWORD *)(&(lpNewBmpInfo->bmiColors[1])) = 0x07E0;  

  187.     *(DWORD *)(&(lpNewBmpInfo->bmiColors[2])) = 0x001F;  

  188.   

  189.     m_hbmpBuffer = ::CreateDIBSection(m_hdcBuffer, (BITMAPINFO *)lpNewBmpInfo,   

  190.         DIB_RGB_COLORS, (void **)&m_lpBitmapBits, NULL, 0);  

  191.   

  192.     HBITMAP hbmp = (HBITMAP)::SelectObject(m_hdcBuffer, m_hbmpBuffer);  

  193.     ::SetBkMode(m_hdcBuffer, TRANSPARENT);  

  194.     ::SetStretchBltMode(m_hdcBuffer, COLORONCOLOR);  

  195.   

  196.     ::PatBlt(hDisplayDC, 0, 0, 800, 480,BLACKNESS);  

  197.   

  198.     for(int i=0; i<=255; ++i)  

  199.     {  

  200.         HPEN hpen = ::CreatePen(0, 1, RGB(i,0, 0));  

  201.         HPEN hOldPen = (HPEN)::SelectObject(m_hdcBuffer, hpen);  

  202.   

  203.         ::MoveToEx(m_hdcBuffer,i, 0, NULL);  

  204.         ::LineTo(m_hdcBuffer, i,480 );  

  205.         ::DeleteObject(::SelectObject(m_hdcBuffer, hOldPen));  

  206.     }  

  207.   

  208.     for(int i=0; i<=255; ++i)  

  209.     {  

  210.         HPEN hpen = ::CreatePen(0, 1, RGB(0,i, 0));  

  211.         HPEN hOldPen = (HPEN)::SelectObject(m_hdcBuffer, hpen);  

  212.   

  213.         ::MoveToEx(m_hdcBuffer, i+256,0, NULL);  

  214.         ::LineTo(m_hdcBuffer, i+256,480 );  

  215.         ::DeleteObject(::SelectObject(m_hdcBuffer, hOldPen));  

  216.     }  

  217.   

  218.     for(int i=0; i<=255; ++i)  

  219.     {  

  220.         HPEN hpen = ::CreatePen(0, 1, RGB(0,0, i));  

  221.         HPEN hOldPen = (HPEN)::SelectObject(m_hdcBuffer, hpen);  

  222.   

  223.         ::MoveToEx(m_hdcBuffer,i+512, 0, NULL);  

  224.         ::LineTo(m_hdcBuffer, i+512, 480);  

  225.         ::DeleteObject(::SelectObject(m_hdcBuffer, hOldPen));  

  226.     }  

  227.     //::SetPixel(m_hdcBuffer, 0, 0, RGB(200, 0, 0));  

  228.     //*((WORD*)m_lpBitmapBits + 1) = rgb565(200, 0, 0);  

  229.     //*((WORD*)m_lpBitmapBits + 2) = rgb565(200, 0, 0);  

  230.     //*((WORD*)m_lpBitmapBits + 3) = rgb565(200, 0, 0);  

  231.   

  232.   

  233.     //::BitBlt(hDisplayDC, 0, 0, 800, 480, m_hdcBuffer, 0, 0, SRCCOPY);  

  234.     DWORD dwTime = ::GetTickCount();  

  235.   

  236.     ::StretchDIBits(hDisplayDC, 0, 0, 800, 480, 0, 0, 800, 480, m_lpBitmapBits,(BITMAPINFO*)lpNewBmpInfo, DIB_RGB_COLORS, SRCCOPY);  

  237.     RETAILMSG(1, (TEXT(" 16BPP StretchDIBits use tickcount is %d/r/n"), ::GetTickCount()-dwTime));  

  238.   

  239.     DeleteObject(::SelectObject(m_hdcBuffer, hbmp));  

  240.     DeleteDC(m_hdcBuffer);  

  241.     //::DeleteDC(hDisplayDC);  

  242.     ::ReleaseDC(m_hWnd, hDisplayDC);  

  243.     delete lpNewBmpInfo;  

  244.   

  245.   

  246. }  

  247.   

  248.   

  249. void CTestDisplayDlg::OnBnClickedButton5()  

  250. {  

  251.   

  252.     //HDC hDisplayDC = ::CreateDC(_T("DISPLAY"), NULL, NULL, NULL);  

  253.     HDC hDisplayDC = ::GetDC(m_hWnd);  

  254.     HDC m_hdcBuffer = ::CreateCompatibleDC(hDisplayDC);  

  255.     HBITMAP m_hbmpBuffer;  

  256.     LPBYTE m_lpBitmapBits;  

  257.     BITMAPINFO* lpNewBmpInfo = (BITMAPINFO *) new BYTE[ (sizeof(BITMAPINFOHEADER) + 3*sizeof(RGBQUAD)) ];      

  258.   

  259.     ZeroMemory(lpNewBmpInfo, sizeof(BITMAPINFO));  

  260.     lpNewBmpInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);  

  261.     lpNewBmpInfo->bmiHeader.biBitCount = 16;  

  262.     lpNewBmpInfo->bmiHeader.biWidth = 800;  

  263.     lpNewBmpInfo->bmiHeader.biHeight = -480;  

  264.     lpNewBmpInfo->bmiHeader.biPlanes = 1;  

  265.   

  266.   

  267.     lpNewBmpInfo->bmiHeader.biSizeImage = 0;  

  268.     lpNewBmpInfo->bmiHeader.biXPelsPerMeter = 0;  

  269.     lpNewBmpInfo->bmiHeader.biYPelsPerMeter = 0;  

  270.     lpNewBmpInfo->bmiHeader.biClrUsed = 0;  

  271.     lpNewBmpInfo->bmiHeader.biClrImportant = 0;  

  272.   

  273.     lpNewBmpInfo->bmiHeader.biCompression = BI_BITFIELDS;  

  274.     *(DWORD *)(&(lpNewBmpInfo->bmiColors[0])) = 0xF800;  

  275.     *(DWORD *)(&(lpNewBmpInfo->bmiColors[1])) = 0x07E0;  

  276.     *(DWORD *)(&(lpNewBmpInfo->bmiColors[2])) = 0x001F;  

  277.   

  278.     m_hbmpBuffer = ::CreateDIBSection(m_hdcBuffer, (BITMAPINFO *)lpNewBmpInfo,   

  279.         DIB_RGB_COLORS, (void **)&m_lpBitmapBits, NULL, 0);  

  280.   

  281.     HBITMAP hbmp = (HBITMAP)::SelectObject(m_hdcBuffer, m_hbmpBuffer);  

  282.     ::SetBkMode(m_hdcBuffer, TRANSPARENT);  

  283.     ::SetStretchBltMode(m_hdcBuffer, COLORONCOLOR);  

  284.   

  285.     ::PatBlt(hDisplayDC, 0, 0, 800, 480,BLACKNESS);  

  286.   

  287.     for(int i=0; i<=255; ++i)  

  288.     {  

  289.         HPEN hpen = ::CreatePen(0, 1, RGB(i,0, 0));  

  290.         HPEN hOldPen = (HPEN)::SelectObject(m_hdcBuffer, hpen);  

  291.   

  292.         ::MoveToEx(m_hdcBuffer,i, 0, NULL);  

  293.         ::LineTo(m_hdcBuffer, i,480 );  

  294.         ::DeleteObject(::SelectObject(m_hdcBuffer, hOldPen));  

  295.     }  

  296.   

  297.     for(int i=0; i<=255; ++i)  

  298.     {  

  299.         HPEN hpen = ::CreatePen(0, 1, RGB(0,i, 0));  

  300.         HPEN hOldPen = (HPEN)::SelectObject(m_hdcBuffer, hpen);  

  301.   

  302.         ::MoveToEx(m_hdcBuffer, i+256,0, NULL);  

  303.         ::LineTo(m_hdcBuffer, i+256,480 );  

  304.         ::DeleteObject(::SelectObject(m_hdcBuffer, hOldPen));  

  305.     }  

  306.   

  307.     for(int i=0; i<=255; ++i)  

  308.     {  

  309.         HPEN hpen = ::CreatePen(0, 1, RGB(0,0, i));  

  310.         HPEN hOldPen = (HPEN)::SelectObject(m_hdcBuffer, hpen);  

  311.   

  312.         ::MoveToEx(m_hdcBuffer,i+512, 0, NULL);  

  313.         ::LineTo(m_hdcBuffer, i+512, 480);  

  314.         ::DeleteObject(::SelectObject(m_hdcBuffer, hOldPen));  

  315.     }  

  316.     //::SetPixel(m_hdcBuffer, 0, 0, RGB(200, 0, 0));  

  317.     //*((WORD*)m_lpBitmapBits + 1) = rgb565(200, 0, 0);  

  318.     //*((WORD*)m_lpBitmapBits + 2) = rgb565(200, 0, 0);  

  319.     //*((WORD*)m_lpBitmapBits + 3) = rgb565(200, 0, 0);  

  320.   

  321.   

  322.     DWORD dwTime = ::GetTickCount();  

  323.   

  324.     BitBlt(hDisplayDC, 0, 0,800 ,480, m_hdcBuffer, 0, 0, SRCCOPY);  

  325.     RETAILMSG(1, (TEXT(" 16BPP BitBlt use tickcount is %d/r/n"), ::GetTickCount()-dwTime));  

  326.   

  327.     DeleteObject(::SelectObject(m_hdcBuffer, hbmp));  

  328.     DeleteDC(m_hdcBuffer);  

  329.     //::DeleteDC(hDisplayDC);  

  330.     ::ReleaseDC(m_hWnd, hDisplayDC);  

  331.     delete lpNewBmpInfo;  

  332.   

  333. }  

  334.   

  335.   

  336. void CTestDisplayDlg::OnBnClickedButton3()  

  337. {  

  338.     //TODO: Add control notification handler code here  

  339.   

  340.   

  341.     char *gpLCDBuf;  

  342.     gpLCDBuf = (char*)VirtualAlloc(NULL,0x100000,MEM_RESERVE,PAGE_NOACCESS);  

  343.     VirtualCopy(gpLCDBuf, (void *)(0x30100000/256), 0x100000, PAGE_READWRITE | PAGE_PHYSICAL | PAGE_NOCACHE);  

  344.     //memset(gpLCDBuf,0xFF,0x100000);      

  345.   

  346.   

  347.     //HDC m_hdcBuffer = CreateDC(TEXT("DISPLAY"),NULL,NULL,NULL);  

  348.   

  349.     //HDC hDisplayDC = ::CreateDC(_T("DISPLAY"), NULL, NULL, NULL);  

  350.     HDC hDisplayDC = ::GetDC(m_hWnd);  

  351.     HDC m_hdcBuffer = ::CreateCompatibleDC(hDisplayDC);  

  352.   

  353.     HBITMAP m_hbmpBuffer;  

  354.     LPBYTE m_lpBitmapBits;  

  355.     BITMAPINFO* lpNewBmpInfo = (BITMAPINFO *) new BYTE[ (sizeof(BITMAPINFOHEADER) + 3*sizeof(RGBQUAD)) ];      

  356.   

  357.     //BITMAPINFO bmpInfo;  

  358.     ZeroMemory(lpNewBmpInfo, sizeof(BITMAPINFO));  

  359.     lpNewBmpInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);  

  360.     lpNewBmpInfo->bmiHeader.biBitCount = 16;  

  361.     lpNewBmpInfo->bmiHeader.biWidth = 800;  

  362.     lpNewBmpInfo->bmiHeader.biHeight = -480;  

  363.     lpNewBmpInfo->bmiHeader.biPlanes = 1;  

  364.     lpNewBmpInfo->bmiHeader.biCompression = BI_BITFIELDS;  

  365.   

  366.   

  367.     lpNewBmpInfo->bmiHeader.biSizeImage = 0;  

  368.     lpNewBmpInfo->bmiHeader.biXPelsPerMeter = 0;  

  369.     lpNewBmpInfo->bmiHeader.biYPelsPerMeter = 0;  

  370.     lpNewBmpInfo->bmiHeader.biClrUsed = 0;  

  371.     lpNewBmpInfo->bmiHeader.biClrImportant = 0;  

  372.   

  373.     *(DWORD *)(&(lpNewBmpInfo->bmiColors[0])) = 0xF800;  

  374.     *(DWORD *)(&(lpNewBmpInfo->bmiColors[1])) = 0x07E0;  

  375.     *(DWORD *)(&(lpNewBmpInfo->bmiColors[2])) = 0x001F;  

  376.   

  377.     m_hbmpBuffer = ::CreateDIBSection(m_hdcBuffer, (BITMAPINFO *)lpNewBmpInfo,   

  378.         DIB_RGB_COLORS, (void **)&m_lpBitmapBits, NULL, 0);  

  379.   

  380.     HBITMAP hbmp = (HBITMAP)::SelectObject(m_hdcBuffer, m_hbmpBuffer);  

  381.     ::SetBkMode(m_hdcBuffer, TRANSPARENT);  

  382.     ::SetStretchBltMode(m_hdcBuffer, COLORONCOLOR);  

  383. //::PatBlt(hDisplayDC, 0, 0, 800, 480,BLACKNESS);  

  384.     memset(m_lpBitmapBits, 0, 800 * 480 * 2);  

  385.     CopyMemory(gpLCDBuf, m_lpBitmapBits, 800 * 480 * 2);  

  386.   

  387.   

  388.   

  389.   

  390.     for(int i=0; i<=255; ++i)  

  391.     {  

  392.         //HPEN hpen = ::CreatePen(0, 1, RGB(i,0, 0));  

  393.         //HPEN hOldPen = (HPEN)::SelectObject(m_hdcBuffer, hpen);  

  394.   

  395.         //::MoveToEx(m_hdcBuffer,i, 0, NULL);  

  396.         //::LineTo(m_hdcBuffer, i,480 );  

  397.         //::DeleteObject(::SelectObject(m_hdcBuffer, hOldPen));  

  398.         LPWORD lpData = (LPWORD)m_lpBitmapBits;  

  399.         for(int j=0; j<480; ++j)  

  400.         {  

  401.             *(lpData + i + 800 * j) = rgb565(i,0,0);  

  402.         }  

  403.     }  

  404.   

  405.     for(int i=0; i<=255; ++i)  

  406.     {  

  407.         LPWORD lpData = (LPWORD)m_lpBitmapBits;  

  408.         for(int j=0; j<480; ++j)  

  409.         {  

  410.             *(lpData + i+ 256 + 800 * j) = rgb565(0,i,0);  

  411.         }  

  412.     /* HPEN hpen = ::CreatePen(0, 1, RGB(0,i, 0));  

  413.         HPEN hOldPen = (HPEN)::SelectObject(m_hdcBuffer, hpen);  

  414.   

  415.         ::MoveToEx(m_hdcBuffer, i+256,0, NULL);  

  416.         ::LineTo(m_hdcBuffer, i+256,480 );  

  417.         ::DeleteObject(::SelectObject(m_hdcBuffer, hOldPen));*/  

  418.     }  

  419.   

  420.     for(int i=0; i<=255; ++i)  

  421.     {  

  422.         LPWORD lpData = (LPWORD)m_lpBitmapBits;  

  423.         for(int j=0; j<480; ++j)  

  424.         {  

  425.             *(lpData + i+ 512 + 800 * j) = rgb565(0,0,i);  

  426.         }  

  427.         //HPEN hpen = ::CreatePen(0, 1, RGB(0,0, i));  

  428.         //HPEN hOldPen = (HPEN)::SelectObject(m_hdcBuffer, hpen);  

  429.   

  430.         //::MoveToEx(m_hdcBuffer,i+512, 0, NULL);  

  431.         //::LineTo(m_hdcBuffer, i+512, 480);  

  432.         //::DeleteObject(::SelectObject(m_hdcBuffer, hOldPen));  

  433.     }  

  434.     //::SetPixel(m_hdcBuffer, 0, 0, RGB(200, 0, 0));  

  435.     //*((WORD*)m_lpBitmapBits + 1) = rgb565(200, 0, 0);  

  436.     //*((WORD*)m_lpBitmapBits + 2) = rgb565(200, 0, 0);  

  437.     //*((WORD*)m_lpBitmapBits + 3) = rgb565(200, 0, 0);  

  438.   

  439.   

  440.   

  441.   

  442.     //for(int i = 0; i<800 * 240; ++i)  

  443.     //{

      

  444.     //*tmp++ = rgb565(255, 0, 0);  

  445.     //}  

  446.     DWORD dwTime = ::GetTickCount();  

  447.         CopyMemory(gpLCDBuf, m_lpBitmapBits, 800 * 480 * 2);  

  448.         RETAILMSG(1, (TEXT("FrameBuffer use tickcount is %d/r/n"), ::GetTickCount()-dwTime));  

  449.   

  450.   

  451. //::StretchDIBits(hDisplayDC, 0, 0, 800, 480, 0, 0, 800, 480, m_lpBitmapBits,(BITMAPINFO*)lpNewBmpInfo, DIB_RGB_COLORS, SRCCOPY);  

  452.   

  453.   

  454.     //BitBlt(hdcTmp, 0, 0, rcWnd.Width(), rcWnd.Height(), m_hdcBuffer, 0, 0, SRCCOPY);  

  455.     //InvalidateRect(NULL);  

  456.   

  457.   

  458.     VirtualFree(gpLCDBuf,0,MEM_RELEASE);  

  459.     DeleteObject(::SelectObject(m_hdcBuffer, hbmp));  

  460.     DeleteDC(m_hdcBuffer);  

  461.   

  462.     //::DeleteDC(hDisplayDC);  

  463.     ::ReleaseDC(m_hWnd, hDisplayDC);  

  464.   

  465.     delete lpNewBmpInfo;  

  466.   

  467. }  

  

 

GDI operation process: Draw 255 gradual vertical lines in red, green and blue on the DC of the window. As shown

 

show result:

Device compatible bitmap DDB: BitBlt use tickcount is 13 
DIB bitmap (format is not compatible): StretchDIBits use tickcount is 184 
rgb565 DIB bitmap: 16BPP StretchDIBits use tickcount is 12 RGB565 
DIB bitmap: 16BPP BitBlt use tickcount is 13 
Direct screen writing : FrameBuffer use tickcount is 9

 

Conclusion: When creating DDB bitmap and DIB bitmap, the speed of texture is the same. The only difference is that if the created DIB bitmap must be in the same format as the bitmap in the driver, including the format of BIT_MASK, which is the RGB565 format in the driver, the bitmap created in the application should also be the RGB565 DIB bitmap. Otherwise, there will be a RGB conversion in the driver of BITBLT, which will cause the drawing speed to be very slow. However, there is no such problem in creating DDB bitmaps, and the speed will not be slow.

 

Time statistics results of all GDI operations (only including GDI operations, creating brushes, MOVETOEX, LINETO, SelectObject, BitBlt, etc., excluding bitmap creation, DC creation, etc.):

BitBlt use tickcount is 443 
StretchDIBits use tickcount is 610 
16BPP StretchDIBits use tickcount is 438 
16BPP BitBlt use tickcount is 439 
FrameBuffer use tickcount is 116

 

Conclusion: When using GDI, the speed in the first four cases is the same, and has nothing to do with the format of the bitmap, but when using BitBlt, it will cause a great performance loss due to the incompatible bitmap format.

But if you use the direct screen writing operation to convert a simple GDI function call into a pure memory assignment operation, this operation can save a lot of time. In fact, you can use the DIB bitmap to perform this operation, and directly write values to the memory data of the DIB bitmap to achieve GDI operations.

Change the BitBlt of 16BPP to the operation of direct memory write value, the time result is:

BitBlt use tickcount is 442 
StretchDIBits use tickcount is 611 
16BPP StretchDIBits use tickcount is 441 
16BPP BitBlt use tickcount is 106 
FrameBuffer use tickcount is 104

It can be seen that in this case, the efficiency is the same as directly writing to the screen. For frequent GDI operation and drawing, rewriting GDI API calls can save a lot of time, provided that the DIB bitmap compatible with the display driver is used. Then write the value directly to the bitmap data.

\