I searched the whole day and can still not figure out, what I am missing. All Examples I found are either incomplete (only not connected snippets) or overcomplete(cannt see what is really part if the principle)
I have an Activity that has a View that extends SurfaceView that should be filled using a native method. It is currently implemented by a memset(..,0,..) but my View is white although all calls seem fine.
MyView:
public class MyView extends SurfaceView implements SurfaceHolder.Callback
{
public MyView(Context context)
{
super(context);
SurfaceHolder sh = getHolder();
sh.addCallback(this);
}
// protected void onDraw(Canvas canvas) // works to make the view red
// { canvas.drawColor(Color.RED);}
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
{
nativeRender(holder.getSurface(), width, height);
}
public void surfaceCreated(SurfaceHolder holder)
{}
public void surfaceDestroyed(SurfaceHolder holder)
{}
private native void nativeRender(Object surface, int width, int height);
}
Native method:
void ...nativeRender(JNIEnv* env, jobject myView, jobject surface, jint width, jint height)
{
ANativeWindow* pWindow(ANativeWindow_fromSurface(env, surface));
ANativeWindow_setBuffersGeometry(pWindow, width,height,WINDOW_FORMAT_RGBX_8888);
ANativeWindow_Buffer buffer;
if (ANativeWindow_lock(pWindow, &buffer, NULL) == 0)
{
memset(buffer.bits, 0, buffer.stride*buffer.height*4);
ANativeWindow_unlockAndPost(pWindow);
}
ANativeWindow_release(pWindow);
}
Things I checked:
Things I tried:
So it looks to me that I fill a buffer of the correct dimensions that is never shown. Probably I' missing something obvious because nobody else seems to have problems in that way.
Thanks in Advance Moritz
Thanks!
fadden's comment was the answer. My code actually called setBackgroundColor() which is obviously not what I wanted...
(Although I would expect that in this context this property would have no meaning or would be what the buffer would be prefilled with...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With