MCPcopy Create free account
hub / github.com/Snapchat/Valdi / CachedBitmap

Class CachedBitmap

valdi/src/java/com/snap/valdi/utils/BitmapPool.kt:36–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34 }
35
36 private class CachedBitmap(private val pool: BitmapPool, private var bitmap: Bitmap?): BitmapHandler {
37
38 private val retainCount = AtomicInteger(1)
39
40 var expirationTime = 0L
41
42 private var isDirty = true
43
44 val isUnused: Boolean
45 get() = retainCount.get() == 0
46
47 override fun getBitmap(): Bitmap {
48 return bitmap!!
49 }
50
51 fun prepareForReuse() {
52 synchronized(this) {
53 if (!isDirty) {
54 return
55 }
56
57 isDirty = false
58 bitmap?.eraseColor(Color.TRANSPARENT)
59 }
60 }
61
62 fun markDirty() {
63 synchronized(this) {
64 isDirty = true
65 }
66 }
67
68 fun destroy() {
69 synchronized(this) {
70 bitmap?.recycle()
71 bitmap = null
72 }
73 }
74
75 override fun retain() {
76 retainCount.incrementAndGet()
77 }
78
79 override fun release() {
80 val newValue = retainCount.decrementAndGet()
81 if (newValue == 0) {
82 pool.onBitmapUnused(this)
83 }
84 }
85 }
86
87 /**
88 * Returns a bitmap with the desired width and height.

Callers 1

getMethod · 0.85

Calls 1

getMethod · 0.65

Tested by

no test coverage detected