Export (0) Print
Expand All

Source Code for ProfApp (Windows Embedded CE 6.0)

1/6/2010

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.

Ee483803.note(en-US,WinEmbedded.60).gifNote:
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;
}

Community Additions

ADD
Show:
© 2014 Microsoft