lottie/optimization: efficient member packing in the VDrawable object.

Change-Id: I545f9a33d1cae329bc9ee140c213e07697b8cccf
This commit is contained in:
subhransu mohanty
2018-09-11 13:18:04 +09:00
parent 10e6788bb2
commit f4f2382964
5 changed files with 60 additions and 56 deletions

View File

@@ -55,7 +55,9 @@ VSize AnimationImpl::size() const
const std::vector<LOTNode *> &AnimationImpl::renderList(size_t frameNo, const VSize &size)
{
update(frameNo, size);
if (update(frameNo, size)) {
mCompItem->buildRenderList();
}
return mCompItem->renderList();
}

View File

@@ -83,7 +83,6 @@ bool LOTCompItem::update(int frameNo)
m.scale(scale, scale).translate(tx, ty);
mRootLayer->update(frameNo, m, 1.0);
buildRenderList();
mCurFrameNo = frameNo;
mUpdateViewBox = false;
return true;
@@ -98,7 +97,7 @@ void LOTCompItem::buildRenderList()
for (auto &i : mDrawableList) {
LOTDrawable *lotDrawable = static_cast<LOTDrawable *>(i);
lotDrawable->sync();
mRenderList.push_back(&lotDrawable->mCNode);
mRenderList.push_back(lotDrawable->mCNode.get());
}
}
@@ -115,6 +114,8 @@ bool LOTCompItem::render(const lottie::Surface &surface)
/* schedule all preprocess task for this frame at once.
*/
mDrawableList.clear();
mRootLayer->renderList(mDrawableList);
for (auto &e : mDrawableList) {
e->preprocess();
}
@@ -990,7 +991,9 @@ void LOTRepeaterItem::renderList(std::vector<VDrawable *> &/*list*/) {}
void LOTDrawable::sync()
{
mCNode.mFlag = ChangeFlagNone;
if (!mCNode) mCNode = std::make_unique<LOTNode>();
mCNode->mFlag = ChangeFlagNone;
if (mFlag & DirtyState::None) return;
if (mFlag & DirtyState::Path) {
@@ -998,89 +1001,89 @@ void LOTDrawable::sync()
const std::vector<VPointF> & pts = mPath.points();
const float *ptPtr = reinterpret_cast<const float *>(pts.data());
const char * elmPtr = reinterpret_cast<const char *>(elm.data());
mCNode.mPath.elmPtr = elmPtr;
mCNode.mPath.elmCount = elm.size();
mCNode.mPath.ptPtr = ptPtr;
mCNode.mPath.ptCount = 2 * pts.size();
mCNode.mFlag |= ChangeFlagPath;
mCNode->mPath.elmPtr = elmPtr;
mCNode->mPath.elmCount = elm.size();
mCNode->mPath.ptPtr = ptPtr;
mCNode->mPath.ptCount = 2 * pts.size();
mCNode->mFlag |= ChangeFlagPath;
}
if (mStroke.enable) {
mCNode.mStroke.width = mStroke.width;
mCNode.mStroke.meterLimit = mStroke.meterLimit;
mCNode.mStroke.enable = 1;
mCNode->mStroke.width = mStroke.width;
mCNode->mStroke.meterLimit = mStroke.meterLimit;
mCNode->mStroke.enable = 1;
switch (mFillRule) {
case FillRule::EvenOdd:
mCNode.mFillRule = LOTFillRule::FillEvenOdd;
mCNode->mFillRule = LOTFillRule::FillEvenOdd;
break;
default:
mCNode.mFillRule = LOTFillRule::FillWinding;
mCNode->mFillRule = LOTFillRule::FillWinding;
break;
}
switch (mStroke.cap) {
case CapStyle::Flat:
mCNode.mStroke.cap = LOTCapStyle::CapFlat;
mCNode->mStroke.cap = LOTCapStyle::CapFlat;
break;
case CapStyle::Square:
mCNode.mStroke.cap = LOTCapStyle::CapSquare;
mCNode->mStroke.cap = LOTCapStyle::CapSquare;
break;
case CapStyle::Round:
mCNode.mStroke.cap = LOTCapStyle::CapRound;
mCNode->mStroke.cap = LOTCapStyle::CapRound;
break;
default:
mCNode.mStroke.cap = LOTCapStyle::CapFlat;
mCNode->mStroke.cap = LOTCapStyle::CapFlat;
break;
}
switch (mStroke.join) {
case JoinStyle::Miter:
mCNode.mStroke.join = LOTJoinStyle::JoinMiter;
mCNode->mStroke.join = LOTJoinStyle::JoinMiter;
break;
case JoinStyle::Bevel:
mCNode.mStroke.join = LOTJoinStyle::JoinBevel;
mCNode->mStroke.join = LOTJoinStyle::JoinBevel;
break;
case JoinStyle::Round:
mCNode.mStroke.join = LOTJoinStyle::JoinRound;
mCNode->mStroke.join = LOTJoinStyle::JoinRound;
break;
default:
mCNode.mStroke.join = LOTJoinStyle::JoinMiter;
mCNode->mStroke.join = LOTJoinStyle::JoinMiter;
break;
}
mCNode.mStroke.dashArray = mStroke.mDash.data();
mCNode.mStroke.dashArraySize = mStroke.mDash.size();
mCNode->mStroke.dashArray = mStroke.mDash.data();
mCNode->mStroke.dashArraySize = mStroke.mDash.size();
} else {
mCNode.mStroke.enable = 0;
mCNode->mStroke.enable = 0;
}
switch (mBrush.type()) {
case VBrush::Type::Solid:
mCNode.mType = LOTBrushType::BrushSolid;
mCNode.mColor.r = mBrush.mColor.r;
mCNode.mColor.g = mBrush.mColor.g;
mCNode.mColor.b = mBrush.mColor.b;
mCNode.mColor.a = mBrush.mColor.a;
mCNode->mType = LOTBrushType::BrushSolid;
mCNode->mColor.r = mBrush.mColor.r;
mCNode->mColor.g = mBrush.mColor.g;
mCNode->mColor.b = mBrush.mColor.b;
mCNode->mColor.a = mBrush.mColor.a;
break;
case VBrush::Type::LinearGradient:
mCNode.mType = LOTBrushType::BrushGradient;
mCNode.mGradient.type = LOTGradientType::GradientLinear;
mCNode.mGradient.start.x = mBrush.mGradient->linear.x1;
mCNode.mGradient.start.y = mBrush.mGradient->linear.y1;
mCNode.mGradient.end.x = mBrush.mGradient->linear.x2;
mCNode.mGradient.end.y = mBrush.mGradient->linear.y2;
mCNode->mType = LOTBrushType::BrushGradient;
mCNode->mGradient.type = LOTGradientType::GradientLinear;
mCNode->mGradient.start.x = mBrush.mGradient->linear.x1;
mCNode->mGradient.start.y = mBrush.mGradient->linear.y1;
mCNode->mGradient.end.x = mBrush.mGradient->linear.x2;
mCNode->mGradient.end.y = mBrush.mGradient->linear.y2;
break;
case VBrush::Type::RadialGradient:
mCNode.mType = LOTBrushType::BrushGradient;
mCNode.mGradient.type = LOTGradientType::GradientRadial;
mCNode.mGradient.center.x = mBrush.mGradient->radial.cx;
mCNode.mGradient.center.y = mBrush.mGradient->radial.cy;
mCNode.mGradient.focal.x = mBrush.mGradient->radial.fx;
mCNode.mGradient.focal.y = mBrush.mGradient->radial.fy;
mCNode.mGradient.cradius = mBrush.mGradient->radial.cradius;
mCNode.mGradient.fradius = mBrush.mGradient->radial.fradius;
mCNode->mType = LOTBrushType::BrushGradient;
mCNode->mGradient.type = LOTGradientType::GradientRadial;
mCNode->mGradient.center.x = mBrush.mGradient->radial.cx;
mCNode->mGradient.center.y = mBrush.mGradient->radial.cy;
mCNode->mGradient.focal.x = mBrush.mGradient->radial.fx;
mCNode->mGradient.focal.y = mBrush.mGradient->radial.fy;
mCNode->mGradient.cradius = mBrush.mGradient->radial.cradius;
mCNode->mGradient.fradius = mBrush.mGradient->radial.fradius;
break;
default:
break;

View File

@@ -159,7 +159,7 @@ class LOTDrawable : public VDrawable
public:
void sync();
public:
LOTNode mCNode;
std::unique_ptr<LOTNode> mCNode;
};
class LOTPathDataItem;

View File

@@ -14,7 +14,7 @@ public:
Brush = 0x00000100,
All = (None | Path | Stroke | Brush)
};
enum class Type {
enum class Type : unsigned char{
Fill,
Stroke,
};
@@ -31,21 +31,21 @@ public:
public:
struct StrokeInfo {
bool enable{false};
std::vector<float> mDash;
float width{0.0};
float meterLimit{10};
bool enable{false};
CapStyle cap{CapStyle::Flat};
JoinStyle join{JoinStyle::Bevel};
float meterLimit{10};
std::vector<float> mDash;
};
DirtyFlag mFlag{DirtyState::All};
VDrawable::Type mType{Type::Fill};
VBrush mBrush;
VPath mPath;
FillRule mFillRule{FillRule::Winding};
std::future<VRle> mRleTask;
VRle mRle;
StrokeInfo mStroke;
DirtyFlag mFlag{DirtyState::All};
FillRule mFillRule{FillRule::Winding};
VDrawable::Type mType{Type::Fill};
};
#endif // VDRAWABLE_H

View File

@@ -266,10 +266,9 @@ public:
uchar b;
};
enum class FillRule { EvenOdd, Winding };
enum class JoinStyle { Miter, Bevel, Round };
enum class CapStyle { Flat, Square, Round };
enum class FillRule: unsigned char { EvenOdd, Winding };
enum class JoinStyle: unsigned char { Miter, Bevel, Round };
enum class CapStyle: unsigned char { Flat, Square, Round };
#ifndef V_CONSTRUCTOR_FUNCTION
#define V_CONSTRUCTOR_FUNCTION0(AFUNC) \