Note: events.cpp is still old code renamed to cpp to make it easier to call functions like gr_fb_width(). I had to modify AOSP fbdev code to provide a separate memory surface for drawing to as drawing directly to the framebuffer resulted in rendering taking about 5 times longer. I also modified AOSP adf code to provide a separate memory surface for drawing for the same performance reasons. The Nexus 9 supports adf graphics. Overlay graphics work on at least one device. Overlay provides a separate memory buffer already so performance is good. I do not have a drm device yet that I know of. I made some attempt to update the drm code to determine the correct pixel format based on the drm graphics format, but what is available in pixel flinger and what is available in drm do not line up all that well. Reports are that the Pixel C is using drm graphics, but performance is slow, likely due to the use of a mmap instead of a memory buffyer. Change-Id: Ibd45bccca6ac2cb826037aa9b2aa5065cf683eed
227 lines
4.0 KiB
C++
227 lines
4.0 KiB
C++
// progressbar.cpp - GUIProgressBar object
|
|
|
|
#include <stdarg.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <fcntl.h>
|
|
#include <sys/reboot.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/time.h>
|
|
#include <sys/mman.h>
|
|
#include <sys/types.h>
|
|
#include <sys/ioctl.h>
|
|
#include <time.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
|
|
#include <string>
|
|
|
|
extern "C" {
|
|
#include "../twcommon.h"
|
|
}
|
|
#include "../minuitwrp/minui.h"
|
|
|
|
#include "rapidxml.hpp"
|
|
#include "objects.hpp"
|
|
|
|
GUIProgressBar::GUIProgressBar(xml_node<>* node) : GUIObject(node)
|
|
{
|
|
xml_attribute<>* attr;
|
|
xml_node<>* child;
|
|
|
|
mEmptyBar = NULL;
|
|
mFullBar = NULL;
|
|
mLastPos = 0;
|
|
mSlide = 0.0;
|
|
mSlideInc = 0.0;
|
|
|
|
if (!node)
|
|
{
|
|
LOGERR("GUIProgressBar created without XML node\n");
|
|
return;
|
|
}
|
|
|
|
child = FindNode(node, "resource");
|
|
if (child)
|
|
{
|
|
mEmptyBar = LoadAttrImage(child, "empty");
|
|
mFullBar = LoadAttrImage(child, "full");
|
|
}
|
|
|
|
// Load the placement
|
|
LoadPlacement(FindNode(node, "placement"), &mRenderX, &mRenderY);
|
|
|
|
// Load the data
|
|
child = FindNode(node, "data");
|
|
if (child)
|
|
{
|
|
mMinValVar = LoadAttrString(child, "min");
|
|
mMaxValVar = LoadAttrString(child, "max");
|
|
mCurValVar = LoadAttrString(child, "name");
|
|
}
|
|
|
|
mRenderW = mEmptyBar->GetWidth();
|
|
mRenderH = mEmptyBar->GetHeight();
|
|
}
|
|
|
|
int GUIProgressBar::Render(void)
|
|
{
|
|
if(!isConditionTrue())
|
|
return 0;
|
|
|
|
// This handles making sure timing updates occur
|
|
Update();
|
|
return RenderInternal();
|
|
}
|
|
|
|
int GUIProgressBar::RenderInternal(void)
|
|
{
|
|
if (!mEmptyBar || !mEmptyBar->GetResource())
|
|
return -1;
|
|
|
|
if (!mFullBar || !mFullBar->GetResource())
|
|
return -1;
|
|
|
|
gr_blit(mEmptyBar->GetResource(), 0, 0, mRenderW, mRenderH, mRenderX, mRenderY);
|
|
gr_blit(mFullBar->GetResource(), 0, 0, mLastPos, mRenderH, mRenderX, mRenderY);
|
|
return 0;
|
|
}
|
|
|
|
int GUIProgressBar::Update(void)
|
|
{
|
|
if(!isConditionTrue())
|
|
return 0;
|
|
|
|
std::string str;
|
|
int min, max, cur, pos;
|
|
|
|
if (mMinValVar.empty())
|
|
min = 0;
|
|
else
|
|
{
|
|
str.clear();
|
|
if (atoi(mMinValVar.c_str()) != 0)
|
|
str = mMinValVar;
|
|
else
|
|
DataManager::GetValue(mMinValVar, str);
|
|
min = atoi(str.c_str());
|
|
}
|
|
|
|
if (mMaxValVar.empty())
|
|
max = 100;
|
|
else
|
|
{
|
|
str.clear();
|
|
if (atoi(mMaxValVar.c_str()) != 0)
|
|
str = mMaxValVar;
|
|
else
|
|
DataManager::GetValue(mMaxValVar, str);
|
|
max = atoi(str.c_str());
|
|
}
|
|
|
|
str.clear();
|
|
DataManager::GetValue(mCurValVar, str);
|
|
cur = atoi(str.c_str());
|
|
|
|
// Do slide, if needed
|
|
if (mSlideFrames)
|
|
{
|
|
mSlide += mSlideInc;
|
|
mSlideFrames--;
|
|
if (cur != (int) mSlide)
|
|
{
|
|
cur = (int) mSlide;
|
|
DataManager::SetValue(mCurValVar, cur);
|
|
}
|
|
}
|
|
|
|
// Normalize to 0
|
|
max -= min;
|
|
cur -= min;
|
|
min = 0;
|
|
|
|
if (cur < min)
|
|
cur = min;
|
|
if (cur > max)
|
|
cur = max;
|
|
|
|
if (max == 0)
|
|
pos = 0;
|
|
else
|
|
pos = (cur * mRenderW) / max;
|
|
|
|
if (pos == mLastPos)
|
|
return 0;
|
|
|
|
mLastPos = pos;
|
|
|
|
if (RenderInternal() != 0)
|
|
return -1;
|
|
return 2;
|
|
}
|
|
|
|
int GUIProgressBar::NotifyVarChange(const std::string& varName, const std::string& value)
|
|
{
|
|
GUIObject::NotifyVarChange(varName, value);
|
|
|
|
if(!isConditionTrue())
|
|
return 0;
|
|
|
|
static int nextPush = 0;
|
|
|
|
if (varName.empty())
|
|
{
|
|
nextPush = 0;
|
|
mLastPos = 0;
|
|
mSlide = 0.0;
|
|
mSlideInc = 0.0;
|
|
return 0;
|
|
}
|
|
|
|
if (varName == "ui_progress_portion" || varName == "ui_progress_frames")
|
|
{
|
|
std::string str;
|
|
int cur;
|
|
|
|
if (mSlideFrames)
|
|
{
|
|
mSlide += (mSlideInc * mSlideFrames);
|
|
cur = (int) mSlide;
|
|
DataManager::SetValue(mCurValVar, cur);
|
|
mSlideFrames = 0;
|
|
}
|
|
|
|
if (nextPush)
|
|
{
|
|
mSlide += nextPush;
|
|
cur = (int) mSlide;
|
|
DataManager::SetValue(mCurValVar, cur);
|
|
nextPush = 0;
|
|
}
|
|
|
|
if (varName == "ui_progress_portion") mSlide = atof(value.c_str());
|
|
else
|
|
{
|
|
mSlideFrames = atol(value.c_str());
|
|
if (mSlideFrames == 0)
|
|
{
|
|
// We're just holding this progress until the next push
|
|
nextPush = mSlide;
|
|
}
|
|
}
|
|
|
|
if (mSlide > 0 && mSlideFrames > 0)
|
|
{
|
|
// Get the current position
|
|
str.clear();
|
|
DataManager::GetValue(mCurValVar, str);
|
|
cur = atoi(str.c_str());
|
|
|
|
mSlideInc = (float) mSlide / (float) mSlideFrames;
|
|
mSlide = cur;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|