fix display metrics

This commit is contained in:
houzh 2023-10-06 14:48:25 +08:00
parent 0da0e59fcc
commit ee9b98277d
10 changed files with 29 additions and 25 deletions

View File

@ -47,29 +47,26 @@ App::App(int argc,const char*argv[],const std::vector<CLA::Argument>&extoptions)
mExitCode = 0;
mInst = this;
if(argc>0){
const char*p = strrchr(argv[0],'/');
if(p)setName(p+1);
const char*p = strrchr(argv[0],'/');
if(p)setName(p+1);
}
LOGD("App %s started",(argc&&argv)?argv[0]:"");
LOGI("App [%s] started c++=%d",(argc&&argv)?argv[0]:"",__cplusplus);
cla.addArguments(ARGS,sizeof(ARGS)/sizeof(CLA::Argument));
cla.addArguments(extoptions.data(),extoptions.size());
cla.setSwitchChars("-");
cla.parse(argc,argv);
if(hasSwitch("debug")){
ViewGroup::DEBUG_DRAW=true;
View::DEBUG_DRAW=true;
}
ViewGroup::DEBUG_DRAW = View::DEBUG_DRAW = hasSwitch("debug");
if(hasSwitch("help")){
std::cout<<cla.getUsageString()<<std::endl;
std::cout<<"params.count="<<getParamCount()<<std::endl;
exit(0);
std::cout<<cla.getUsageString()<<std::endl;
std::cout<<"params.count="<<getParamCount()<<std::endl;
exit(0);
}
chograph.setFrameDelay(getArgAsInt("framedelay",chograph.getFrameDelay()));
GFXInit();
DisplayMetrics::DENSITY_DEVICE = getArgAsInt("density",DisplayMetrics::DENSITY_DEVICE);
WindowManager::getInstance().setDisplayRotation((getArgAsInt("rotate",0)/90)%4);
setOpacity(getArgAsInt("alpha",255));
GraphDevice::getInstance().showFPS(hasSwitch("fps"));
DisplayMetrics::DENSITY_DEVICE = getArgAsInt("density",DisplayMetrics::getDeviceDensity());
InputEventSource*inputsource=&InputEventSource::getInstance();//(getArg("record",""));
addEventHandler(inputsource);
inputsource->playback(getArg("monkey",""));
@ -88,6 +85,10 @@ App::~App(){
delete &GraphDevice::getInstance();
}
void App::onInit(){
GFXInit();
}
const std::string App::getDataPath()const{
std::string path=getArg("data","./");
if(path.back()!='/')path+='/';

View File

@ -20,6 +20,7 @@ private:
protected:
CLA cla;
static App*mInst;
void onInit()override;
public:
App(int argc=0,const char*argv[]=NULL,const std::vector<CLA::Argument>&extoptions={});
~App();

View File

@ -26,6 +26,8 @@ struct Assets::COMPLEXCOLOR {
};
Assets::Assets() {
onInit();
mDisplayMetrics.setToDefaults();
mNextAutofillViewId=100000;
addResource("cdroid.pak","cdroid");
}
@ -56,7 +58,10 @@ Assets::~Assets() {
std::cout<<" Assets destroied!"<<std::endl;
}
const DisplayMetrics& Assets::getDisplayMetrics() {
void Assets::onInit(){
}
const DisplayMetrics& Assets::getDisplayMetrics()const{
return mDisplayMetrics;
}

View File

@ -29,6 +29,7 @@ private:
protected:
std::string mName;
DisplayMetrics mDisplayMetrics;
virtual void onInit();
void loadStrings(const std::string&lan);
int addResource(const std::string&path,const std::string&name=std::string());
int loadKeyValues(const std::string&resid,
@ -42,7 +43,7 @@ public:
const std::string getPackageName()const override;
const std::string getTheme()const override;
void setTheme(const std::string&theme)override;
const DisplayMetrics&getDisplayMetrics()override;
const DisplayMetrics&getDisplayMetrics()const override;
int getId(const std::string&)const override;
int getNextAutofillId()override;
const std::string& getString(const std::string&id,const std::string&lan="")override;

View File

@ -26,7 +26,6 @@ AttributeSet::AttributeSet():AttributeSet(nullptr,""){
AttributeSet::AttributeSet(Context*ctx,const std::string&package){
mContext = ctx;
mPackage = package;
mDisplayMetrics.setToDefaults();
}
void AttributeSet::setContext(Context*ctx,const std::string&package){
@ -213,10 +212,11 @@ int AttributeSet::getDimensionPixelSize(const std::string&key,int def)const{
def = std::strtol(v.c_str(),nullptr,10);
p = strpbrk(v.c_str(),"sdp");
if(p){
const DisplayMetrics& dm=mContext->getDisplayMetrics();
if(strncmp(p,"dp",2)==0||strncmp(p,"dip",3)==0)
def = (mDisplayMetrics.density * def /*+0.5f*/);
def = (dm.density * def /*+0.5f*/);
if(strncmp(p,"sp",2)==0)
def = (mDisplayMetrics.scaledDensity * def /*+0.5f*/);
def = (dm.scaledDensity * def /*+0.5f*/);
}
return def;
}

View File

@ -12,7 +12,6 @@ class AttributeSet{
private:
std::string mPackage;
class Context*mContext;
DisplayMetrics mDisplayMetrics;
std::map<std::string,std::string>mAttrs;
public:
AttributeSet();

View File

@ -18,7 +18,7 @@ public:
virtual const std::string getPackageName()const=0;
virtual const std::string getTheme()const=0;
virtual void setTheme(const std::string&theme)=0;
virtual const DisplayMetrics&getDisplayMetrics()=0;
virtual const DisplayMetrics&getDisplayMetrics()const=0;
virtual int getId(const std::string&)const=0;
virtual int getNextAutofillId()=0;
virtual const std::string& getString(const std::string&id,const std::string&lan="")=0;

View File

@ -50,10 +50,12 @@ int Display::getRotation(){
}
void Display::getMetrics(DisplayMetrics&outMetrics){
outMetrics.setToDefaults();
GFXGetDisplaySize(mDisplayId,(UINT*)&outMetrics.widthPixels,(UINT*)&outMetrics.heightPixels);
}
void Display::getRealMetrics(DisplayMetrics&outMetrics){
outMetrics.setToDefaults();
GFXGetDisplaySize(mDisplayId,(UINT*)&outMetrics.widthPixels,(UINT*)&outMetrics.heightPixels);
}

View File

@ -7,10 +7,6 @@ int DisplayMetrics::DENSITY_DEVICE = getDeviceDensity();//DENSITY_DEFAULT;
int DisplayMetrics::DENSITY_DEVICEE_STABLE = getDeviceDensity();//DENSITY_DEFAULT;
DisplayMetrics::DisplayMetrics(){
/*static int grap_Inited =-1;
if(grap_Inited!=E_OK)
grap_Inited = GFXInit();
setToDefaults();*/
}
void DisplayMetrics::setTo(const DisplayMetrics& o) {

View File

@ -29,7 +29,6 @@ list(APPEND INGENIC_INCLUDE_DIRS ../include)
add_subdirectory(lib2d)
link_directories(${PROJECT_SOURCE_DIR} ./lib2d)
list(APPEND INGENIC_LIBS pthread hardware2)
include_directories(./
../common ../include
lib2d/include
@ -42,6 +41,6 @@ set(PREFIX ${CMAKE_INSTALL_PREFIX})
add_library(tvhal SHARED ${INGENIC_SRCS} ../common/graph_fb.c)
add_library(tvhal-g2d SHARED ${INGENIC_SRCS} ./graph_g2d.c)
target_link_libraries(tvhal ${INGENIC_LIBS} dl)
target_link_libraries(tvhal-g2d ${INGENIC_LIBS} ingenic2d dl)
target_link_libraries(tvhal-g2d ${INGENIC_LIBS} ingenic2d)
add_dependencies(tvhal tvhal-g2d)
install (TARGETS tvhal tvhal-g2d DESTINATION lib)