ok, thanks to your suggestions and to these threads:
https://groups.google.com/forum/#!topic/skia-discuss/V-2yei14Czshttps://groups.google.com/forum/#!topic/skia-discuss/6y8xm0wiOBoI managed, using a standard surfaceview, to get an image (a red square on green background) correctly rendered at screen, but after that the application becomes unresponsive and i get the most feared ANR message. Here's the code, can someone spot what's wrong in it?
I removed error checking and log calls for readability, the jni function is called in the java surfaceview's surfaceChanged(...). Commented lines show some attempts i made that had no effects on the result.
JNIEXPORT void JNICALL Java_my_testskia_app_InitializeNativeWindow(JNIEnv* env, jobject thiz, jobject jsurface, jobject jAssetMgr)
{
const EGLint configAttribs[] = {
EGL_RENDERABLE_TYPE,EGL_OPENGL_ES2_BIT, EGL_SURFACE_TYPE,EGL_WINDOW_BIT,
EGL_BLUE_SIZE,8, EGL_GREEN_SIZE,8, EGL_RED_SIZE,8, EGL_ALPHA_SIZE,8,
EGL_STENCIL_SIZE,8, EGL_NONE };
const EGLint contextAttribs[] = {EGL_CONTEXT_CLIENT_VERSION,2, EGL_NONE };
const EGLint surfaceAttribs[] = {EGL_RENDER_BUFFER,EGL_BACK_BUFFER, EGL_NONE };
EGLint numConfigs, format;
EGLConfig config;
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglInitialize(display, NULL, NULL);
eglChooseConfig(display, configAttribs, &config, 1, &numConfigs);
EGLContext context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs);
eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
ANativeWindow* window = ANativeWindow_fromSurface(env, jsurface);
ANativeWindow_setBuffersGeometry(window, 0, 0, format);
EGLSurface surface = eglCreateWindowSurface(display, config, window, surfaceAttribs);
eglMakeCurrent(display, surface, surface, context);
int surfaceWidth,surfaceHeight;
eglQuerySurface(display, surface, EGL_WIDTH, &surfaceWidth);
eglQuerySurface(display, surface, EGL_HEIGHT, &surfaceHeight);
glViewport(0, 0, surfaceWidth, surfaceHeight);
GrContext* ctx = GrContext::Create(kOpenGL_Shaders_GrEngine,0);
GLint fboID = 0;
GrPlatformRenderTargetDesc desc;
desc.fWidth = surfaceWidth;
desc.fHeight = surfaceHeight;
desc.fConfig = kRGBA_8888_PM_GrPixelConfig; // or kBGRA_8888_PM_GrPixelConfig
desc.fStencilBits = 8; // assuming you created an 8 bit stencil buffer
desc.fRenderTargetHandle = fboID;
GrRenderTarget* target = ctx->createPlatformRenderTarget(desc);
SkGpuDevice* gpuDevice = new SkGpuDevice(ctx, target);
SkCanvas gpuCanvas;
gpuCanvas.setDevice(gpuDevice);
SkRect rectRed;
rectRed.setXYWH(29,12,80,80);
SkPaint paint;
paint.setColor(SK_ColorRED);
gpuCanvas.drawColor(SK_ColorGREEN);
gpuCanvas.drawRect(rectRed,paint);
//gpuCanvas.flush();
//ctx->flush();
eglSwapBuffers(display,surface))
//eglMakeCurrent(display, EGL_NO_SURFACE,EGL_NO_SURFACE,EGL_NO_CONTEXT);
}
thanks!
athos