Back to index

nux  3.0.0
Public Member Functions | Public Attributes
nux::CairoWrapper::Impl Struct Reference
Collaboration diagram for nux::CairoWrapper::Impl:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Impl (CairoWrapper *parent, Geometry const &geo, DrawCanvasCallback callback)
 ~Impl ()
bool CreateBitmap ()
bool Invalidate (Geometry const &geom)
void SetDrawCanvasCallback (DrawCanvasCallback callback)
bool DumpToFile (std::string const &filename)
bool Recreate ()
void DeleteResources ()

Public Attributes

CairoWrapperparent_
Geometry geometry_
DrawCanvasCallback draw_canvas_callback_
cairo_t * cr_
cairo_surface_t * surface_
NBitmapDatabitmap_
BaseTexturetexture_

Detailed Description

Definition at line 26 of file CairoWrapper.cpp.


Constructor & Destructor Documentation

nux::CairoWrapper::Impl::Impl ( CairoWrapper parent,
Geometry const &  geo,
DrawCanvasCallback  callback 
)

Definition at line 47 of file CairoWrapper.cpp.

    : parent_(parent)
    , geometry_(geo)
    , draw_canvas_callback_(callback)
    , cr_(0)
    , surface_(0)
    , bitmap_(0)
    , texture_(0)
  {
  }

Definition at line 58 of file CairoWrapper.cpp.


Member Function Documentation

Definition at line 131 of file CairoWrapper.cpp.

  {
    if (geometry_.width < 1 || geometry_.height < 1)
    {
      g_debug ("Width or height invalid!");
      return false;
    }

    if (bitmap_)
    {
      delete bitmap_;
      bitmap_ = 0;
    }

    BitmapFormat bitmap_format = BITFMT_B8G8R8A8;
    bitmap_ = new NTextureData (bitmap_format,
                                geometry_.width,
                                geometry_.height,
                                1);
    unsigned char* ptr = cairo_image_surface_get_data (surface_);
    int stride = cairo_image_surface_get_stride (surface_);

    if (ptr == 0 || stride == 0)
    {
      g_debug ("Invalid surface!");
      return false;
    }

    for (int j = 0; j < geometry_.height; j++)
    {
      Memcpy (bitmap_->GetSurface (0).GetPtrRawData() + j * bitmap_->GetSurface (0).GetPitch(),
                (const void *) (&ptr[j * stride]),
                geometry_.width * GPixelFormats[bitmap_format].NumComponents);
    }

    return true;
  }

Here is the call graph for this function:

Definition at line 63 of file CairoWrapper.cpp.

  {
    if (surface_)
    {
      cairo_surface_destroy (surface_);
      surface_ = 0;
    }

    if (cr_)
    {
      cairo_destroy (cr_);
      cr_ = 0;
    }

    if (bitmap_)
    {
      delete bitmap_;
      bitmap_ = 0;
    }

    if (texture_)
    {
      texture_->UnReference ();
      texture_ = 0;
    }
  }
bool nux::CairoWrapper::Impl::DumpToFile ( std::string const &  filename)

Definition at line 178 of file CairoWrapper.cpp.

  {
    if (!surface_)
      Recreate();

    cairo_surface_write_to_png (surface_, filename.c_str ());

    return true;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 188 of file CairoWrapper.cpp.

  {
    if (geometry_.width  == geom.width && geometry_.height == geom.height)
      return false;

    geometry_.x      = geom.x;
    geometry_.y      = geom.y;
    geometry_.width  = geom.width;
    geometry_.height = geom.height;

    DeleteResources(); 

    return true;
  }

Here is the caller graph for this function:

Definition at line 90 of file CairoWrapper.cpp.

  {
    DeleteResources();

    surface_ = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                           geometry_.width,
                                           geometry_.height);

    if (cairo_surface_status (surface_) != CAIRO_STATUS_SUCCESS)
    {
      g_debug ("Could not create image-surface!");
      return false;
    }

    cr_ = cairo_create (surface_);
    if (cairo_status (cr_) != CAIRO_STATUS_SUCCESS)
    {
      cairo_surface_destroy (surface_);
      g_debug ("Could not create cairo-context!");
      return false;
    }

    if (!draw_canvas_callback_)
      return false;

    draw_canvas_callback_ (geometry_, cr_);

    CreateBitmap ();
    NBitmapData* bitmap = parent_->GetBitmap ();
    if (texture_)
        texture_->UnReference ();

    if (GetGraphicsDisplay()->GetGraphicsEngine() == 0)
      return false;

    texture_ = GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableTexture();
    texture_->Update (bitmap);

    return true;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 169 of file CairoWrapper.cpp.

  {
    if (!callback)
      return;

    draw_canvas_callback_ = callback;
    Recreate (); 
  }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 43 of file CairoWrapper.cpp.

Definition at line 41 of file CairoWrapper.cpp.

Definition at line 40 of file CairoWrapper.cpp.

Definition at line 39 of file CairoWrapper.cpp.

Definition at line 38 of file CairoWrapper.cpp.

Definition at line 42 of file CairoWrapper.cpp.

Definition at line 44 of file CairoWrapper.cpp.


The documentation for this struct was generated from the following file: