Native window rendering issue on Samsung Galaxy S3

不问归期 提交于 2019-12-06 06:36:45

问题


I am using Skia (prebuilt) to draw in an android native window, that i get from a java surface. The code performs well on every device I could test it on, except for a Samsung Galaxy S3 (with android 4.0.4 on it). The first image is what I should see, and the second what appears on the Galaxy S3:

The jni function that draws the rectangle is:

JNIEXPORT void JNICALL Java_com_test_TestSkia_InitializeWindow(JNIEnv* env, jobject thiz, jobject surface)
{
     ANativeWindow* window = ANativeWindow_fromSurface(env, surface);
     ANativeWindow_Buffer buffer;
     ANativeWindow_lock(window, &buffer, NULL);
     SkBitmap  bitmap;
     bitmap.setConfig(convertPixelFormat(buffer.format), buffer.width, buffer.height);
     bitmap.setPixels(buffer.bits);
     SkCanvas canvas;
     canvas.setBitmapDevice(bitmap);
     SkRect rectRed;
     rectRed.setXYWH(30,30,400,700);
     SkPaint paint;
     paint.setColor(SK_ColorRED);
     canvas.drawRect(rectRed,paint);
     ANativeWindow_unlockAndPost(window);
}

I tested it on the following devices, with no issue:

  • Sony X8 (android 2.3.7 customized rom)
  • Samsung Nexus S (android 4.0.4)
  • Samsung Galaxy Tab 10.1 (android 3.2)
  • Samsung Galaxy S2 (android 2.3.5)
  • Emulator (android 4.0.3, same screen size and dpi than the galaxy S3)

I tried calling ANativeWindow_setBuffersGeometry(window,0,0,0) with no luck (anyway, the buffer's dimensions and format after the window lock appear to be ok).

So far, only the Galaxy S3 is giving me troubles, at this point I don't know what to do, I can't even tell if the problem is with the ndk native window api or with skia, or maybe it is related to the galaxy S3 using TouchWiz... any idea would be welcome!


回答1:


You need to take buffer.stride into account. Your picture clearly shows that you are having buffer.stride != buffer.width

I'm not able to test, but probably the following change is enough:

 SkBitmap bitmap;
 SkBitmap::Config cfg = convertPixelFormat(buffer.format);
 bitmap.setConfig(cfg, buffer.width, buffer.height,
       SkBitmap::ComputeBytesPerPixel(cfg) * buffer.stride);


来源:https://stackoverflow.com/questions/11211773/native-window-rendering-issue-on-samsung-galaxy-s3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!