Python API to get image data from gr. manager for tests

This commit is contained in:
Kovid Goyal
2017-09-27 20:18:41 +05:30
parent cf33ef8666
commit 7567f96a34
2 changed files with 32 additions and 0 deletions

View File

@@ -413,6 +413,36 @@ dealloc(GraphicsManager* self) {
grman_free(self);
}
static inline PyObject*
image_as_dict(Image *img) {
#define U(x) #x, img->x
return Py_BuildValue("{sI sI sI sI sI sI sH sH sN}",
U(texture_id), U(client_id), U(width), U(height), U(internal_id), U(refcnt), U(data_loaded),
"is_4byte_aligned", img->load_data.is_4byte_aligned,
"data", Py_BuildValue("y#", img->load_data.data, img->load_data.data_sz)
);
#undef U
}
#define W(x) static PyObject* py##x(GraphicsManager *self, PyObject *args)
#define PA(fmt, ...) if(!PyArg_ParseTuple(args, fmt, __VA_ARGS__)) return NULL;
W(image_for_client_id) {
unsigned long id = PyLong_AsUnsignedLong(args);
bool existing = false;
Image *img = find_or_create_image(self, id, &existing);
if (existing) { Py_RETURN_NONE; }
return image_as_dict(img);
}
#define M(x, va) {#x, (PyCFunction)py##x, va, ""}
static PyMethodDef methods[] = {
M(image_for_client_id, METH_O),
{NULL} /* Sentinel */
};
PyTypeObject GraphicsManager_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
@@ -422,6 +452,7 @@ PyTypeObject GraphicsManager_Type = {
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_doc = "GraphicsManager",
.tp_new = new,
.tp_methods = methods,
};
bool

View File

@@ -1573,6 +1573,7 @@ static PyGetSetDef getsetters[] = {
static PyMemberDef members[] = {
{"callbacks", T_OBJECT_EX, offsetof(Screen, callbacks), 0, "callbacks"},
{"cursor", T_OBJECT_EX, offsetof(Screen, cursor), READONLY, "cursor"},
{"grman", T_OBJECT_EX, offsetof(Screen, grman), READONLY, "grman"},
{"color_profile", T_OBJECT_EX, offsetof(Screen, color_profile), READONLY, "color_profile"},
{"linebuf", T_OBJECT_EX, offsetof(Screen, linebuf), READONLY, "linebuf"},
{"historybuf", T_OBJECT_EX, offsetof(Screen, historybuf), READONLY, "historybuf"},