SkSurface created by MakeFromBackendRenderTarget readpixels return empty data

Skip to first unread message

l1 shu

Apr 16, 2021, 6:51:53 AMApr 16
to skia-discuss
Hi all, I make a SkSurface based on GPU, it all normal except for when I readpixels from the SkSurface,  I got a empty data

Here is the way I created SkSurface :
GrGLFramebufferInfo framebufferInfo = {};
framebufferInfo.fFBOID = 0;
framebufferInfo.fFormat = GL_RGBA8_OES;
GrBackendRenderTarget renderTarget(mWidth0, mHeight, 0, 0, framebufferInfo);

return SkSurface::MakeFromBackendRenderTarget(
   context, // the GrDirectContext made outside


Here is the way I used it
char* buf = (char*)malloc(mWidth * mHeight * 4);
memset(buf, 0, mWidth * mHeight * 4);
const SkImageInfo imageInfo = SkImageInfo::Make(

bool success = mSkSurface->readPixels(
   mWidth * 4,



the `success` is true, but the `buf` read from skSurface is empty

l1 shu

Apr 22, 2021, 5:53:54 AMApr 22
to skia-discuss
The reason is the readPixels shoud not using  after  swapBuffers.... 

Brian Salomon

Apr 23, 2021, 7:12:14 AMApr 23
Oh glad you figured it out. If you need that to work you can probably configure your windowing layer to preserve the backbuffer during a swap, but you'll incur a copy of the contents.

You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

l1 shu

Apr 25, 2021, 10:19:57 PMApr 25
to skia-discuss
Thanks for replying, Brian
Reply all
Reply to author
0 new messages