Skip to content

Instantly share code, notes, and snippets.

@taeguk
Created June 22, 2017 16:33
Show Gist options
  • Save taeguk/7c198d2dc5fcdd8462d188a776f6a68d to your computer and use it in GitHub Desktop.
Save taeguk/7c198d2dc5fcdd8462d188a776f6a68d to your computer and use it in GitHub Desktop.
haha3.cpp
static volatile int taeguk = 0;
// Added by taeguk.
static void fb_fake_for_taeguk(char* fb_ptr/*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;
/*
if (called_cnt % 20 != 0)
{
ALOGE("[@@TAEGUK@@] <%s,%d> #%d# immediately return;\n", __FUNCTION__, __LINE__, called_cnt);
return;
}
*/
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 = width < height ? width : height;
int tmp_width = tmp_height;
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] = 0; // R
//fb_pixel_ptr[1] = 255; // G
//fb_pixel_ptr[2] = 0; // B
//fb_pixel_ptr[3] = 127; // A
}
}
*/
int arr[3][3] = {
{ 1, 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 0 }
};
//int* base_ptr = (int*)(fb_ptr + (y + yoffset) * m->finfo.line_length + xoffset * bpp);
for (int r = 0; r < 3; ++r)
{
for (int c = 0; c < 3; ++c)
{
if (arr[r][c] == r * 3 + c)
continue;
int tr = arr[r][c] / 3;
int tc = arr[r][c] % 3;
for (int y=0; y<tmp_height/3; ++y)
{
int* ptr = (int*)(fb_ptr + (y + yoffset + r * (tmp_height/3)) * m->finfo.line_length + (xoffset + c * (tmp_width/3)) * bpp);
int* tptr = (int*)(fb_ptr + (y + yoffset + tr * (tmp_height/3)) * m->finfo.line_length + (xoffset + tc * (tmp_width/3)) * bpp);
for (int x=0; x<tmp_width/3; ++x, ++ptr, ++tptr)
{
int tmp = *ptr;
*ptr = *tptr;
*tptr = tmp;
}
}
int tmp = arr[r][c];
arr[r][c] = arr[tr][tc];
arr[tr][tc] = tmp;
--c;
}
}
}
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;
/*
if (taeguk == 1)
return 0;
*/
while (taeguk != 0);
taeguk = 1;
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);
*/
const size_t offset = hnd->base - m->framebuffer->base;
m->info.activate = FB_ACTIVATE_VBL;
m->info.yoffset = offset / m->finfo.line_length;
ALOGE("[!!!!!!! BIG !!!!!!! @@TAEGUK@@] <%s,%d> hnd->base = %p, m->framebuffer->base = %p, vaddr = %p, offset = %u\n", __FUNCTION__, __LINE__, hnd->base, m->framebuffer->base, vaddr, offset);
// Added by taeguk.
//fb_fake_for_taeguk(hnd, m);
//fb_fake_for_taeguk((char*)vaddr, m);
fb_fake_for_taeguk((char*)m->framebuffer->base, m);
//fb_fake_for_taeguk((char*)m->framebuffer->base + m->finfo.line_length * ALIGN_PIXEL_128(m->info.yres), m);
//fb_fake_for_taeguk((char*)m->framebuffer->base + 2 * m->finfo.line_length * ALIGN_PIXEL_128(m->info.yres), m);
if (ioctl(m->framebuffer->fd, FBIOPAN_DISPLAY, &m->info) == -1) {
ALOGW("FBIOPAN_DISPLAY failed: %s", strerror(errno));
ALOGE("[****** SIBALNOMAR ****** @@TAEGUK@@] <%s,%d> \n", __FUNCTION__, __LINE__);
m->currentBuffer = buffer;
taeguk = 0;
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);
}
taeguk = 0;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment