[cairo-commit] CairoJava/jni CairoImageBuffer.cpp, NONE, 1.1 CairoGlitzSurface.cpp, NONE, 1.1 CairoLinearPattern.cpp, NONE, 1.1 CairoImageBufferSurface.cpp, NONE, 1.1

Soorya Kuloor commit at pdx.freedesktop.org
Fri Apr 30 10:46:39 PDT 2004


Committed by: skuloor

Update of /cvs/cairo/CairoJava/jni
In directory pdx:/tmp/cvs-serv13722/jni

Added Files:
	CairoImageBuffer.cpp CairoGlitzSurface.cpp 
	CairoLinearPattern.cpp CairoImageBufferSurface.cpp 
Log Message:
Initial version

--- NEW FILE: CairoImageBuffer.cpp ---
/*
 * $Id: Cairo.java,v 1.5 2003/12/23 17:36:01 skuloor Exp $
 * 
 * Copyright (C) 2003 Verano
 * 
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that copyright
 * notice and this permission notice appear in supporting documentation, and
 * that the name of Verano not be used in advertising or publicity pertaining to
 * distribution of the software without specific, written prior permission.
 * Verano makes no representations about the suitability of this software for
 * any purpose. It is provided "as is" without express or implied warranty.
 * 
 * VERANO MAKES NO REPRESENTATIONS OR WARRANTIES OR COVENANTS, EITHER EXPRESS OR
 * IMPLIED, WITH RESPECT TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION,
 * STATUTORY OR IMPLIED WARRANTIES OR CONDITIONS OF MERCHANTABILITY, FITNESS FOR
 * A PARTICULAR PURPOSE, TITLE, NON-INFRINGEMENT, OR ARISING FROM CUSTOM, COURSE
 * OF DEALING, USAGE OF TRADE OR COURSE OF PERFORMANCE, ALL OF WHICH ARE
 * EXPRESSLY DISCLAIMED TO THE FULLEST EXTENT ALLOWABLE BY APPLICABLE LAW. IN NO
 * EVENT SHALL VERANO BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 */
#include <cairo.h>
#include "CairoImageBuffer.h"
#include "utils.h"
#include <gdk/gdkx.h>
#include <gtk/gtkwidget.h>

/*
 * Class:     org_cairographics_cairo_CairoImageBuffer
 * Method:    image_buffer_create
 * Signature: (SII)J
 */
JNIEXPORT jlong JNICALL Java_org_cairographics_cairo_CairoImageBuffer_image_1buffer_1create
(JNIEnv *env, jclass me, jshort format, jint width, jint height)
{
    cairo_image_buffer_t *img = (cairo_image_buffer_t *) malloc(sizeof(cairo_image_buffer_t));

    img->width = width;
    img->height = height;
    img->format = (cairo_format_t) format;

    img->bytes = (char *) malloc( width * height * 4);
    memset(img->bytes, 1, width * height * 4);

    img->stride = width * 4;
    
    return TO_LONG(img);
}

/*
 * Class:     org_cairographics_cairo_CairoImageBuffer
 * Method:    image_buffer_destroy
 * Signature: (J)V
 */
JNIEXPORT void JNICALL Java_org_cairographics_cairo_CairoImageBuffer_image_1buffer_1destroy
(JNIEnv *env, jclass me, jlong imgp)
{
    cairo_image_buffer_t *img = TO_PTR(cairo_image_buffer_t, imgp);
    free(img->bytes);
    free(img);
}

/*
 * Class:     org_cairographics_cairo_CairoImageBuffer
 * Method:    image_buffer_draw
 * Signature: (JIIIIIIII)V
 */
JNIEXPORT void JNICALL Java_org_cairographics_cairo_CairoImageBuffer_image_1buffer_1draw
  (JNIEnv *env, jclass me, jlong imgp, jint widget, jint gc,
   jint src_x, jint src_y, jint dst_x, jint dst_y, jint width, jint height)
{
    GdkDrawable *drawable;
    gint x_offset, y_offset;
    
    gdk_window_get_internal_paint_info (((GtkWidget *) (long) widget)->window,
                                        &drawable, &x_offset, &y_offset);

    GdkGC* gdkgc = TO_PTR(GdkGC, gc);
    cairo_image_buffer_t *img = TO_PTR(cairo_image_buffer_t, imgp);

    Drawable xid = GDK_DRAWABLE_XID(drawable);
    GC xgc = GDK_GC_XGC(gdkgc);
    Display* dpy = GDK_WINDOW_XDISPLAY(drawable);

    XImage *image = XCreateImage(
        dpy, DefaultVisual(dpy, DefaultScreen(dpy)),
        DefaultDepth(dpy, DefaultScreen(dpy)),
        ZPixmap, 0, img->bytes, img->width, img->height,
        32, img->stride);

    if (image == NULL)
        return;

    XPutImage(dpy, xid, xgc,
              image, src_x, src_y, dst_x, dst_y, width, height);

    // Don't let XDestoryImage free our image data
    image->data = NULL;
    XDestroyImage(image);
}


--- NEW FILE: CairoGlitzSurface.cpp ---
/*
 * $Id: Cairo.java,v 1.5 2003/12/23 17:36:01 skuloor Exp $
 * 
 * Copyright (C) 2003 Verano
 * 
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that copyright
 * notice and this permission notice appear in supporting documentation, and
 * that the name of Verano not be used in advertising or publicity pertaining to
 * distribution of the software without specific, written prior permission.
 * Verano makes no representations about the suitability of this software for
 * any purpose. It is provided "as is" without express or implied warranty.
 * 
 * VERANO MAKES NO REPRESENTATIONS OR WARRANTIES OR COVENANTS, EITHER EXPRESS OR
 * IMPLIED, WITH RESPECT TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION,
 * STATUTORY OR IMPLIED WARRANTIES OR CONDITIONS OF MERCHANTABILITY, FITNESS FOR
 * A PARTICULAR PURPOSE, TITLE, NON-INFRINGEMENT, OR ARISING FROM CUSTOM, COURSE
 * OF DEALING, USAGE OF TRADE OR COURSE OF PERFORMANCE, ALL OF WHICH ARE
 * EXPRESSLY DISCLAIMED TO THE FULLEST EXTENT ALLOWABLE BY APPLICABLE LAW. IN NO
 * EVENT SHALL VERANO BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 */
#include <cairo.h>
#include <glitz-glx.h>
#include <gdk/gdkx.h>
#include <gtk/gtkwidget.h>
#include "CairoGlitzSurface.h"
#include "utils.h"

/*
 * Class:     org_cairographics_cairo_CairoGlitzSurface
 * Method:    cairo_set_target_gl
 * Signature: (JJ)V
 */
JNIEXPORT void JNICALL Java_org_cairographics_cairo_CairoGlitzSurface_cairo_1set_1target_1gl
(JNIEnv * env, jclass me, jlong crp, jlong sfp)
{
    cairo_set_target_gl(TO_PTR(cairo_t, crp), TO_PTR(glitz_surface_t, sfp));
}

/*
 * Class:     org_cairographics_cairo_CairoGlitzSurface
 * Method:    glitz_glx_surface_create_for_window
 * Signature: ([SI)J
 */
JNIEXPORT jlong JNICALL Java_org_cairographics_cairo_CairoGlitzSurface_glitz_1glx_1surface_1create_1for_1window
(JNIEnv *env, jclass me, jlong widgetp)
{
    GtkWidget *widget = TO_PTR(GtkWidget, widgetp);
    gtk_widget_set_double_buffered (widget, FALSE);

    Display *dpy = GDK_WINDOW_XDISPLAY(widget->window);
    if (!dpy) {
        fprintf (stderr, "Couldn't find a usable display\n");
        exit (1);
    }
  

    glitz_format_t *format = glitz_glx_find_standard_format (dpy, DefaultScreen (dpy),
                                                             GLITZ_FORMAT_OPTION_ONSCREEN_MASK,
                                                             GLITZ_STANDARD_ARGB32);
    if (!format) {
        fprintf (stderr, "Couldn't find a usable GLITZ format\n");
        exit (1);
    }
  
    XVisualInfo *vinfo = glitz_glx_get_visual_info_from_format (dpy,
                                                                DefaultScreen (dpy),
                                                                format);
    if (!vinfo) {
        printf ("no visual info\n");
        exit (1);
    }
  
    Window win = GDK_WINDOW_XID(widget->window);
    glitz_surface_t *glitz_surface =
        glitz_glx_surface_create_for_window (dpy, DefaultScreen (dpy),
                                             format, win);
    if (!glitz_surface) {
        printf ("failed to create glitz surface\n");
        exit (1);
    }
  
    return TO_LONG(glitz_surface);
}

/*
 * Class:     org_cairographics_cairo_CairoGlitzSurface
 * Method:    glitz_glx_surface_flush
 * Signature: (JIIII)V
 */
JNIEXPORT void JNICALL Java_org_cairographics_cairo_CairoGlitzSurface_glitz_1glx_1surface_1flush
(JNIEnv *env, jclass me, jlong glitz_surfacep, jint x, jint y, jint width, jint height)
{
    glitz_surface_flush(TO_PTR(glitz_surface_t, glitz_surfacep), x, y, width, height);
}

--- NEW FILE: CairoLinearPattern.cpp ---
/*
 * $Id: Cairo.java,v 1.5 2003/12/23 17:36:01 skuloor Exp $
 * 
 * Copyright (C) 2003 Verano
 * 
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that copyright
 * notice and this permission notice appear in supporting documentation, and
 * that the name of Verano not be used in advertising or publicity pertaining to
 * distribution of the software without specific, written prior permission.
 * Verano makes no representations about the suitability of this software for
 * any purpose. It is provided "as is" without express or implied warranty.
 * 
 * VERANO MAKES NO REPRESENTATIONS OR WARRANTIES OR COVENANTS, EITHER EXPRESS OR
 * IMPLIED, WITH RESPECT TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION,
 * STATUTORY OR IMPLIED WARRANTIES OR CONDITIONS OF MERCHANTABILITY, FITNESS FOR
 * A PARTICULAR PURPOSE, TITLE, NON-INFRINGEMENT, OR ARISING FROM CUSTOM, COURSE
 * OF DEALING, USAGE OF TRADE OR COURSE OF PERFORMANCE, ALL OF WHICH ARE
 * EXPRESSLY DISCLAIMED TO THE FULLEST EXTENT ALLOWABLE BY APPLICABLE LAW. IN NO
 * EVENT SHALL VERANO BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 */
 
#include <cairo.h>
#include "CairoLinearPattern.h"
#include "utils.h"

/*
 * Class:     org_cairographics_cairo_CairoLinearPattern
 * Method:    cairo_pattern_create_linear
 * Signature: (DDDD)J
 */
JNIEXPORT jlong JNICALL Java_org_cairographics_cairo_CairoLinearPattern_cairo_1pattern_1create_1linear
(JNIEnv *env, jclass me, jdouble x0, jdouble y0, jdouble x1, jdouble y1)
{
    return TO_LONG(cairo_pattern_create_linear(x0, y0, x1, y1));
}

--- NEW FILE: CairoImageBufferSurface.cpp ---
/*
 * $Id: Cairo.java,v 1.5 2003/12/23 17:36:01 skuloor Exp $
 * 
 * Copyright (C) 2003 Verano
 * 
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that copyright
 * notice and this permission notice appear in supporting documentation, and
 * that the name of Verano not be used in advertising or publicity pertaining to
 * distribution of the software without specific, written prior permission.
 * Verano makes no representations about the suitability of this software for
 * any purpose. It is provided "as is" without express or implied warranty.
 * 
 * VERANO MAKES NO REPRESENTATIONS OR WARRANTIES OR COVENANTS, EITHER EXPRESS OR
 * IMPLIED, WITH RESPECT TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION,
 * STATUTORY OR IMPLIED WARRANTIES OR CONDITIONS OF MERCHANTABILITY, FITNESS FOR
 * A PARTICULAR PURPOSE, TITLE, NON-INFRINGEMENT, OR ARISING FROM CUSTOM, COURSE
 * OF DEALING, USAGE OF TRADE OR COURSE OF PERFORMANCE, ALL OF WHICH ARE
 * EXPRESSLY DISCLAIMED TO THE FULLEST EXTENT ALLOWABLE BY APPLICABLE LAW. IN NO
 * EVENT SHALL VERANO BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 */
#include <cairo.h>
#include "CairoImageBufferSurface.h"
#include "utils.h"

/*
 * Class:     org_cairographics_cairo_CairoImageBufferSurface
 * Method:    cairo_image_buffer_surface_create
 * Signature: (JII)J
 */
JNIEXPORT jlong JNICALL Java_org_cairographics_cairo_CairoImageBufferSurface_cairo_1image_1buffer_1surface_1create
(JNIEnv *env, jclass me, jlong bufferp)
{
    cairo_image_buffer_t *img = TO_PTR(cairo_image_buffer_t, bufferp);
    cairo_surface_t *surface =
        cairo_surface_create_for_image(
            img->bytes,
            img->format,
            img->width,
            img->height,
            img->stride);
    return TO_LONG(surface);
}






More information about the cairo-commit mailing list