From 5cc48c20486292fa4bacb9073dd72c6df5414c74 Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Wed, 19 Jan 2005 21:31:04 +0000 Subject: [PATCH] Added Ecore::Evas::Buffer. --- src/ecore_evas/Makefile.am | 5 +- src/ecore_evas/rb_buffer.c | 94 +++++++++++++++++++++++++++++ src/ecore_evas/rb_buffer.h | 26 ++++++++ src/ecore_evas/rb_ecore_evas_main.c | 6 +- 4 files changed, 127 insertions(+), 4 deletions(-) create mode 100644 src/ecore_evas/rb_buffer.c create mode 100644 src/ecore_evas/rb_buffer.h diff --git a/src/ecore_evas/Makefile.am b/src/ecore_evas/Makefile.am index 9818ce8..35c93e4 100644 --- a/src/ecore_evas/Makefile.am +++ b/src/ecore_evas/Makefile.am @@ -1,4 +1,4 @@ -## $Id: Makefile.am 120 2004-10-18 20:23:32Z tilman $ +## $Id: Makefile.am 174 2005-01-19 21:31:04Z tilman $ AM_CFLAGS = $(ECORE_CFLAGS) $(EVAS_CFLAGS) INCLUDES = -I$(RUBYDIR) -I$(RUBYSITEDIR) @@ -10,7 +10,8 @@ ecore_evas_la_SOURCES = rb_ecore_evas_main.c rb_ecore_evas_main.h \ rb_ecore_evas.c rb_ecore_evas.h \ rb_software_x11.c rb_software_x11.h \ rb_gl_x11.c rb_gl_x11.h \ - rb_fb.c rb_fb.h + rb_fb.c rb_fb.h \ + rb_buffer.c rb_buffer.h ecore_evas_la_LIBADD = -L$(RUBYLIBDIR) $(RUBYLIB) $(ECORE_LIBS) $(EVAS_LIBS) ecore_evas_la_LDFLAGS = -module -avoid-version diff --git a/src/ecore_evas/rb_buffer.c b/src/ecore_evas/rb_buffer.c new file mode 100644 index 0000000..db316cc --- /dev/null +++ b/src/ecore_evas/rb_buffer.c @@ -0,0 +1,94 @@ +/* + * $Id: rb_buffer.c 174 2005-01-19 21:31:04Z tilman $ + * + * Copyright (C) 2004-2005 ruby-ecore team (see AUTHORS) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include +#include + +#include "../ecore/rb_ecore.h" +#include "rb_ecore_evas_main.h" +#include "rb_ecore_evas.h" + +static void c_free (RbEcoreEvas *ee) +{ + c_ecore_evas_free (ee, true); +} + +/* + * call-seq: + * Ecore::Evas::Buffer.new([w, h]) => buffer + * + * Creates an Ecore::Evas::Buffer object. + */ +static VALUE c_new (int argc, VALUE *argv, VALUE klass) +{ + VALUE self, w, h; + RbEcoreEvas *ee = NULL; + int iw = 0, ih = 0; + + self = Data_Make_Struct (klass, RbEcoreEvas, + c_ecore_evas_mark, c_free, ee); + + rb_scan_args (argc, argv, "02", &w, &h); + + if (!NIL_P (w)) { + Check_Type (w, T_FIXNUM); + iw = FIX2INT (w); + } + + if (!NIL_P (h)) { + Check_Type (h, T_FIXNUM); + ih = FIX2INT (h); + } + + ecore_init (); + ecore_evas_init (); + + ee->real = ecore_evas_buffer_new (iw, ih); + + rb_obj_call_init (self, 0, NULL); + + return self; +} + +static VALUE c_pixels_get (VALUE self) +{ + const int *p; + int w = 0, h = 0; + + GET_OBJ (self, RbEcoreEvas, ee); + + p = ecore_evas_buffer_pixels_get (ee->real); + if (!p) + return rb_str_new2 (""); /* FIXME raise an error instead? */ + + ecore_evas_geometry_get (ee->real, NULL, NULL, &w, &h); + + return rb_str_new ((char *) p, h * w * 4); +} + +void Init_Buffer (void) +{ + VALUE c = rb_define_class_under (mEvas, "Buffer", cEcoreEvas); + + rb_define_singleton_method (c, "new", c_new, -1); + rb_define_method (c, "pixels", c_pixels_get, 0); +} diff --git a/src/ecore_evas/rb_buffer.h b/src/ecore_evas/rb_buffer.h new file mode 100644 index 0000000..27f11a3 --- /dev/null +++ b/src/ecore_evas/rb_buffer.h @@ -0,0 +1,26 @@ +/* + * $Id: rb_buffer.h 174 2005-01-19 21:31:04Z tilman $ + * + * Copyright (C) 2004-2005 ruby-ecore team (see AUTHORS) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef __RB_BUFFER_H +#define __RB_BUFFER_H + +void Init_Buffer (void); + +#endif diff --git a/src/ecore_evas/rb_ecore_evas_main.c b/src/ecore_evas/rb_ecore_evas_main.c index 432f64a..da98b48 100644 --- a/src/ecore_evas/rb_ecore_evas_main.c +++ b/src/ecore_evas/rb_ecore_evas_main.c @@ -1,7 +1,7 @@ /* - * $Id: rb_ecore_evas_main.c 77 2004-08-19 17:39:29Z tilman $ + * $Id: rb_ecore_evas_main.c 174 2005-01-19 21:31:04Z tilman $ * - * Copyright (C) 2004 ruby-ecore team (see AUTHORS) + * Copyright (C) 2004-2005 ruby-ecore team (see AUTHORS) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -28,6 +28,7 @@ #include "rb_software_x11.h" #include "rb_gl_x11.h" #include "rb_fb.h" +#include "rb_buffer.h" void Init_ecore_evas (void) { @@ -40,4 +41,5 @@ void Init_ecore_evas (void) Init_SoftwareX11 (); Init_GlX11 (); Init_Fb (); + Init_Buffer (); } -- 2.30.2