⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 enable.c

📁 WinCE 3.0 BSP, 包含Inter SA1110, Intel_815E, Advantech_PCM9574 等
💻 C
📖 第 1 页 / 共 2 页
字号:
//
// Permedia3 Sample Display Driver
// enable.c
//
// Copyright (c) 2000 Microsoft Corporation. All rights reserved.
//
// This module exposes all of the code necessary to locate and enable the
// Permedia3 device on startup. It assumes that the Permedia3 chip is on the
// PCI bus. It also includes the GDI startup code, and the DllMain entry
// point.

#include "pch.h"  // Precompiled header support.
#include "const.h"
#include "debug.h"
#include "struct.h"
#include "global.h"
#include "proto.h"

// These structs are private to this module. 

// These are the private data members that we will append to the DEVMODEW
// structure.

typedef struct t_PRIVATE_DEVMODEW {

  ULONG DisplayMode;

} PRIVATE_DEVMODEW;

// The combined DEVMODE. It represents both the public DEVMODEW members and
// our private data after. By instructing GDI to allocate the extra memory
// in DrvGetModes, we can store both using this structure.

typedef struct t_COMBINED_DEVMODEW {

  DEVMODEW PublicData;
  PRIVATE_DEVMODEW PrivateData;

} COMBINED_DEVMODEW;

// This is the array of function pointers we pass to GDI for use as the
// driver entry points.

static const DRVENABLEDATA l_DrvFunctionArray =
{
  { DrvEnablePDEV },
  { NULL }, //DrvDisablePDEV },
  { DrvEnableSurface },
  { NULL }, //DrvDisableSurface },
  { DrvCreateDeviceBitmap },
  { DrvDeleteDeviceBitmap },
  { DrvRealizeBrush },
  { DrvStrokePath },
  { DrvFillPath },
  { NULL },                        // DrvPaint
  { DrvBitBlt },
  { NULL },                        // DrvCopyBits
  { DrvAnyBlt },
  { DrvTransparentBlt },
  { NULL },                        // DrvSetPalette
  { DrvSetPointerShape },
  { DrvMovePointer },
  { DrvGetModes },
  { DrvRealizeColor },
  { NULL },                        // DrvGetMasks
  { DrvUnrealizeColor },
  { DrvContrastControl },
  { DrvPowerHandler },
  { NULL },                        // DrvEndDoc
  { NULL },                        // DrvStartDoc
  { NULL },                        // DrvStartPage
  { DrvEscape }
};

// Internal prototypes. These functions are not exposed outside this module.

ULONG
Log2(
  ULONG n
  );

BOOL WINAPI
DllMain(
  HANDLE DllInstance,
  DWORD  Reason, 
  LPVOID Reserved
  )
{
  // DllMain
  // This entry is called when the GWES process attaches and detaches to the
  // driver. It also could hanlde thread attachments, but does not. We do
  // only the most basic initialization here. DllMain should never be called
  // with DLL_PROCESS_ATTACH more than once.

  // Local variables.

  BOOL FnRetVal = FALSE;

  Enter(L"DllMain");

  switch (Reason) {

  case DLL_PROCESS_ATTACH:

    // Initialize our dynamic system memory access.

    FnRetVal = InitializeSystemMem();

    break;

  case DLL_PROCESS_DETACH:

    // Currently, do nothing on process detach. We should never see this:
    // GWES should never be shut down.

    FnRetVal = TRUE;
    break;
    
  case DLL_THREAD_ATTACH:
  case DLL_THREAD_DETACH:

    // Do nothing on thread calls.

    FnRetVal = TRUE;
    break;

  default:

    Error(L"Unknown reason for calling DllMain.\n");
    break;
  }

  Exit(L"DllMain");

  return FnRetVal;
}

BOOL
DrvEnableDriver(
  ULONG           EngineVersion,
  ULONG           SizeofDrvEnableData,
  DRVENABLEDATA * DrvEnableData,
  PENGCALLBACKS   EngineCallbacks
  )
{
  // DrvEnableDriver
  // This function is exposed as an entry point into the driver dll. It allows
  // GDI to get pointers to the internal driver calls. It also allows GDI to
  // pass us it's own array of driver helper calls (the EngineCallbacks.)
  // Finally, because it is only called once as part of the GWES startup,
  // all one-time card initialization can go here.

  // Local variables.

  BOOL FnRetVal = FALSE;  // Return value for this function.

  // Check parameters.

  Assert(EngineVersion == GetEngineVersion());
  Assert(SizeofDrvEnableData == sizeof(DRVENABLEDATA));
  AssertWritePtr(DrvEnableData, SizeofDrvEnableData);
  AssertReadPtr(EngineCallbacks, sizeof(ENGCALLBACKS));

  Enter(L"DrvEnableDriver");

  // First, do all of the one-time hardware initialization.

  if (InitializeHardware()) {

    // Hand off the GDI "engine" pointers to the module that will manage them.

    if (InitializeEngineManager(EngineVersion,
                                EngineCallbacks)) {

      // Now, fill in the DrvEnableData with pointers to our own calls.
      // Eventually, you'll want to check the SizeofDrvEnableData parameter
      // to work out which array you need to pass back. For now, there is only
      // the standard CE DDI specification and nothing else.

      *DrvEnableData = l_DrvFunctionArray;

      // Note that DrvEnablePDEV could not have possibly been called before
      // DrvEnableDriver.

      g_Config.GraphicsPDEVEnabled = FALSE;

      FnRetVal = TRUE;
    }
    else {
      Error(L"Unable to initialize GDI Engine Manager.\n");
    }
  }
  else {
    Error(L"Unable to initialize Permedia3 hardware!\n");
  }

  Exit(L"DrvEnableDriver");

  return FnRetVal;
}

ULONG
DrvGetModes(
  HANDLE     DriverHandle,
  ULONG      SizeofDevMode,
  DEVMODEW * DevMode
  )
{
  // DrvGetModes
  // This entrypoint is used by GDI to get access to our display mode table.
  // It can be used one of two ways: you can get the number of entries in
  // the mode table by passing a NULL DevMode. Or, it will also copy the mode
  // table into the user's DevMode buffer if it is not NULL.

  // Local variables.

  ULONG FnRetVal = 0;
  ULONG ModeCount = 0;
  ULONG i = 0;
  ULONG SizeofModeTable = 0;

  COMBINED_DEVMODEW * CombinedDevMode;

  // Check parameters.

  // No check necessary for DriverHandle (it's a bogus value, for now.)
  if (SizeofDevMode == 0) {
    Assert(DevMode == NULL);
  }
  else {
    AssertWritePtr(DevMode, SizeofDevMode);
  }

  Enter(L"DrvGetModes");

  CombinedDevMode = (COMBINED_DEVMODEW *)DevMode;

  ModeCount = GetDisplayModeCount();
  SizeofModeTable = ModeCount * sizeof(COMBINED_DEVMODEW);

  Assert(SizeofDevMode >= SizeofModeTable || SizeofDevMode == 0);

  if (DevMode != NULL) {

    // Copy the display mode table into the user's buffer and return the
    // number of bytes we copied.

    memset(CombinedDevMode, 0, SizeofDevMode);

    for (i = 0; i < ModeCount; i++) {

      // Get the details.

      CombinedDevMode[i].PublicData.dmBitsPerPel = GetDisplayModeBPP(i);
      CombinedDevMode[i].PublicData.dmPelsWidth = GetDisplayModeWidth(i);
      CombinedDevMode[i].PublicData.dmPelsHeight = GetDisplayModeHeight(i);

      // Copy the name of the device into the DEVMODEW : make sure we don't
      // copy trash or overrun the DEVMODE string.

      memcpy(CombinedDevMode[i].PublicData.dmDeviceName, DEVICE_NAME, sizeof(DEVICE_NAME));

      // Other DEVMODE fields.

      CombinedDevMode[i].PublicData.dmSize = sizeof(DEVMODEW);
      CombinedDevMode[i].PublicData.dmDriverExtra = sizeof(PRIVATE_DEVMODEW);
      CombinedDevMode[i].PublicData.dmFields = DM_BITSPERPEL | 
                                               DM_PELSWIDTH | 
                                               DM_PELSHEIGHT | 
                                               DM_DISPLAYFREQUENCY |
                                               DM_DISPLAYFLAGS;

      // Fill in our private data.

      CombinedDevMode[i].PrivateData.DisplayMode = i;
    }

    FnRetVal = SizeofDevMode;
  }
  else {

    // We need only return the number of bytes necessary to store the mode
    // table.

    FnRetVal = SizeofModeTable;
  }

  Exit(L"DrvGetModes");

  return FnRetVal;
}

DHPDEV
DrvEnablePDEV(
  DEVMODEW * DevMode,
  LPWSTR     LogicalAddress,
  ULONG      NumFillPatterns,
  HSURF *    FillPatterns,
  ULONG      SizeofCaps,
  ULONG *    Caps,
  ULONG      SizeofDevInfo,
  DEVINFO *  DevInfo,
  HDEV       DeviceHandle,
  LPWSTR     DeviceName,
  HANDLE     DriverHandle
  )
{
  // DrvEnablePDEV
  // This function is called by GDI to gather capabilities of the driver as
  // well as to enable a device mode for drawing. In most cases this means
  // setting a display mode.

  // Local variables.

  GDIINFO * GdiInfo = NULL;
  COMBINED_DEVMODEW * CombinedDevMode = NULL;

  ULONG DisplayMode;

  ULONG MaskCount;
  ULONG BitMasks[4];

  // !TODO! Return value for this function.

  // Check parameters.

  AssertReadPtr(DevMode, sizeof(DEVMODEW));
  // !TODO! Check LogicalAddress
  Assert(NumFillPatterns == 0);
  Assert(FillPatterns == NULL);
  Assert(SizeofCaps == sizeof(GDIINFO));
  AssertWritePtr(Caps, SizeofCaps);
  Assert(SizeofDevInfo == sizeof(DEVINFO));
  AssertWritePtr(DevInfo, SizeofDevInfo);
  // No checks necessary for DeviceHandle, DeviceName, and DriverHandle. They
  // are all bogus values.

  Enter(L"DrvEnablePDEV");

  CombinedDevMode = (COMBINED_DEVMODEW *)DevMode;

  if (!g_Config.GraphicsPDEVEnabled) {

    // Do the graphics specific initialization that need only happen once.

    DisplayMode = CombinedDevMode->PrivateData.DisplayMode;

    // Set the required display mode.

    SetMode(DisplayMode);

    g_Config.GraphicsPDEVEnabled = TRUE;
  }
  else {

    // Graphics have already been initialized, thus we can call to retrieve
    // the current mode.

    DisplayMode = GetCurrentMode();
  }

  // Fill in the capabilities : GdiInfo.

  GdiInfo = (GDIINFO *)Caps;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -