classpath
[Top][All Lists]
Advanced

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

Re: Proposal: Graphics2D rewrite branch


From: Per Bothner
Subject: Re: Proposal: Graphics2D rewrite branch
Date: Wed, 07 Dec 2005 12:58:04 -0800
User-agent: Mozilla Thunderbird 1.0.6-1.1.fc4 (X11/20050720)

David Gilbert wrote:
Regarding 3) and BufferedImages, I think I recall Sven saying he was mistaken about the DataBuffer classes. As far as I could tell (from writing some Mauve tests for them) they use real Java arrays.

It should be possible to have a hybrid implementation that can use
native buffers or Java arrays.  If constructed using (say)
  DataBufferInt(int size, int numBanks)
then it can allocated a native buffer.
The complicatation is getData and getBankData.  If using native buffers,
these would have to allocate new buffers, copy the data of of the
native buffers, release the native buffers, and switch to using the
Java arrays for future references.

This isn't too bad if you're using CNI and a non-copying gc, since
you can use a "native pointer" in all cases, and just have the
natve pointer point into the Java arrray in the Java case.
If using a copying GC, you can use a delta.  For simplicity, I
assume a single bank:

DataBufferInt {
  int[] array;
  native size_t offset;

  int getElem(int i) { return *(int*)((char*) array + offset + 4 * i); }

  DataBufferInt(int size) {
    void* buf = allocate_native_buffer(size);
    array = null;
    offset = buf;
  }

  DataBufferInt(int[] arr) {
     array = arr;
     offset = SIZE_OF_ARRAY_HEADER;
  }

  int[] getData () {
    int[] ar = new int[size];
    copy_form_native_buffer_into(ar);
    array = ar;
   offset = SIZE_OF_ARRAY_HEADER;
  }
}

This works even if the array is moved by the gc.
--
        --Per Bothner
address@hidden   http://per.bothner.com/




reply via email to

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