Add getPointer for USAGE_SHARED allocations.
Change-Id: I13a2af09bbbeec6cc6131b935979ac21c02820be
diff --git a/tests/cppbasic-getpointer/Android.mk b/tests/cppbasic-getpointer/Android.mk
new file mode 100644
index 0000000..eb4ac34
--- /dev/null
+++ b/tests/cppbasic-getpointer/Android.mk
@@ -0,0 +1,26 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES:= \
+ mono.rs \
+ compute.cpp
+
+LOCAL_SHARED_LIBRARIES := \
+ libRScpp \
+ libstlport
+
+LOCAL_MODULE:= rstest-compute-getpointer
+
+LOCAL_MODULE_TAGS := tests
+
+intermediates := $(call intermediates-dir-for,STATIC_LIBRARIES,libRS,TARGET,)
+
+LOCAL_C_INCLUDES += external/stlport/stlport bionic/ bionic/libstdc++/include
+LOCAL_C_INCLUDES += frameworks/rs/cpp
+LOCAL_C_INCLUDES += frameworks/rs
+LOCAL_C_INCLUDES += $(intermediates)
+
+LOCAL_CLANG := true
+
+include $(BUILD_EXECUTABLE)
+
diff --git a/tests/cppbasic-getpointer/compute.cpp b/tests/cppbasic-getpointer/compute.cpp
new file mode 100644
index 0000000..033e7b3
--- /dev/null
+++ b/tests/cppbasic-getpointer/compute.cpp
@@ -0,0 +1,100 @@
+
+#include "RenderScript.h"
+
+#include "ScriptC_mono.h"
+
+#include <stdlib.h>
+
+using namespace android;
+using namespace RSC;
+
+const uint32_t DIMX = 128;
+const uint32_t DIMY = 128;
+
+int test_compute()
+{
+ bool failed = false;
+
+ sp<RS> rs = new RS();
+ printf("New RS %p\n", rs.get());
+
+ // only legitimate because this is a standalone executable
+ bool r = rs->init("/system/bin");
+ printf("Init returned %i\n", r);
+
+ sp<const Element> e = Element::U32(rs);
+ printf("Element %p\n", e.get());
+
+ Type::Builder tb(rs, e);
+ tb.setX(DIMX);
+ tb.setY(DIMY);
+ sp<const Type> t = tb.create();
+ printf("Type %p\n", t.get());
+
+
+ sp<Allocation> a1 = Allocation::createSized(rs, e, 1000);
+ printf("Allocation %p\n", a1.get());
+
+ sp<Allocation> ain = Allocation::createTyped(rs, t, RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_SHARED);
+ sp<Allocation> aout = Allocation::createTyped(rs, t, RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_SHARED);
+ printf("Allocation %p %p\n", ain.get(), aout.get());
+
+ size_t inputStride, outputStride;
+
+ uint32_t *input = (uint32_t*)ain->getPointer(&inputStride);
+ uint32_t *output = (uint32_t*)aout->getPointer(&outputStride);
+
+ printf("Input pointer: %p\n", input);
+ printf("Input stride: %u\n", inputStride);
+ printf("Output pointer: %p\n", output);
+ printf("Output stride: %u\n", outputStride);
+
+ inputStride /= sizeof(uint32_t);
+ outputStride /= sizeof(uint32_t);
+
+ for (size_t i = 0; i < DIMY; i++) {
+ for (size_t j = 0; j < DIMX; j++) {
+ input[i * inputStride + j] = rand();
+ output[i * inputStride + j] = 0;
+ }
+ }
+
+ ain->syncAll(RS_ALLOCATION_USAGE_SHARED);
+ aout->syncAll(RS_ALLOCATION_USAGE_SHARED);
+
+ printf("Launching script\n");
+
+ sp<ScriptC_mono> sc = new ScriptC_mono(rs);
+ sc->forEach_copyAndNot(ain, aout);
+ rs->finish();
+
+ printf("Script completed\n");
+
+ ain->syncAll(RS_ALLOCATION_USAGE_SCRIPT);
+ aout->syncAll(RS_ALLOCATION_USAGE_SCRIPT);
+
+ for (size_t i = 0; i < DIMY; i++) {
+ for (size_t j = 0; j < DIMX; j++) {
+ if (input[i * inputStride + j] != ~(output[i * inputStride + j])) {
+ printf("Mismatch at location %u, %u\n", j, i);
+ failed = true;
+ return failed;
+ }
+ }
+ }
+
+
+ return failed;
+}
+
+int main() {
+ bool failed = test_compute();
+
+ if (failed) {
+ printf("TEST FAILED!\n");
+ } else {
+ printf("TEST PASSED!\n");
+ }
+
+ return failed;
+}
diff --git a/tests/cppbasic-getpointer/mono.rs b/tests/cppbasic-getpointer/mono.rs
new file mode 100644
index 0000000..25e60df
--- /dev/null
+++ b/tests/cppbasic-getpointer/mono.rs
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
+#pragma version(1)
+#pragma rs java_package_name(com.android.rs.cppbasic)
+#pragma rs_fp_relaxed
+
+uint32_t __attribute__((kernel)) copyAndNot(uint32_t in) {
+ return ~in;
+}