summaryrefslogtreecommitdiff
path: root/cpp/Allocation.cpp
diff options
context:
space:
mode:
authorMiao Wang <miaowang@google.com>2015-03-18 20:09:20 -0700
committerMiao Wang <miaowang@google.com>2015-04-07 13:15:39 -0700
commit09d2dd26af70a16de928e7450ef500a61c5b810a (patch)
tree0704269905aea45ec480e920ebf736108e6287a5 /cpp/Allocation.cpp
parent8a38a04f62281dbb9cdf18ae248615b0ee20608a (diff)
Add setSurface() and getSurface() to RScpp.
Change-Id: I53ac88ce3f482e01bd70df57a1aaf0b71b1f49af
Diffstat (limited to 'cpp/Allocation.cpp')
-rw-r--r--cpp/Allocation.cpp70
1 files changed, 49 insertions, 21 deletions
diff --git a/cpp/Allocation.cpp b/cpp/Allocation.cpp
index 85304404..cae51911 100644
--- a/cpp/Allocation.cpp
+++ b/cpp/Allocation.cpp
@@ -20,6 +20,7 @@
using namespace android;
using namespace RSC;
+
void * Allocation::getIDSafe() const {
return getID();
}
@@ -164,27 +165,6 @@ void Allocation::syncAll(RsAllocationUsageType srcLocation) {
tryDispatch(mRS, RS::dispatch->AllocationSyncAll(mRS->getContext(), getIDSafe(), srcLocation));
}
-void Allocation::ioSendOutput() {
-//TODO: Also make it able to use for compatlib.
-#ifndef RS_COMPATIBILITY_LIB
- if ((mUsage & RS_ALLOCATION_USAGE_IO_OUTPUT) == 0) {
- mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Can only send buffer if IO_OUTPUT usage specified.");
- return;
- }
- tryDispatch(mRS, RS::dispatch->AllocationIoSend(mRS->getContext(), getID()));
-#endif
-}
-
-void Allocation::ioGetInput() {
-#ifndef RS_COMPATIBILITY_LIB
- if ((mUsage & RS_ALLOCATION_USAGE_IO_INPUT) == 0) {
- mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Can only get buffer if IO_INPUT usage specified.");
- return;
- }
- tryDispatch(mRS, RS::dispatch->AllocationIoReceive(mRS->getContext(), getID()));
-#endif
-}
-
void * Allocation::getPointer(size_t *stride) {
void *p = nullptr;
if (!(mUsage & RS_ALLOCATION_USAGE_SHARED)) {
@@ -492,3 +472,51 @@ sp<Allocation> Allocation::createSized2D(sp<RS> rs, sp<const Element> e,
return createTyped(rs, t, usage);
}
+
+void Allocation::ioSendOutput() {
+#ifndef RS_COMPATIBILITY_LIB
+ if ((mUsage & RS_ALLOCATION_USAGE_IO_OUTPUT) == 0) {
+ mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Can only send buffer if IO_OUTPUT usage specified.");
+ return;
+ }
+ tryDispatch(mRS, RS::dispatch->AllocationIoSend(mRS->getContext(), getID()));
+#endif
+}
+
+void Allocation::ioGetInput() {
+#ifndef RS_COMPATIBILITY_LIB
+ if ((mUsage & RS_ALLOCATION_USAGE_IO_INPUT) == 0) {
+ mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Can only get buffer if IO_INPUT usage specified.");
+ return;
+ }
+ tryDispatch(mRS, RS::dispatch->AllocationIoReceive(mRS->getContext(), getID()));
+#endif
+}
+
+#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
+#include <gui/Surface.h>
+
+RSC::sp<Surface> Allocation::getSurface() {
+ if ((mUsage & RS_ALLOCATION_USAGE_IO_INPUT) == 0) {
+ mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Can only get Surface if IO_INPUT usage specified.");
+ return nullptr;
+ }
+ IGraphicBufferProducer *v = (IGraphicBufferProducer *)RS::dispatch->AllocationGetSurface(mRS->getContext(),
+ getID());
+ android::sp<IGraphicBufferProducer> bp = v;
+ v->decStrong(nullptr);
+
+ return new Surface(bp, true);;
+}
+
+void Allocation::setSurface(RSC::sp<Surface> s) {
+ if ((mUsage & RS_ALLOCATION_USAGE_IO_OUTPUT) == 0) {
+ mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Can only set Surface if IO_OUTPUT usage specified.");
+ return;
+ }
+ tryDispatch(mRS, RS::dispatch->AllocationSetSurface(mRS->getContext(), getID(),
+ static_cast<ANativeWindow *>(s.get())));
+}
+
+#endif
+