forked from KolibriOS/kolibrios
7a91a704c5
git-svn-id: svn://kolibrios.org@1806 a494cfbc-eb01-0410-851d-a64ba20cac60
84 lines
2.6 KiB
Plaintext
84 lines
2.6 KiB
Plaintext
|
|
Smart Dirty Rectangle Management
|
|
--------------------------------
|
|
|
|
pig_dirty() contains an algorithm that tries to find
|
|
the the best dirtyrect candidates for merging. While
|
|
searching, it looks out for perfect or sufficiently
|
|
good candidates.
|
|
|
|
(Perfect candidate:)
|
|
The merged rectangle is of the same size
|
|
as the largest of the two input rectangles:
|
|
|
|
Amerged <= MAX(A1, A2)
|
|
|
|
We don't actually test for this, but rather for...
|
|
|
|
Instant Pick candidate:
|
|
Not Perfect, but good enough to be treated
|
|
as such, considering the cost of going on
|
|
searching for a better candidate:
|
|
Amerged 100 / MAX(A1, A2) - 100 <= PIG_INSTANT_MERGE
|
|
|
|
(That is, the area of the merged rect must be
|
|
no more than PIG_INSTANT_MERGE % bigger than
|
|
the area of the larger of the two input rects.)
|
|
|
|
Note that this is also about how likely it is
|
|
that thereis* a better candidate. Assuming
|
|
that PIG_INSTANT_MERGE is set to a sensible
|
|
value, it is not very likely at all. There
|
|
would have to be another dirtyrect nearby, and
|
|
the chance of that being a better match is
|
|
rather low, since that would most likely have
|
|
caused it to be merged with the tested dirtyrect
|
|
long before our new rect came in.
|
|
|
|
(Good candidate:)
|
|
The area of the merged rectangle is smaller
|
|
than the total area of the two input rectangles:
|
|
|
|
(Amerged - A1 - A2) < 0
|
|
|
|
We don't actually test for this, but rather for...
|
|
|
|
Acceptable candidate:
|
|
The area of the merged rectangle is larger
|
|
than the total of the two input rectangles, but
|
|
since there is some per-rectangle overhead,
|
|
merging is still a win:
|
|
|
|
(Amerged - A1 - A2) <= PIG_WORST_MERGE
|
|
|
|
The default setting assumes that the cost of a
|
|
rectangle is in the range of 300 pixels. One
|
|
should probably benchmark a few different systems
|
|
to see if that's reasonable.
|
|
|
|
Unacceptable candidate:
|
|
The area of the merged rectangle is larger than
|
|
the total of the input rectangles to the degree
|
|
that merging is a definite loss:
|
|
|
|
(Amerged - A1 - A2) > PIG_WORST_MERGE
|
|
|
|
The algorithm instantly returns Perfect candidates as
|
|
solutions. If there are only Good and Acceptable
|
|
candidates, the best one (lowest number of wasted
|
|
pixels) is the solution.
|
|
|
|
If there are only Unacceptable candidates, there is no
|
|
sensible merger solution, so pig_dirty() will try to add
|
|
a new dirtyrect.
|
|
|
|
If that fails (table full), the best candidate is used,
|
|
even though it would have been Unacceptable under normal
|
|
circumstances.
|
|
|
|
|
|
TODO: Thereare* more alternatives than just "merge" or
|
|
TODO: "don't merge"! For example, it might pay off to
|
|
TODO: detect overlapping and clip dirtyrects to avoid
|
|
TODO: it, when merging is not a viable option.
|