diff --git a/libs/hwui/BakedOpDispatcher.cpp b/libs/hwui/BakedOpDispatcher.cpp index ca1f8f94f382f..12e64f6a5bd12 100644 --- a/libs/hwui/BakedOpDispatcher.cpp +++ b/libs/hwui/BakedOpDispatcher.cpp @@ -663,7 +663,7 @@ static void renderShadow(BakedOpRenderer& renderer, const BakedOpState& state, f } void BakedOpDispatcher::onShadowOp(BakedOpRenderer& renderer, const ShadowOp& op, const BakedOpState& state) { - TessellationCache::vertexBuffer_pair_t buffers = *(op.shadowTask->getResult()); + TessellationCache::vertexBuffer_pair_t buffers = op.shadowTask->getResult(); renderShadow(renderer, state, op.casterAlpha, buffers.first, buffers.second); } diff --git a/libs/hwui/TessellationCache.cpp b/libs/hwui/TessellationCache.cpp index 461e8190c9746..fd9fb852171cb 100644 --- a/libs/hwui/TessellationCache.cpp +++ b/libs/hwui/TessellationCache.cpp @@ -242,23 +242,21 @@ void tessellateShadows( spotBuffer); } -class ShadowProcessor : public TaskProcessor { +class ShadowProcessor : public TaskProcessor { public: ShadowProcessor(Caches& caches) - : TaskProcessor(&caches.tasks) {} + : TaskProcessor(&caches.tasks) {} ~ShadowProcessor() {} - virtual void onProcess(const sp >& task) override { + virtual void onProcess(const sp >& task) override { TessellationCache::ShadowTask* t = static_cast(task.get()); ATRACE_NAME("shadow tessellation"); - VertexBuffer* ambientBuffer = new VertexBuffer; - VertexBuffer* spotBuffer = new VertexBuffer; tessellateShadows(&t->drawTransform, &t->localClip, t->opaque, &t->casterPerimeter, &t->transformXY, &t->transformZ, t->lightCenter, t->lightRadius, - *ambientBuffer, *spotBuffer); + t->ambientBuffer, t->spotBuffer); - t->setResult(new TessellationCache::vertexBuffer_pair_t(ambientBuffer, spotBuffer)); + t->setResult(TessellationCache::vertexBuffer_pair_t(&t->ambientBuffer, &t->spotBuffer)); } }; @@ -373,7 +371,7 @@ void TessellationCache::getShadowBuffers(const Matrix4* drawTransform, const Rec task = static_cast(mShadowCache.get(key)); } LOG_ALWAYS_FATAL_IF(task == nullptr, "shadow not precached"); - outBuffers = *(task->getResult()); + outBuffers = task->getResult(); } sp TessellationCache::getShadowTask( @@ -392,13 +390,6 @@ sp TessellationCache::getShadowTask( return task; } -TessellationCache::ShadowTask::~ShadowTask() { - TessellationCache::vertexBuffer_pair_t* bufferPair = getResult(); - delete bufferPair->getFirst(); - delete bufferPair->getSecond(); - delete bufferPair; -} - /////////////////////////////////////////////////////////////////////////////// // Tessellation precaching /////////////////////////////////////////////////////////////////////////////// diff --git a/libs/hwui/TessellationCache.h b/libs/hwui/TessellationCache.h index 977c2d9e9f8aa..6dcc8120cf481 100644 --- a/libs/hwui/TessellationCache.h +++ b/libs/hwui/TessellationCache.h @@ -21,6 +21,7 @@ #include "Matrix.h" #include "Rect.h" #include "Vector.h" +#include "VertexBuffer.h" #include "thread/TaskProcessor.h" #include "utils/Macros.h" #include "utils/Pair.h" @@ -89,7 +90,7 @@ public: hash_t hash() const; }; - class ShadowTask : public Task { + class ShadowTask : public Task { public: ShadowTask(const Matrix4* drawTransform, const Rect& localClip, bool opaque, const SkPath* casterPerimeter, const Matrix4* transformXY, const Matrix4* transformZ, @@ -104,13 +105,11 @@ public: , lightRadius(lightRadius) { } - ~ShadowTask(); - /* Note - we deep copy all task parameters, because *even though* pointers into Allocator * controlled objects (like the SkPath and Matrix4s) should be safe for the entire frame, * certain Allocators are destroyed before trim() is called to flush incomplete tasks. * - * These deep copies could be avoided, long term, by cancelling or flushing outstanding + * These deep copies could be avoided, long term, by canceling or flushing outstanding * tasks before tearing down single-frame LinearAllocators. */ const Matrix4 drawTransform; @@ -121,6 +120,8 @@ public: const Matrix4 transformZ; const Vector3 lightCenter; const float lightRadius; + VertexBuffer ambientBuffer; + VertexBuffer spotBuffer; }; TessellationCache(); @@ -217,12 +218,12 @@ private: /////////////////////////////////////////////////////////////////////////////// // Shadow tessellation caching /////////////////////////////////////////////////////////////////////////////// - sp > mShadowProcessor; + sp > mShadowProcessor; // holds a pointer, and implicit strong ref to each shadow task of the frame - LruCache*> mShadowCache; - class BufferPairRemovedListener : public OnEntryRemoved*> { - void operator()(ShadowDescription& description, Task*& bufferPairTask) override { + LruCache*> mShadowCache; + class BufferPairRemovedListener : public OnEntryRemoved*> { + void operator()(ShadowDescription& description, Task*& bufferPairTask) override { bufferPairTask->decStrong(nullptr); } };