gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] gzz gfx/jni/GzzGL-jni.cxx gfx/libimagecache/Ima...


From: Tero Mäyränen
Subject: [Gzz-commits] gzz gfx/jni/GzzGL-jni.cxx gfx/libimagecache/Ima...
Date: Wed, 18 Sep 2002 04:04:05 -0400

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Tero Mäyränen <address@hidden>  02/09/18 04:04:05

Modified files:
        gfx/jni        : GzzGL-jni.cxx 
        gfx/libimagecache: ImageCache.cxx ImageCache.hxx 
        gfx/librenderables: renderables.py 
Added files:
        gzz/gfx/gl     : GLBackgroundImageLoader.java 

Log message:
        GLBackgroundImageLoader is a background Runnable-spawning imageloader 
that
        uses jni to send its data to libimagecache and is also called by
        libimagecache when it's time to load an image from a given URI.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/jni/GzzGL-jni.cxx.diff?tr1=1.19&tr2=1.20&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libimagecache/ImageCache.cxx.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libimagecache/ImageCache.hxx.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/librenderables/renderables.py.diff?tr1=1.43&tr2=1.44&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gzz/gfx/gl/GLBackgroundImageLoader.java?rev=1.1

Patches:
Index: gzz/gfx/jni/GzzGL-jni.cxx
diff -c gzz/gfx/jni/GzzGL-jni.cxx:1.19 gzz/gfx/jni/GzzGL-jni.cxx:1.20
*** gzz/gfx/jni/GzzGL-jni.cxx:1.19      Tue Sep 17 05:23:23 2002
--- gzz/gfx/jni/GzzGL-jni.cxx   Wed Sep 18 04:04:05 2002
***************
*** 42,48 ****
  
  ObjectStorer<Os::Window> windows;
  ObjectStorer<Image> images;
- ObjectStorer<GdkPixbufLoader> gdkpixbufloaders;
  ObjectStorer<Mosaic::MosaicTile> imagetiles;
  ObjectStorer<RealFont> fonts;
  ObjectStorer<Renderable0> renderable0s;
--- 42,47 ----
***************
*** 272,293 ****
        w->addTimeout(ms, tid);
    }
  
! // GdkPixbufLoader
  
! JNIEXPORT jint JNICALL Java_gzz_gfx_gl_GZZGL_createImageLoaderImpl
!   (JNIEnv *env, jclass) {
!       GdkPixbufLoader *ldr = gdk_pixbuf_loader_new();
!       return gdkpixbufloaders.add(ldr);
!   }
! 
! JNIEXPORT void JNICALL Java_gzz_gfx_gl_GZZGL_deleteImageLoader
!   (JNIEnv *, jclass, jint i) {
!       gdkpixbufloaders.remove(i);
!   }
! 
! JNIEXPORT void JNICALL Java_gzz_gfx_gl_GZZGL_imageLoaderWrite
!   (JNIEnv *, jclass, jint i, jbyteArray buf, jint len) {
!       gdk_pixbuf_loader_write(gdkpixbufloaders.get(i), (guchar *)buf, len);
    }
  
  // Image
--- 271,283 ----
        w->addTimeout(ms, tid);
    }
  
! // ImageCache
  
! JNIEXPORT void JNICALL Java_gzz_gfx_gl_GZZGL_getImage
!   (JNIEnv *env, jclass, jstring juri, jint lod) {
!     string uri = new string((*env)->GetStringUTFChars(env, jstr, 0));
!     (*env)->ReleaseStringUTFChars(env, jstr, str);
!     imageCache->getPixbuf();
    }
  
  // Image
Index: gzz/gfx/libimagecache/ImageCache.cxx
diff -c gzz/gfx/libimagecache/ImageCache.cxx:1.2 
gzz/gfx/libimagecache/ImageCache.cxx:1.3
*** gzz/gfx/libimagecache/ImageCache.cxx:1.2    Fri Sep 13 10:35:37 2002
--- gzz/gfx/libimagecache/ImageCache.cxx        Wed Sep 18 04:04:05 2002
***************
*** 18,25 ****
  
  //---------------------------------------------------------------------------
  
- #define START_PIXBUF_BACKGROUND_LOADER        ((GdkPixbuf *)(-1))
- 
      CachedImage::CachedImage() {
        loader = NULL;
        requestedLOD = -1;
--- 18,23 ----
***************
*** 149,159 ****
        size = 0;
        loading = gdk_pixbuf_new(GDK_COLORSPACE_RGB, false, 8, 16, 16);
        gdk_pixbuf_ref(loading);
      }
  
      ImageCache::~ImageCache() {
!       imageByUrx.clear();
!       urxByImage.clear();
  
        list<CachedImage *>::iterator iter;
  
--- 147,158 ----
        size = 0;
        loading = gdk_pixbuf_new(GDK_COLORSPACE_RGB, false, 8, 16, 16);
        gdk_pixbuf_ref(loading);
+       gtk_object_set_user_data(GTK_OBJECT(loading), (gpointer)(-1));
      }
  
      ImageCache::~ImageCache() {
!       imageByUri.clear();
!       uriByImage.clear();
  
        list<CachedImage *>::iterator iter;
  
***************
*** 167,178 ****
        gdk_pixbuf_unref(loading);
      }
  
!     GdkPixbuf *ImageCache::getPixbuf(string urx, int lod) {
!       CachedImage *ci = imageByUrx[urx];
        if (ci == NULL) {
            ci = new CachedImage();
!           imageByUrx[urx] = ci;
!           urxByImage[ci] = urx;
        }
        else recentlyUsedImages.remove(ci);
  
--- 166,177 ----
        gdk_pixbuf_unref(loading);
      }
  
!     GdkPixbuf *ImageCache::getPixbuf(string uri, int lod) {
!       CachedImage *ci = imageByUri[uri];
        if (ci == NULL) {
            ci = new CachedImage();
!           imageByUri[uri] = ci;
!           uriByImage[ci] = uri;
        }
        else recentlyUsedImages.remove(ci);
  
***************
*** 183,201 ****
        GdkPixbuf *pb = ci->getPixbuf(lod);
        if (pb == START_PIXBUF_BACKGROUND_LOADER) {
  
!           //backgroundLoader->startLoading(urx);
  
            pb = ci->getPixbuf(lod);
        }
        return (pb == NULL ? loading : pb);
      }
  
!     int ImageCache::write(string urx, char *data, int len) {
!       CachedImage *ci = imageByUrx[urx];
        return (ci == NULL ? -1 : ci->write(data, len));
      }
  
!     int ImageCache::cropToSize(int maxSize) {
        CachedImage *ci;
        int sizeChange;
        while ((size >= maxSize) && (!recentlyUsedImages.empty())) {
--- 182,200 ----
        GdkPixbuf *pb = ci->getPixbuf(lod);
        if (pb == START_PIXBUF_BACKGROUND_LOADER) {
  
!           //backgroundLoader->startLoading(uri);
  
            pb = ci->getPixbuf(lod);
        }
        return (pb == NULL ? loading : pb);
      }
  
!     int ImageCache::write(string uri, char *data, int len) {
!       CachedImage *ci = imageByUri[uri];
        return (ci == NULL ? -1 : ci->write(data, len));
      }
  
!     int ImageCache::trimToSize(int maxSize) {
        CachedImage *ci;
        int sizeChange;
        while ((size >= maxSize) && (!recentlyUsedImages.empty())) {
***************
*** 206,214 ****
  
            sizeChange = ci->getSizeChange();
            if (sizeChange == 0) {
!               string urx = urxByImage[ci];
!               urxByImage.erase(ci);
!               imageByUrx.erase(urx);
                size -= ci->getCurrentSize();
                delete ci;
            }
--- 205,213 ----
  
            sizeChange = ci->getSizeChange();
            if (sizeChange == 0) {
!               string uri = uriByImage[ci];
!               uriByImage.erase(ci);
!               imageByUri.erase(uri);
                size -= ci->getCurrentSize();
                delete ci;
            }
Index: gzz/gfx/libimagecache/ImageCache.hxx
diff -c gzz/gfx/libimagecache/ImageCache.hxx:1.2 
gzz/gfx/libimagecache/ImageCache.hxx:1.3
*** gzz/gfx/libimagecache/ImageCache.hxx:1.2    Fri Sep 13 10:35:37 2002
--- gzz/gfx/libimagecache/ImageCache.hxx        Wed Sep 18 04:04:05 2002
***************
*** 12,17 ****
--- 12,19 ----
  #include <gdk-pixbuf/gdk-pixbuf.h>
  #include <gdk-pixbuf/gdk-pixbuf-loader.h>
  
+ #define START_PIXBUF_BACKGROUND_LOADER        ((GdkPixbuf *)(-1))
+ 
  namespace ImageCache {
  
  using std::string;
***************
*** 30,61 ****
        CachedImage();
        ~CachedImage();
  
!       GdkPixbuf *getPixbuf(int lod);
        int write(char *data, int len);
        void dropLOD();
        void loaderPrepared();
        void loaderDone();
        void closeLoader();
        int getSizeChange();
        int getCurrentSize();
      };
  
      class ImageCache {
      private:
        GdkPixbuf *loading;
!       map<string,CachedImage *> imageByUrx;
!       map<CachedImage *,string> urxByImage;
        list<CachedImage *> recentlyUsedImages;
        int size;
      public:
        ImageCache();
        ~ImageCache();
  
!       GdkPixbuf *getPixbuf(string urx, int lod);
! 
!       int write(string urx, char *data, int n);
! 
!       int cropToSize(int maxSize);
      };
  }
  
--- 32,138 ----
        CachedImage();
        ~CachedImage();
  
!       /**
!        *      Returns the Pixbuf of this Image.  If the requested lod
!        *      is better (a smaller number) than what is available, the
!        *      call returns START_PIXBUF_BACKGROUND_LOADER. After that
!        *      it is safe to start calling write();... It is also safe to
!        *      call this method again - whatever Level of Detail is
!        *      available will be returned. The GdkPixbuf will have its
!        *      level of detail stored in its user_data field. Use
!        *      gtk_object_get_user_data() to get it.
!        */
!       GdkPixbuf *getPixbuf(int lod);
!       /**
!        *      Write data to this image's GdkPixbufLoader.
!        */
        int write(char *data, int len);
+       /**
+        *      Make this image's Level of Detail one step "larger".
+        *      A larger LOD means a smaller resolution. This is called
+        *      by ImageCache to make the cache smaller.
+        */
        void dropLOD();
+       /**
+        *      loaderPrepared will be called when the GdkPixbufLoader
+        *      has completed loading enough of an image to be able to
+        *      say how large the image area is.
+        */
        void loaderPrepared();
+       /**
+        *      loaderDone will be called when the GdkPixbufLoader
+        *      has completed loading an image.
+        */
        void loaderDone();
+       /**
+        *      Calling closeLoader will close the GdkPixbufLoader and
+        *      set it to NULL.
+        */
        void closeLoader();
+       /**
+        *      Returns the amount of change in this image's size since
+        *      the last time this was called. This is called by ImageCache
+        *      to keep track of the cache's size.
+        */
        int getSizeChange();
+       /**
+        *      Returns the current size of the image in bytes.
+        */
        int getCurrentSize();
      };
  
      class ImageCache {
      private:
        GdkPixbuf *loading;
!       map<string,CachedImage *> imageByUri;
!       map<CachedImage *,string> uriByImage;
        list<CachedImage *> recentlyUsedImages;
        int size;
      public:
        ImageCache();
        ~ImageCache();
  
!       /**
!        *      Get an image from the given URI with preferably at least
!        *      the given Level of Detail.
!        *
!        *      If the image is not yet available, you will either get
!        *      a loader-image, or a version of the image with a smaller
!        *      resolution. The image may also be incomplete.
!        *
!        *      If you get a smaller resolution than you asked for, or
!        *      the image is incomplete, or you got the loader-image, then
!        *      the cache will already be trying to load a better version.
!        *
!        *      The Level of Detail of an image can be found in the user_data
!        *      field of the GdkPixbuf. You can get it by using
!        *      gtk_object_get_used_data();
!        *
!        *      The Level of Detail for the loader-image will be -1.
!        */
!       GdkPixbuf *getPixbuf(string uri, int lod);
! 
!       /**
!        *      Trim cache to maxSize (if the cache is larger than that)
!        *      and return the size of the cache.
!        *
!        *      That means making the least recently used images smaller
!        *      (resizing them to the next level of detail)
!        *      (making their resolution poorer)
!        *      until the cache is smaller or equal to the requested size.
!        *
!        *      maxSize is in bytes.
!        *      The return value is also in bytes.
!        */
!       int trimToSize(int maxSize);
! 
!       /**
!        *      Write raw data to the GdkImageLoader of a given URI.
!        *
!        *      This will be called by the JNI interface when it receives
!        *      data from the Java BackgroundLoader.
!        */
!       int write(string uri, char *data, int n);
      };
  }
  
Index: gzz/gfx/librenderables/renderables.py
diff -c gzz/gfx/librenderables/renderables.py:1.43 
gzz/gfx/librenderables/renderables.py:1.44
*** gzz/gfx/librenderables/renderables.py:1.43  Wed Sep 18 02:41:35 2002
--- gzz/gfx/librenderables/renderables.py       Wed Sep 18 04:04:05 2002
***************
*** 1324,1343 ****
        static private native void deleteImage(int i);
        static private native int getImageSize(int id, int dimNo);
  
!     //--------- GdkPixbufLoader
!       static public class ImageLoader extends NonRenderableJavaObject {
!           private ImageLoader(int id) { super(id); }
!           protected void deleteObj() { deleteImageLoader(getId()); }
!           public void write(byte buf[], int len) {
!               imageLoaderWrite(getId(), buf, len);
            }
        }
!       static public ImageLoader createImageLoader() {
!           return new ImageLoader(createImageLoaderImpl());
        }
-       static private native int createImageLoaderImpl();
-       static private native void deleteImageLoader(int i);
-       static private native void imageLoaderWrite(int i, byte buf[], int len);
  
      //--------- TexRect
        /** A rectangular region of an image, loaded into a texture.
--- 1324,1346 ----
        static private native void deleteImage(int i);
        static private native int getImageSize(int id, int dimNo);
  
!     //--------- ImageCache
!       static public class ImageCache {
!           public static TexRect getTexRect(String uri, int lod) {
!               return getFromImageCache(uri, lod);
!           }
! 
!           public static void write(String uri, char buf[], int len) {
!               writeToImageCache(uri, buf, len);
            }
        }
! 
!       static private native TexRect getFromImageCache(String uri, int lod);
!       static private native void writeToImageCache(String uri, char buf[], 
int len);
! 
!       static public void startLoader(String uri) {
!           gzz.gfx.gl.GLBackgroundImageLoader.startLoading(uri);
        }
  
      //--------- TexRect
        /** A rectangular region of an image, loaded into a texture.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]