Skip to content

Commit ead00f1

Browse files
committed
better support subssurfaces
1 parent f40f479 commit ead00f1

File tree

1 file changed

+42
-33
lines changed

1 file changed

+42
-33
lines changed

src_c/surface.c

+42-33
Original file line numberDiff line numberDiff line change
@@ -2277,39 +2277,7 @@ _surf_fblits_cached_item_check_and_blit(pgSurfaceObject *self, PyObject *item,
22772277
return FBLITS_ERR_INVALID_SEQUENCE_LENGTH;
22782278
}
22792279

2280-
/* load destinations */
2281-
PyObject **list_items = PySequence_Fast_ITEMS(pos_list);
2282-
Py_ssize_t current_size = 0;
2283-
for (i = 0; i < destinations->size; i++) {
2284-
int x, y;
2285-
PyObject *tup = list_items[i];
2286-
2287-
if (!PyTuple_Check(tup) || PyTuple_GET_SIZE(tup) != 2) {
2288-
return FBLITS_ERR_TUPLE_REQUIRED;
2289-
}
2290-
2291-
if (!pg_IntFromObj(PyTuple_GET_ITEM(tup, 0), &x) ||
2292-
!pg_IntFromObj(PyTuple_GET_ITEM(tup, 1), &y)) {
2293-
return FBLITS_ERR_INVALID_DESTINATION;
2294-
}
2295-
2296-
SDL_Rect *clip_rect = &dst->clip_rect;
2297-
SDL_Rect clipped;
2298-
if (!SDL_IntersectRect(clip_rect, &(SDL_Rect){x, y, src->w, src->h},
2299-
&clipped))
2300-
continue; /* Skip out of bounds destinations */
2301-
2302-
CachedBlitDest *blit_struct = &destinations->sequence[current_size++];
2303-
2304-
blit_struct->pixels =
2305-
(Uint32 *)dst->pixels + clipped.y * dst->pitch / 4 + clipped.x;
2306-
blit_struct->w = clipped.w;
2307-
blit_struct->h = clipped.h;
2308-
blit_struct->x = x < clip_rect->x ? clip_rect->x - x : 0;
2309-
blit_struct->y = y < clip_rect->y ? clip_rect->y - y : 0;
2310-
}
2311-
2312-
if (!(destinations->size = current_size))
2280+
if (destinations->size == 0)
23132281
return 0;
23142282

23152283
if (self->subsurface) {
@@ -2342,6 +2310,47 @@ _surf_fblits_cached_item_check_and_blit(pgSurfaceObject *self, PyObject *item,
23422310
subsurface = NULL;
23432311
}
23442312

2313+
/* load destinations */
2314+
PyObject **list_items = PySequence_Fast_ITEMS(pos_list);
2315+
Py_ssize_t current_size = 0;
2316+
SDL_Rect src_dest = {0, 0, src->w, src->h};
2317+
SDL_Rect temp, *argrect;
2318+
for (i = 0; i < destinations->size; i++) {
2319+
PyObject *item = list_items[i];
2320+
2321+
if (pg_TwoIntsFromObj(item, &src_dest.x, &src_dest.y)) {
2322+
}
2323+
else if ((argrect = pgRect_FromObject(item, &temp))) {
2324+
src_dest.x = argrect->x;
2325+
src_dest.y = argrect->y;
2326+
}
2327+
else {
2328+
return FBLITS_ERR_INVALID_DESTINATION;
2329+
}
2330+
2331+
SDL_Rect *clip_rect = &dst->clip_rect;
2332+
SDL_Rect clipped;
2333+
if (!SDL_IntersectRect(clip_rect, &src_dest, &clipped))
2334+
continue; /* Skip out of bounds destinations */
2335+
2336+
CachedBlitDest *d_item = &destinations->sequence[current_size++];
2337+
2338+
d_item->pixels = (Uint32 *)dst->pixels;
2339+
d_item->pixels += clipped.y * dst->pitch / 4 + clipped.x;
2340+
d_item->w = clipped.w;
2341+
d_item->h = clipped.h;
2342+
d_item->x = src_dest.x < clip_rect->x ? clip_rect->x - src_dest.x : 0;
2343+
d_item->y = src_dest.y < clip_rect->y ? clip_rect->y - src_dest.y : 0;
2344+
}
2345+
2346+
if (!(destinations->size = current_size)) {
2347+
if (subsurface)
2348+
SDL_SetClipRect(subsurface, &orig_clip);
2349+
else
2350+
pgSurface_Unprep(self);
2351+
return 0;
2352+
}
2353+
23452354
pgSurface_Prep((pgSurfaceObject *)src_surf);
23462355

23472356
error = SoftCachedBlitPyGame(src, dst, blend_flags, destinations);

0 commit comments

Comments
 (0)