}
}
-/* This function originally from Jean-Edouard Lachand-Robert, and
- * available at www.codeguru.com. Simplified for our needs, not sure
- * how much of the original code left any longer. Now handles just
- * one-bit deep bitmaps (in Window parlance, ie those that GDK calls
- * bitmaps (and not pixmaps), with zero pixels being transparent.
- */
-
-/* bitmap_to_hrgn : Create a region from the
- * "non-transparent" pixels of a bitmap.
- */
-
-static HRGN
-bitmap_to_hrgn (GdkPixmap *pixmap)
-{
- HRGN hRgn = NULL;
- HRGN h;
- DWORD maxRects;
- RGNDATA *pData;
- guchar *bits;
- gint width, height, bpl;
- guchar *p;
- gint x, y;
-
- g_assert (GDK_PIXMAP_OBJECT(pixmap)->depth == 1);
-
- bits = GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl)->bits;
- width = GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl)->width;
- height = GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl)->height;
- bpl = ((width - 1)/32 + 1)*4;
-
- /* For better performances, we will use the ExtCreateRegion()
- * function to create the region. This function take a RGNDATA
- * structure on entry. We will add rectangles by amount of
- * ALLOC_UNIT number in this structure.
- */
- #define ALLOC_UNIT 100
- maxRects = ALLOC_UNIT;
-
- pData = g_malloc (sizeof (RGNDATAHEADER) + (sizeof (RECT) * maxRects));
- pData->rdh.dwSize = sizeof (RGNDATAHEADER);
- pData->rdh.iType = RDH_RECTANGLES;
- pData->rdh.nCount = pData->rdh.nRgnSize = 0;
- SetRect (&pData->rdh.rcBound, MAXLONG, MAXLONG, 0, 0);
-
- for (y = 0; y < height; y++)
- {
- /* Scan each bitmap row from left to right*/
- p = (guchar *) bits + y * bpl;
- for (x = 0; x < width; x++)
- {
- /* Search for a continuous range of "non transparent pixels"*/
- gint x0 = x;
- while (x < width)
- {
- if ((((p[x/8])>>(7-(x%8)))&1) == 0)
- /* This pixel is "transparent"*/
- break;
- x++;
- }
-
- if (x > x0)
- {
- RECT *pr;
- /* Add the pixels (x0, y) to (x, y+1) as a new rectangle
- * in the region
- */
- if (pData->rdh.nCount >= maxRects)
- {
- maxRects += ALLOC_UNIT;
- pData = g_realloc (pData, sizeof(RGNDATAHEADER)
- + (sizeof(RECT) * maxRects));
- }
- pr = (RECT *) &pData->Buffer;
- SetRect (&pr[pData->rdh.nCount], x0, y, x, y+1);
- if (x0 < pData->rdh.rcBound.left)
- pData->rdh.rcBound.left = x0;
- if (y < pData->rdh.rcBound.top)
- pData->rdh.rcBound.top = y;
- if (x > pData->rdh.rcBound.right)
- pData->rdh.rcBound.right = x;
- if (y+1 > pData->rdh.rcBound.bottom)
- pData->rdh.rcBound.bottom = y+1;
- pData->rdh.nCount++;
-
- /* On Windows98, ExtCreateRegion() may fail if the
- * number of rectangles is too large (ie: >
- * 4000). Therefore, we have to create the region by
- * multiple steps.
- */
- if (pData->rdh.nCount == 2000)
- {
- HRGN h = ExtCreateRegion (NULL, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects), pData);
- if (hRgn)
- {
- CombineRgn(hRgn, hRgn, h, RGN_OR);
- DeleteObject(h);
- }
- else
- hRgn = h;
- pData->rdh.nCount = 0;
- SetRect (&pData->rdh.rcBound, MAXLONG, MAXLONG, 0, 0);
- }
- }
- }
- }
-
- /* Create or extend the region with the remaining rectangles*/
- h = ExtCreateRegion (NULL, sizeof (RGNDATAHEADER)
- + (sizeof (RECT) * maxRects), pData);
- if (hRgn)
- {
- CombineRgn (hRgn, hRgn, h, RGN_OR);
- DeleteObject (h);
- }
- else
- hRgn = h;
-
- /* Clean up*/
- g_free (pData);
-
- return hRgn;
-}
-
-cairo_region_t *
-_gdk_windowing_get_shape_for_mask (GdkBitmap *mask)
-{
- cairo_region_t *region;
- HRGN hrgn = bitmap_to_hrgn (mask);
-
- region = _gdk_win32_hrgn_to_region (hrgn);
- DeleteObject (hrgn);
-
- return region;
-}
-
void
_gdk_windowing_window_set_composited (GdkWindow *window, gboolean composited)
{