本文介绍了在三星Galaxy S3本地窗口呈现的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Skia的(prebuilt)在Android原生窗口画画,我从一个java表面得到。在code每一个设备,我可以上测试它,除了三星Galaxy S3(与Android 4.0.4就可以了)上表现良好。第一张图片是我应该看到,和银河S3什么出现的第二个:

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:


这是绘制矩形JNI函数是:

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:


  • 索尼X8(安卓2.3.7定制ROM)

  • 三星Nexus S(安卓4.0.4)

  • 三星Galaxy Tab 10.1(Android 3.2的)

  • 三星Galaxy S2(安卓2.3.5)

  • 仿真器(安卓4.0.3,相同的屏幕尺寸和DPI比Galaxy S3)

我打过电话ANativeWindow_setBuffersGeometry(窗口,0,0,0),没有运气(反正缓冲区的大小和格式的窗口锁定后,似乎确定)。​​

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).

到目前为止,只有银河S3是给我的烦恼,在这一点上,我不知道该怎么办,我甚至不能告诉如果问题与NDK机窗口API或Skia的,也可能是是关系到使用的TouchWiz银河S3 ......任何想法会受到欢迎!

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!

推荐答案

您需要采取 buffer.stride 考虑。您的图片清楚地表明,你有 buffer.stride!= buffer.width

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);

这篇关于在三星Galaxy S3本地窗口呈现的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 23:54