GRenderWinG Class Reference

A GDraw render region that uses normal DIBs for the bitmap and WinG to blit them. More...

#include <grndwing.h>

Inheritance diagram for GRenderWinG:

GRenderRegion RenderRegion ListItem CCObject SimpleCCObject List of all members.

Public Types

typedef HDC(PASCAL * WING_CREATEDC )(void)
typedef BOOL(PASCAL * WING_RECOMMENDED )(BITMAPINFO FAR *pFormat)
typedef HBITMAP(PASCAL * WING_CREATEBITMAP )(HDC WinGDC, BITMAPINFO const FAR *pHeader, void FAR *FAR *ppBits)
typedef BOOL(PASCAL * WING_BITBLT )(HDC hdcDest, INT32 nXOriginDest, INT32 nYOriginDest, INT32 nWidthDest, INT32 nHeightDest, HDC hdcSrc, INT32 nXOriginSrc, INT32 nYOriginSrc)

Public Member Functions

 GRenderWinG (DocRect ClipRegion, Matrix ConvertMatrix, FIXED16 ViewScale, UINT32 Depth, double dpi)
 GRenderWinG constructor. Doesn't do anything actually, just calls base class. INT32 dpi changed to FIXED16 dpi (12/12/95) to improve the range of values allowed at the < 1000dpi settings that we will be using.
 ~GRenderWinG ()
 GRenderWinG destructor. Frees up the bitmap.

Static Public Member Functions

static BOOL Init (BOOL)
 Determines whether WinG is available on this platform.
static void Deinit ()
 Tidies up WinG before exit. Frees up necessary resources etc.
static BOOL CanWinG (UINT32 Depth)
 Use before creating GRenderWinGs inc case they are not supported. Currently only uses WinG if depth matches the recommended format.

Static Public Attributes

static HINSTANCE WinGDLL
static WING_CREATEDC pWinGCreateDC
static WING_RECOMMENDED pWinGRecommendedDIBFormat
static WING_CREATEBITMAP pWinGCreateBitmap
static WING_BITBLT pWinGBitBlt

Private Member Functions

LPBITMAPINFO GetLPBits (INT32 Width, INT32 Height, INT32 Depth, LPBYTE *)
 Allocates a bitmap header and the bitmap bytes.
void FreeLPBits (LPBITMAPINFO, LPBYTE)
 Frees up a bitmap allocated with GetLPBits.
BOOL DisplayBits (LPBITMAPINFO lpDisplayBitmapInfo=NULL, LPBYTE lpDisplayBits=NULL)
 Plots the DIB onto the owner device.
BOOL StartRenderAfter (GMATRIX *GMat)
 Updates the Gavin matrix to cope with the upside-down nature of DIBs if that is the recommended format.

Private Attributes

HBITMAP WinGBitmap
BOOL Inverted

Static Private Attributes

static HDC OffScreenDC

Detailed Description

A GDraw render region that uses normal DIBs for the bitmap and WinG to blit them.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/6/94

Definition at line 111 of file grndwing.h.


Member Typedef Documentation

typedef BOOL(PASCAL * GRenderWinG::WING_BITBLT)(HDC hdcDest, INT32 nXOriginDest, INT32 nYOriginDest, INT32 nWidthDest, INT32 nHeightDest, HDC hdcSrc, INT32 nXOriginSrc, INT32 nYOriginSrc)
 

Definition at line 133 of file grndwing.h.

typedef HBITMAP(PASCAL * GRenderWinG::WING_CREATEBITMAP)(HDC WinGDC, BITMAPINFO const FAR *pHeader, void FAR *FAR *ppBits)
 

Definition at line 131 of file grndwing.h.

typedef HDC(PASCAL * GRenderWinG::WING_CREATEDC)(void)
 

Definition at line 129 of file grndwing.h.

typedef BOOL(PASCAL * GRenderWinG::WING_RECOMMENDED)(BITMAPINFO FAR *pFormat)
 

Definition at line 130 of file grndwing.h.


Constructor & Destructor Documentation

GRenderWinG::GRenderWinG DocRect  ClipRegion,
Matrix  ConvertMatrix,
FIXED16  ViewScale,
UINT32  Depth,
double  dpi
 

GRenderWinG constructor. Doesn't do anything actually, just calls base class. INT32 dpi changed to FIXED16 dpi (12/12/95) to improve the range of values allowed at the < 1000dpi settings that we will be using.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/6/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
GRenderRegion::GRenderRegion

Definition at line 309 of file grndwing.cpp.

00310     : GRenderRegion( ClipRegion, ConvertMatrix, ViewScale, Depth, dpi)
00311 {
00312     WinGBitmap = NULL;
00313     Inverted = FALSE;
00314 }

GRenderWinG::~GRenderWinG  ) 
 

GRenderWinG destructor. Frees up the bitmap.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
2/6/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

Definition at line 437 of file grndwing.cpp.

00438 {
00439     if (LocalBitmap)
00440     {
00441         if (HaveRenderedSomething)
00442             // We're not clean - flush bitmap to screen
00443             DisplayBits();
00444 
00445 //      FreeLPBits( lpBitmapInfo, lpBits );
00446         FreeOffscreenState();
00447         lpBitmapInfo = NULL;
00448         lpBits = NULL;
00449     }
00450     // will call GRenderRegions destructor here
00451 }


Member Function Documentation

BOOL GRenderWinG::CanWinG UINT32  Depth  )  [static]
 

Use before creating GRenderWinGs inc case they are not supported. Currently only uses WinG if depth matches the recommended format.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/6/94
Parameters:
Pixel depth required [INPUTS]
Returns:
TRUE if GRenderWinG can be done at such a depth, FALSE if cannot

Errors: - Scope: Static public

Definition at line 279 of file grndwing.cpp.

00280 {
00281     if (
00282         WinGDLL                             &&      // must have DLL
00283         OffScreenDC                         &&      // and screen DC
00284         (RecommendedDIB.biPlanes == 1)      &&      // mono planar
00285         (Depth == RecommendedDIB.biBitCount)        // and correct depth
00286        )
00287         return TRUE;
00288 
00289     return FALSE;
00290 }

void GRenderWinG::Deinit void   )  [static]
 

Tidies up WinG before exit. Frees up necessary resources etc.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/6/94
Returns:
Errors: - Scope: Static

Definition at line 255 of file grndwing.cpp.

00256 {
00257     if (OffScreenDC)
00258     {
00259         DeleteDC(OffScreenDC);
00260         OffScreenDC = NULL;
00261     }
00262 }

BOOL GRenderWinG::DisplayBits LPBITMAPINFO  lpDisplayBitmapInfo = NULL,
LPBYTE  lpDisplayBits = NULL
[private, virtual]
 

Plots the DIB onto the owner device.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/6/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if worked, FALSE if failed.

Errors: -

Implements GRenderRegion.

Definition at line 504 of file grndwing.cpp.

00505 {
00506     BOOL ok = FALSE;
00507 
00508     if (lpBitmapInfo && lpBits && RenderDC)
00509     {
00510         HBITMAP hOldBitmap;
00511 
00512         hOldBitmap = SelectBitmap( OffScreenDC, WinGBitmap );
00513         if (hOldBitmap)
00514         {
00515             ok = pWinGBitBlt( RenderDC->m_hDC,          // dest
00516                                 WRect.left, WRect.top,      // dest XY
00517                                 WRect.right-WRect.left,
00518                                 WRect.bottom-WRect.top,
00519                                 OffScreenDC,                // source
00520                                 0,0                         // source XY
00521                             );
00522             SelectBitmap( OffScreenDC, hOldBitmap );
00523         }
00524     }
00525     return ok;
00526 }

void GRenderWinG::FreeLPBits LPBITMAPINFO  lpBMI,
LPBYTE  lpB
[private, virtual]
 

Frees up a bitmap allocated with GetLPBits.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/6/94
Parameters:
Bitmap characteristics. [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
GRenderWinG::FreeLPBits

Implements GRenderRegion.

Definition at line 413 of file grndwing.cpp.

00414 {
00415     if (WinGBitmap)
00416     {
00417         DeleteObject( WinGBitmap );
00418         WinGBitmap = NULL;
00419     }
00420     FreeDIB( lpBMI, NULL );
00421 }

LPBITMAPINFO GRenderWinG::GetLPBits INT32  Width,
INT32  Height,
INT32  Depth,
LPBYTE lplpBits
[private, virtual]
 

Allocates a bitmap header and the bitmap bytes.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/6/94
Parameters:
Bitmap characteristics. [INPUTS]
*lplpBits is made to point to the bytes of the bitmap. [OUTPUTS]
Returns:
The bitmap header, or NULL if not enough memory.

Errors: -

See also:
GRenderWinG::FreeLPBits

Implements GRenderRegion.

Definition at line 331 of file grndwing.cpp.

00332 {
00333     // get a bitmap header with no bits
00334     const LPBITMAPINFO bmInfo = AllocDIB( Width, Height, Depth, NULL );
00335     if (!bmInfo)
00336         return NULL;
00337 
00338     // tell it the sort of palette we want - we want Gavin's
00339     if (Depth==8)
00340     {
00341     #if 0
00342         RGBQUAD *rgb = bmInfo->bmiColors;
00343         LPPALETTEENTRY lpPal = GetRecommendedPalette()->palPalEntry;
00344 
00345         size_t i ;
00346         for ( i=0 ; i<256 ; i++ )
00347         {
00348             rgb->rgbRed = lpPal->peRed;
00349             rgb->rgbGreen = lpPal->peGreen;
00350             rgb->rgbBlue = lpPal->peBlue;
00351             rgb->rgbReserved = 0;
00352             rgb ++;
00353             lpPal++;
00354         }
00355     #else
00356 
00357         GetSystemPaletteEntries (
00358             RenderDC->m_hDC, 0, 256, (LPPALETTEENTRY) bmInfo->bmiColors
00359         ) ;
00360         RGBQUAD *rgb = bmInfo->bmiColors ;                  // Swap R and B.
00361         size_t i ;
00362         for ( i=0 ; i<256 ; i++ )
00363         {
00364             BYTE t = rgb->rgbRed ;
00365             rgb->rgbRed = rgb->rgbBlue ;
00366             rgb->rgbBlue = t ;
00367             rgb ++ ;
00368         }
00369     #endif
00370     }
00371 
00372     // if WinG wants it upside-down then go for it
00373     if (RecommendedDIB.biHeight == -1)
00374     {
00375         Inverted = TRUE;
00376         bmInfo->bmiHeader.biHeight = -bmInfo->bmiHeader.biHeight;
00377     }
00378     else
00379         Inverted = FALSE;
00380 
00381     // now get a lovely WinG bitmap
00382     WinGBitmap = pWinGCreateBitmap( OffScreenDC, bmInfo, (void FAR* FAR *)lplpBits );
00383     if (WinGBitmap==NULL)
00384     {
00385         TRACE( _T("WinGCreateBitmap failed\n"));
00386         FreeDIB( bmInfo, NULL );
00387         return NULL;
00388     }
00389 
00390     // turn it back the other way else Gavin is likely to get confused
00391     if (Inverted)
00392         bmInfo->bmiHeader.biHeight = -bmInfo->bmiHeader.biHeight;
00393 
00394     //TRACE( _T("WinG Alloc %lx=%lx:%lx\n"), this, bmInfo, *lplpBits);
00395     return bmInfo;
00396 }

BOOL GRenderWinG::Init BOOL  FirstTime  )  [static]
 

Determines whether WinG is available on this platform.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/6/94
Parameters:
FirstTime is TRUE if called on startup, FALSE if called subsequently [INPUTS] (e.g. screen mode change).
- [OUTPUTS]
Returns:
TRUE if we can use WinG, FALSE if we cannot.

Errors: - Scope: Public static

Reimplemented from GRenderRegion.

Definition at line 144 of file grndwing.cpp.

00145 {
00146     if (!FirstTime)
00147     {
00148         // only a screen mode change so don't redo DLL etc, just get new DC
00149         if (WinGDLL)
00150         {
00151             // kill old one
00152             if (OffScreenDC)
00153                 DeleteDC( OffScreenDC );
00154 
00155             // go get new one
00156             OffScreenDC = pWinGCreateDC();
00157             if (OffScreenDC)
00158                 return TRUE;
00159         }
00160         return FALSE;
00161     }
00162 
00163 #if WIN32
00164     // lets see if the DLL is there
00165 
00166     // on NT 3.1 the DLL init code fails the load and produces an ugly dialog, so we don't
00167     // bother
00168     if (IsWin32NT())
00169     {
00170         const WORD Ver = LOWORD( GetVersion() );
00171         if (
00172             (LOBYTE(Ver) == 3) &&                   // NT 3.5 is minimum requirement
00173             (HIBYTE(Ver) < 50)
00174            )
00175             return FALSE;
00176     }
00177 
00178     // try the DLL now
00179     WinGDLL = LoadLibrary("WING32.DLL");
00180     if (WinGDLL)
00181     {
00182         // (ordinal values extracted from DLL using DUMPBIN -export)
00183 
00184         pWinGCreateDC =     (WING_CREATEDC)     GetProcAddress( WinGDLL, MAKEINTRESOURCE(0x3e9) );
00185         pWinGCreateBitmap = (WING_CREATEBITMAP) GetProcAddress( WinGDLL, MAKEINTRESOURCE(0x3eb) );
00186         pWinGBitBlt =       (WING_BITBLT)       GetProcAddress( WinGDLL, MAKEINTRESOURCE(0x3f2) );
00187         pWinGRecommendedDIBFormat =
00188                             (WING_RECOMMENDED)  GetProcAddress( WinGDLL, MAKEINTRESOURCE( 0x3ea ) );
00189 
00190         if (
00191             (pWinGCreateDC == NULL)     ||
00192             (pWinGCreateBitmap == NULL) ||
00193             (pWinGBitBlt == NULL)       ||
00194             (pWinGRecommendedDIBFormat==NULL)
00195            )
00196         {
00197             TRACE( _T("WinG32 DLL entrypoints missing!\n"));
00198             FreeLibrary( WinGDLL );
00199             WinGDLL = NULL;
00200             return FALSE;
00201         }
00202     }
00203     else
00204     {
00205         TRACE( _T("WinG DLL not found (error %d)\n"), GetLastError() );
00206         return FALSE;
00207     }
00208 
00209     // remember the DLL handle so it gets cleaned up for us always on exit
00210     ExtraDLLs[ WinG_DLL ] = WinGDLL;
00211 
00212     RecommendedDIB.biSize = sizeof(BITMAPINFOHEADER);
00213 
00214     // excuse the seemingly rampant cast but I think the official prototype is wrong
00215     const BOOL ok = pWinGRecommendedDIBFormat( (LPBITMAPINFO)&RecommendedDIB );
00216         
00217     if (IsUserName("Andy"))
00218     {
00219         TRACE( _T("Recommended bitmap:\n"));
00220         if (ok)
00221         {
00222             TRACE( _T("%dx%d height=%d comp=%d\n"),
00223                     (INT32)RecommendedDIB.biPlanes,
00224                     (INT32)RecommendedDIB.biBitCount,
00225                     (INT32)RecommendedDIB.biHeight,
00226                     (INT32)RecommendedDIB.biCompression
00227                 );
00228         }
00229         else
00230             TRACE( _T("ERROR - isnt one\n"));
00231     }
00232 
00233     OffScreenDC = pWinGCreateDC();
00234     if (OffScreenDC)
00235         return TRUE;
00236 
00237 #endif
00238 
00239     // if we get here it means we failed
00240     return FALSE;
00241 }

BOOL GRenderWinG::StartRenderAfter GMATRIX GMat  )  [private, virtual]
 

Updates the Gavin matrix to cope with the upside-down nature of DIBs if that is the recommended format.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
30/6/94
Parameters:
Pointer to Gavins matrix created by GRenderRegion::StartRender [INPUTS]
Update matrix if required. [OUTPUTS]
Returns:
TRUE if worked, FALSE if failed.

Errors: Always returns TRUE.

See also:
GRenderDDB::StartRenderAfter

Reimplemented from GRenderRegion.

Definition at line 470 of file grndwing.cpp.

00471 {
00472     if (Inverted)
00473     {
00474         // flip up other way
00475         GMat->BY = -GMat->BY;
00476 
00477         // calculate the new offset
00478         //XLONG ydisp = (XLONG)( (WRect.bottom -  WRect.top ) * 72000 ) / (XLONG)(PixelsPerInch.MakeXlong() * ScaleFactor);
00479         FIXED16 ScaledDpi = FIXED16(PixelsPerInch) * ScaleFactor;
00480         XLONG Size = (WRect.bottom -  WRect.top ) * 72000;
00481         XLONG ydisp = Size / ScaledDpi.MakeXlong();
00482 
00483         GMat->CY = -GMat->CY + Mul(-GMat->BY, ydisp);
00484     }
00485 
00486     // we cannot fail
00487     return TRUE;
00488 }


Member Data Documentation

BOOL GRenderWinG::Inverted [private]
 

Definition at line 157 of file grndwing.h.

HDC GRenderWinG::OffScreenDC [static, private]
 

Definition at line 161 of file grndwing.h.

GRenderWinG::WING_BITBLT GRenderWinG::pWinGBitBlt [static]
 

Definition at line 146 of file grndwing.h.

GRenderWinG::WING_CREATEBITMAP GRenderWinG::pWinGCreateBitmap [static]
 

Definition at line 145 of file grndwing.h.

GRenderWinG::WING_CREATEDC GRenderWinG::pWinGCreateDC [static]
 

Definition at line 143 of file grndwing.h.

GRenderWinG::WING_RECOMMENDED GRenderWinG::pWinGRecommendedDIBFormat [static]
 

Definition at line 144 of file grndwing.h.

HBITMAP GRenderWinG::WinGBitmap [private]
 

Definition at line 156 of file grndwing.h.

HINSTANCE GRenderWinG::WinGDLL [static]
 

Definition at line 141 of file grndwing.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:55:01 2007 for Camelot by  doxygen 1.4.4