From 6e068c0182f6f85bccb855a647510724d1c65a13 Mon Sep 17 00:00:00 2001 From: Chris Craik Date: Fri, 15 Jan 2016 16:15:30 -0800 Subject: Early kickoff of shadow tasks bug:26562703 Change-Id: I7cdf18f2c662380bd31c7ffeefd5c3f569e5c1c6 --- libs/hwui/TessellationCache.cpp | 64 ++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 40 deletions(-) (limited to 'libs/hwui/TessellationCache.cpp') diff --git a/libs/hwui/TessellationCache.cpp b/libs/hwui/TessellationCache.cpp index 0835c29aee97..461e8190c974 100644 --- a/libs/hwui/TessellationCache.cpp +++ b/libs/hwui/TessellationCache.cpp @@ -160,45 +160,6 @@ private: // Shadow tessellation task processing /////////////////////////////////////////////////////////////////////////////// -class ShadowTask : public Task { -public: - ShadowTask(const Matrix4* drawTransform, const Rect& localClip, bool opaque, - const SkPath* casterPerimeter, const Matrix4* transformXY, const Matrix4* transformZ, - const Vector3& lightCenter, float lightRadius) - : drawTransform(*drawTransform) - , localClip(localClip) - , opaque(opaque) - , casterPerimeter(*casterPerimeter) - , transformXY(*transformXY) - , transformZ(*transformZ) - , lightCenter(lightCenter) - , lightRadius(lightRadius) { - } - - ~ShadowTask() { - TessellationCache::vertexBuffer_pair_t* bufferPair = getResult(); - delete bufferPair->getFirst(); - delete bufferPair->getSecond(); - delete bufferPair; - } - - /* 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 tasks - * before tearning down single-frame LinearAllocators. - */ - const Matrix4 drawTransform; - const Rect localClip; - bool opaque; - const SkPath casterPerimeter; - const Matrix4 transformXY; - const Matrix4 transformZ; - const Vector3 lightCenter; - const float lightRadius; -}; - static void mapPointFakeZ(Vector3& point, const mat4* transformXY, const mat4* transformZ) { // map z coordinate with true 3d matrix point.z = transformZ->mapZ(point); @@ -288,7 +249,7 @@ public: ~ShadowProcessor() {} virtual void onProcess(const sp >& task) override { - ShadowTask* t = static_cast(task.get()); + TessellationCache::ShadowTask* t = static_cast(task.get()); ATRACE_NAME("shadow tessellation"); VertexBuffer* ambientBuffer = new VertexBuffer; @@ -415,6 +376,29 @@ void TessellationCache::getShadowBuffers(const Matrix4* drawTransform, const Rec outBuffers = *(task->getResult()); } +sp TessellationCache::getShadowTask( + const Matrix4* drawTransform, const Rect& localClip, + bool opaque, const SkPath* casterPerimeter, + const Matrix4* transformXY, const Matrix4* transformZ, + const Vector3& lightCenter, float lightRadius) { + ShadowDescription key(casterPerimeter, drawTransform); + ShadowTask* task = static_cast(mShadowCache.get(key)); + if (!task) { + precacheShadows(drawTransform, localClip, opaque, casterPerimeter, + transformXY, transformZ, lightCenter, lightRadius); + task = static_cast(mShadowCache.get(key)); + } + LOG_ALWAYS_FATAL_IF(task == nullptr, "shadow not precached"); + return task; +} + +TessellationCache::ShadowTask::~ShadowTask() { + TessellationCache::vertexBuffer_pair_t* bufferPair = getResult(); + delete bufferPair->getFirst(); + delete bufferPair->getSecond(); + delete bufferPair; +} + /////////////////////////////////////////////////////////////////////////////// // Tessellation precaching /////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3-59-g8ed1b