~ubuntu-branches/ubuntu/precise/gtk+2.0/precise-updates

« back to all changes in this revision

Viewing changes to gdk/win32/gdkpixmap-win32.c

  • Committer: Package Import Robot
  • Author(s): Ken VanDine
  • Date: 2011-12-01 11:40:06 UTC
  • mfrom: (1.14.11)
  • Revision ID: package-import@ubuntu.com-20111201114006-nrmf6qu3pg512veo
Tags: 2.24.8-0ubuntu1
* New upstream release 
  - gtkfilechooser should be more robust to malformed URIs
    in .gtk-bookmarks (LP: #189494)
* debian/patches/010_make_bg_changes_queue_repaint.patch
  - dropped it introduces performance regressions in some gtk2 
    apps (LP: #889019)
* 101_filechooser.patch, 000git_file_chooser.patch: dropped, upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
#include "gdkscreen.h"
36
36
 
37
37
#include "gdkprivate-win32.h"
 
38
#include <cairo-win32.h>
38
39
 
39
40
static void gdk_pixmap_impl_win32_get_size   (GdkDrawable        *drawable,
40
41
                                              gint               *width,
109
110
  GDK_NOTE (PIXMAP, g_print ("gdk_pixmap_impl_win32_finalize: %p\n",
110
111
                             GDK_PIXMAP_HBITMAP (wrapper)));
111
112
 
112
 
  _gdk_win32_drawable_finish (GDK_DRAWABLE (object));  
 
113
  if (!impl->is_foreign)
 
114
    GDK_DRAWABLE_IMPL_WIN32 (impl)->hdc_count--;
113
115
 
114
 
  GDI_CALL (DeleteObject, (GDK_PIXMAP_HBITMAP (wrapper)));
 
116
  _gdk_win32_drawable_finish (GDK_DRAWABLE (object));
115
117
 
116
118
  gdk_win32_handle_table_remove (GDK_PIXMAP_HBITMAP (wrapper));
117
119
 
135
137
                gint         height,
136
138
                gint         depth)
137
139
{
138
 
  struct {
139
 
    BITMAPINFOHEADER bmiHeader;
140
 
    union {
141
 
      WORD bmiIndices[256];
142
 
      DWORD bmiMasks[3];
143
 
      RGBQUAD bmiColors[256];
144
 
    } u;
145
 
  } bmi;
146
 
  UINT iUsage;
147
140
  HDC hdc;
148
 
  HWND hwnd;
149
141
  HPALETTE holdpal = NULL;
150
142
  HBITMAP hbitmap;
151
143
  GdkPixmap *pixmap;
152
144
  GdkDrawableImplWin32 *drawable_impl;
153
145
  GdkPixmapImplWin32 *pixmap_impl;
154
146
  GdkColormap *cmap;
155
 
  guchar *bits;
156
 
  gint i;
157
147
  gint window_depth;
 
148
  cairo_surface_t *dib_surface, *image_surface;
 
149
  cairo_format_t format;
158
150
 
159
151
  g_return_val_if_fail (drawable == NULL || GDK_IS_DRAWABLE (drawable), NULL);
160
152
  g_return_val_if_fail ((drawable != NULL) || (depth != -1), NULL);
173
165
  GDK_NOTE (PIXMAP, g_print ("gdk_pixmap_new: %dx%dx%d drawable=%p\n",
174
166
                             width, height, depth, drawable));
175
167
 
 
168
  switch (depth)
 
169
    {
 
170
    case 1:
 
171
      format = CAIRO_FORMAT_A1;
 
172
      break;
 
173
 
 
174
    case 8:
 
175
      format = CAIRO_FORMAT_A8;
 
176
      break;
 
177
 
 
178
    case 24:
 
179
    case 32:
 
180
      format = CAIRO_FORMAT_RGB24;
 
181
      break;
 
182
 
 
183
    default:
 
184
      g_warning ("gdk_win32_pixmap_new: depth = %d not supported", depth);
 
185
      return NULL;
 
186
      break;
 
187
    }
 
188
 
176
189
  pixmap = g_object_new (gdk_pixmap_get_type (), NULL);
177
190
  drawable_impl = GDK_DRAWABLE_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl);
178
191
  pixmap_impl = GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl);
189
202
      if (cmap)
190
203
        gdk_drawable_set_colormap (pixmap, cmap);
191
204
    }
192
 
  
193
 
  if (GDK_IS_WINDOW (drawable))
194
 
    hwnd = GDK_WINDOW_HWND (drawable);
195
 
  else
196
 
    hwnd = GetDesktopWindow ();
197
 
  if ((hdc = GetDC (hwnd)) == NULL)
198
 
    {
199
 
      WIN32_GDI_FAILED ("GetDC");
200
 
      g_object_unref ((GObject *) pixmap);
201
 
      return NULL;
202
 
    }
203
 
 
204
 
  bmi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
205
 
  bmi.bmiHeader.biWidth = width;
206
 
  bmi.bmiHeader.biHeight = -height;
207
 
  bmi.bmiHeader.biPlanes = 1;
208
 
  switch (depth)
209
 
    {
210
 
    case 1:
211
 
    case 24:
212
 
    case 32:
213
 
      bmi.bmiHeader.biBitCount = _gdk_windowing_get_bits_for_depth (gdk_display_get_default (), depth);
214
 
      break;
215
 
 
216
 
    case 4:
217
 
      bmi.bmiHeader.biBitCount = 4;
218
 
      break;
219
 
      
220
 
    case 5:
221
 
    case 6:
222
 
    case 7:
223
 
    case 8:
224
 
      bmi.bmiHeader.biBitCount = 8;
225
 
      break;
226
 
      
227
 
    case 15:
228
 
    case 16:
229
 
      bmi.bmiHeader.biBitCount = 16;
230
 
      break;
231
 
 
232
 
    default:
233
 
      g_warning ("gdk_win32_pixmap_new: depth = %d", depth);
234
 
      g_assert_not_reached ();
235
 
    }
236
 
 
237
 
  if (bmi.bmiHeader.biBitCount == 16)
238
 
    bmi.bmiHeader.biCompression = BI_BITFIELDS;
239
 
  else
240
 
    bmi.bmiHeader.biCompression = BI_RGB;
241
 
 
242
 
  bmi.bmiHeader.biSizeImage = 0;
243
 
  bmi.bmiHeader.biXPelsPerMeter =
244
 
    bmi.bmiHeader.biYPelsPerMeter = 0;
245
 
  bmi.bmiHeader.biClrUsed = 0;
246
 
  bmi.bmiHeader.biClrImportant = 0;
247
 
 
248
 
  iUsage = DIB_RGB_COLORS;
249
 
  if (depth == 1)
250
 
    {
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;
255
 
 
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;
260
 
    }
261
 
  else
262
 
    {
263
 
      if (depth <= 8 && drawable_impl->colormap != NULL)
264
 
        {
265
 
          GdkColormapPrivateWin32 *cmapp =
266
 
            GDK_WIN32_COLORMAP_DATA (drawable_impl->colormap);
267
 
          gint k;
268
 
 
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");
273
 
          else if (k > 0)
274
 
            GDK_NOTE (PIXMAP_OR_COLORMAP, g_print ("_gdk_win32_pixmap_new: realized %p: %d colors\n",
275
 
                                                   cmapp->hpal, k));
276
 
 
277
 
          iUsage = DIB_PAL_COLORS;
278
 
          for (i = 0; i < 256; i++)
279
 
            bmi.u.bmiIndices[i] = i;
280
 
        }
281
 
      else if (bmi.bmiHeader.biBitCount == 16)
282
 
        {
283
 
          GdkVisual *visual = gdk_visual_get_system ();
284
 
 
285
 
          bmi.u.bmiMasks[0] = visual->red_mask;
286
 
          bmi.u.bmiMasks[1] = visual->green_mask;
287
 
          bmi.u.bmiMasks[2] = visual->blue_mask;
288
 
        }
289
 
    }
290
 
 
291
 
  hbitmap = CreateDIBSection (hdc, (BITMAPINFO *) &bmi,
292
 
                              iUsage, (PVOID *) &bits, NULL, 0);
293
 
  if (holdpal != NULL)
294
 
    SelectPalette (hdc, holdpal, FALSE);
295
 
 
296
 
  GDI_CALL (ReleaseDC, (hwnd, hdc));
297
 
 
298
 
  GDK_NOTE (PIXMAP, g_print ("... =%p bits=%p pixmap=%p\n", hbitmap, bits, pixmap));
299
 
 
300
 
  if (hbitmap == NULL)
301
 
    {
302
 
      WIN32_GDI_FAILED ("CreateDIBSection");
303
 
      g_object_unref ((GObject *) pixmap);
304
 
      return NULL;
305
 
    }
306
 
 
 
205
 
 
206
  dib_surface = cairo_win32_surface_create_with_dib (format, width, height);
 
207
  if (dib_surface == NULL)
 
208
    {
 
209
      g_object_unref ((GObject *) pixmap);
 
210
      return NULL;
 
211
    }
 
212
 
 
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);
 
216
 
 
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 */
 
221
 
 
222
  /* No need to create a new surface when needed, as we have one already */
 
223
  drawable_impl->cairo_surface = dib_surface;
 
224
 
 
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;
 
228
 
 
229
  image_surface = cairo_win32_surface_get_image (dib_surface);
 
230
  pixmap_impl->bits = cairo_image_surface_get_data (image_surface);
309
231
 
310
232
  gdk_win32_handle_table_insert (&GDK_PIXMAP_HBITMAP (pixmap), pixmap);
311
233
 
486
408
  
487
409
  draw_impl->handle = hbitmap;
488
410
  draw_impl->colormap = NULL;
 
411
  pix_impl->is_foreign = TRUE;
489
412
  pix_impl->width = size.cx;
490
413
  pix_impl->height = size.cy;
491
414
  pix_impl->bits = NULL;