From 588ae69c45b184364e6ed130503ae05b4cc65407 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Wed, 24 Feb 2010 21:50:20 +0000 Subject: [PATCH] Changes to prevent inconsistent main/key state and move alphablend to a separate function call. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@29722 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 9 ++++ Source/win32/WIN32Server.m | 9 ++++ Source/winlib/WIN32GState.m | 97 +++++++++++++++++++++++++++++++------ 3 files changed, 99 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 93e7799..d668883 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-02-24 16:45-EST Gregory John Casamento + + * Source/win32/WIN32Server.m: Added a boolean to control if + callbacks are honored so that we can ignore the + SetActiveWindow(...) call when windows are resigned. Otherwise + this causes some issues and could result in an inconsistent state. + * Source/winlib/WIN32GState.m: Moved AlphaBlend to seperate + function so that it can be called elsewhere. + 2010-02-20 Fred Kiefer * Source/gsc/GSStreamContext.m diff --git a/Source/win32/WIN32Server.m b/Source/win32/WIN32Server.m index 6b31ca1..36ba72d 100644 --- a/Source/win32/WIN32Server.m +++ b/Source/win32/WIN32Server.m @@ -60,6 +60,8 @@ #include #endif +static BOOL _enableCallbacks = YES; + static NSEvent *process_key_event(WIN32Server *svr, HWND hwnd, WPARAM wParam, LPARAM lParam, NSEventType eventType); @@ -1429,7 +1431,9 @@ LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, } if (state == GSTitleBarMain) { + _enableCallbacks = NO; SetActiveWindow((HWND)winNum); + _enableCallbacks = YES; } } @@ -1990,6 +1994,11 @@ LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { WIN32Server *ctxt = (WIN32Server *)GSCurrentServer(); + + if(_enableCallbacks == NO) + { + return (LRESULT)NULL; + } return [ctxt windowEventProc: hwnd : uMsg : wParam : lParam]; } diff --git a/Source/winlib/WIN32GState.m b/Source/winlib/WIN32GState.m index 41c0c57..e061ac4 100644 --- a/Source/winlib/WIN32GState.m +++ b/Source/winlib/WIN32GState.m @@ -116,6 +116,79 @@ RECT GSViewRectToWin(WIN32GState *s, NSRect r) return GSWindowRectToMS(s, r); } +void* get_bits(HDC dc, + int w, + int h, + HBITMAP *bitmap) +{ + void *bits = NULL; + BITMAPINFO info; + HDC cDC; + + info.bmiHeader.biSize = sizeof(BITMAPINFO); + info.bmiHeader.biWidth = w; + info.bmiHeader.biHeight = h; + info.bmiHeader.biPlanes = 1; + info.bmiHeader.biBitCount = 32; + info.bmiHeader.biCompression = BI_RGB; + info.bmiHeader.biSizeImage = 0; + info.bmiHeader.biXPelsPerMeter = 0; + info.bmiHeader.biYPelsPerMeter = 0; + info.bmiHeader.biClrUsed = 0; + info.bmiHeader.biClrImportant = 0; + + if(!(cDC = CreateCompatibleDC(dc))) + { + NSLog(@"Could not create compatible DC"); + return NULL; + } + + if(!(*bitmap = CreateDIBSection(dc, (LPBITMAPINFO)&info, + DIB_RGB_COLORS, &bits, + NULL, 0))) + { + NSLog(@"Could not create bit map from DC"); + return NULL; + } + + SelectObject(cDC, *bitmap); + + return bits; +} + +BOOL alpha_blend_source_over(HDC destDC, + HDC srcDC, + RECT rectFrom, + int x, int y, int w, int h, + float delta) +{ + BOOL success = YES; + +#ifdef USE_ALPHABLEND + // Use (0..1) fraction to set a (0..255) alpha constant value + BYTE SourceConstantAlpha = (BYTE)(delta * 255); + BLENDFUNCTION blendFunc + = {AC_SRC_OVER, 0, SourceConstantAlpha, AC_SRC_ALPHA}; + + /* There is actually a very real chance this could fail, even on + computers that supposedly support it. It's not known why it + fails though... */ + success = AlphaBlend(destDC, + x, y, w, h, + srcDC, + rectFrom.left, rectFrom.top, + w, h, blendFunc); + // #else + // HBITMAP sbitmap; + // HBITMAP dbitmap; + // unsigned char *sbits = (unsigned char *)get_bits(srcDC,w,h,&sbitmap); + // unsigned char *dbits = (unsigned char *)get_bits(destDC,w,h,&dbitmap); + +#endif + + return success; +} + @interface WIN32GState (WinOps) - (void) setStyle: (HDC)hDC; - (void) restoreStyle: (HDC)hDC; @@ -238,22 +311,13 @@ RECT GSViewRectToWin(WIN32GState *s, NSRect r) { case NSCompositeSourceOver: { -#ifdef USE_ALPHABLEND - // Use (0..1) fraction to set a (0..255) alpha constant value - BYTE SourceConstantAlpha = (BYTE)(delta * 255); - BLENDFUNCTION blendFunc - = {AC_SRC_OVER, 0, SourceConstantAlpha, AC_SRC_ALPHA}; - success = AlphaBlend(hDC, - x, y, w, h, - sourceDC, - rectFrom.left, rectFrom.top, - w, h, blendFunc); - /* There is actually a very real chance this could fail, even on - computers that supposedly support it. It's not known why it - fails though... */ - if (success) - break; -#endif + success = alpha_blend_source_over(hDC, + sourceDC, + rectFrom, + x, y, w, h, + delta); + if (success) + break; } case NSCompositeCopy: { @@ -291,6 +355,7 @@ RECT GSViewRectToWin(WIN32GState *s, NSRect r) op: (NSCompositingOperation)op { float gray; + BOOL success = NO; // FIXME: This is taken from the xlib backend [self DPScurrentgray: &gray];