diff options
author | Romain Guy <romainguy@google.com> | 2010-06-15 18:03:40 -0700 |
---|---|---|
committer | Romain Guy <romainguy@google.com> | 2010-06-15 18:03:40 -0700 |
commit | 0bbae0836426ba2704e38e7f90a9d0ca502ab71d (patch) | |
tree | 1c10bf9a0585a027b38d85683ebc8c3aae8790e0 /tests/HwAccelerationTest | |
parent | 7e28c0108b2926832f29503682f950ab7506f684 (diff) | |
download | frameworks_base-0bbae0836426ba2704e38e7f90a9d0ca502ab71d.zip frameworks_base-0bbae0836426ba2704e38e7f90a9d0ca502ab71d.tar.gz frameworks_base-0bbae0836426ba2704e38e7f90a9d0ca502ab71d.tar.bz2 |
Add new API to check whether a Bitmap was modified.
Bitmap.getGenerationId() can be used by caches to find out if a Bitmap has been
modified. This simply exposes an existing Skia API.
This change also adds a small test app for Canvas hardware acceleration. The new
Bitmap API is required to implement a texture cache.
Change-Id: I8547b146cd14c8afe1a2327fcd6d71b1b1cb68fc
Diffstat (limited to 'tests/HwAccelerationTest')
-rw-r--r-- | tests/HwAccelerationTest/Android.mk | 26 | ||||
-rw-r--r-- | tests/HwAccelerationTest/AndroidManifest.xml | 30 | ||||
-rw-r--r-- | tests/HwAccelerationTest/src/com/google/android/test/hwui/HwUiActivity.java | 81 |
3 files changed, 137 insertions, 0 deletions
diff --git a/tests/HwAccelerationTest/Android.mk b/tests/HwAccelerationTest/Android.mk new file mode 100644 index 0000000..d4743f9 --- /dev/null +++ b/tests/HwAccelerationTest/Android.mk @@ -0,0 +1,26 @@ +# +# 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) diff --git a/tests/HwAccelerationTest/AndroidManifest.xml b/tests/HwAccelerationTest/AndroidManifest.xml new file mode 100644 index 0000000..22feeca --- /dev/null +++ b/tests/HwAccelerationTest/AndroidManifest.xml @@ -0,0 +1,30 @@ +<?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> diff --git a/tests/HwAccelerationTest/src/com/google/android/test/hwui/HwUiActivity.java b/tests/HwAccelerationTest/src/com/google/android/test/hwui/HwUiActivity.java new file mode 100644 index 0000000..1ee2dc1 --- /dev/null +++ b/tests/HwAccelerationTest/src/com/google/android/test/hwui/HwUiActivity.java @@ -0,0 +1,81 @@ +/* + * 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); + } + } +} |