OLD | NEW |
| (Empty) |
1 /* Based on GTK code by the Chromium Authors. The original header for that code | |
2 * continues below */ | |
3 | |
4 /* GDK - The GIMP Drawing Kit | |
5 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald | |
6 * | |
7 * This library is free software; you can redistribute it and/or | |
8 * modify it under the terms of the GNU Lesser General Public | |
9 * License as published by the Free Software Foundation; either | |
10 * version 2 of the License, or (at your option) any later version. | |
11 * | |
12 * This library is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Lesser General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Lesser General Public | |
18 * License along with this library; if not, write to the | |
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
20 * Boston, MA 02111-1307, USA. | |
21 */ | |
22 | |
23 /* | |
24 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS | |
25 * file for a list of people on the GTK+ Team. See the ChangeLog | |
26 * files for a list of changes. These files are distributed with | |
27 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. | |
28 */ | |
29 | |
30 #include <stdio.h> | |
31 | |
32 #include <gdk/gdk.h> | |
33 #include <SkCanvas.h> | |
34 #include <SkBitmap.h> | |
35 #include <SkDevice.h> | |
36 | |
37 #include "gdkskiadrawable.h" | |
38 | |
39 static GdkGC *gdk_skia_create_gc (GdkDrawable *drawable, | |
40 GdkGCValues *values, | |
41 GdkGCValuesMask mask); | |
42 static void gdk_skia_draw_rectangle (GdkDrawable *drawable, | |
43 GdkGC *gc, | |
44 gboolean filled, | |
45 gint x, | |
46 gint y, | |
47 gint width, | |
48 gint height); | |
49 static void gdk_skia_draw_arc (GdkDrawable *drawable, | |
50 GdkGC *gc, | |
51 gboolean filled, | |
52 gint x, | |
53 gint y, | |
54 gint width, | |
55 gint height, | |
56 gint angle1, | |
57 gint angle2); | |
58 static void gdk_skia_draw_polygon (GdkDrawable *drawable, | |
59 GdkGC *gc, | |
60 gboolean filled, | |
61 GdkPoint *points, | |
62 gint npoints); | |
63 static void gdk_skia_draw_text (GdkDrawable *drawable, | |
64 GdkFont *font, | |
65 GdkGC *gc, | |
66 gint x, | |
67 gint y, | |
68 const gchar *text, | |
69 gint text_length); | |
70 static void gdk_skia_draw_text_wc (GdkDrawable *drawable, | |
71 GdkFont *font, | |
72 GdkGC *gc, | |
73 gint x, | |
74 gint y, | |
75 const GdkWChar *text, | |
76 gint text_length); | |
77 static void gdk_skia_draw_drawable (GdkDrawable *drawable, | |
78 GdkGC *gc, | |
79 GdkPixmap *src, | |
80 gint xsrc, | |
81 gint ysrc, | |
82 gint xdest, | |
83 gint ydest, | |
84 gint width, | |
85 gint height); | |
86 static void gdk_skia_draw_points (GdkDrawable *drawable, | |
87 GdkGC *gc, | |
88 GdkPoint *points, | |
89 gint npoints); | |
90 static void gdk_skia_draw_segments (GdkDrawable *drawable, | |
91 GdkGC *gc, | |
92 GdkSegment *segs, | |
93 gint nsegs); | |
94 static void gdk_skia_draw_lines (GdkDrawable *drawable, | |
95 GdkGC *gc, | |
96 GdkPoint *points, | |
97 gint npoints); | |
98 | |
99 static void gdk_skia_draw_glyphs (GdkDrawable *drawable, | |
100 GdkGC *gc, | |
101 PangoFont *font, | |
102 gint x, | |
103 gint y, | |
104 PangoGlyphString *glyphs); | |
105 static void gdk_skia_draw_glyphs_transformed (GdkDrawable *drawable, | |
106 GdkGC *gc, | |
107 PangoMatrix *matrix, | |
108 PangoFont *font, | |
109 gint x, | |
110 gint y, | |
111 PangoGlyphString *glyphs); | |
112 | |
113 static void gdk_skia_draw_image (GdkDrawable *drawable, | |
114 GdkGC *gc, | |
115 GdkImage *image, | |
116 gint xsrc, | |
117 gint ysrc, | |
118 gint xdest, | |
119 gint ydest, | |
120 gint width, | |
121 gint height); | |
122 static void gdk_skia_draw_pixbuf (GdkDrawable *drawable, | |
123 GdkGC *gc, | |
124 GdkPixbuf *pixbuf, | |
125 gint src_x, | |
126 gint src_y, | |
127 gint dest_x, | |
128 gint dest_y, | |
129 gint width, | |
130 gint height, | |
131 GdkRgbDither dither, | |
132 gint x_dither, | |
133 gint y_dither); | |
134 static void gdk_skia_draw_trapezoids (GdkDrawable *drawable, | |
135 GdkGC *gc, | |
136 GdkTrapezoid *trapezoids, | |
137 gint n_trapezoids); | |
138 | |
139 static void gdk_skia_real_get_size (GdkDrawable *drawable, | |
140 gint *width, | |
141 gint *height); | |
142 | |
143 static GdkImage* gdk_skia_copy_to_image (GdkDrawable *drawable, | |
144 GdkImage *image, | |
145 gint src_x, | |
146 gint src_y, | |
147 gint dest_x, | |
148 gint dest_y, | |
149 gint width, | |
150 gint height); | |
151 | |
152 static cairo_surface_t *gdk_skia_ref_cairo_surface (GdkDrawable *drawable); | |
153 | |
154 static GdkVisual* gdk_skia_real_get_visual (GdkDrawable *drawable); | |
155 static gint gdk_skia_real_get_depth (GdkDrawable *drawable); | |
156 static void gdk_skia_real_set_colormap (GdkDrawable *drawable, | |
157 GdkColormap *cmap); | |
158 static GdkColormap* gdk_skia_real_get_colormap (GdkDrawable *drawable); | |
159 static GdkScreen* gdk_skia_real_get_screen (GdkDrawable *drawable); | |
160 static void gdk_skia_init (GdkSkiaObject *skia); | |
161 static void gdk_skia_class_init (GdkSkiaObjectClass *klass); | |
162 static void gdk_skia_finalize (GObject *object); | |
163 | |
164 static gpointer parent_class = NULL; | |
165 | |
166 // ----------------------------------------------------------------------------- | |
167 // Usually GDK code is C code. However, since we are interfacing to a C++ | |
168 // library, we must compile in C++ mode to parse its headers etc. Thankfully, | |
169 // these are the only non-static symbol in the file so we can just wrap them in | |
170 // an extern decl to disable name mangling and everything should be happy. | |
171 // ----------------------------------------------------------------------------- | |
172 extern "C" { | |
173 GType | |
174 gdk_skia_get_type (void) | |
175 { | |
176 static GType object_type = 0; | |
177 | |
178 if (!object_type) | |
179 object_type = g_type_register_static_simple (GDK_TYPE_DRAWABLE, | |
180 "GdkSkia", | |
181 sizeof (GdkSkiaObjectClass), | |
182 (GClassInitFunc) gdk_skia_class
_init, | |
183 sizeof (GdkSkiaObject), | |
184 (GInstanceInitFunc) gdk_skia_in
it, | |
185 (GTypeFlags) 0); | |
186 | |
187 return object_type; | |
188 } | |
189 | |
190 GdkSkia* | |
191 gdk_skia_new(SkCanvas *canvas) | |
192 { | |
193 GdkSkia *skia = GDK_SKIA(g_object_new (GDK_TYPE_SKIA, NULL)); | |
194 reinterpret_cast<GdkSkiaObject*>(skia)->canvas = canvas; | |
195 return skia; | |
196 } | |
197 | |
198 } // extern "C" | |
199 | |
200 static void | |
201 gdk_skia_init (GdkSkiaObject *skia) | |
202 { | |
203 /* 0 initialization is fine for us */ | |
204 } | |
205 | |
206 static void | |
207 gdk_skia_class_init (GdkSkiaObjectClass *klass) | |
208 { | |
209 GObjectClass *object_class = G_OBJECT_CLASS (klass); | |
210 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass); | |
211 | |
212 parent_class = g_type_class_peek_parent (klass); | |
213 | |
214 object_class->finalize = gdk_skia_finalize; | |
215 | |
216 drawable_class->create_gc = gdk_skia_create_gc; | |
217 drawable_class->draw_rectangle = gdk_skia_draw_rectangle; | |
218 drawable_class->draw_arc = gdk_skia_draw_arc; | |
219 drawable_class->draw_polygon = gdk_skia_draw_polygon; | |
220 drawable_class->draw_text = gdk_skia_draw_text; | |
221 drawable_class->draw_text_wc = gdk_skia_draw_text_wc; | |
222 drawable_class->draw_drawable = gdk_skia_draw_drawable; | |
223 drawable_class->draw_points = gdk_skia_draw_points; | |
224 drawable_class->draw_segments = gdk_skia_draw_segments; | |
225 drawable_class->draw_lines = gdk_skia_draw_lines; | |
226 drawable_class->draw_glyphs = gdk_skia_draw_glyphs; | |
227 drawable_class->draw_glyphs_transformed = gdk_skia_draw_glyphs_transformed; | |
228 drawable_class->draw_image = gdk_skia_draw_image; | |
229 drawable_class->draw_pixbuf = gdk_skia_draw_pixbuf; | |
230 drawable_class->draw_trapezoids = gdk_skia_draw_trapezoids; | |
231 drawable_class->get_depth = gdk_skia_real_get_depth; | |
232 drawable_class->get_screen = gdk_skia_real_get_screen; | |
233 drawable_class->get_size = gdk_skia_real_get_size; | |
234 drawable_class->set_colormap = gdk_skia_real_set_colormap; | |
235 drawable_class->get_colormap = gdk_skia_real_get_colormap; | |
236 drawable_class->get_visual = gdk_skia_real_get_visual; | |
237 drawable_class->_copy_to_image = gdk_skia_copy_to_image; | |
238 drawable_class->ref_cairo_surface = gdk_skia_ref_cairo_surface; | |
239 } | |
240 | |
241 static void | |
242 gdk_skia_finalize (GObject *object) | |
243 { | |
244 GdkSkiaObject *const skia = (GdkSkiaObject *) object; | |
245 if (skia->surface) | |
246 cairo_surface_destroy(skia->surface); | |
247 G_OBJECT_CLASS (parent_class)->finalize(object); | |
248 } | |
249 | |
250 #define NOTIMPLEMENTED fprintf(stderr, "GDK Skia not implemented: %s\n", __PRETT
Y_FUNCTION__) | |
251 | |
252 static GdkGC * | |
253 gdk_skia_create_gc(GdkDrawable *drawable, | |
254 GdkGCValues *values, | |
255 GdkGCValuesMask mask) { | |
256 NOTIMPLEMENTED; | |
257 return NULL; | |
258 } | |
259 | |
260 static void | |
261 gc_set_paint(GdkGC *gc, SkPaint *paint) { | |
262 GdkGCValues values; | |
263 gdk_gc_get_values(gc, &values); | |
264 | |
265 paint->setARGB(255, | |
266 values.foreground.pixel >> 16, | |
267 values.foreground.pixel >> 8, | |
268 values.foreground.pixel); | |
269 paint->setStrokeWidth(values.line_width); | |
270 } | |
271 | |
272 static void | |
273 gdk_skia_draw_rectangle(GdkDrawable *drawable, | |
274 GdkGC *gc, | |
275 gboolean filled, | |
276 gint x, | |
277 gint y, | |
278 gint width, | |
279 gint height) { | |
280 GdkSkiaObject *skia = (GdkSkiaObject *) drawable; | |
281 SkPaint paint; | |
282 gc_set_paint(gc, &paint); | |
283 | |
284 if (filled) { | |
285 paint.setStyle(SkPaint::kFill_Style); | |
286 } else { | |
287 paint.setStyle(SkPaint::kStroke_Style); | |
288 } | |
289 | |
290 SkRect rect; | |
291 rect.set(x, y, x + width, y + height); | |
292 | |
293 skia->canvas->drawRect(rect, paint); | |
294 } | |
295 | |
296 static void | |
297 gdk_skia_draw_arc(GdkDrawable *drawable, | |
298 GdkGC *gc, | |
299 gboolean filled, | |
300 gint x, | |
301 gint y, | |
302 gint width, | |
303 gint height, | |
304 gint angle1, | |
305 gint angle2) { | |
306 NOTIMPLEMENTED; | |
307 } | |
308 | |
309 static void | |
310 gdk_skia_draw_polygon(GdkDrawable *drawable, | |
311 GdkGC *gc, | |
312 gboolean filled, | |
313 GdkPoint *points, | |
314 gint npoints) { | |
315 NOTIMPLEMENTED; | |
316 } | |
317 | |
318 static void | |
319 gdk_skia_draw_text(GdkDrawable *drawable, | |
320 GdkFont *font, | |
321 GdkGC *gc, | |
322 gint x, | |
323 gint y, | |
324 const gchar *text, | |
325 gint text_length) { | |
326 NOTIMPLEMENTED; | |
327 } | |
328 | |
329 static void | |
330 gdk_skia_draw_text_wc(GdkDrawable *drawable, | |
331 GdkFont *font, | |
332 GdkGC *gc, | |
333 gint x, | |
334 gint y, | |
335 const GdkWChar *text, | |
336 gint text_length) { | |
337 NOTIMPLEMENTED; | |
338 } | |
339 | |
340 static void | |
341 gdk_skia_draw_drawable(GdkDrawable *drawable, | |
342 GdkGC *gc, | |
343 GdkPixmap *src, | |
344 gint xsrc, | |
345 gint ysrc, | |
346 gint xdest, | |
347 gint ydest, | |
348 gint width, | |
349 gint height) { | |
350 NOTIMPLEMENTED; | |
351 } | |
352 | |
353 static void | |
354 gdk_skia_draw_points(GdkDrawable *drawable, | |
355 GdkGC *gc, | |
356 GdkPoint *points, | |
357 gint npoints) { | |
358 NOTIMPLEMENTED; | |
359 } | |
360 | |
361 static void | |
362 gdk_skia_draw_segments(GdkDrawable *drawable, | |
363 GdkGC *gc, | |
364 GdkSegment *segs, | |
365 gint nsegs) { | |
366 NOTIMPLEMENTED; | |
367 } | |
368 | |
369 static void | |
370 gdk_skia_draw_lines(GdkDrawable *drawable, | |
371 GdkGC *gc, | |
372 GdkPoint *points, | |
373 gint npoints) { | |
374 NOTIMPLEMENTED; | |
375 } | |
376 | |
377 static void | |
378 gdk_skia_draw_glyphs(GdkDrawable *drawable, | |
379 GdkGC *gc, | |
380 PangoFont *font, | |
381 gint x, | |
382 gint y, | |
383 PangoGlyphString *glyphs) { | |
384 NOTIMPLEMENTED; | |
385 } | |
386 | |
387 static void | |
388 gdk_skia_draw_glyphs_transformed(GdkDrawable *drawable, | |
389 GdkGC *gc, | |
390 PangoMatrix *matrix, | |
391 PangoFont *font, | |
392 gint x, | |
393 gint y, | |
394 PangoGlyphString *glyphs) { | |
395 NOTIMPLEMENTED; | |
396 } | |
397 | |
398 static void | |
399 gdk_skia_draw_image(GdkDrawable *drawable, | |
400 GdkGC *gc, | |
401 GdkImage *image, | |
402 gint xsrc, | |
403 gint ysrc, | |
404 gint xdest, | |
405 gint ydest, | |
406 gint width, | |
407 gint height) { | |
408 NOTIMPLEMENTED; | |
409 } | |
410 | |
411 static void | |
412 gdk_skia_draw_pixbuf(GdkDrawable *drawable, | |
413 GdkGC *gc, | |
414 GdkPixbuf *pixbuf, | |
415 gint src_x, | |
416 gint src_y, | |
417 gint dest_x, | |
418 gint dest_y, | |
419 gint width, | |
420 gint height, | |
421 GdkRgbDither dither, | |
422 gint x_dither, | |
423 gint y_dither) { | |
424 NOTIMPLEMENTED; | |
425 } | |
426 | |
427 static void | |
428 gdk_skia_draw_trapezoids(GdkDrawable *drawable, | |
429 GdkGC *gc, | |
430 GdkTrapezoid *trapezoids, | |
431 gint n_trapezoids) { | |
432 NOTIMPLEMENTED; | |
433 } | |
434 | |
435 static void | |
436 gdk_skia_real_get_size(GdkDrawable *drawable, | |
437 gint *width, | |
438 gint *height) { | |
439 NOTIMPLEMENTED; | |
440 } | |
441 | |
442 static GdkImage* | |
443 gdk_skia_copy_to_image(GdkDrawable *drawable, | |
444 GdkImage *image, | |
445 gint src_x, | |
446 gint src_y, | |
447 gint dest_x, | |
448 gint dest_y, | |
449 gint width, | |
450 gint height) { | |
451 NOTIMPLEMENTED; | |
452 return NULL; | |
453 } | |
454 | |
455 static cairo_surface_t * | |
456 gdk_skia_ref_cairo_surface(GdkDrawable *drawable) { | |
457 GdkSkiaObject *const skia = (GdkSkiaObject *) drawable; | |
458 | |
459 if (!skia->surface) { | |
460 SkDevice *const dev = skia->canvas->getDevice(); | |
461 const SkBitmap *const bm = &dev->accessBitmap(true); | |
462 | |
463 skia->surface = cairo_image_surface_create_for_data | |
464 ((unsigned char *) bm->getPixels(), | |
465 CAIRO_FORMAT_ARGB32, dev->width(), dev->height(), bm->rowBytes()); | |
466 } | |
467 | |
468 return cairo_surface_reference(skia->surface); | |
469 } | |
470 | |
471 static GdkVisual* | |
472 gdk_skia_real_get_visual(GdkDrawable *drawable) { | |
473 NOTIMPLEMENTED; | |
474 return NULL; | |
475 } | |
476 | |
477 static gint | |
478 gdk_skia_real_get_depth(GdkDrawable *drawable) { | |
479 GdkSkiaObject *skia = (GdkSkiaObject *) drawable; | |
480 const SkBitmap::Config config = skia->canvas->getDevice()->config(); | |
481 | |
482 switch (config) { | |
483 case SkBitmap::kARGB_8888_Config: | |
484 return 24; | |
485 default: | |
486 // NOTREACHED | |
487 *reinterpret_cast<char*>(NULL) = 0; | |
488 return 0; | |
489 } | |
490 } | |
491 | |
492 static void | |
493 gdk_skia_real_set_colormap(GdkDrawable *drawable, | |
494 GdkColormap *cmap) { | |
495 NOTIMPLEMENTED; | |
496 } | |
497 | |
498 static GdkColormap* | |
499 gdk_skia_real_get_colormap(GdkDrawable *drawable) { | |
500 NOTIMPLEMENTED; | |
501 return NULL; | |
502 } | |
503 | |
504 static GdkScreen* | |
505 gdk_skia_real_get_screen(GdkDrawable *drawable) { | |
506 NOTIMPLEMENTED; | |
507 return NULL; | |
508 } | |
OLD | NEW |