add the 2.1-bootstrap dir to MONO_PATH when running smcs
[moon.git] / src / bitmapsource.cpp
blobfa22fed89b56fc71ebfa241528f41a50c9642eed
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * bitmapsource.cpp
5 * Contact:
6 * Moonlight List (moonlight-list@lists.ximian.com)
8 * Copyright 2007-2008 Novell, Inc. (http://www.novell.com)
10 * See the LICENSE file included with the distribution for details.
14 #include <config.h>
16 #include <stdio.h>
18 #include "application.h"
19 #include "bitmapsource.h"
20 #include "runtime.h"
22 BitmapSource::BitmapSource ()
24 SetObjectType (Type::BITMAPSOURCE);
25 image_surface = NULL;
26 native_surface = NULL;
27 data = NULL;
30 BitmapSource::~BitmapSource ()
32 if (image_surface)
33 cairo_surface_destroy (image_surface);
34 if (native_surface)
35 cairo_surface_destroy (native_surface);
37 if (this->data)
38 g_free (this->data);
41 gpointer
42 BitmapSource::GetBitmapData ()
44 return data;
47 void
48 BitmapSource::SetBitmapData (gpointer data)
50 if (this->data)
51 g_free (this->data);
52 this->data = data;
55 void
56 BitmapSource::Invalidate ()
58 if (GetPixelWidth () == 0 || GetPixelHeight () == 0)
59 return;
61 if (native_surface) {
62 cairo_surface_destroy (native_surface);
63 native_surface = NULL;
65 if (image_surface)
66 cairo_surface_destroy (image_surface);
68 image_surface = cairo_image_surface_create_for_data ((unsigned char *) GetBitmapData (), GetPixelFormat () == PixelFormatBgr32 ? CAIRO_FORMAT_RGB24 : CAIRO_FORMAT_ARGB32, GetPixelWidth (), GetPixelHeight (), GetPixelWidth ()*4);
71 cairo_surface_t *
72 BitmapSource::GetSurface (cairo_t *cr)
74 if (image_surface == NULL)
75 return NULL;
77 if (native_surface)
78 return native_surface;
80 if (cr == NULL)
81 return image_surface;
83 native_surface = cairo_surface_create_similar (cairo_get_group_target (cr),
84 cairo_surface_get_content (image_surface),
85 GetPixelWidth (), GetPixelHeight ());
87 cairo_t *context = cairo_create (native_surface);
89 cairo_set_source_surface (context, image_surface, 0, 0);
90 cairo_pattern_set_filter (cairo_get_source (context), CAIRO_FILTER_FAST);
92 cairo_paint (context);
93 cairo_destroy (context);
95 return native_surface;