コード例 #1
0
cairo_surface_t *
_gdk_windowing_create_cairo_surface (GdkDrawable *drawable,
				     int          width,
				     int          height)
{
  CGContextRef cg_context;
  GdkQuartzCairoSurfaceData *surface_data;
  cairo_surface_t *surface;

  cg_context = gdk_quartz_drawable_get_context (drawable, TRUE);

  if (!cg_context)
    return NULL;

  surface_data = g_new (GdkQuartzCairoSurfaceData, 1);
  surface_data->drawable = drawable;
  surface_data->cg_context = cg_context;

  surface = cairo_quartz_surface_create_for_cg_context (cg_context,
                                                        width, height);

  cairo_surface_set_user_data (surface, &gdk_quartz_cairo_key,
                               surface_data,
                               gdk_quartz_cairo_surface_destroy);

  return surface;
}
コード例 #2
0
ファイル: Cairo.cpp プロジェクト: Justinmaurer/Cinder
/////////////////////////////////////////////////////////////////////////////
// SurfaceCgBitmapContext
SurfaceCgBitmapContext::SurfaceCgBitmapContext( int32_t width, int32_t height, bool alpha )
	: SurfaceBase( width, height )
{
	mSurface = cinder::Surface( width, height, alpha, SurfaceConstraintsCgBitmapContext() );
	mCgContextRef = cinder::cocoa::createCgBitmapContext( mSurface );
	// Need to flip this vertically since Quartz is lower-left origin
	::CGContextTranslateCTM( mCgContextRef, 0.0f, height );
	::CGContextScaleCTM( mCgContextRef, 1.0f, -1.0f );

	mCairoSurface = cairo_quartz_surface_create_for_cg_context( mCgContextRef, width, height ); 
}
コード例 #3
0
ファイル: cairo_box.cpp プロジェクト: Andy1978/cairo_plot
cairo_surface_t*  cairo_box::set_surface(int wo, int ho)
{
#ifdef WIN32
#warning win32 mode
  /* Get a Cairo surface for the current DC */
  HDC dc = fl_gc;                                     /* Exported by fltk */
  return cairo_win32_surface_create(dc);
#elif defined (__APPLE__)
#warning Apple Quartz mode
  /* Get a Cairo surface for the current CG context */
  CGContext *ctx = fl_gc;
  return cairo_quartz_surface_create_for_cg_context(ctx, wo, ho);
#else
  /* Get a Cairo surface for the current display */
  return cairo_xlib_surface_create(fl_display, fl_window, fl_visual->visual, wo, ho);
#endif
}
コード例 #4
0
gfxQuartzSurface::gfxQuartzSurface(CGContextRef context,
                                   const gfxIntSize& size,
                                   bool aForPrinting)
    : mCGContext(context), mSize(size), mForPrinting(aForPrinting)
{
    if (!CheckSurfaceSize(size))
        MakeInvalid();

    unsigned int width = static_cast<unsigned int>(mSize.width);
    unsigned int height = static_cast<unsigned int>(mSize.height);

    cairo_surface_t *surf = 
        cairo_quartz_surface_create_for_cg_context(context,
                                                   width, height);

    CGContextRetain(mCGContext);

    Init(surf);
}
コード例 #5
0
gfxQuartzSurface::gfxQuartzSurface(CGContextRef context,
                                   const mozilla::gfx::IntSize& size)
    : mCGContext(context), mSize(size)
{
    if (!CheckSurfaceSize(size))
        MakeInvalid();

    unsigned int width = static_cast<unsigned int>(mSize.width);
    unsigned int height = static_cast<unsigned int>(mSize.height);

    cairo_surface_t *surf = 
        cairo_quartz_surface_create_for_cg_context(context,
                                                   width, height);

    CGContextRetain(mCGContext);

    Init(surf);
    if (mSurfaceValid) {
      RecordMemoryUsed(mSize.height * 4 + sizeof(gfxQuartzSurface));
    }
}
コード例 #6
0
gfxQuartzSurface::gfxQuartzSurface(CGContextRef context,
                                   const gfxSize& desiredSize,
                                   bool aForPrinting)
    : mCGContext(context), mSize(desiredSize), mForPrinting(aForPrinting)
{
    gfxIntSize size((unsigned int) floor(desiredSize.width),
                    (unsigned int) floor(desiredSize.height));
    if (!CheckSurfaceSize(size))
        MakeInvalid();

    unsigned int width = static_cast<unsigned int>(mSize.width);
    unsigned int height = static_cast<unsigned int>(mSize.height);

    cairo_surface_t *surf =
        cairo_quartz_surface_create_for_cg_context(context,
                                                   width, height);

    CGContextRetain(mCGContext);

    Init(surf);
    if (mSurfaceValid) {
      RecordMemoryUsed(mSize.height * 4 + sizeof(gfxQuartzSurface));
    }
}
コード例 #7
0
ファイル: Cairo.cpp プロジェクト: Justinmaurer/Cinder
SurfaceQuartz::SurfaceQuartz( CGContextRef cgContext, int32_t width, int32_t height )
	: SurfaceBase( width, height ), mCgContextRef( cgContext )
{
	mCairoSurface = cairo_quartz_surface_create_for_cg_context( cgContext, width, height ); 
}
コード例 #8
0
static VALUE
cr_quartz_surface_initialize (int argc, VALUE *argv, VALUE self)
{
  id objc_object = nil;
  CGContextRef context;
  unsigned int width, height;
  cairo_surface_t *surface = NULL;
  cairo_format_t format = CAIRO_FORMAT_ARGB32;
  VALUE arg1, arg2, arg3, rb_width, rb_height;
  static VALUE rb_cOSXCGContextRef = Qnil;

  rb_scan_args (argc, argv, "21", &arg1, &arg2, &arg3);

  if (argc == 2)
    {
      rb_width = arg1;
      rb_height = arg2;
    }
  else
    {
      switch (TYPE (arg1))
        {
        case T_NIL:
          break;
        case T_STRING:
        case T_SYMBOL:
        case T_FIXNUM:
          format = RVAL2CRFORMAT (arg1);
          break;
        default:
          if (NIL_P (rb_cOSXCGContextRef))
            rb_cOSXCGContextRef =
              rb_const_get (rb_const_get (rb_cObject, rb_intern ("OSX")),
                            rb_intern ("CGContextRef"));

          if (RTEST (rb_obj_is_kind_of (arg1, rb_cOSXCGContextRef)))
            rbobj_to_nsobj (arg1, &objc_object);
          else
            rb_raise (rb_eArgError,
                      "invalid argument (expect "
                      "(width, height), "
                      "(format, width, height) or "
                      "(cg_context, width, height)): %s",
                      inspect (rb_ary_new3 (3, arg1, arg2, arg3)));
          break;
        }

      rb_width = arg2;
      rb_height = arg3;
    }

  width = NUM2UINT (rb_width);
  height = NUM2UINT (rb_height);

  if (objc_object == nil)
    {
      surface = cairo_quartz_surface_create (format, width, height);
    }
  else
    {
      context = (CGContextRef)objc_object;
      surface =
        cairo_quartz_surface_create_for_cg_context (context, width, height);
    }

  cr_surface_check_status (surface);
  DATA_PTR (self) = surface;
  if (rb_block_given_p ())
    yield_and_finish (self);
  return Qnil;
}