Loading core/jni/android/graphics/Bitmap.cpp +5 −0 Original line number Diff line number Diff line Loading @@ -313,6 +313,10 @@ static int Bitmap_config(JNIEnv* env, jobject, SkBitmap* bitmap) { return bitmap->config(); } static int Bitmap_getGenerationId(JNIEnv* env, jobject, SkBitmap* bitmap) { return bitmap->getGenerationID(); } static jboolean Bitmap_hasAlpha(JNIEnv* env, jobject, SkBitmap* bitmap) { return !bitmap->isOpaque(); } Loading Loading @@ -606,6 +610,7 @@ static JNINativeMethod gBitmapMethods[] = { (void*)Bitmap_writeToParcel }, { "nativeExtractAlpha", "(II[I)Landroid/graphics/Bitmap;", (void*)Bitmap_extractAlpha }, { "nativeGenerationId", "(I)I", (void*)Bitmap_getGenerationId }, { "nativeGetPixel", "(III)I", (void*)Bitmap_getPixel }, { "nativeGetPixels", "(I[IIIIIII)V", (void*)Bitmap_getPixels }, { "nativeSetPixel", "(IIII)V", (void*)Bitmap_setPixel }, Loading graphics/java/android/graphics/Bitmap.java +14 −0 Original line number Diff line number Diff line Loading @@ -171,6 +171,19 @@ public final class Bitmap implements Parcelable { return mRecycled; } /** * Returns the generation ID of this bitmap. The generation ID changes * whenever the bitmap is modified. This can be used as an efficient way to * check if a bitmap has changed. * * @return The current generation ID for this bitmap. * * @hide */ public int getGenerationId() { return nativeGenerationId(mNativeBitmap); } /** * This is called by methods that want to throw an exception if the bitmap * has already been recycled. Loading Loading @@ -1041,6 +1054,7 @@ public final class Bitmap implements Parcelable { private static native void nativeCopyPixelsToBuffer(int nativeBitmap, Buffer dst); private static native void nativeCopyPixelsFromBuffer(int nb, Buffer src); private static native int nativeGenerationId(int nativeBitmap); private static native Bitmap nativeCreateFromParcel(Parcel p); // returns true on success Loading tests/HwAccelerationTest/Android.mk 0 → 100644 +26 −0 Original line number Diff line number Diff line # # Copyright (C) 2010 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES := $(call all-subdir-java-files) LOCAL_PACKAGE_NAME := HwAccelerationTest LOCAL_MODULE_TAGS := tests include $(BUILD_PACKAGE) tests/HwAccelerationTest/AndroidManifest.xml 0 → 100644 +30 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2010 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.android.test.hwui"> <application android:label="HwUi"> <activity android:name="HwUiActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> tests/HwAccelerationTest/src/com/google/android/test/hwui/HwUiActivity.java 0 → 100644 +81 −0 Original line number Diff line number Diff line /* * Copyright (C) 2010 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.android.test.hwui; import android.app.Activity; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; import android.os.Bundle; import android.view.View; import static android.util.Log.d; public class HwUiActivity extends Activity { private static final String LOG_TAG = "HwUi"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new DirtyBitmapView(this)); } static int dipToPx(Context c, int dip) { return (int) (c.getResources().getDisplayMetrics().density * dip + 0.5f); } static class DirtyBitmapView extends View { private Bitmap mCache; DirtyBitmapView(Context c) { super(c); final int width = dipToPx(c, 100); final int height = dipToPx(c, 100); mCache = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); logGenerationId("Dirty cache created", mCache); Canvas canvas = new Canvas(mCache); logGenerationId("Canvas cache created", mCache); canvas.drawColor(0xffff0000); logGenerationId("Cache filled", mCache); Paint p = new Paint(); p.setColor(0xff0000ff); canvas.drawRect(width / 2.0f, height / 2.0f, width, height, p); logGenerationId("Cache modified", mCache); } private static void logGenerationId(String message, Bitmap b) { d(LOG_TAG, message); d(LOG_TAG, " bitmap id=" + b.getGenerationId()); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawBitmap(mCache, 0, 0, null); logGenerationId("Cache drawn", mCache); } } } Loading
core/jni/android/graphics/Bitmap.cpp +5 −0 Original line number Diff line number Diff line Loading @@ -313,6 +313,10 @@ static int Bitmap_config(JNIEnv* env, jobject, SkBitmap* bitmap) { return bitmap->config(); } static int Bitmap_getGenerationId(JNIEnv* env, jobject, SkBitmap* bitmap) { return bitmap->getGenerationID(); } static jboolean Bitmap_hasAlpha(JNIEnv* env, jobject, SkBitmap* bitmap) { return !bitmap->isOpaque(); } Loading Loading @@ -606,6 +610,7 @@ static JNINativeMethod gBitmapMethods[] = { (void*)Bitmap_writeToParcel }, { "nativeExtractAlpha", "(II[I)Landroid/graphics/Bitmap;", (void*)Bitmap_extractAlpha }, { "nativeGenerationId", "(I)I", (void*)Bitmap_getGenerationId }, { "nativeGetPixel", "(III)I", (void*)Bitmap_getPixel }, { "nativeGetPixels", "(I[IIIIIII)V", (void*)Bitmap_getPixels }, { "nativeSetPixel", "(IIII)V", (void*)Bitmap_setPixel }, Loading
graphics/java/android/graphics/Bitmap.java +14 −0 Original line number Diff line number Diff line Loading @@ -171,6 +171,19 @@ public final class Bitmap implements Parcelable { return mRecycled; } /** * Returns the generation ID of this bitmap. The generation ID changes * whenever the bitmap is modified. This can be used as an efficient way to * check if a bitmap has changed. * * @return The current generation ID for this bitmap. * * @hide */ public int getGenerationId() { return nativeGenerationId(mNativeBitmap); } /** * This is called by methods that want to throw an exception if the bitmap * has already been recycled. Loading Loading @@ -1041,6 +1054,7 @@ public final class Bitmap implements Parcelable { private static native void nativeCopyPixelsToBuffer(int nativeBitmap, Buffer dst); private static native void nativeCopyPixelsFromBuffer(int nb, Buffer src); private static native int nativeGenerationId(int nativeBitmap); private static native Bitmap nativeCreateFromParcel(Parcel p); // returns true on success Loading
tests/HwAccelerationTest/Android.mk 0 → 100644 +26 −0 Original line number Diff line number Diff line # # Copyright (C) 2010 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_SRC_FILES := $(call all-subdir-java-files) LOCAL_PACKAGE_NAME := HwAccelerationTest LOCAL_MODULE_TAGS := tests include $(BUILD_PACKAGE)
tests/HwAccelerationTest/AndroidManifest.xml 0 → 100644 +30 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2010 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.android.test.hwui"> <application android:label="HwUi"> <activity android:name="HwUiActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
tests/HwAccelerationTest/src/com/google/android/test/hwui/HwUiActivity.java 0 → 100644 +81 −0 Original line number Diff line number Diff line /* * Copyright (C) 2010 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.android.test.hwui; import android.app.Activity; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Paint; import android.os.Bundle; import android.view.View; import static android.util.Log.d; public class HwUiActivity extends Activity { private static final String LOG_TAG = "HwUi"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new DirtyBitmapView(this)); } static int dipToPx(Context c, int dip) { return (int) (c.getResources().getDisplayMetrics().density * dip + 0.5f); } static class DirtyBitmapView extends View { private Bitmap mCache; DirtyBitmapView(Context c) { super(c); final int width = dipToPx(c, 100); final int height = dipToPx(c, 100); mCache = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); logGenerationId("Dirty cache created", mCache); Canvas canvas = new Canvas(mCache); logGenerationId("Canvas cache created", mCache); canvas.drawColor(0xffff0000); logGenerationId("Cache filled", mCache); Paint p = new Paint(); p.setColor(0xff0000ff); canvas.drawRect(width / 2.0f, height / 2.0f, width, height, p); logGenerationId("Cache modified", mCache); } private static void logGenerationId(String message, Bitmap b) { d(LOG_TAG, message); d(LOG_TAG, " bitmap id=" + b.getGenerationId()); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawBitmap(mCache, 0, 0, null); logGenerationId("Cache drawn", mCache); } } }