Commit 53f3de7e authored by Wei-Yin Chen (陳威尹)'s avatar Wei-Yin Chen (陳威尹) Committed by Commit Bot

Do not call StaticResource.getBitmap().recycle()

StaticResource.getBitmap() is and should only be called once in its
life cycle. This CL adds an assertion to guarantee this property.

Since StaticResource.getBitmap() would only be called once, it can
release the Bitmap after getBitmap() is called, and it's no longer
necessary to call recycle() on the Bitmap.

Bug: 965580
Change-Id: I070f9530aefea12a6dc72330a10e021103cfdd16
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1625901
Commit-Queue: Wei-Yin Chen (陳威尹) <wychen@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664411}
parent 376f8515
......@@ -15,10 +15,11 @@ import org.chromium.ui.resources.statics.NinePatchData;
*/
public interface Resource {
/**
* The {@link Bitmap} can only be used in
* This can only be called in
* {@link ResourceLoader.ResourceLoaderCallback#onResourceLoaded(int, int, Resource)}, where it
* would be called exactly once per invocation, and deep-copied into the CC layer, so it is
* encouraged to make sure we don't keep an extra copy at the Java side unnecessarily.
* would be called exactly once per invocation, and the {@link Bitmap} would be deep-copied into
* the CC layer, so it is encouraged to make sure we don't keep an extra copy at the Java side
* unnecessarily.
* @return A {@link Bitmap} representing the resource.
*/
Bitmap getBitmap();
......
......@@ -99,7 +99,6 @@ public class AsyncPreloadResourceLoader extends ResourceLoader {
private void registerResource(Resource resource, int resourceId) {
notifyLoadFinished(resourceId, resource);
if (resource != null) resource.getBitmap().recycle();
mOutstandingLoads.remove(resourceId);
}
......
......@@ -20,7 +20,7 @@ import org.chromium.ui.resources.ResourceFactory;
* this means a {@link Bitmap} and a potential {@link NinePatchData}.
*/
public class StaticResource implements Resource {
private final Bitmap mBitmap;
private Bitmap mBitmap;
private final NinePatchData mNinePatchData;
private final Rect mBitmapSize;
......@@ -42,7 +42,10 @@ public class StaticResource implements Resource {
@Override
public Bitmap getBitmap() {
return mBitmap;
assert mBitmap != null : "StaticResource#getBitmap can only be called once per lifecycle";
Bitmap bitmap = mBitmap;
mBitmap = null;
return bitmap;
}
@Override
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment