diff --git a/build/sdk.atree b/build/sdk.atree index 6d0d20b70..e0cf7f08e 100644 --- a/build/sdk.atree +++ b/build/sdk.atree @@ -51,6 +51,11 @@ bin/dx platform-tools/dx bin/dexdump platform-tools/dexdump framework/dx.jar platform-tools/lib/dx.jar +# Framework include for Renderscript +frameworks/rs/scriptc platform-tools/renderscript/include +external/clang/lib/Headers platform-tools/renderscript/clang-include +external/clang/LICENSE.TXT platform-tools/renderscript/clang-include/LICENSE.TXT + # API database for tools such as lint development/sdk/api-versions.xml platform-tools/api/api-versions.xml @@ -197,6 +202,7 @@ development/samples/WiFiDirectDemo samples/${PLATFORM_NAME}/WiFiDire development/samples/Wiktionary samples/${PLATFORM_NAME}/Wiktionary development/samples/WiktionarySimple samples/${PLATFORM_NAME}/WiktionarySimple development/samples/XmlAdapters samples/${PLATFORM_NAME}/XmlAdapters +development/samples/RenderScript/HelloCompute samples/${PLATFORM_NAME}/RenderScript/HelloCompute # NOTICE files are copied by build/core/Makefile from sdk.git sdk/files/sdk_files_NOTICE.txt samples/${PLATFORM_NAME}/NOTICE.txt diff --git a/samples/RenderScript/Android.mk b/samples/RenderScript/Android.mk new file mode 100644 index 000000000..5053e7d64 --- /dev/null +++ b/samples/RenderScript/Android.mk @@ -0,0 +1 @@ +include $(call all-subdir-makefiles) diff --git a/samples/RenderScript/HelloCompute/Android.mk b/samples/RenderScript/HelloCompute/Android.mk new file mode 100644 index 000000000..e19f35103 --- /dev/null +++ b/samples/RenderScript/HelloCompute/Android.mk @@ -0,0 +1,27 @@ +# +# Copyright (C) 2011 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_MODULE_TAGS := optional + +LOCAL_SRC_FILES := $(call all-java-files-under, src) \ + $(call all-renderscript-files-under, src) + +LOCAL_PACKAGE_NAME := RsHelloCompute + +include $(BUILD_PACKAGE) diff --git a/samples/RenderScript/HelloCompute/AndroidManifest.xml b/samples/RenderScript/HelloCompute/AndroidManifest.xml new file mode 100644 index 000000000..73e1110f0 --- /dev/null +++ b/samples/RenderScript/HelloCompute/AndroidManifest.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + diff --git a/samples/RenderScript/HelloCompute/_index.html b/samples/RenderScript/HelloCompute/_index.html new file mode 100644 index 000000000..abfd9784a --- /dev/null +++ b/samples/RenderScript/HelloCompute/_index.html @@ -0,0 +1,2 @@ +

A Renderscript compute sample that filters a bitmap. No Renderscript graphics APIs are used +in this sample.

\ No newline at end of file diff --git a/samples/RenderScript/HelloCompute/res/drawable/data.jpg b/samples/RenderScript/HelloCompute/res/drawable/data.jpg new file mode 100644 index 000000000..81a87b172 Binary files /dev/null and b/samples/RenderScript/HelloCompute/res/drawable/data.jpg differ diff --git a/samples/RenderScript/HelloCompute/res/layout/main.xml b/samples/RenderScript/HelloCompute/res/layout/main.xml new file mode 100644 index 000000000..3f7de4313 --- /dev/null +++ b/samples/RenderScript/HelloCompute/res/layout/main.xml @@ -0,0 +1,31 @@ + + + + + + + + + + diff --git a/samples/RenderScript/HelloCompute/src/com/example/android/rs/hellocompute/HelloCompute.java b/samples/RenderScript/HelloCompute/src/com/example/android/rs/hellocompute/HelloCompute.java new file mode 100644 index 000000000..0d6c47be1 --- /dev/null +++ b/samples/RenderScript/HelloCompute/src/com/example/android/rs/hellocompute/HelloCompute.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2011 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.example.android.rs.hellocompute; + +import android.app.Activity; +import android.os.Bundle; +import android.graphics.BitmapFactory; +import android.graphics.Bitmap; +import android.renderscript.RenderScript; +import android.renderscript.Allocation; +import android.widget.ImageView; + +public class HelloCompute extends Activity { + private Bitmap mBitmapIn; + private Bitmap mBitmapOut; + + private RenderScript mRS; + private Allocation mInAllocation; + private Allocation mOutAllocation; + private ScriptC_mono mScript; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main); + + mBitmapIn = loadBitmap(R.drawable.data); + mBitmapOut = Bitmap.createBitmap(mBitmapIn.getWidth(), mBitmapIn.getHeight(), + mBitmapIn.getConfig()); + + ImageView in = (ImageView) findViewById(R.id.displayin); + in.setImageBitmap(mBitmapIn); + + ImageView out = (ImageView) findViewById(R.id.displayout); + out.setImageBitmap(mBitmapOut); + + createScript(); + } + + + private void createScript() { + mRS = RenderScript.create(this); + + mInAllocation = Allocation.createFromBitmap(mRS, mBitmapIn, + Allocation.MipmapControl.MIPMAP_NONE, + Allocation.USAGE_SCRIPT); + mOutAllocation = Allocation.createTyped(mRS, mInAllocation.getType()); + + mScript = new ScriptC_mono(mRS, getResources(), R.raw.mono); + + mScript.forEach_root(mInAllocation, mOutAllocation); + mOutAllocation.copyTo(mBitmapOut); + } + + private Bitmap loadBitmap(int resource) { + final BitmapFactory.Options options = new BitmapFactory.Options(); + options.inPreferredConfig = Bitmap.Config.ARGB_8888; + return BitmapFactory.decodeResource(getResources(), resource, options); + } +} diff --git a/samples/RenderScript/HelloCompute/src/com/example/android/rs/hellocompute/mono.rs b/samples/RenderScript/HelloCompute/src/com/example/android/rs/hellocompute/mono.rs new file mode 100644 index 000000000..08592f558 --- /dev/null +++ b/samples/RenderScript/HelloCompute/src/com/example/android/rs/hellocompute/mono.rs @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2011 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. + */ + +#pragma version(1) +#pragma rs java_package_name(com.example.android.rs.hellocompute) + +const static float3 gMonoMult = {0.299f, 0.587f, 0.114f}; + +void root(const uchar4 *v_in, uchar4 *v_out) { + float4 f4 = rsUnpackColor8888(*v_in); + + float3 mono = dot(f4.rgb, gMonoMult); + *v_out = rsPackColorTo8888(mono); +} + diff --git a/samples/RenderScript/Levels/Android.mk b/samples/RenderScript/Levels/Android.mk new file mode 100644 index 000000000..3f1445daf --- /dev/null +++ b/samples/RenderScript/Levels/Android.mk @@ -0,0 +1,26 @@ +# +# Copyright (C) 2012 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_MODULE_TAGS := optional + +LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src) + +LOCAL_PACKAGE_NAME := LevelsRS + +include $(BUILD_PACKAGE) diff --git a/samples/RenderScript/Levels/AndroidManifest.xml b/samples/RenderScript/Levels/AndroidManifest.xml new file mode 100644 index 000000000..829404843 --- /dev/null +++ b/samples/RenderScript/Levels/AndroidManifest.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples/RenderScript/Levels/res/drawable-nodpi/city.png b/samples/RenderScript/Levels/res/drawable-nodpi/city.png new file mode 100644 index 000000000..856eeff59 Binary files /dev/null and b/samples/RenderScript/Levels/res/drawable-nodpi/city.png differ diff --git a/samples/RenderScript/Levels/res/layout/main.xml b/samples/RenderScript/Levels/res/layout/main.xml new file mode 100644 index 000000000..a6a075cbe --- /dev/null +++ b/samples/RenderScript/Levels/res/layout/main.xml @@ -0,0 +1,140 @@ + + + + + + + + + +