26
CairoWrapper::CairoWrapper (Geometry const& geom, DrawCanvasCallback callback)
28
draw_canvas_callback_ = callback;
31
geometry_.width = geom.width;
32
geometry_.height = geom.height;
40
CairoWrapper::~CairoWrapper ()
26
struct CairoWrapper::Impl
28
Impl(CairoWrapper* parent, Geometry const& geo, DrawCanvasCallback callback);
32
bool Invalidate (Geometry const& geom);
33
void SetDrawCanvasCallback (DrawCanvasCallback callback);
34
bool DumpToFile (std::string const& filename);
36
void DeleteResources();
38
CairoWrapper* parent_;
40
DrawCanvasCallback draw_canvas_callback_;
42
cairo_surface_t* surface_;
44
BaseTexture* texture_;
47
CairoWrapper::Impl::Impl(CairoWrapper* parent, Geometry const& geo, DrawCanvasCallback callback)
50
, draw_canvas_callback_(callback)
58
CairoWrapper::Impl::~Impl()
63
void CairoWrapper::Impl::DeleteResources()
43
67
cairo_surface_destroy (surface_);
46
73
cairo_destroy (cr_);
52
85
texture_->UnReference ();
55
bool CairoWrapper::Recreate ()
90
bool CairoWrapper::Impl::Recreate ()
58
cairo_surface_destroy (surface_);
63
94
surface_ = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
67
98
if (cairo_surface_status (surface_) != CAIRO_STATUS_SUCCESS)
69
100
g_debug ("Could not create image-surface!");
84
115
draw_canvas_callback_ (geometry_, cr_);
87
NBitmapData* bitmap = GetBitmap ();
118
NBitmapData* bitmap = parent_->GetBitmap ();
89
120
texture_->UnReference ();
91
if (GetGraphicsDisplay()->GetGraphicsEngine() == NULL)
122
if (GetGraphicsDisplay()->GetGraphicsEngine() == 0)
94
125
texture_ = GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableTexture();
95
126
texture_->Update (bitmap);
100
bool CairoWrapper::CreateBitmap ()
131
bool CairoWrapper::Impl::CreateBitmap ()
102
133
if (geometry_.width < 1 || geometry_.height < 1)
119
150
t_u8* ptr = cairo_image_surface_get_data (surface_);
120
151
int stride = cairo_image_surface_get_stride (surface_);
122
if (ptr == NULL || stride == 0)
153
if (ptr == 0 || stride == 0)
124
155
g_debug ("Invalid surface!");
138
NBitmapData* CairoWrapper::GetBitmap () const
143
void CairoWrapper::SetDrawCanvasCallback (DrawCanvasCallback callback)
169
void CairoWrapper::Impl::SetDrawCanvasCallback (DrawCanvasCallback callback)
148
174
draw_canvas_callback_ = callback;
178
bool CairoWrapper::Impl::DumpToFile (std::string const& filename)
183
cairo_surface_write_to_png (surface_, filename.c_str ());
188
bool CairoWrapper::Impl::Invalidate (Geometry const& geom)
190
if (geometry_.width == geom.width && geometry_.height == geom.height)
193
geometry_.x = geom.x;
194
geometry_.y = geom.y;
195
geometry_.width = geom.width;
196
geometry_.height = geom.height;
203
CairoWrapper::CairoWrapper (Geometry const& geom, DrawCanvasCallback callback)
204
: pimpl(new Impl(this, geom, callback))
209
CairoWrapper::~CairoWrapper ()
214
bool CairoWrapper::Invalidate (Geometry const& geom)
216
return pimpl->Invalidate(geom);
219
void CairoWrapper::SetDrawCanvasCallback (DrawCanvasCallback callback)
221
pimpl->SetDrawCanvasCallback(callback);
153
224
bool CairoWrapper::DumpToFile (std::string const& filename)
155
cairo_surface_write_to_png (surface_, filename.c_str ());
226
return pimpl->DumpToFile(filename);
229
bool CairoWrapper::Recreate ()
231
return pimpl->Recreate();
234
NBitmapData* CairoWrapper::GetBitmap () const
239
return pimpl->bitmap_;
160
242
BaseTexture* CairoWrapper::GetTexture () const
244
if (!pimpl->texture_)
247
return pimpl->texture_;
165
250
cairo_surface_t* CairoWrapper::GetCairoSurface () const
252
if (!pimpl->surface_)
255
return pimpl->surface_;
170
258
cairo_t* CairoWrapper::GetCairoContext () const
175
bool CairoWrapper::Invalidate (Geometry const& geom)
177
if (geometry_.width == geom.width &&
178
geometry_.height == geom.height)
181
geometry_.x = geom.x;
182
geometry_.y = geom.y;
183
geometry_.width = geom.width;
184
geometry_.height = geom.height;