Changeset View
Changeset View
Standalone View
Standalone View
source/blender/python/gpu/gpu_py_buffer.c
| Show First 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | static BPyGPUBuffer *pygpu_buffer_make_from_data(PyObject *parent, | ||||
| buffer->shape_len = shape_len; | buffer->shape_len = shape_len; | ||||
| buffer->shape = MEM_mallocN(shape_len * sizeof(*buffer->shape), "BPyGPUBuffer shape"); | buffer->shape = MEM_mallocN(shape_len * sizeof(*buffer->shape), "BPyGPUBuffer shape"); | ||||
| memcpy(buffer->shape, shape, shape_len * sizeof(*buffer->shape)); | memcpy(buffer->shape, shape, shape_len * sizeof(*buffer->shape)); | ||||
| buffer->buf.as_void = buf; | buffer->buf.as_void = buf; | ||||
| if (parent) { | if (parent) { | ||||
| Py_INCREF(parent); | Py_INCREF(parent); | ||||
| buffer->parent = parent; | buffer->parent = parent; | ||||
| BLI_assert(!PyObject_GC_IsTracked((PyObject *)buffer)); | |||||
| PyObject_GC_Track(buffer); | PyObject_GC_Track(buffer); | ||||
| } | } | ||||
| return buffer; | return buffer; | ||||
| } | } | ||||
| static PyObject *pygpu_buffer__sq_item(BPyGPUBuffer *self, int i) | static PyObject *pygpu_buffer__sq_item(BPyGPUBuffer *self, int i) | ||||
| { | { | ||||
| if (i >= self->shape[0] || i < 0) { | if (i >= self->shape[0] || i < 0) { | ||||
| ▲ Show 20 Lines • Show All 253 Lines • ▼ Show 20 Lines | if (init && pygpu_buffer_ass_slice(buffer, 0, shape[0], init)) { | ||||
| Py_DECREF(buffer); | Py_DECREF(buffer); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| } | } | ||||
| return (PyObject *)buffer; | return (PyObject *)buffer; | ||||
| } | } | ||||
| static int pygpu_buffer__tp_is_gc(BPyGPUBuffer *self) | |||||
| { | |||||
| return self->parent != NULL; | |||||
| } | |||||
| /* BPyGPUBuffer sequence methods */ | /* BPyGPUBuffer sequence methods */ | ||||
| static int pygpu_buffer__sq_length(BPyGPUBuffer *self) | static int pygpu_buffer__sq_length(BPyGPUBuffer *self) | ||||
| { | { | ||||
| return self->shape[0]; | return self->shape[0]; | ||||
| } | } | ||||
| static PyObject *pygpu_buffer_slice(BPyGPUBuffer *self, Py_ssize_t begin, Py_ssize_t end) | static PyObject *pygpu_buffer_slice(BPyGPUBuffer *self, Py_ssize_t begin, Py_ssize_t end) | ||||
| ▲ Show 20 Lines • Show All 239 Lines • ▼ Show 20 Lines | |||||
| #endif | #endif | ||||
| .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, | .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, | ||||
| .tp_doc = pygpu_buffer__tp_doc, | .tp_doc = pygpu_buffer__tp_doc, | ||||
| .tp_traverse = (traverseproc)pygpu_buffer__tp_traverse, | .tp_traverse = (traverseproc)pygpu_buffer__tp_traverse, | ||||
| .tp_clear = (inquiry)pygpu_buffer__tp_clear, | .tp_clear = (inquiry)pygpu_buffer__tp_clear, | ||||
| .tp_methods = pygpu_buffer__tp_methods, | .tp_methods = pygpu_buffer__tp_methods, | ||||
| .tp_getset = pygpu_buffer_getseters, | .tp_getset = pygpu_buffer_getseters, | ||||
| .tp_new = pygpu_buffer__tp_new, | .tp_new = pygpu_buffer__tp_new, | ||||
| .tp_is_gc = (inquiry)pygpu_buffer__tp_is_gc, | |||||
| }; | }; | ||||
| static size_t pygpu_buffer_calc_size(const int format, | static size_t pygpu_buffer_calc_size(const int format, | ||||
| const int shape_len, | const int shape_len, | ||||
| const Py_ssize_t *shape) | const Py_ssize_t *shape) | ||||
| { | { | ||||
| return pygpu_buffer_dimensions_tot_elem(shape, shape_len) * GPU_texture_dataformat_size(format); | return pygpu_buffer_dimensions_tot_elem(shape, shape_len) * GPU_texture_dataformat_size(format); | ||||
| } | } | ||||
| Show All 20 Lines | |||||