I am looking to implement a module that manages a blute queue. There is one surface, and parts of this surface (limited by rectangles) are copied to another place on the surface:
add_blt(rect src, point dst);
A queue can have any number of operations sent to the queue. In the end, the queue user will cease to place glare and ask for the optimal set of operations for actual execution on the surface. The task of the module is to ensure that the pixel will not be copied unnecessarily.
It gets complicated due to coincidences, of course. Blit can rekindle a previously copied pixel. Ideally related operations are subdivided into the optimization phase in such a way that each block goes to its final location with one operation.
It is difficult, but not impossible to combine it. I'm just trying not to reinvent the wheel.
I looked around the net, and the only thing I found was the SDL_BlitPool Library , which assumes the source surface is different from the destination. It also makes a lot of grunts, seemingly unnecessary: ββregions and similar building blocks are preset. I am looking for something of a higher level. Of course, Iβm not going to look like a gift horse in my mouth, and I donβt mind doing the real job either ... If someone can offer a basic idea that makes this problem less complicated than the right one now it would be great too.
EDIT:
Thinking about the answer aaronasterling ... can this work?
Introduce an individual area handler code that can support metadata for each rectangle it contains. When a region handler splits a rectangle, it automatically associates the metadata of that rectangle with the resulting sub-rectangles.
When the optimization starts, create an empty area processed by the above code, name it master region
Iterate through the blt and for each entry:
Let srcrect be the source rectangle for blt beng reviewed
Get the intersection of srcrect and master region in temp region
Remove temp region from master region , so master region no longer covers temp region
srcrect to the area ( srcrgn ) and subtract temp region from it
The offset of temp region and srcrgn with the vector of the current blt : their union will cover the destination area of ββthe current blt
Add to the master region all the rectangles in the temp region , preserving the original metadata of the source code (step 1 of adding the current blt to the master region )
Add to the master region all the rectangles in srcrgn , adding the source information for the current blt (the second step is to add the current blt to the master region )
Optimize the master region by checking if adjacent sub-rectangles that are merge candidates have the same metadata. Two sub-rectangles are candidates for merging if (r1.x1 == r2.x1 && r1.x2 == r2.x2) | (r1.y1 == r2.y1 && r1.y2 == r2.y2) (r1.x1 == r2.x1 && r1.x2 == r2.x2) | (r1.y1 == r2.y1 && r1.y2 == r2.y2) . If yes, connect them.
List the sub-rectangles of the master region . Each rectangle returned is an optimized blt operation destination. Associated metadata is the source of the blt operation.
source share