Source Code for ProfApp (Windows CE 5.0)

Send Feedback

The following code is for ProfApp, the target application used in How to Profile and Optimize a Display Driver. ProfApp only exercises a portion of a display driver's capabilities; it is not a general application for display driver profiling. A driver that is designed to run well for the operations in ProfApp may not perform well for other operations.

Note   To make the following code example easier to read, error checking is not included. This code example should not be used in a release configuration unless it has been modified to include secure error handling.

// A sample application for display profiling.
#include <windows.h>

struct {
   BITMAPINFOHEADER bmiHeader;
   ULONG            bmiColors[4];
} bmi;

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPWSTR,int)
{
   int i, j;
   HDC Dc = GetDC(NULL);
   RECT WorkArea;

   SystemParametersInfo(SPI_GETWORKAREA, 0, &WorkArea, 0);

   int Width  = WorkArea.right - WorkArea.left;
   int Height = WorkArea.bottom - WorkArea.top;

   // Create a RGB555 DIB section and give it a green and blue pattern.
   HDC DibDc = CreateCompatibleDC(Dc);

   memset(&bmi, 0, sizeof (bmi));
   bmi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
   bmi.bmiHeader.biWidth = Width;
   bmi.bmiHeader.biHeight = -Height;  // top-down bitmap
   bmi.bmiHeader.biPlanes = 1;
   bmi.bmiHeader.biBitCount = 16;
   bmi.bmiHeader.biCompression = BI_BITFIELDS;

   bmi.bmiColors[0] = 0x7C00;
   bmi.bmiColors[1] = 0x03E0;
   bmi.bmiColors[2] = 0x001F;
   bmi.bmiColors[3] = 0;         // No alpha channel.

   void * pBits = NULL;

   HBITMAP Dib = CreateDIBSection(DibDc, (BITMAPINFO *)&bmi,
                                  DIB_RGB_COLORS, &pBits, NULL, 0);
   if (NULL == Dib)
   {
       // Failed to allocate DIB!
       return -1;
   }

   HGDIOBJ OldDib = SelectObject(DibDc, Dib);
   HBRUSH GreenBrush = CreateSolidBrush(RGB(0, 255, 0));
   HBRUSH BlueBrush  = CreateSolidBrush(RGB(0, 0, 255));

   bool Parity = false;

   for (i = 0; i < Height; i += 16)
   {
      bool LineParity = Parity;

      for (j = 0; j < Width; j += 16)
      {
         RECT Rect;
         Rect.left   = j;
         Rect.top    = i;
         Rect.right  = j + 16;
         Rect.bottom = i + 16;

         FillRect(DibDc, &Rect, (LineParity ? GreenBrush : BlueBrush));

         LineParity = !LineParity;
      }
      Parity = !Parity;
   }

   DeleteObject(GreenBrush);
   DeleteObject(BlueBrush);

   // Randomly copy the offscreen bitmaps to the screen.

   DWORD StartTime = GetTickCount();

   for (i = 0; i < 1000; i++)
   {
      int BltWidth  = rand() % Width;
      int BltHeight = rand() % Height;
      int XPos      = rand() % Width;
      int YPos      = rand() % Height;

      BitBlt(Dc, WorkArea.left + XPos, WorkArea.top + YPos,
             BltWidth, BltHeight, DibDc, XPos, YPos, SRCCOPY);
   }

   DWORD StopTime = GetTickCount();

   RETAILMSG(1, (L"ProfApp:  Took %d ms to perform blts.",
                 StopTime - StartTime));

   // Clean up.
   SelectObject(DibDc, OldDib);
   DeleteObject(OldDib);
   DeleteObject(DibDc);
   ReleaseDC(NULL, Dc);

   return 0;
}

See Also

How to Profile and Optimize a Display Driver | Creating a Target Application for Profiling the FLAT Display Driver

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.