How to efficiently transfer image data from an XPC service to a host application

TL / DR: What is the most efficient way to decode images in the XPC service, move the data to the main application and then display it?

In several WWDC videos that relate to XPC services on macOS, an example that seems like a good candidate for using the XPC service is image and video decoding. I have an application that does a lot of image decoding that I would like to move to the XPC service, but I would like to better understand how to efficiently move the decoded image data from the XPC service to the main application. There are many APIs that you can use when working with images, and this is not clear to me, which is the most efficient (and effective) when used in the XPC service.

Image reading:

  • Using the Apple Image I / O Structure and CGImage
  • Using Core Image and CIImage
  • Using third-party libraries such as OpenImage IO

All three of these APIs can take a file path and return "image data". The Apple APIs typically do "lazy decoding" and only decompress image data when the image needs to be drawn. Third-party libraries tend to simply return a decoded data buffer, which can then be wrapped using CGImageat a later date.

When you decode an image using the Apple API in the XPC service, you need a way to return the results to the main application, and neither CGImage, nor CIImagecan initially be transferred through the XPC connection. However, Apple does provide two APIs for efficiently transferring shared data over an XPC connection:

  • IOSurface
  • dispatch_data

, , , XPC . CGImage , CIImage CIContext. - , , ?

( , contents CALayer.)

IOSurface dispatch_data , IOSurface (-) contents CALayer. CIContext API IOSurface, CGImage / CGImageDestination .

( vImage CGImage CVPixelBuffer, IOSurface, ... ?)

Core Image , , , . Image IO CGImageSourceCreateThumbnailAtIndex , . ( RAW , JPEG, , Core Image RAW.)

, , ? -, XPC, ?

XPC, Image IO Core Image , ? , ( , )? , .

+4

Source: https://habr.com/ru/post/1684741/


All Articles