Skip to content

Commit 1e484e2

Browse files
committed
better support subssurfaces
1 parent 5cc4899 commit 1e484e2

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
@@ -2267,39 +2267,7 @@ _surf_fblits_cached_item_check_and_blit(pgSurfaceObject *self, PyObject *item,
22672267
return FBLITS_ERR_INVALID_SEQUENCE_LENGTH;
22682268
}
22692269

2270-
/* load destinations */
2271-
PyObject **list_items = PySequence_Fast_ITEMS(pos_list);
2272-
Py_ssize_t current_size = 0;
2273-
for (i = 0; i < destinations->size; i++) {
2274-
int x, y;
2275-
PyObject *tup = list_items[i];
2276-
2277-
if (!PyTuple_Check(tup) || PyTuple_GET_SIZE(tup) != 2) {
2278-
return FBLITS_ERR_TUPLE_REQUIRED;
2279-
}
2280-
2281-
if (!pg_IntFromObj(PyTuple_GET_ITEM(tup, 0), &x) ||
2282-
!pg_IntFromObj(PyTuple_GET_ITEM(tup, 1), &y)) {
2283-
return FBLITS_ERR_INVALID_DESTINATION;
2284-
}
2285-
2286-
SDL_Rect *clip_rect = &dst->clip_rect;
2287-
SDL_Rect clipped;
2288-
if (!SDL_IntersectRect(clip_rect, &(SDL_Rect){x, y, src->w, src->h},
2289-
&clipped))
2290-
continue; /* Skip out of bounds destinations */
2291-
2292-
CachedBlitDest *blit_struct = &destinations->sequence[current_size++];
2293-
2294-
blit_struct->pixels =
2295-
(Uint32 *)dst->pixels + clipped.y * dst->pitch / 4 + clipped.x;
2296-
blit_struct->w = clipped.w;
2297-
blit_struct->h = clipped.h;
2298-
blit_struct->x = x < clip_rect->x ? clip_rect->x - x : 0;
2299-
blit_struct->y = y < clip_rect->y ? clip_rect->y - y : 0;
2300-
}
2301-
2302-
if (!(destinations->size = current_size))
2270+
if (destinations->size == 0)
23032271
return 0;
23042272

23052273
if (self->subsurface) {
@@ -2332,6 +2300,47 @@ _surf_fblits_cached_item_check_and_blit(pgSurfaceObject *self, PyObject *item,
23322300
subsurface = NULL;
23332301
}
23342302

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

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

0 commit comments

Comments
 (0)