Skip to content

Commit

Permalink
rlottie: ran clang-format with the latest code
Browse files Browse the repository at this point in the history
  • Loading branch information
smohantty committed Jun 24, 2019
1 parent 9c1cba0 commit b2ded24
Show file tree
Hide file tree
Showing 26 changed files with 1,009 additions and 982 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
Language: Cpp
# BasedOnStyle: Tizen
BasedOnStyle: Google
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
Expand Down
165 changes: 80 additions & 85 deletions src/lottie/lottieanimation.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
/*
/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "config.h"
#include "rlottie.h"
#include "lottieitem.h"
#include "lottieloader.h"
#include "lottiemodel.h"
#include "rlottie.h"

#include <fstream>

Expand All @@ -29,30 +29,32 @@ struct RenderTask {
RenderTask() { receiver = sender.get_future(); }
std::promise<Surface> sender;
std::future<Surface> receiver;
AnimationImpl *playerImpl{nullptr};
size_t frameNo{0};
Surface surface;
AnimationImpl * playerImpl{nullptr};
size_t frameNo{0};
Surface surface;
};
using SharedRenderTask = std::shared_ptr<RenderTask>;

class AnimationImpl {

public:
void init(const std::shared_ptr<LOTModel> &model);
bool update(size_t frameNo, const VSize &size);
VSize size() const {return mCompItem->size();}
double duration() const {return mModel->duration();}
double frameRate() const {return mModel->frameRate();}
size_t totalFrame() const {return mModel->totalFrame();}
size_t frameAtPos(double pos) const {return mModel->frameAtPos(pos);}
VSize size() const { return mCompItem->size(); }
double duration() const { return mModel->duration(); }
double frameRate() const { return mModel->frameRate(); }
size_t totalFrame() const { return mModel->totalFrame(); }
size_t frameAtPos(double pos) const { return mModel->frameAtPos(pos); }
Surface render(size_t frameNo, const Surface &surface);
std::future<Surface> renderAsync(size_t frameNo, Surface &&surface);
const LOTLayerNode *
renderTree(size_t frameNo, const VSize &size);
const LOTLayerNode * renderTree(size_t frameNo, const VSize &size);

const LayerInfoList& layerInfoList() const { return mModel->layerInfoList();}
const LayerInfoList &layerInfoList() const
{
return mModel->layerInfoList();
}
void setValue(const std::string &keypath, LOTVariant &&value);
void removeFilter(const std::string &keypath, Property prop);

private:
std::string mFilePath;
std::shared_ptr<LOTModel> mModel;
Expand All @@ -70,36 +72,34 @@ void AnimationImpl::setValue(const std::string &keypath, LOTVariant &&value)
const LOTLayerNode *AnimationImpl::renderTree(size_t frameNo, const VSize &size)
{
if (update(frameNo, size)) {
mCompItem->buildRenderTree();
mCompItem->buildRenderTree();
}
return mCompItem->renderTree();
}

bool AnimationImpl::update(size_t frameNo, const VSize &size)
{
frameNo += mModel->startFrame();
frameNo += mModel->startFrame();

if (frameNo > mModel->endFrame())
frameNo = mModel->endFrame();
if (frameNo > mModel->endFrame()) frameNo = mModel->endFrame();

if (frameNo < mModel->startFrame())
frameNo = mModel->startFrame();
if (frameNo < mModel->startFrame()) frameNo = mModel->startFrame();

mCompItem->resize(size);
return mCompItem->update(frameNo);
mCompItem->resize(size);
return mCompItem->update(frameNo);
}

Surface AnimationImpl::render(size_t frameNo, const Surface &surface)
{
bool renderInProgress = mRenderInProgress.load();
if (renderInProgress)
{
if (renderInProgress) {
vCritical << "Already Rendering Scheduled for this Animation";
return surface;
}
}

mRenderInProgress.store(true);
update(frameNo, VSize(surface.drawRegionWidth(), surface.drawRegionHeight()));
update(frameNo,
VSize(surface.drawRegionWidth(), surface.drawRegionHeight()));
mCompItem->render(surface);
mRenderInProgress.store(false);

Expand All @@ -115,8 +115,8 @@ void AnimationImpl::init(const std::shared_ptr<LOTModel> &model)

#ifdef LOTTIE_THREAD_SUPPORT

#include "vtaskqueue.h"
#include <thread>
#include "vtaskqueue.h"

/*
* Implement a task stealing schduler to perform render task
Expand All @@ -133,12 +133,12 @@ class RenderTaskScheduler {
const unsigned _count{std::thread::hardware_concurrency()};
std::vector<std::thread> _threads;
std::vector<TaskQueue<SharedRenderTask>> _q{_count};
std::atomic<unsigned> _index{0};
std::atomic<unsigned> _index{0};

void run(unsigned i)
{
while (true) {
bool success = false;
bool success = false;
SharedRenderTask task;
for (unsigned n = 0; n != _count * 32; ++n) {
if (_q[(i + n) % _count].try_pop(task)) {
Expand All @@ -148,7 +148,8 @@ class RenderTaskScheduler {
}
if (!success && !_q[i].pop(task)) break;

auto result = task->playerImpl->render(task->frameNo, task->surface);
auto result =
task->playerImpl->render(task->frameNo, task->surface);
task->sender.set_value(result);
}
}
Expand All @@ -161,10 +162,10 @@ class RenderTaskScheduler {
}

public:
static RenderTaskScheduler& instance()
static RenderTaskScheduler &instance()
{
static RenderTaskScheduler singleton;
return singleton;
static RenderTaskScheduler singleton;
return singleton;
}

~RenderTaskScheduler()
Expand Down Expand Up @@ -194,10 +195,10 @@ class RenderTaskScheduler {
#else
class RenderTaskScheduler {
public:
static RenderTaskScheduler& instance()
static RenderTaskScheduler &instance()
{
static RenderTaskScheduler singleton;
return singleton;
static RenderTaskScheduler singleton;
return singleton;
}

std::future<Surface> process(SharedRenderTask task)
Expand All @@ -209,8 +210,8 @@ class RenderTaskScheduler {
};
#endif


std::future<Surface> AnimationImpl::renderAsync(size_t frameNo, Surface &&surface)
std::future<Surface> AnimationImpl::renderAsync(size_t frameNo,
Surface &&surface)
{
if (!mTask) {
mTask = std::make_shared<RenderTask>();
Expand All @@ -230,8 +231,9 @@ std::future<Surface> AnimationImpl::renderAsync(size_t frameNo, Surface &&surfac
* Description about the setFilePath Api
* @param path add the details
*/
std::unique_ptr<Animation>
Animation::loadFromData(std::string jsonData, const std::string &key, const std::string &resourcePath)
std::unique_ptr<Animation> Animation::loadFromData(
std::string jsonData, const std::string &key,
const std::string &resourcePath)
{
if (jsonData.empty()) {
vWarning << "jason data is empty";
Expand All @@ -248,8 +250,7 @@ Animation::loadFromData(std::string jsonData, const std::string &key, const std:
return nullptr;
}

std::unique_ptr<Animation>
Animation::loadFromFile(const std::string &path)
std::unique_ptr<Animation> Animation::loadFromFile(const std::string &path)
{
if (path.empty()) {
vWarning << "File path is empty";
Expand Down Expand Up @@ -293,8 +294,8 @@ size_t Animation::frameAtPos(double pos)
return d->frameAtPos(pos);
}

const LOTLayerNode *
Animation::renderTree(size_t frameNo, size_t width, size_t height) const
const LOTLayerNode *Animation::renderTree(size_t frameNo, size_t width,
size_t height) const
{
return d->renderTree(frameNo, VSize(width, height));
}
Expand All @@ -309,98 +310,92 @@ void Animation::renderSync(size_t frameNo, Surface surface)
d->render(frameNo, surface);
}

const LayerInfoList& Animation::layers() const
const LayerInfoList &Animation::layers() const
{
return d->layerInfoList();
}

void Animation::setValue(Color_Type,Property prop,
const std::string &keypath,
void Animation::setValue(Color_Type, Property prop, const std::string &keypath,
Color value)
{
d->setValue(keypath, LOTVariant(prop, [value](const FrameInfo &){ return value;}));
d->setValue(keypath,
LOTVariant(prop, [value](const FrameInfo &) { return value; }));
}

void Animation::setValue(Float_Type, Property prop,
const std::string &keypath,
void Animation::setValue(Float_Type, Property prop, const std::string &keypath,
float value)
{
d->setValue(keypath, LOTVariant(prop, [value](const FrameInfo &){ return value;}));
d->setValue(keypath,
LOTVariant(prop, [value](const FrameInfo &) { return value; }));
}

void Animation::setValue(Size_Type,Property prop,
const std::string &keypath,
void Animation::setValue(Size_Type, Property prop, const std::string &keypath,
Size value)
{
d->setValue(keypath, LOTVariant(prop, [value](const FrameInfo &){ return value;}));
d->setValue(keypath,
LOTVariant(prop, [value](const FrameInfo &) { return value; }));
}

void Animation::setValue(Point_Type, Property prop,
const std::string &keypath,
void Animation::setValue(Point_Type, Property prop, const std::string &keypath,
Point value)
{
d->setValue(keypath, LOTVariant(prop, [value](const FrameInfo &){ return value;}));
d->setValue(keypath,
LOTVariant(prop, [value](const FrameInfo &) { return value; }));
}

void Animation::setValue(Color_Type,Property prop,
const std::string &keypath,
std::function<Color(const FrameInfo &)> && value)
void Animation::setValue(Color_Type, Property prop, const std::string &keypath,
std::function<Color(const FrameInfo &)> &&value)
{
d->setValue(keypath, LOTVariant(prop, value));
}

void Animation::setValue(Float_Type, Property prop,
const std::string &keypath,
std::function<float(const FrameInfo &)> && value)
void Animation::setValue(Float_Type, Property prop, const std::string &keypath,
std::function<float(const FrameInfo &)> &&value)
{
d->setValue(keypath, LOTVariant(prop, value));
}

void Animation::setValue(Size_Type,Property prop,
const std::string &keypath,
std::function<Size(const FrameInfo &)> && value)
void Animation::setValue(Size_Type, Property prop, const std::string &keypath,
std::function<Size(const FrameInfo &)> &&value)
{
d->setValue(keypath, LOTVariant(prop, value));
}

void Animation::setValue(Point_Type, Property prop,
const std::string &keypath,
std::function<Point(const FrameInfo &)> && value)
void Animation::setValue(Point_Type, Property prop, const std::string &keypath,
std::function<Point(const FrameInfo &)> &&value)
{
d->setValue(keypath, LOTVariant(prop, value));
}

Animation::Animation(): d(std::make_unique<AnimationImpl>()) {}
Animation::Animation() : d(std::make_unique<AnimationImpl>()) {}

/*
* this is only to supress build fail
* because unique_ptr expects the destructor in the same translation unit.
*/
Animation::~Animation(){}

Surface::Surface(uint32_t *buffer,
size_t width, size_t height, size_t bytesPerLine)
:mBuffer(buffer),
mWidth(width),
mHeight(height),
mBytesPerLine(bytesPerLine)
Animation::~Animation() {}

Surface::Surface(uint32_t *buffer, size_t width, size_t height,
size_t bytesPerLine)
: mBuffer(buffer),
mWidth(width),
mHeight(height),
mBytesPerLine(bytesPerLine)
{
mDrawArea.w = mWidth;
mDrawArea.h = mHeight;
}

void Surface::setDrawRegion(size_t x, size_t y, size_t width, size_t height)
{
if ((x + width > mWidth) ||
(y + height > mHeight)) return;
if ((x + width > mWidth) || (y + height > mHeight)) return;

mDrawArea.x = x;
mDrawArea.y = y;
mDrawArea.w = width;
mDrawArea.h = height;
}


#ifdef LOTTIE_LOGGING_SUPPORT
void initLogging()
{
Expand Down
Loading

0 comments on commit b2ded24

Please sign in to comment.