Skip to content

Instantly share code, notes, and snippets.

@taeguk
Created June 22, 2017 09:54
Show Gist options
  • Save taeguk/b5120d3d5a9859d79f2300ba39f7f6a8 to your computer and use it in GitHub Desktop.
Save taeguk/b5120d3d5a9859d79f2300ba39f7f6a8 to your computer and use it in GitHub Desktop.
haha2.cpp
// Added by taeguk.
static void fb_fake_for_taeguk(private_handle_t const* hnd, private_module_t* m)
{
static int called_cnt = 0;
int width = m->info.xres;
int height = m->info.yres;
int bpp = m->info.bits_per_pixel / 8;
int xoffset = m->info.xoffset;
int yoffset = m->info.yoffset;
char* fb_ptr = reinterpret_cast<char *>(hnd->base);
++called_cnt;
ALOGE("[@@TAEGUK@@] <%s,%d> #%d# fb_fake_for_taeguk() called!\n", __FUNCTION__, __LINE__, called_cnt);
ALOGE("[@@TAEGUK@@] <%s,%d> #%d# width = %d, height = %d, bpp = %d, xoffset = %d, yoffset = %d, line_length = %d\n", __FUNCTION__, __LINE__, called_cnt, width, height, bpp, xoffset, yoffset, m->finfo.line_length);
int tmp_height = height / 8;
int tmp_width = width / 8;
if (m->info.bits_per_pixel == 32)
{
/*
* RGBA 8/8/8/8
*/
for (int y=0; y<tmp_height; ++y)
{
char* fb_pixel_ptr = fb_ptr + (y + yoffset) * m->finfo.line_length + xoffset * bpp;
for (int x=0; x<tmp_width; ++x, fb_pixel_ptr += bpp)
{
fb_pixel_ptr[0] = 255; // R
fb_pixel_ptr[1] = 0; // G
fb_pixel_ptr[2] = 0; // B
fb_pixel_ptr[3] = 0; // A
}
}
}
else
{
ALOGE("[!@#$!@#$!@#%!@$@@TAEGUK@@ - WHAT?! 16bit pixel##############] <%s,%d> \n", __FUNCTION__, __LINE__);
for (int y=0; y<tmp_height; ++y)
{
char* fb_pixel_ptr = fb_ptr + (y + yoffset) * m->finfo.line_length + xoffset * bpp;
for (int x=0; x<tmp_width; ++x, fb_pixel_ptr += bpp)
{
/*
* RGB 5/6/5
*/
unsigned short* pixel = reinterpret_cast<unsigned short*>(fb_pixel_ptr);
//*pixel = *pixel & (0xFFFF >> 5); // Remove Red.
*pixel = 0xF800;
}
}
}
ALOGE("[@@TAEGUK@@] <%s,%d> #%d# fb_fake_for_taeguk() finished!\n", __FUNCTION__, __LINE__, called_cnt);
}
static int fb_post(struct framebuffer_device_t* dev, buffer_handle_t buffer)
{
if (!buffer)
return -EINVAL;
fb_context_t* ctx = (fb_context_t*)dev;
private_handle_t const* hnd = reinterpret_cast<private_handle_t const*>(buffer);
private_module_t* m = reinterpret_cast<private_module_t*>(
dev->common.module);
if (m->currentBuffer) {
m->base.unlock(&m->base, m->currentBuffer);
m->currentBuffer = 0;
}
if (hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) {
void *vaddr = NULL;
m->base.lock(&m->base, buffer,
private_module_t::PRIV_USAGE_LOCKED_FOR_POST,
0, 0, ALIGN_PIXEL(m->info.xres), ALIGN_PIXEL_128(m->info.yres), &vaddr);
// Added by taeguk.
fb_fake_for_taeguk(hnd, m);
const size_t offset = hnd->base - m->framebuffer->base;
m->info.activate = FB_ACTIVATE_VBL;
m->info.yoffset = offset / m->finfo.line_length;
if (ioctl(m->framebuffer->fd, FBIOPAN_DISPLAY, &m->info) == -1) {
ALOGW("FBIOPAN_DISPLAY failed: %s", strerror(errno));
m->currentBuffer = buffer;
return 0;
//return -errno;
}
m->currentBuffer = buffer;
} else {
ALOGE("[$$$$$^^^^^FFFUCKING TRASH SITUATION^^^^^$$$$$ - @@TAEGUK@@] <%s,%d> \n", __FUNCTION__, __LINE__);
// If we can't do the page_flip, just copy the buffer to the front
// FIXME: use copybit HAL instead of memcpy
void* fb_vaddr;
void* buffer_vaddr;
m->base.lock(&m->base, m->framebuffer,
GRALLOC_USAGE_SW_WRITE_RARELY,
0, 0, ALIGN_PIXEL(m->info.xres), ALIGN_PIXEL_128(m->info.yres),
&fb_vaddr);
m->base.lock(&m->base, buffer,
GRALLOC_USAGE_SW_READ_RARELY,
0, 0, ALIGN_PIXEL(m->info.xres), ALIGN_PIXEL_128(m->info.yres),
&buffer_vaddr);
memcpy(fb_vaddr, buffer_vaddr, m->finfo.line_length * ALIGN_PIXEL_128(m->info.yres));
m->base.unlock(&m->base, buffer);
m->base.unlock(&m->base, m->framebuffer);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment