Skip to content

Commit 7290d93

Browse files
jreckAndroid (Google) Code Review
authored andcommitted
Merge "Yell loudly about undefined behind in Bitmap, but work anyway" into mnc-dev
2 parents 0faca96 + 01a0af3 commit 7290d93

2 files changed

Lines changed: 30 additions & 7 deletions

File tree

core/jni/android/graphics/Bitmap.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ int Bitmap::getAshmemFd() const {
218218
}
219219

220220
const SkImageInfo& Bitmap::info() const {
221-
assertValid();
222221
return mPixelRef->info();
223222
}
224223

graphics/java/android/graphics/Bitmap.java

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.os.Parcelable;
2424
import android.os.Trace;
2525
import android.util.DisplayMetrics;
26+
import android.util.Log;
2627

2728
import dalvik.system.VMRuntime;
2829

@@ -33,6 +34,8 @@
3334
import java.nio.ShortBuffer;
3435

3536
public final class Bitmap implements Parcelable {
37+
private static final String TAG = "Bitmap";
38+
3639
/**
3740
* Indicates that the bitmap was created for an unknown pixel density.
3841
*
@@ -159,6 +162,9 @@ void reinit(int width, int height, boolean requestPremultiplied) {
159162
* @see #DENSITY_NONE
160163
*/
161164
public int getDensity() {
165+
if (mRecycled) {
166+
Log.w(TAG, "Called getDensity() on a recycle()'d bitmap! This is undefined behavior!");
167+
}
162168
return mDensity;
163169
}
164170

@@ -330,7 +336,9 @@ public final boolean isRecycled() {
330336
* @return The current generation ID for this bitmap.
331337
*/
332338
public int getGenerationId() {
333-
if (mRecycled) return 0;
339+
if (mRecycled) {
340+
Log.w(TAG, "Called getGenerationId() on a recycle()'d bitmap! This is undefined behavior!");
341+
}
334342
return nativeGenerationId(mFinalizer.mNativeBitmap);
335343
}
336344

@@ -1057,7 +1065,9 @@ public final boolean isMutable() {
10571065
* @see BitmapFactory.Options#inPremultiplied
10581066
*/
10591067
public final boolean isPremultiplied() {
1060-
if (mRecycled) return false;
1068+
if (mRecycled) {
1069+
Log.w(TAG, "Called isPremultiplied() on a recycle()'d bitmap! This is undefined behavior!");
1070+
}
10611071
return nativeIsPremultiplied(mFinalizer.mNativeBitmap);
10621072
}
10631073

@@ -1089,11 +1099,17 @@ public final void setPremultiplied(boolean premultiplied) {
10891099

10901100
/** Returns the bitmap's width */
10911101
public final int getWidth() {
1102+
if (mRecycled) {
1103+
Log.w(TAG, "Called getWidth() on a recycle()'d bitmap! This is undefined behavior!");
1104+
}
10921105
return mWidth;
10931106
}
10941107

10951108
/** Returns the bitmap's height */
10961109
public final int getHeight() {
1110+
if (mRecycled) {
1111+
Log.w(TAG, "Called getHeight() on a recycle()'d bitmap! This is undefined behavior!");
1112+
}
10971113
return mHeight;
10981114
}
10991115

@@ -1176,7 +1192,9 @@ static public int scaleFromDensity(int size, int sdensity, int tdensity) {
11761192
* @return number of bytes between rows of the native bitmap pixels.
11771193
*/
11781194
public final int getRowBytes() {
1179-
if (mRecycled) return 0;
1195+
if (mRecycled) {
1196+
Log.w(TAG, "Called getRowBytes() on a recycle()'d bitmap! This is undefined behavior!");
1197+
}
11801198
return nativeRowBytes(mFinalizer.mNativeBitmap);
11811199
}
11821200

@@ -1220,7 +1238,9 @@ public final int getAllocationByteCount() {
12201238
* that config, otherwise return null.
12211239
*/
12221240
public final Config getConfig() {
1223-
if (mRecycled) return Config.ARGB_8888;
1241+
if (mRecycled) {
1242+
Log.w(TAG, "Called getConfig() on a recycle()'d bitmap! This is undefined behavior!");
1243+
}
12241244
return Config.nativeToConfig(nativeConfig(mFinalizer.mNativeBitmap));
12251245
}
12261246

@@ -1233,7 +1253,9 @@ public final Config getConfig() {
12331253
* it will return true by default.
12341254
*/
12351255
public final boolean hasAlpha() {
1236-
if (mRecycled) return false;
1256+
if (mRecycled) {
1257+
Log.w(TAG, "Called hasAlpha() on a recycle()'d bitmap! This is undefined behavior!");
1258+
}
12371259
return nativeHasAlpha(mFinalizer.mNativeBitmap);
12381260
}
12391261

@@ -1270,7 +1292,9 @@ public void setHasAlpha(boolean hasAlpha) {
12701292
* @see #setHasMipMap(boolean)
12711293
*/
12721294
public final boolean hasMipMap() {
1273-
if (mRecycled) return false;
1295+
if (mRecycled) {
1296+
Log.w(TAG, "Called hasMipMap() on a recycle()'d bitmap! This is undefined behavior!");
1297+
}
12741298
return nativeHasMipMap(mFinalizer.mNativeBitmap);
12751299
}
12761300

0 commit comments

Comments
 (0)