Skip to content

Commit

Permalink
mmapped shm
Browse files Browse the repository at this point in the history
  • Loading branch information
Goheeca committed May 17, 2019
1 parent 0e058de commit f1e4757
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 30 deletions.
7 changes: 7 additions & 0 deletions src/fbterm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ void FbTerm::init()
sigaddset(&sigmask, SIGALRM);
sigaddset(&sigmask, SIGTERM);
sigaddset(&sigmask, SIGHUP);
sigaddset(&sigmask, SIGIO);

sigprocmask(SIG_BLOCK, &sigmask, &oldSigmask);
new SignalIo(sigmask);
Expand All @@ -142,6 +143,7 @@ void FbTerm::init()
signal(SIGALRM, sh);
signal(SIGTERM, sh);
signal(SIGHUP, sh);
signal(SIGIO, sh);
#endif
signal(SIGPIPE, SIG_IGN);

Expand Down Expand Up @@ -216,6 +218,11 @@ void FbTerm::processSignal(u32 signo)
}
break;

case SIGIO:
Screen::instance()->redrawBg();
FbShellManager::instance()->redraw(0, 0, Screen::instance()->cols(), Screen::instance()->rows());
break;

default:
break;
}
Expand Down
2 changes: 2 additions & 0 deletions src/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public :
void showInfo(bool verbose);
virtual void switchVc(bool enter);

void redrawBg();

protected:
u32 mWidth, mHeight;
u16 mCols, mRows;
Expand Down
49 changes: 19 additions & 30 deletions src/screen_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ static u32 fillColors[NR_COLORS];

static u8 *bgimage_mem;
static u8 bgcolor;
static char *backgroundPath = NULL;

void Screen::setPalette(const Color *palette)
{
Expand Down Expand Up @@ -68,7 +69,6 @@ void Screen::setPalette(const Color *palette)

void Screen::initFillDraw()
{
char* backgroundPath;
if (mBitsPerPixel == 15) bytes_per_pixel = 2;
else bytes_per_pixel = (mBitsPerPixel >> 3);

Expand All @@ -77,7 +77,8 @@ void Screen::initFillDraw()
ppb = ppl >> 2;

bool bg = false;
if (getenv("FBTERM_BACKGROUND_IMAGE")) {
if (getenv("FBTERM_BACKGROUND_IMAGE")
|| (backgroundPath = getenv("FBTERM_BACKGROUND_IMAGE_PATH"))) {
bg = true;
mScrollType = Redraw;

Expand All @@ -86,36 +87,16 @@ void Screen::initFillDraw()
if (color > 7) color = 0;
bgcolor = color;

u32 size = mBytesPerLine * ((mRotateType == Rotate0 || mRotateType == Rotate180) ? mHeight : mWidth);
bgimage_mem = new u8[size];
memcpy(bgimage_mem, mVMemBase, size);
} else if (backgroundPath = getenv("FBTERM_BACKGROUND_IMAGE_PATH")) {
mBackgroundFd = open(backgroundPath, O_RDWR | O_CREAT, 0644);
if (mBackgroundFd != -1) {
struct stat st;
stat(backgroundPath, &st);
bool created = st.st_size == 0;

bg = true;
mScrollType = Redraw;

u32 color = 0;
Config::instance()->getOption("color-background", color);
if (color > 7) color = 0;
bgcolor = color;

mSize = mBytesPerLine * ((mRotateType == Rotate0 || mRotateType == Rotate180) ? mHeight : mWidth);
bgimage_mem = new u8[mSize];

mSize = mBytesPerLine * ((mRotateType == Rotate0 || mRotateType == Rotate180) ? mHeight : mWidth);
bgimage_mem = new u8[mSize];
if (!backgroundPath) {
memcpy(bgimage_mem, mVMemBase, mSize);
} else if ((mBackgroundFd = shm_open(backgroundPath, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)) != -1) {
ftruncate(mBackgroundFd, mSize);
int falloc = 0;
if(created) {
falloc = fallocate(mBackgroundFd, FALLOC_FL_ZERO_RANGE, 0, mSize);
}
if(!falloc) {
if (falloc = fallocate(mBackgroundFd, FALLOC_FL_ZERO_RANGE, 0, mSize)) {
mBackgroundData = mmap(NULL, mSize, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, mBackgroundFd, 0);
if (mBackgroundData != MAP_FAILED) {
mempcpy(bgimage_mem, mBackgroundData, mSize);
}
redrawBg();
}
}
}
Expand Down Expand Up @@ -146,6 +127,14 @@ void Screen::endFillDraw()
munmap(mBackgroundData, mSize);
}
close(mBackgroundFd);
shm_unlink(backgroundPath);
}
}

void Screen::redrawBg()
{
if (mBackgroundData != MAP_FAILED) {
mempcpy(bgimage_mem, mBackgroundData, mSize);
}
}

Expand Down

0 comments on commit f1e4757

Please sign in to comment.