Using an existing EGL context as backend

364 views
Skip to first unread message

grun...@gmail.com

unread,
May 14, 2015, 1:31:21 PM5/14/15
to skia-d...@googlegroups.com
Hi,

I'm trying to use an EGL context as backend for a skia canvas,
but am quite unsure, if I got things correct.

As I understood, all I have to do is to create a GrContext from an EGLDisplay variable,
and use wrapBackendRenderTarget to create a GrRenderTarget
.
My code segfaults at wrapBackendRenderTarget and valgrind reports,
that there is already an invalid read at 
GrContext::Create call.

Could you give me some advice, what I got wrong at using skia?
I guess, that it's not actually the EGLDisplay I have to use but something else,
though EGLSurface even lead to an earlier segfault.



EGLDisplay m_display;
EGLContext m_context;
EGLSurface m_surface;

GrContext* cont=GrContext::Create(kOpenGL_GrBackend,(intptr_t)m_display,NULL);

GrBackendRenderTargetDesc desc;
desc.fWidth=width;
desc.fHeight=height;
desc.fConfig=kSkia8888_GrPixelConfig;
desc.fOrigin=kBottomLeft_GrSurfaceOrigin;
desc.fSampleCnt=0;
desc.fStencilBits=8;
desc.fRenderTargetHandle=0;

GrBackendRenderTargetDesc& refToDesc=desc;
GrRenderTarget* rendertarget=
cont->wrapBackendRenderTarget(refToDesc); // segfault

SkSurface* surface=SkSurface::NewRenderTargetDirect(rendertarget);
SkCanvas* eglCanvas=surface->getCanvas();
eglCanvas->drawColor(SK_ColorGREEN);
eglSwapBuffers(m_display, m_surface);


------

==3815== Invalid read of size 4
==3815==    at 0x11B338: operator unsigned char const* (*)(unsigned int) (GrGLInterface.h:104)
==3815==    by 0x11B338: GrGLContextInfo::initialize(GrGLInterface const*) (GrGLContext.cpp:28)
==3815==    by 0xEFB39: GrGLContext (GrGLContext.h:96)
==3815==    by 0xEFB39: gl_gpu_create(int, GrContext*) (GrGpuFactory.cpp:35)
==3815==    by 0xE22BD: init (GrContext.cpp:113)
==3815==    by 0xE22BD: GrContext::Create(GrBackend, int, GrContext::Options const*) (GrContext.cpp:86)
==3815==
==3815== Invalid read of size 4
==3815==    at 0xE2928: ??? (GrContext.cpp:375)
==3815==    by 0x13233: main (gpu.cpp:120)
==3815==  Address 0x2c is not stack'd, malloc'd or (recently) free'd

cruz...@gmail.com

unread,
May 16, 2015, 7:51:18 PM5/16/15
to skia-d...@googlegroups.com
Are you creating the egl context as well?

The setup I've used goes something like...

m_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglInitialize(m_display, &major, &minor);
eglChooseConfig(m_display, configAttr, &m_config, 1, &size);
m_context = eglCreateContext(m_display, m_config, EGL_NO_CONTEXT, ctxAttr);
m_surface = eglCreateWindowSurface(m_display, m_config, m_window, NULL);
eglMakeCurrent(m_display, m_surface, m_surface, m_context);

m_grInterface.reset(GrGLCreateNativeInterface());
m_grContext.reset(GrContext::Create(GrBackend::kOpenGL_GrBackend, (GrBackendContext)m_grInterface.get()));


GrBackendRenderTargetDesc brtd;
brtd.fConfig = GrPixelConfig::kRGBA_8888_GrPixelConfig;
brtd.fRenderTargetHandle = 0;
brtd.fWidth = m_width;
brtd.fHeight = m_height;

m_grRenderTarget.reset(m_grContext->textureProvider()->wrapBackendRenderTarget(brtd));
m_skSurface.reset(SkSurface::NewRenderTargetDirect(m_grRenderTarget->asRenderTarget()));

SkCanvas* canvas = m_skSurface->getCanvas();
canvas->drawColor(SK_ColorGREEN);
canvas->flush();
eglSwapBuffers(m_display, m_surface);


-Jose
Reply all
Reply to author
Forward
0 new messages