summaryrefslogtreecommitdiff
path: root/libs/rs/rsAllocation.cpp
diff options
context:
space:
mode:
author Jason Sams <rjsams@android.com> 2010-08-09 18:13:33 -0700
committer Jason Sams <rjsams@android.com> 2010-08-09 18:13:33 -0700
commitb28ca96fd69be0d3d12106f81c415439d185b017 (patch)
tree827b9e5aced31b103fdacb7d01d14fbc9f966b34 /libs/rs/rsAllocation.cpp
parent05716aa0a1f42b72e04a2f41d565f3ca6c3aea1e (diff)
Refcounting in allocations.
Change-Id: Ida2dfb404b2cd832e622d981d73a938d5bc5b821
Diffstat (limited to 'libs/rs/rsAllocation.cpp')
-rw-r--r--libs/rs/rsAllocation.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp
index 6560101e6a89..d62fa554093d 100644
--- a/libs/rs/rsAllocation.cpp
+++ b/libs/rs/rsAllocation.cpp
@@ -234,6 +234,12 @@ void Allocation::data(const void *data, uint32_t sizeBytes)
LOGE("Allocation::data called with mismatched size expected %i, got %i", size, sizeBytes);
return;
}
+
+ if (mType->getElement()->getHasReferences()) {
+ incRefs(data, sizeBytes / mType->getElement()->getSizeBytes());
+ decRefs(mPtr, sizeBytes / mType->getElement()->getSizeBytes());
+ }
+
memcpy(mPtr, data, size);
sendDirty();
mUploadDefered = true;
@@ -256,6 +262,12 @@ void Allocation::subData(uint32_t xoff, uint32_t count, const void *data, uint32
mType->dumpLOGV("type info");
return;
}
+
+ if (mType->getElement()->getHasReferences()) {
+ incRefs(data, count);
+ decRefs(ptr, count);
+ }
+
memcpy(ptr, data, size);
sendDirty();
mUploadDefered = true;
@@ -279,6 +291,10 @@ void Allocation::subData(uint32_t xoff, uint32_t yoff,
for (uint32_t line=yoff; line < (yoff+h); line++) {
uint8_t * ptr = static_cast<uint8_t *>(mPtr);
+ if (mType->getElement()->getHasReferences()) {
+ incRefs(src, w);
+ decRefs(dst, w);
+ }
memcpy(dst, src, lineSize);
src += lineSize;
dst += destW * eSize;
@@ -387,6 +403,32 @@ void Allocation::sendDirty() const
}
}
+void Allocation::incRefs(const void *ptr, size_t ct) const
+{
+ const uint8_t *p = static_cast<const uint8_t *>(ptr);
+ const Element *e = mType->getElement();
+ uint32_t stride = e->getSizeBytes();
+
+ while (ct > 0) {
+ e->incRefs(p);
+ ct --;
+ p += stride;
+ }
+}
+
+void Allocation::decRefs(const void *ptr, size_t ct) const
+{
+ const uint8_t *p = static_cast<const uint8_t *>(ptr);
+ const Element *e = mType->getElement();
+ uint32_t stride = e->getSizeBytes();
+
+ while (ct > 0) {
+ e->decRefs(p);
+ ct --;
+ p += stride;
+ }
+}
+
/////////////////
//