Change image internal_id type to id_type

This commit is contained in:
Kovid Goyal 2019-07-23 09:34:04 +05:30
parent 88f25ccc76
commit 8daab0ba41
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 10 additions and 9 deletions

View File

@ -19,7 +19,7 @@
#include "png-reader.h" #include "png-reader.h"
PyTypeObject GraphicsManager_Type; PyTypeObject GraphicsManager_Type;
#define STORAGE_LIMIT (320 * (1024 * 1024)) #define STORAGE_LIMIT (320u * (1024u * 1024u))
#define REPORT_ERROR(...) { log_error(__VA_ARGS__); } #define REPORT_ERROR(...) { log_error(__VA_ARGS__); }
@ -75,10 +75,10 @@ dealloc(GraphicsManager* self) {
Py_TYPE(self)->tp_free((PyObject*)self); Py_TYPE(self)->tp_free((PyObject*)self);
} }
static size_t internal_id_counter = 1; static id_type internal_id_counter = 1;
static inline Image* static inline Image*
img_by_internal_id(GraphicsManager *self, size_t id) { img_by_internal_id(GraphicsManager *self, id_type id) {
for (size_t i = 0; i < self->image_count; i++) { for (size_t i = 0; i < self->image_count; i++) {
if (self->images[i].internal_id == id) return self->images + i; if (self->images[i].internal_id == id) return self->images + i;
} }
@ -574,7 +574,7 @@ grman_update_layers(GraphicsManager *self, unsigned int scrolled_by, float scree
// Calculate the group counts // Calculate the group counts
i = 0; i = 0;
while (i < self->count) { while (i < self->count) {
size_t image_id = self->render_data[i].image_id, start = i; id_type image_id = self->render_data[i].image_id, start = i;
if (start == self->count - 1) i = self->count; if (start == self->count - 1) i = self->count;
else { else {
while (i < self->count - 1 && self->render_data[++i].image_id == image_id) {} while (i < self->count - 1 && self->render_data[++i].image_id == image_id) {}
@ -811,7 +811,7 @@ new(PyTypeObject UNUSED *type, PyObject UNUSED *args, PyObject UNUSED *kwds) {
static inline PyObject* static inline PyObject*
image_as_dict(Image *img) { image_as_dict(Image *img) {
#define U(x) #x, img->x #define U(x) #x, img->x
return Py_BuildValue("{sI sI sI sI sI sI sO sO sN}", return Py_BuildValue("{sI sI sI sI sK sI sO sO sN}",
U(texture_id), U(client_id), U(width), U(height), U(internal_id), U(refcnt), U(texture_id), U(client_id), U(width), U(height), U(internal_id), U(refcnt),
"data_loaded", img->data_loaded ? Py_True : Py_False, "data_loaded", img->data_loaded ? Py_True : Py_False,
"is_4byte_aligned", img->load_data.is_4byte_aligned ? Py_True : Py_False, "is_4byte_aligned", img->load_data.is_4byte_aligned ? Py_True : Py_False,
@ -871,7 +871,7 @@ W(update_layers) {
ImageRenderData *r = self->render_data + i; ImageRenderData *r = self->render_data + i;
#define R(offset) Py_BuildValue("{sf sf sf sf}", "left", r->vertices[offset + 8], "top", r->vertices[offset + 1], "right", r->vertices[offset], "bottom", r->vertices[offset + 5]) #define R(offset) Py_BuildValue("{sf sf sf sf}", "left", r->vertices[offset + 8], "top", r->vertices[offset + 1], "right", r->vertices[offset], "bottom", r->vertices[offset + 5])
PyTuple_SET_ITEM(ans, i, PyTuple_SET_ITEM(ans, i,
Py_BuildValue("{sN sN sI si sI}", "src_rect", R(0), "dest_rect", R(2), "group_count", r->group_count, "z_index", r->z_index, "image_id", r->image_id) Py_BuildValue("{sN sN sI si sK}", "src_rect", R(0), "dest_rect", R(2), "group_count", r->group_count, "z_index", r->z_index, "image_id", r->image_id)
); );
#undef R #undef R
} }

View File

@ -43,7 +43,7 @@ typedef struct {
typedef struct { typedef struct {
uint32_t texture_id, client_id, width, height; uint32_t texture_id, client_id, width, height;
size_t internal_id; id_type internal_id;
bool data_loaded; bool data_loaded;
LoadData load_data; LoadData load_data;
@ -58,13 +58,14 @@ typedef struct {
float vertices[16]; float vertices[16];
uint32_t texture_id, group_count; uint32_t texture_id, group_count;
int z_index; int z_index;
size_t image_id; id_type image_id;
} ImageRenderData; } ImageRenderData;
typedef struct { typedef struct {
PyObject_HEAD PyObject_HEAD
size_t image_count, images_capacity, loading_image; size_t image_count, images_capacity;
id_type loading_image;
GraphicsCommand last_init_graphics_command; GraphicsCommand last_init_graphics_command;
Image *images; Image *images;
size_t count, capacity; size_t count, capacity;