Does QQuickImageProvider use QPixmapCache ?

  • Does QQuickImageProvider use QPixmapCache ?

  • No, it does not. It uses the internal QQuickPixmapCache which caches images and QQuickTextureFactory instances.

  • Thanks sletta.
    Can I change the QQuickPixmapCache cache limit like QPixmapCache::setCacheLimit() ?

  • Afraid not, there is no public API for it. The limit is hardcoded here:

    Can I ask why you want to change it?

    If you want to trim the cache, you can use QQuickWindow::releaseResources() and if you want to avoid textures being released, just keep a reference to the Image that uses them.

  • I have 7 QML image elements in a QML page and the image sources are change (every image has 5 different optional sources).
    I saw that every source change calls the PixmapImageProvider::requestPixmap to load the image again and I want to reduce the number of times images will be reloaded again.

  • IIRC, changing the source explicitly evicts the image element from the cache, so you want to avoid that as much as possible. What you want is to create one Image element for each of the sources and alternate between which one is visible: true.

    For instance:

    // ImageFlipper.qml
    Item {
    id: root
    property int index: 0;
    Image { source: "source1.png"; visible: root.index == 0 }
    Image { source: "source2.png"; visible: root.index == 1 }
    Image { source: "source3.png"; visible: root.index == 2 }
    Image { source: "source4.png"; visible: root.index == 3 }
    Image { source: "source5.png"; visible: root.index == 4 }

  • Does it makse sense to increase the cache_limit to 20 MB if I have an embedded device with 0.5 GB RAM and I want more images to be kept in cache ?

  • No, changing the size doesn't make much sense. The cache is for unreferenced stuff. What you want is to explicitly reference your images.

  • I saw on qquickpixmapcache.cpp that if the QQuickImageProvider image type is QQuickImageProvider::Pixmap, the createPixmapDataSync function convert the pixmap to QImage.
    Is it better to use QQuickImageProvider::Image as the image type of the QQuickImageProvider ?

  • The default implementation of QPixmap is based on QImage, so the conversion cost between the two is negligible.

    QPixmap has some code making sure the format is somewhat more optimal though, such as keeping the image in ARGB32_Premultiplied and maybe discarding the alpha channel of pngs which in practice have no alpha, so you are probably better off using Pixmap.

  • If I have 16 bit display. Is it better to convert the image to QImage::Format_ARGB8565_Premultiplied instead of ARGB32_Premultiplied ?

  • The texture atlas uses 32 bit textures, so unless you reimplement that using a custom scene graph adaptation layer, you are better of using ARGB32_PM.

  • Do you know where is the convertion from the 32 bit texture to the physical 16 bit display takes place ?

  • That depends on your setup. If you have a 32 bit rendering target, the conversion happens when the frame is presented, if you have a 16 bit rendering context, the conversion most likely happens in the GPU as part of rasterization.

  • How can I determine if my rendering target is 32 bit or 16 bit ?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.