REPLAY-1891: Optimize bitmap processing#1576
Conversation
4b3f6bc to
bc46d0d
Compare
Codecov Report
@@ Coverage Diff @@
## feature/base64-jmoskovich #1576 +/- ##
=============================================================
- Coverage 83.38% 83.29% -0.09%
=============================================================
Files 444 446 +2
Lines 15095 15181 +86
Branches 2279 2288 +9
=============================================================
+ Hits 12586 12644 +58
- Misses 1910 1932 +22
- Partials 599 605 +6
|
ae02b0d to
48d83f7
Compare
c7b5c2f to
0f66105
Compare
48d83f7 to
8e2d12a
Compare
0xnm
left a comment
There was a problem hiding this comment.
nice! I left some comments, let me know wdyt.
|
|
||
| import android.graphics.Bitmap | ||
|
|
||
| internal data class EnrichedBitmap( |
There was a problem hiding this comment.
I find this class name a bit generic. There is no enrichment here, it is just an additional flag attached to the bitmap. Maybe we can have some better name?
There was a problem hiding this comment.
You're right - I've eliminated the class and moved it to being just an additional boolean flag
| view: ImageView, | ||
| drawable: Drawable, | ||
| density: Float | ||
| ): Pair<Long, Long> { |
There was a problem hiding this comment.
we probably need to document that first is width, last is height.
There was a problem hiding this comment.
Changing it to DrawableDimensions
| ) | ||
|
|
||
| // Then | ||
| verify(mockDrawableUtils, times(1)).createBitmapOfApproxSizeFromDrawable( |
There was a problem hiding this comment.
it is times(1) by default, so I guess we can omit this argument here and in similar calls
There was a problem hiding this comment.
This is to make it explicit that the call should happen only once. If I omit times(1) then the test will pass regardless of how many calls were made to the method (>0)
| ) | ||
|
|
||
| // Then | ||
| verify(mockBitmapPool, times(0)).put(any()) |
There was a problem hiding this comment.
it is better to use never instead of times(0) or maybe something like verifyNoInteractions even.
| @LongForgery(min = 1, max = 1000) | ||
| var fakeDrawableHeight: Long = 0L | ||
|
|
||
| val mockDrawableXY: Pair<Long, Long> = Pair(30, 30) |
There was a problem hiding this comment.
strictly speaking it is not a mock. maybe we can also randomize the point? knowing dimensions of the drawable.
8e2d12a to
c8741a0
Compare
0f66105 to
be9a3a8
Compare
c8741a0 to
2929fee
Compare
be9a3a8 to
5be1cc0
Compare
2929fee to
923b9e0
Compare
| drawable.bitmap != null && | ||
| !drawable.bitmap.isRecycled | ||
| ) { | ||
| shouldCacheBitmap = false |
There was a problem hiding this comment.
It seems this is not required as shouldCacheBitmap was initialised as falsed a few lines above.
Another option would be to do something like:
val (bitmap, shouldCache) = if (…) {
drawable.bitmap to false
} else {
drawableUtils.createBitmapOfApproxSizeFromDrawable(…) to true
}| } | ||
|
|
||
| bitmapPool?.put(bitmap) | ||
| if (shouldCacheBitmap) { |
There was a problem hiding this comment.
Should we add some size limit to the cachable bitmaps? E.g.: only cache bitmaps smaller than x Mb?
There was a problem hiding this comment.
All the cached bitmaps will be after resizing, so they would at most be around 15kbs each. The original bitmaps that aren't resized won't be cached
a6c445b to
556a0ca
Compare
mariusc83
left a comment
There was a problem hiding this comment.
I am letting this go but I strongly recommend that you refactor the way you resolve your View backgrounds in the BaseWireframeMapper
| base64Serializer?.registerAsyncLoadingCallback(asyncImageProcessingCallback) | ||
| } | ||
|
|
||
| private fun resolveViewBackground( |
There was a problem hiding this comment.
looks way better now, tks for this change.
fb59d82 to
7753112
Compare
Get Bitmap from BitmapDrawable if available Extract base64 logic from mapper to ImageWireframeHelper Get background images if they exist Support scaletypes
e814de7
7753112 to
e814de7
Compare
What does this PR do?
• Gets the bitmap from BitmapDrawable if available (use new EnrichedBitmap class to know if we should later cache it)
• Extraction of the base64 logic from the ImageButtonMapper to ImageWireframeHelper
• Gets background images if they exist (added an example to the sample app)
• Support scaletypes (atm only fitXY and center-crop)
• Move registration of bitmapPool for callbacks from DrawableUtils to Base64Serializer
Motivation
Additional improvements necessary to rollout base64 imagebutton support
What inspired you to submit this pull request?
Additional Notes
Anything else we should know when reviewing?
Review checklist (to be filled by reviewers)