Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-90627

Research a better PixmapCache <-> Image Provider interaction

    XMLWordPrintable

Details

    Description

      Currently image providers are registered on a per engine basis, something we'd like to avoid in the future if at all possible.

      The one reason to have a non-optional plugin with an initializeEngine() method is to add an image provider that lives in the plugin to the engine. We want to get rid of non-optional plugins. All plugins without image providers in Qt that I have seen can be made optional.

      Some observations:

      • The QML engine itself does not do anything with the image providers. It only stores them.
      • The pixmap cache is the only place where image providers are actually used. The pixmap cache is a completely unprotected global static.
      • The usual initializeEngine() methods in image provider-based plugins just indiscriminately add the image provider to any engine that shows up. How would they discern between engines anyway? Of course someone might have come up with a way to pass information via objectName() or similar. So, we probably need to keep this association around somewhere.
      • The QML engine takes ownership of image providers by storing them in a QSharedPointer. The pointer is never shared with anything.
      • We also have another global static map of pixmap readers, keyed by QQmlEngine: QQuickPixmapReader::readers.

      So, how can we redesign this?

      • We need the image providers to be stored somewhere else
      • We need to allow an image provider to be associated with a QML engine for backwards compatibility

      An obvious solution would be to add a static method to QQuickImageProvider that adds an image provider to the global pixmap cache and on access search that in addition to the engine-specific image providers. The question is then how to statically add pixmap providers to this cache on loading. We have Q_CONSTRUCTOR_FUNCTION, but that still doesn't work in various cases as linkers tend to optimize it away.

      One thing we might do is add a QML_CONSTRUCTOR_FUNCTION(globalFunction) to the list of QML macros. qmltyperegistrar would just generate a call to globalFunction() into the type registration function. Then you could define a function that adds the image provider to the pixmap cache and have that executed when importing the module. We'd conveniently chain this to the static initialization problem we already have ...

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              qtqmlteam Qt Qml Team User
              max.goldstein Maximilian Goldstein
              Votes:
              2 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes