Android 如何在surfaceview上显示帧缓冲区图形?
我在帧缓冲区上做了一些绘图,但它们没有显示在我的surfaceview上 JNI代码:Android 如何在surfaceview上显示帧缓冲区图形?,android,surfaceview,framebuffer,Android,Surfaceview,Framebuffer,我在帧缓冲区上做了一些绘图,但它们没有显示在我的surfaceview上 JNI代码: extern "C" JNIEXPORT jint JNICALL Java_com_example_testskia_Skia_initFramebuffer(JNIEnv *env, jobject obj) { const char *devfile = "/dev/graphics/fb0"; int fbFd = 0; int location = 0; int b
extern "C" JNIEXPORT jint JNICALL
Java_com_example_testskia_Skia_initFramebuffer(JNIEnv *env, jobject obj) {
const char *devfile = "/dev/graphics/fb0";
int fbFd = 0;
int location = 0;
int bytes_per_pixel;
// Open the file for reading and writing
fbFd = open (devfile, O_RDWR);
if (fbFd == -1) {
perror("Error cannot open framebuffer device");
LOGI("Error cannot open framebuffer device");
exit (1);
}
LOGI("Succeed open framebuffer device");
//获取finfo信息并显示
if (ioctl (fbFd, FBIOGET_FSCREENINFO, &finfo) == -1) {
perror("Error reading fixed information");
LOGI("Error reading fixed information");
exit (2);
}
LOGI("Succeed reading fixed information");
//获取vinfo信息并显示
if (ioctl (fbFd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
perror("Error reading variable information");
LOGI("Error reading variable information");
exit (3);
}
LOGI("Succeed reading variable information");
bytes_per_pixel = vinfo.bits_per_pixel / 8;
screensize = vinfo.xres * vinfo.yres * bytes_per_pixel; //单帧画面空间 单位:字节
LOGI("vinfo.xres=%d vinfo.yres=%d bytes_per_pixel=%d", vinfo.xres, vinfo.yres, bytes_per_pixel);
LOGI("screensize=%ld\n", screensize);
// Figure out the size of the screen in bytes
//screensize = finfo.smem_len;
//LOGI("Succeed screensize:%ld", screensize);
// Map the device to memory
frameBuffer = (char *) mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbFd, 0);
if (frameBuffer == MAP_FAILED) {
perror("Error Failed to map framebuffer device to memory");
LOGI("Error Failed to map framebuffer device to memory");
exit (4);
}
LOGI("Succeed map framebuffer device to memory");
memset(frameBuffer, 0, screensize);
performSpeedTest(frameBuffer, screensize);
for(int i = 0; i < (854*480); i++)
frameBuffer[i] = 0x00ff0000;
sleep(5);
/*char *buffer = (char*)malloc(vinfo.yres * finfo.line_length);
for (int i = 0; i <= 0xff; i += 0x0f) {
memset(buffer, i, vinfo.yres * finfo.line_length);
flush_screen(buffer, frameBuffer, vinfo.xres, vinfo.yres);
//sleep(1);
}*/
//draw rectangle
int x = 0, y = 0;
int guage_height = 20, step = 10;
y = (vinfo.yres - guage_height) / 2 - 2; // Where we are going to put the pixel
for (x = step - 2; x < vinfo.xres - step + 2; x++) {
location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
(y+vinfo.yoffset) * finfo.line_length;
*((unsigned short int*)(frameBuffer + location)) = 255;
}
y = (vinfo.yres + guage_height) / 2 + 2; // Where we are going to put the pixel
for (x = step - 2; x < vinfo.xres - step + 2; x++) {
location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
(y+vinfo.yoffset) * finfo.line_length;
*((unsigned short int*)(frameBuffer + location)) = 255;
}
x = step - 2;
for (y = (vinfo.yres - guage_height) / 2 - 2; y < (vinfo.yres + guage_height) / 2 + 2; y++) {
location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
(y+vinfo.yoffset) * finfo.line_length;
*((unsigned short int*)(frameBuffer + location)) = 255;
}
x = vinfo.xres - step + 2;
for (y = (vinfo.yres - guage_height) / 2 - 2; y < (vinfo.yres + guage_height) / 2 + 2; y++) {
location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
(y+vinfo.yoffset) * finfo.line_length;
*((unsigned short int*)(frameBuffer + location)) = 255;
}
// Figure out where in memory to put the pixel
for ( x = step; x < vinfo.xres - step; x++ ) {
for ( y = (vinfo.yres - guage_height) / 2; y < (vinfo.yres + guage_height) / 2; y++ ) {
location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
(y+vinfo.yoffset) * finfo.line_length;
if ( vinfo.bits_per_pixel == 32 ) {
*(frameBuffer + location) = 100; // Some blue
*(frameBuffer + location + 1) = 15+(x-100)/2; // A little green
*(frameBuffer + location + 2) = 200-(y-100)/5; // A lot of red
*(frameBuffer + location + 3) = 0; // No transparency
} else { //assume 16bpp
unsigned char b = 255 * x / (vinfo.xres - step);
unsigned char g = 255; // (x - 100)/6 A little green
unsigned char r = 255; // A lot of red
unsigned short int t = make16color(r, g, b);
*((unsigned short int*)(frameBuffer + location)) = t;
}
}
//printf("x = %d, temp = %d\n", x, temp);
//sleep to see it
usleep(200);
}
}
extern "C" JNIEXPORT jint JNICALL
Java_com_example_testskia_Skia_initSkia(JNIEnv *env, jclass clazz, jobject _bitmap) {
LOGI("Java_com_example_testskia_Skia_initSkia");
//register_android_graphics_Graphics(env, clazz, _bitmap);
AndroidBitmapInfo info;
int ret;
ret = AndroidBitmap_getInfo(env, _bitmap, &info);
LOGI("Java_com_example_testskia_Skia_initSkia info");
ret = AndroidBitmap_lockPixels(env, _bitmap, (void**)&pixels);
LOGI("Java_com_example_testskia_Skia_initSkia pixels");
int width = (int)info.width;
int height = (int)info.height;
LOGI("Java_com_example_testskia_Skia_initSkia end width = %d, height=%d", width, height);
sk_bitmap = SkBitmap();
sk_bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height, 0);
sk_bitmap.setPixels((void*)pixels);
sk_canvas = new SkCanvas(sk_bitmap);
paint.setStyle(SkPaint::kStroke_Style);
paint.setColor(SK_ColorGREEN);
sk_canvas->drawLine(220, 300, 400, 300, paint);
memcpy(frameBuffer, sk_bitmap.getPixels(), screensize);
return 0;
}
extern“C”JNIEXPORT jint JNICALL
Java_com_示例_testskia_Skia_initFramebuffer(JNIEnv*env,jobject obj){
const char*devfile=“/dev/graphics/fb0”;
int fbFd=0;
int位置=0;
每像素整数字节;
//打开文件进行读写
fbFd=打开(devfile,O_RDWR);
如果(fbFd==-1){
perror(“错误无法打开帧缓冲区设备”);
LOGI(“错误无法打开帧缓冲区设备”);
出口(1);
}
LOGI(“成功打开帧缓冲区设备”);
//获取芬福信息并显示
如果(ioctl(fbFd、FBIOGET_FSCREENINFO和finfo)=-1){
perror(“读取固定信息时出错”);
LOGI(“读取固定信息时出错”);
出口(2);
}
LOGI(“成功读取固定信息”);
//获取葡萄酒信息并显示
如果(ioctl(fbFd、FBIOGET\U VSCREENINFO和vinfo)=-1){
perror(“错误读取变量信息”);
LOGI(“读取变量信息时出错”);
出口(3);
}
LOGI(“成功读取变量信息”);
字节/像素=vinfo.bits/像素/8;
屏幕大小=vinfo.xres*vinfo.yres*每像素字节数//单帧画面空间 单位:字节
LOGI(“vinfo.xres=%d vinfo.yres=%d字节/u像素=%d”,vinfo.xres,vinfo.yres,字节/u像素);
LOGI(“屏幕大小=%ld\n”,屏幕大小);
//计算屏幕的大小(以字节为单位)
//屏幕大小=finfo.smem_len;
//LOGI(“成功屏幕大小:%ld”,屏幕大小);
//将设备映射到内存
帧缓冲区=(字符*)mmap(0,屏幕大小,保护读写,保护共享,fbFd,0);
如果(帧缓冲区==映射_失败){
perror(“将帧缓冲区设备映射到内存失败的错误”);
LOGI(“将帧缓冲区设备映射到内存失败的错误”);
出口(4);
}
LOGI(“成功将帧缓冲区设备映射到内存”);
memset(帧缓冲区,0,屏幕大小);
performSpeedTest(帧缓冲区、屏幕大小);
对于(int i=0;i<(854*480);i++)
帧缓冲区[i]=0x00ff0000;
睡眠(5);
/*char*buffer=(char*)malloc(vinfo.yres*finfo.line_长度);
对于(int i=0;i绘制线(220300400300,油漆);
memcpy(帧缓冲区,sk_bitmap.getPixels(),屏幕大小);
返回0;
}
您的设置环境设置是什么?您的设置环境设置是什么?