190
203
gdk_drawable_set_colormap (pixmap, cmap);
193
if (GDK_IS_WINDOW (drawable))
194
hwnd = GDK_WINDOW_HWND (drawable);
196
hwnd = GetDesktopWindow ();
197
if ((hdc = GetDC (hwnd)) == NULL)
199
WIN32_GDI_FAILED ("GetDC");
200
g_object_unref ((GObject *) pixmap);
204
bmi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
205
bmi.bmiHeader.biWidth = width;
206
bmi.bmiHeader.biHeight = -height;
207
bmi.bmiHeader.biPlanes = 1;
213
bmi.bmiHeader.biBitCount = _gdk_windowing_get_bits_for_depth (gdk_display_get_default (), depth);
217
bmi.bmiHeader.biBitCount = 4;
224
bmi.bmiHeader.biBitCount = 8;
229
bmi.bmiHeader.biBitCount = 16;
233
g_warning ("gdk_win32_pixmap_new: depth = %d", depth);
234
g_assert_not_reached ();
237
if (bmi.bmiHeader.biBitCount == 16)
238
bmi.bmiHeader.biCompression = BI_BITFIELDS;
240
bmi.bmiHeader.biCompression = BI_RGB;
242
bmi.bmiHeader.biSizeImage = 0;
243
bmi.bmiHeader.biXPelsPerMeter =
244
bmi.bmiHeader.biYPelsPerMeter = 0;
245
bmi.bmiHeader.biClrUsed = 0;
246
bmi.bmiHeader.biClrImportant = 0;
248
iUsage = DIB_RGB_COLORS;
251
bmi.u.bmiColors[0].rgbBlue =
252
bmi.u.bmiColors[0].rgbGreen =
253
bmi.u.bmiColors[0].rgbRed = 0x00;
254
bmi.u.bmiColors[0].rgbReserved = 0x00;
256
bmi.u.bmiColors[1].rgbBlue =
257
bmi.u.bmiColors[1].rgbGreen =
258
bmi.u.bmiColors[1].rgbRed = 0xFF;
259
bmi.u.bmiColors[1].rgbReserved = 0x00;
263
if (depth <= 8 && drawable_impl->colormap != NULL)
265
GdkColormapPrivateWin32 *cmapp =
266
GDK_WIN32_COLORMAP_DATA (drawable_impl->colormap);
269
if ((holdpal = SelectPalette (hdc, cmapp->hpal, FALSE)) == NULL)
270
WIN32_GDI_FAILED ("SelectPalette");
271
else if ((k = RealizePalette (hdc)) == GDI_ERROR)
272
WIN32_GDI_FAILED ("RealizePalette");
274
GDK_NOTE (PIXMAP_OR_COLORMAP, g_print ("_gdk_win32_pixmap_new: realized %p: %d colors\n",
277
iUsage = DIB_PAL_COLORS;
278
for (i = 0; i < 256; i++)
279
bmi.u.bmiIndices[i] = i;
281
else if (bmi.bmiHeader.biBitCount == 16)
283
GdkVisual *visual = gdk_visual_get_system ();
285
bmi.u.bmiMasks[0] = visual->red_mask;
286
bmi.u.bmiMasks[1] = visual->green_mask;
287
bmi.u.bmiMasks[2] = visual->blue_mask;
291
hbitmap = CreateDIBSection (hdc, (BITMAPINFO *) &bmi,
292
iUsage, (PVOID *) &bits, NULL, 0);
294
SelectPalette (hdc, holdpal, FALSE);
296
GDI_CALL (ReleaseDC, (hwnd, hdc));
298
GDK_NOTE (PIXMAP, g_print ("... =%p bits=%p pixmap=%p\n", hbitmap, bits, pixmap));
302
WIN32_GDI_FAILED ("CreateDIBSection");
303
g_object_unref ((GObject *) pixmap);
206
dib_surface = cairo_win32_surface_create_with_dib (format, width, height);
207
if (dib_surface == NULL)
209
g_object_unref ((GObject *) pixmap);
213
/* We need to have cairo create the dibsection for us, because
214
creating a cairo surface from a hdc only works for rgb24 format */
215
hdc = cairo_win32_surface_get_dc (dib_surface);
217
/* We need to use the same hdc, because only one hdc
218
can render to the same bitmap */
219
drawable_impl->hdc = hdc;
220
drawable_impl->hdc_count = 1; /* Ensure we never free the cairo surface HDC */
222
/* No need to create a new surface when needed, as we have one already */
223
drawable_impl->cairo_surface = dib_surface;
225
/* Get the bitmap from the cairo hdc */
226
hbitmap = GetCurrentObject (hdc, OBJ_BITMAP);
307
227
drawable_impl->handle = hbitmap;
308
pixmap_impl->bits = bits;
229
image_surface = cairo_win32_surface_get_image (dib_surface);
230
pixmap_impl->bits = cairo_image_surface_get_data (image_surface);
310
232
gdk_win32_handle_table_insert (&GDK_PIXMAP_HBITMAP (pixmap), pixmap);