Optimize the CopyTo method of SKBitmap#3489
Conversation
|
@dotnet-policy-service agree |
@dotnet-policy-service agree |
|
I also have a memory copy approach since CopyTo is both slow and leaky as is (#2915). Unfortunately, this one doesn't handle that the bitmap might be a subset of another, in which case the source pixel span can be a lot bigger than the destination. I don't mind putting in a PR for mine or helping fix this if it's of interest though? |
you are right. Actually I'm not a Skia professor😢 and I have never used ExtractSubset. I just find my project use up 1gb memories for no reason but a copyto. |
|
No worries. I think a fair few people have been tripped up by the leak there. I have a PR to fix that: #3317 You can just copy the code from there for that if you want, but a memory copy like what you were doing is orders of magnitude faster 👍 |
It seems that there isn't a property refers to if a skbitmap is a subset of the other one. I don't know whether it's available in skia (not skiasharp ) So maybe the easiest way to solve the problem is to delete ExtractSubset or let the method create a new skbitmap with new memory. It is not worthwhile to reduce the security and efficiency of the commonly used CopyTo method at the cost of improving the efficiency of the infrequently used ExtractSubset method. And I think since the name of the method is CopyTo, it must be designed to copy a bitmap to the other one which has the same color type and size. The current CopyTo must be called "DrawTo". This will only lead to ambiguity and inefficiency It is meaningless to blindly conform to Skia's api |
jyswjjgdwtdtj
left a comment
There was a problem hiding this comment.
Test if the skbitmap is a subset of another bitmap
I add some code, and in it I copy pixels row by row when one or both of the src and des bitmap is a subset of another bitmap. |
Description of Change
A simple PR
Optimize the CopyTo method of SKBitmap.
Use direct memory copy instead of creating SKCanvas and DrawBitmap when source and destination Bitmap have the same SKColorType and Width.
Bugs Fixed
None
API Changes
None.
Behavioral Changes
None.
Required skia PR
None.
PR Checklist