SkSurface created by MakeFromBackendRenderTarget readpixels return empty data

306 views
Skip to first unread message

l1 shu

unread,
Apr 16, 2021, 6:51:53 AM4/16/21
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
   renderTarget,
   GrSurfaceOrigin::kBottomLeft_GrSurfaceOrigin,
   kRGBA_8888_SkColorType,
   SkColorSpace::MakeSRGB(),
   nullptr
);

```

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(
   mWidth,
   mHeight,
   kRGBA_8888_SkColorType,
   kPremul_SkAlphaType,
   SkColorSpace::MakeSRGB()
);

bool success = mSkSurface->readPixels(
   imageInfo,
   buf,
   mWidth * 4,
   0,
   0
);

free(buf);

```

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

l1 shu

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

Brian Salomon

unread,
Apr 23, 2021, 7:12:14 AM4/23/21
to skia-d...@googlegroups.com
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 skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/d50c76ce-8f79-485d-82b3-96a784af78fdn%40googlegroups.com.

l1 shu

unread,
Apr 25, 2021, 10:19:57 PM4/25/21
to skia-discuss
Thanks for replying, Brian
Reply all
Reply to author
Forward
0 new messages