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.
15 #include "transform.h"
19 #include "writeablebitmap.h"
21 WriteableBitmap::WriteableBitmap ()
23 SetObjectType (Type::WRITEABLEBITMAP
);
24 pthread_mutex_init (&surface_mutex
, NULL
);
28 WriteableBitmap::InitializeFromBitmapSource (BitmapSource
*source
)
35 SetPixelHeight (source
->GetPixelHeight ());
36 SetPixelWidth (source
->GetPixelWidth ());
37 SetPixelFormat (PixelFormatPbgra32
);
39 image_surface
= cairo_image_surface_create (GetPixelFormat () == PixelFormatBgr32
? CAIRO_FORMAT_RGB24
: CAIRO_FORMAT_ARGB32
, GetPixelWidth (), GetPixelHeight ());
40 cr
= cairo_create (image_surface
);
41 cairo_set_source_surface (cr
, source
->GetImageSurface (), 0, 0);
45 SetBitmapData (cairo_image_surface_get_data (image_surface
));
47 return GetBitmapData ();
50 WriteableBitmap::~WriteableBitmap ()
52 pthread_mutex_destroy (&surface_mutex
);
56 WriteableBitmap::Lock ()
58 pthread_mutex_lock (&surface_mutex
);
62 WriteableBitmap::Unlock ()
64 pthread_mutex_unlock (&surface_mutex
);
68 WriteableBitmap::GetSurface (cairo_t
*cr
)
74 WriteableBitmap::Render (UIElement
*element
, Transform
*transform
)
83 if (!GetSurface (NULL
)) {
87 cr
= cairo_create (GetSurface (NULL
));
89 // Region is the entire WB size
90 region
= new Region (Rect (0, 0, GetPixelWidth (), GetPixelHeight ()));
92 // FIXME is this supposed to clear the surface?
93 cairo_set_operator (cr
, CAIRO_OPERATOR_CLEAR
);
95 cairo_set_operator (cr
, CAIRO_OPERATOR_OVER
);
99 transform
->GetTransform (&xform
);
101 element
->Paint (cr
, region
, &xform
);
104 cairo_surface_flush (image_surface
);