From: subhransu mohanty Date: Thu, 1 Aug 2019 01:52:12 +0000 (+0900) Subject: optimization: move rare propery field to extra structure to minimize memory footprint... X-Git-Tag: submit/tizen/20190812.090759~12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c4dc9a64ecb3b8287be7d487d1d910d96c454ba4;p=platform%2Fcore%2Fuifw%2Flottie-player.git optimization: move rare propery field to extra structure to minimize memory footprint of LOTTransformData. - only layer transform object can have position property as separate X and Y by keeping them in the main structure incurs an overhead of 32 bytes to the user of the structure. as well as 8 byte on the book keeping (mSeparate) by moving those rarely used field along with 3D data to ExtraData we could trim the object size by 40bytes. - with this patch now the object size is reduced from 128 bytes to 88bytes. --- diff --git a/src/lottie/lottiemodel.cpp b/src/lottie/lottiemodel.cpp index 4c6b7e3..ab7e984 100644 --- a/src/lottie/lottiemodel.cpp +++ b/src/lottie/lottiemodel.cpp @@ -111,19 +111,19 @@ VMatrix TransformData::matrix(int frameNo, bool autoOrient) const { VMatrix m; VPointF position; - if (mSeparate) { - position.setX(mX.value(frameNo)); - position.setY(mY.value(frameNo)); + if (mExtra && mExtra->mSeparate) { + position.setX(mExtra->mSeparateX.value(frameNo)); + position.setY(mExtra->mSeparateY.value(frameNo)); } else { position = mPosition.value(frameNo); } float angle = autoOrient ? mPosition.angle(frameNo) : 0; - if (m3D) { + if (mExtra && mExtra->m3DData) { m.translate(position) - .rotate(m3D->mRz.value(frameNo) + angle) - .rotate(m3D->mRy.value(frameNo), VMatrix::Axis::Y) - .rotate(m3D->mRx.value(frameNo), VMatrix::Axis::X) + .rotate(mExtra->m3DRz.value(frameNo) + angle) + .rotate(mExtra->m3DRy.value(frameNo), VMatrix::Axis::Y) + .rotate(mExtra->m3DRx.value(frameNo), VMatrix::Axis::X) .scale(mScale.value(frameNo) / 100.f) .translate(-mAnchor.value(frameNo)); } else { diff --git a/src/lottie/lottiemodel.h b/src/lottie/lottiemodel.h index 550a003..db66ebb 100644 --- a/src/lottie/lottiemodel.h +++ b/src/lottie/lottiemodel.h @@ -423,37 +423,40 @@ struct LOTAsset VBitmap mBitmap; }; -struct LOT3DData +struct TransformDataExtra { - LOTAnimatable mRx{0}; - LOTAnimatable mRy{0}; - LOTAnimatable mRz{0}; + LOTAnimatable m3DRx{0}; + LOTAnimatable m3DRy{0}; + LOTAnimatable m3DRz{0}; + LOTAnimatable mSeparateX{0}; + LOTAnimatable mSeparateY{0}; + bool mSeparate{false}; + bool m3DData{false}; }; struct TransformData { VMatrix matrix(int frameNo, bool autoOrient = false) const; float opacity(int frameNo) const { return mOpacity.value(frameNo)/100.0f; } - bool isStatic() const { return mStatic;} - std::unique_ptr m3D; - LOTAnimatable mRotation{0}; /* "r" */ - LOTAnimatable mScale{{100, 100}}; /* "s" */ - LOTAnimatable mPosition; /* "p" */ - LOTAnimatable mX{0}; - LOTAnimatable mY{0}; - LOTAnimatable mAnchor; /* "a" */ - LOTAnimatable mOpacity{100}; /* "o" */ - bool mSeparate{false}; - bool mStatic{false}; + void createExtraData() + { + if (!mExtra) mExtra = std::make_unique(); + } + LOTAnimatable mRotation{0}; /* "r" */ + LOTAnimatable mScale{{100, 100}}; /* "s" */ + LOTAnimatable mPosition; /* "p" */ + LOTAnimatable mAnchor; /* "a" */ + LOTAnimatable mOpacity{100}; /* "o" */ + std::unique_ptr mExtra; }; class LOTTransformData : public LOTData { public: LOTTransformData():LOTData(LOTData::Type::Transform){} - void set(std::unique_ptr data) + void set(std::unique_ptr data, bool staticFlag) { - setStatic(data->isStatic()); + setStatic(staticFlag); if (isStatic()) { new (&impl.mStaticData) static_data(data->matrix(0), data->opacity(0)); } else { diff --git a/src/lottie/lottieparser.cpp b/src/lottie/lottieparser.cpp index 3d84a4f..7212e03 100644 --- a/src/lottie/lottieparser.cpp +++ b/src/lottie/lottieparser.cpp @@ -1387,7 +1387,10 @@ std::shared_ptr LottieParserImpl::parseTransformObject( std::make_shared(); auto obj = std::make_unique(); - if (ddd) obj->m3D = std::make_unique(); + if (ddd) { + obj->createExtraData(); + obj->mExtra->m3DData = true; + } while (const char *key = NextObjectKey()) { if (0 == strcmp(key, "nm")) { @@ -1396,15 +1399,18 @@ std::shared_ptr LottieParserImpl::parseTransformObject( parseProperty(obj->mAnchor); } else if (0 == strcmp(key, "p")) { EnterObject(); + bool separate = false; while (const char *key = NextObjectKey()) { if (0 == strcmp(key, "k")) { parsePropertyHelper(obj->mPosition); } else if (0 == strcmp(key, "s")) { - obj->mSeparate = GetBool(); - } else if (obj->mSeparate && (0 == strcmp(key, "x"))) { - parseProperty(obj->mX); - } else if (obj->mSeparate && (0 == strcmp(key, "y"))) { - parseProperty(obj->mY); + obj->createExtraData(); + obj->mExtra->mSeparate = GetBool(); + separate = true; + } else if (separate && (0 == strcmp(key, "x"))) { + parseProperty(obj->mExtra->mSeparateX); + } else if (separate && (0 == strcmp(key, "y"))) { + parseProperty(obj->mExtra->mSeparateY); } else { Skip(key); } @@ -1418,25 +1424,28 @@ std::shared_ptr LottieParserImpl::parseTransformObject( } else if (0 == strcmp(key, "hd")) { sharedTransform->mHidden = GetBool(); } else if (0 == strcmp(key, "rx")) { - parseProperty(obj->m3D->mRx); + parseProperty(obj->mExtra->m3DRx); } else if (0 == strcmp(key, "ry")) { - parseProperty(obj->m3D->mRy); + parseProperty(obj->mExtra->m3DRy); } else if (0 == strcmp(key, "rz")) { - parseProperty(obj->m3D->mRz); + parseProperty(obj->mExtra->m3DRz); } else { Skip(key); } } - obj->mStatic = obj->mAnchor.isStatic() && obj->mPosition.isStatic() && - obj->mRotation.isStatic() && obj->mScale.isStatic() && - obj->mX.isStatic() && obj->mY.isStatic() && - obj->mOpacity.isStatic(); - if (obj->m3D) { - obj->mStatic = obj->mStatic && obj->m3D->mRx.isStatic() && - obj->m3D->mRy.isStatic() && obj->m3D->mRz.isStatic(); + bool isStatic = obj->mAnchor.isStatic() && obj->mPosition.isStatic() && + obj->mRotation.isStatic() && obj->mScale.isStatic() && + obj->mOpacity.isStatic(); + if (obj->mExtra) { + isStatic = isStatic && + obj->mExtra->m3DRx.isStatic() && + obj->mExtra->m3DRy.isStatic() && + obj->mExtra->m3DRz.isStatic() && + obj->mExtra->mSeparateX.isStatic() && + obj->mExtra->mSeparateY.isStatic(); } - sharedTransform->set(std::move(obj)); + sharedTransform->set(std::move(obj), isStatic); return sharedTransform; }