OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [native/] [jni/] [gtk-peer/] [gnu_java_awt_peer_gtk_GtkVolatileImage.c] - Blame information for rev 774

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 774 jeremybenn
/* gnu_java_awt_peer_gtk_VolatileImage.c
2
   Copyright (C)  2006 Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
#include "jcl.h"
39
#include "gtkpeer.h"
40
#include <gdk/gdktypes.h>
41
#include <gdk/gdkprivate.h>
42
#include <gdk-pixbuf/gdk-pixbuf.h>
43
#include <gdk-pixbuf/gdk-pixdata.h>
44
 
45
#include "gnu_java_awt_peer_gtk_GtkVolatileImage.h"
46
#include "cairographics2d.h"
47
 
48
 
49
/**
50
 * Creates a cairo surface, ARGB32, native ordering, premultiplied alpha.
51
 */
52
JNIEXPORT jlong JNICALL
53
Java_gnu_java_awt_peer_gtk_GtkVolatileImage_init (JNIEnv *env,
54
                                                  jobject obj __attribute__ ((__unused__)),
55
                                                  jobject peer,
56
                                                  jint width, jint height)
57
{
58
  GtkWidget *widget = NULL;
59
  GdkPixmap* pixmap;
60
  void *ptr = NULL;
61
 
62
  gdk_threads_enter();
63
 
64
  if( peer != NULL )
65
    {
66
      ptr = gtkpeer_get_widget (env, peer);
67
      g_assert (ptr != NULL);
68
 
69
      widget = GTK_WIDGET (ptr);
70
      g_assert (widget != NULL);
71
      pixmap = gdk_pixmap_new( widget->window, width, height, -1 );
72
    }
73
  else
74
    pixmap = gdk_pixmap_new( NULL, width, height,
75
                             gdk_rgb_get_visual()->depth );
76
 
77
  gdk_threads_leave();
78
 
79
  g_assert( pixmap != NULL );
80
 
81
  return PTR_TO_JLONG( pixmap );
82
}
83
 
84
/**
85
 * Destroy the surface
86
 */
87
JNIEXPORT void JNICALL
88
Java_gnu_java_awt_peer_gtk_GtkVolatileImage_destroy
89
(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)),
90
 jlong pointer)
91
{
92
  GdkPixmap* pixmap = JLONG_TO_PTR(GdkPixmap, pointer);
93
  if( pixmap != NULL )
94
    {
95
      gdk_threads_enter();
96
      g_object_unref( pixmap );
97
      gdk_threads_leave();
98
    }
99
}
100
 
101
/**
102
 * Gets all pixels in an array
103
 */
104
JNIEXPORT jintArray JNICALL
105
Java_gnu_java_awt_peer_gtk_GtkVolatileImage_nativeGetPixels
106
(JNIEnv *env, jobject obj, jlong pointer)
107
{
108
  /* jint *pixeldata, *jpixdata; */
109
  jint *jpixdata;
110
  GdkPixmap *pixmap;
111
  GdkPixbuf *pixbuf;
112
  jintArray jpixels;
113
  int width, height, depth, size;
114
  jclass cls;
115
  jfieldID field;
116
  guchar *pixels;
117
 
118
  cls = (*env)->GetObjectClass (env, obj);
119
  field = (*env)->GetFieldID (env, cls, "width", "I");
120
  g_assert (field != 0);
121
  width = (*env)->GetIntField (env, obj, field);
122
 
123
  field = (*env)->GetFieldID (env, cls, "height", "I");
124
  g_assert (field != 0);
125
  height = (*env)->GetIntField (env, obj, field);
126
 
127
  pixmap = JLONG_TO_PTR(GdkPixmap, pointer);
128
  g_assert(pixmap != NULL);
129
 
130
  gdk_threads_enter();
131
 
132
  /* get depth in bytes */
133
  depth = gdk_drawable_get_depth( pixmap ) >> 3;
134
  size = width * height;
135
  jpixels = (*env)->NewIntArray ( env, size );
136
  jpixdata = (*env)->GetIntArrayElements (env, jpixels, NULL);
137
 
138
  pixbuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB, TRUE, 8, width, height );
139
  gdk_pixbuf_get_from_drawable( pixbuf, pixmap, NULL, 0, 0, 0, 0, width, height );
140
 
141
  if (pixbuf != NULL)
142
    {
143
      pixels = gdk_pixbuf_get_pixels(pixbuf);
144
      memcpy (jpixdata, pixels, size * sizeof(jint));
145
    }
146
 
147
  (*env)->ReleaseIntArrayElements (env, jpixels, jpixdata, 0);
148
 
149
  gdk_threads_leave();
150
 
151
  return jpixels;
152
}
153
 
154
/**
155
 * Copy area
156
 */
157
JNIEXPORT void JNICALL
158
Java_gnu_java_awt_peer_gtk_GtkVolatileImage_nativeCopyArea
159
(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)),
160
 jlong pointer, jint x, jint y, jint w, jint h, jint dx, jint dy)
161
{
162
  GdkPixbuf *pixbuf;
163
  GdkPixmap* pixmap = JLONG_TO_PTR(GdkPixmap, pointer);
164
 
165
  g_assert (pixmap != NULL);
166
 
167
  gdk_threads_enter();
168
 
169
  pixbuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB, TRUE, 8, w, h );
170
  gdk_pixbuf_get_from_drawable( pixbuf, pixmap, NULL, x, y, 0, 0, w, h );
171
  gdk_draw_pixbuf (pixmap, NULL, pixbuf,
172
                   0, 0, x + dx, y + dy,
173
                   w, h,
174
                   GDK_RGB_DITHER_NORMAL, 0, 0);
175
  gdk_threads_leave();
176
}
177
 
178
JNIEXPORT void JNICALL
179
Java_gnu_java_awt_peer_gtk_GtkVolatileImage_nativeDrawVolatile
180
(JNIEnv *env __attribute__((unused)), jobject obj __attribute__((unused)),
181
 jlong pointer, jlong srcptr, jint x, jint y, jint w, jint h)
182
{
183
  GdkPixmap *dst, *src;
184
  GdkGC *gc;
185
 
186
  src = JLONG_TO_PTR(GdkPixmap, srcptr);
187
  dst = JLONG_TO_PTR(GdkPixmap, pointer);
188
  g_assert (src != NULL);
189
  g_assert (dst != NULL);
190
 
191
  gdk_threads_enter();
192
 
193
  gc = gdk_gc_new( dst );
194
  gdk_draw_drawable(dst,
195
                    gc,
196
                    src,
197
                    0, 0,
198
                    x, y,
199
                    w, h);
200
  g_object_unref( gc );
201
 
202
  gdk_threads_leave();
203
}
204
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.