1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
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.
18 #include "application.h"
19 #include "bitmapsource.h"
22 BitmapSource::BitmapSource ()
24 SetObjectType (Type::BITMAPSOURCE
);
26 native_surface
= NULL
;
31 BitmapSource::~BitmapSource ()
34 cairo_surface_destroy (image_surface
);
36 cairo_surface_destroy (native_surface
);
43 BitmapSource::GetBitmapData ()
49 BitmapSource::SetBitmapData (gpointer data
, bool own_data
)
51 if (this->data
&& this->own_data
)
53 this->own_data
= own_data
;
58 BitmapSource::Invalidate ()
60 if (GetPixelWidth () == 0 || GetPixelHeight () == 0)
64 cairo_surface_destroy (native_surface
);
65 native_surface
= NULL
;
68 cairo_surface_destroy (image_surface
);
70 image_surface
= cairo_image_surface_create_for_data ((unsigned char *) GetBitmapData (), GetPixelFormat () == PixelFormatBgr32
? CAIRO_FORMAT_RGB24
: CAIRO_FORMAT_ARGB32
, GetPixelWidth (), GetPixelHeight (), GetPixelWidth ()*4);
72 Emit (BitmapSource::PixelDataChangedEvent
);
76 BitmapSource::GetSurface (cairo_t
*cr
)
78 if (image_surface
== NULL
)
82 return native_surface
;
87 native_surface
= cairo_surface_create_similar (cairo_get_group_target (cr
),
88 cairo_surface_get_content (image_surface
),
89 GetPixelWidth (), GetPixelHeight ());
91 cairo_t
*context
= cairo_create (native_surface
);
93 cairo_set_source_surface (context
, image_surface
, 0, 0);
94 cairo_pattern_set_filter (cairo_get_source (context
), CAIRO_FILTER_FAST
);
96 cairo_paint (context
);
97 cairo_destroy (context
);
99 return native_surface
;