Question about SkYUVAPixmaps::Allocate()

36 views
Skip to first unread message

zhou

unread,
Jun 6, 2021, 9:15:58 PM6/6/21
to skia-discuss
Hi all, initially I pick the SkYUVAPixmaps::FromExternalMemory() to use passed in memory as backing store for pixmaps' pixels. After initialized, yuva_pixmaps will have a backing memory shared with decoded_pixmap. Then I can put decoded YUVA data directly into yuva_pixmaps.
Old codes:
  SkBitmap bitmap;
  if (!bitmap->tryAllocPixels(decode_info)) {
      return false;
  }

  SkPixmap decoded_pixmap;
  decode_pixmap = bitmap->pixmap();
  SkYUVAPixmaps yuva_pixmaps;
   yuva_pixmaps = SkYUVAPixmaps::FromExternalMemory(yuva_pixmap_info,
                                                                             decode_pixmap.writable_addr());

Then I find there is another function SkYUVAPixmaps::Allocate(), which might have the same usage. But after done with "yuva_pixmaps->Allocate(yuva_pixmap_info);", the yuva_pixmaps doesn't get a backing memory to use. I look into its code path, I see that SkYUVAPixmaps::Allocate() will call SkData::MakeUninitialized(size_t length). In SkData::MakeUninitialized(size_t length), it returns PrivateNewWithCopy(nullptr, length), here the first inputted parameter is nullptr. 

Does this cause the yuva_pixmaps couldn't get a backing memory?
If so, how to correctly use SkYUVAPixmaps::Allocate() to get a real allocated backing memory for the yuva_pixmaps?

Thanks

Brian Salomon

unread,
Jun 7, 2021, 5:30:34 PM6/7/21
to skia-d...@googlegroups.com
Hi,

The nullptr there just means there is no initial data to copy in, so the memory backing the SkData will be uninitialized. SkYUVAPixmaps::Allocate is a static function that returns a new SkYUVAPixmaps. It looks like you're trying to use it on an existing SkYUVAPixmaps and ignoring the return.

The factories are intended for these use cases:

FromExternalMemory: You have a pointer to contiguous memory that has enough space to hold all the planes. You'll copy the plane data in either before or after making this call. You can use SkYUVAPixmaps::plane(i).writable_addr() to find out the address within the range where we'll expect each plane to be. You must ensure the memory range you passed in stays valid for the lifetime of the SkYUVAPixmaps.

FromExternalPixmaps: This allows you to wrap non-contiguous plane allocations into a SkYUVAPixmaps. Like FromExternalMemory, the SkYUVAPixmaps doesn't own the planes' backing stores. You must keep the memory of the SkPixmaps passed in valid for the lifetime of SkYUVAPixmaps. If your data is in SkBItmaps you can just ensure you keep the SkBitmaps alive until you're done with the SkYUVAPixmaps.

Allocate: A SkYUVAPixmaps will be returned that allocates and owns the storage for the pixmap data. You'll copy the data into each plane after making the SkYUVAPixmaps but don't need to worry about lifetime after that.

Also just to make sure this is the right class for you, it assumes you already have planar data. It does not make planar data from RGBA data.

--
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/4100de48-17cc-41c4-a1f2-9bf6851e66dan%40googlegroups.com.

zhou

unread,
Jun 7, 2021, 10:24:00 PM6/7/21
to skia-discuss
Got it! Thanks Brian! :D
Reply all
Reply to author
Forward
0 new messages