Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
VLC-Android
Manage
Activity
Members
Labels
Plan
Issues
531
Issue boards
Milestones
Wiki
Code
Merge requests
14
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VideoLAN
VLC-Android
Commits
1c6ff588
Commit
1c6ff588
authored
7 years ago
by
Geoffrey Métais
Browse files
Options
Downloads
Patches
Plain Diff
Use references in Cache
SoftReferences make in inefficient
parent
97830784
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
vlc-android/src/org/videolan/vlc/gui/helpers/BitmapCache.java
+10
-44
10 additions, 44 deletions
...android/src/org/videolan/vlc/gui/helpers/BitmapCache.java
with
10 additions
and
44 deletions
vlc-android/src/org/videolan/vlc/gui/helpers/BitmapCache.java
+
10
−
44
View file @
1c6ff588
...
...
@@ -31,20 +31,15 @@ import android.support.v4.util.LruCache;
import
android.util.Log
;
import
org.videolan.libvlc.util.AndroidUtil
;
import
org.videolan.vlc.R
;
import
org.videolan.vlc.VLCApplication
;
import
java.lang.ref.SoftReference
;
import
org.videolan.vlc.util.Strings
;
public
class
BitmapCache
{
public
final
static
String
TAG
=
"VLC/BitmapCache"
;
private
final
static
boolean
LOG_ENABLED
=
false
;
private
final
static
String
TAG
=
"VLC/BitmapCache"
;
private
static
final
String
CONE_KEY
=
"res:"
+
R
.
drawable
.
cone
;
private
static
final
String
CONE_O_KEY
=
"res:"
+
R
.
drawable
.
ic_cone_o
;
private
static
BitmapCache
mInstance
;
private
final
LruCache
<
String
,
Cacheable
Bitmap
>
mMemCache
;
private
final
LruCache
<
String
,
Bitmap
>
mMemCache
;
public
synchronized
static
BitmapCache
getInstance
()
{
if
(
mInstance
==
null
)
...
...
@@ -64,35 +59,30 @@ public class BitmapCache {
// Use 1/5th of the available memory for this memory cache.
final
int
cacheSize
=
1024
*
1024
*
memClass
/
5
;
Log
.
i
(
TAG
,
"LRUCache size set to "
+
cacheSize
);
Log
.
i
(
TAG
,
"LRUCache size set to "
+
Strings
.
readableSize
(
cacheSize
)
)
;
mMemCache
=
new
LruCache
<
String
,
Cacheable
Bitmap
>(
cacheSize
)
{
mMemCache
=
new
LruCache
<
String
,
Bitmap
>(
cacheSize
)
{
@Override
protected
int
sizeOf
(
String
key
,
Cacheable
Bitmap
value
)
{
return
value
.
get
Size
();
protected
int
sizeOf
(
String
key
,
Bitmap
value
)
{
return
value
.
get
RowBytes
()
*
value
.
getHeight
();
}
};
}
public
synchronized
Bitmap
getBitmapFromMemCache
(
String
key
)
{
final
CacheableBitmap
cacheableBitmap
=
mMemCache
.
get
(
key
);
if
(
cacheableBitmap
==
null
)
return
null
;
Bitmap
b
=
cacheableBitmap
.
get
();
final
Bitmap
b
=
mMemCache
.
get
(
key
);
if
(
b
==
null
){
mMemCache
.
remove
(
key
);
return
null
;
}
if
(
LOG_ENABLED
)
Log
.
d
(
TAG
,
(
b
==
null
)
?
"Cache miss"
:
"Cache found"
);
return
b
;
}
public
synchronized
void
addBitmapToMemCache
(
String
key
,
Bitmap
bitmap
)
{
if
(
key
!=
null
&&
bitmap
!=
null
&&
getBitmapFromMemCache
(
key
)
==
null
)
{
final
CacheableBitmap
cacheableBitmap
=
new
CacheableBitmap
(
bitmap
);
mMemCache
.
put
(
key
,
cacheableBitmap
);
mMemCache
.
put
(
key
,
bitmap
);
}
}
...
...
@@ -117,28 +107,4 @@ public class BitmapCache {
}
return
bitmap
;
}
private
static
class
CacheableBitmap
{
final
int
mSize
;
final
SoftReference
<
Bitmap
>
mReference
;
CacheableBitmap
(
Bitmap
bitmap
){
mReference
=
new
SoftReference
<
Bitmap
>(
bitmap
);
mSize
=
bitmap
==
null
?
0
:
bitmap
.
getRowBytes
()
*
bitmap
.
getHeight
();
}
public
SoftReference
<
Bitmap
>
getReference
(){
return
mReference
;
}
public
Bitmap
get
(){
if
(
mReference
!=
null
)
return
mReference
.
get
();
return
null
;
}
public
int
getSize
(){
return
mSize
;
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment