diff options
author | Michael Bien <[email protected]> | 2010-09-02 23:45:05 +0200 |
---|---|---|
committer | Michael Bien <[email protected]> | 2010-09-02 23:45:05 +0200 |
commit | bc4e1521cc2ccc91a033998847dc35e1a8c8687b (patch) | |
tree | ebd2a6e94b69519afc5aed07ebf49b03b80fbaea /src/com | |
parent | 048f09aafe49e4eaddfe25ec4b302268510bc27b (diff) |
CLMemObjectDestructorCallback for HLB and LLB.
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/jogamp/opencl/CLMemObjectListener.java | 19 | ||||
-rw-r--r-- | src/com/jogamp/opencl/CLMemory.java | 13 | ||||
-rw-r--r-- | src/com/jogamp/opencl/impl/CLImpl.java | 12 | ||||
-rw-r--r-- | src/com/jogamp/opencl/impl/CLMemObjectDestructorCallback.java | 19 |
4 files changed, 63 insertions, 0 deletions
diff --git a/src/com/jogamp/opencl/CLMemObjectListener.java b/src/com/jogamp/opencl/CLMemObjectListener.java new file mode 100644 index 00000000..4ee32b9f --- /dev/null +++ b/src/com/jogamp/opencl/CLMemObjectListener.java @@ -0,0 +1,19 @@ +/* + * Created on Tuesday, July 06 2010 00:46 + */ + +package com.jogamp.opencl; + +/** + * A callback which is invoked by the OpenCL implementation when the memory + * object is deleted and its resources freed. + * @author Michael Bien + */ +public interface CLMemObjectListener { + + /** + * + */ + public void memoryDeallocated(CLMemory<?> mem); + +} diff --git a/src/com/jogamp/opencl/CLMemory.java b/src/com/jogamp/opencl/CLMemory.java index d66db3c8..416b8019 100644 --- a/src/com/jogamp/opencl/CLMemory.java +++ b/src/com/jogamp/opencl/CLMemory.java @@ -3,6 +3,7 @@ package com.jogamp.opencl; import com.jogamp.opencl.gl.CLGLI; import com.jogamp.common.nio.Buffers; import com.jogamp.common.nio.PointerBuffer; +import com.jogamp.opencl.impl.CLMemObjectDestructorCallback; import java.nio.Buffer; import java.nio.ByteBuffer; import java.nio.DoubleBuffer; @@ -73,6 +74,18 @@ public abstract class CLMemory <B extends Buffer> extends CLObject implements CL } /** + * Registers a callback which will be called by the OpenCL implementation + * when the memory object is released. + */ + public void registerDestructorCallback(final CLMemObjectListener listener) { + cl.clSetMemObjectDestructorCallback(ID, new CLMemObjectDestructorCallback() { + public void memoryDeallocated(long memObjID) { + listener.memoryDeallocated(CLMemory.this); + } + }); + } + + /** * Returns a new instance of CLMemory pointing to the same CLResource but using a different Buffer. */ public abstract <T extends Buffer> CLMemory<T> cloneWith(T directBuffer); diff --git a/src/com/jogamp/opencl/impl/CLImpl.java b/src/com/jogamp/opencl/impl/CLImpl.java index b9dd9835..98db94ea 100644 --- a/src/com/jogamp/opencl/impl/CLImpl.java +++ b/src/com/jogamp/opencl/impl/CLImpl.java @@ -134,6 +134,18 @@ public class CLImpl extends CLAbstractImpl { private native int clSetEventCallback0(long event, int type, CLEventCallback cb, long address); + + public int clSetMemObjectDestructorCallback(long memObjID, CLMemObjectDestructorCallback cb) { + final long address = addressTable._addressof_clSetMemObjectDestructorCallback; + if (address == 0) { + throw new UnsupportedOperationException("Method not available"); + } + return clSetMemObjectDestructorCallback0(memObjID, cb, address); + } + + private native int clSetMemObjectDestructorCallback0(long memObjID, CLMemObjectDestructorCallback cb, long address); + + /** Interface to C language function: <br> <code> void * {@native clEnqueueMapImage}(cl_command_queue command_queue, cl_mem image, uint32_t blocking_map, uint64_t map_flags, const size_t * , const size_t * , size_t * image_row_pitch, size_t * image_slice_pitch, uint32_t num_events_in_wait_list, cl_event * event_wait_list, cl_event * event, int32_t * errcode_ret); </code> @param origin a direct {@link com.jogamp.common.nio.PointerBuffer} @param range a direct {@link com.jogamp.common.nio.PointerBuffer} diff --git a/src/com/jogamp/opencl/impl/CLMemObjectDestructorCallback.java b/src/com/jogamp/opencl/impl/CLMemObjectDestructorCallback.java new file mode 100644 index 00000000..df6f18f6 --- /dev/null +++ b/src/com/jogamp/opencl/impl/CLMemObjectDestructorCallback.java @@ -0,0 +1,19 @@ +/* + * Created on Thursday, September 02 2010 23:09 + */ + +package com.jogamp.opencl.impl; + +/** + * A callback which is invoked by the OpenCL implementation when the memory + * object is deleted and its resources freed. + * @author Michael Bien + */ +public interface CLMemObjectDestructorCallback { + + /** + * + */ + public void memoryDeallocated(long memObjID); + +} |