Changeset 100613 in webkit


Ignore:
Timestamp:
Nov 17, 2011 6:22:48 AM (12 years ago)
Author:
Simon Hausmann
Message:

[Qt] Layer violation: Image::loadPlatformResource uses QWebSettings::webGraphic
https://bugs.webkit.org/show_bug.cgi?id=72594

Reviewed by Kenneth Rohde Christiansen.

Source/WebCore:

Move the cache for the resource pixmaps into ImageQt.cpp.

  • platform/graphics/Image.h: Add Qt specific setter for resource pixmaps.
  • platform/graphics/qt/ImageQt.cpp: Moved resource pixmap hash from qwebsettings.

(earlyClearGraphics):
(graphics):
(loadResourcePixmap):
(WebCore::Image::setPlatformResource):

Source/WebKit/qt:

Move resource pixmap cache into ImageQt.cpp.

  • Api/qwebsettings.cpp:

(resourceNameForWebGraphic): Helper function to translate between public API enums and
resource names.
(QWebSettings::setWebGraphic): Call the new ImageQt::setPlatformResource setter.
(QWebSettings::webGraphic): Call Image::loadPlatformResource to read from the cache
in WebCore.

Location:
trunk/Source
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r100612 r100613  
     12011-11-17  Simon Hausmann  <simon.hausmann@nokia.com>
     2
     3        [Qt] Layer violation: Image::loadPlatformResource uses QWebSettings::webGraphic
     4        https://bugs.webkit.org/show_bug.cgi?id=72594
     5
     6        Reviewed by Kenneth Rohde Christiansen.
     7
     8        Move the cache for the resource pixmaps into ImageQt.cpp.
     9
     10        * platform/graphics/Image.h: Add Qt specific setter for resource pixmaps.
     11        * platform/graphics/qt/ImageQt.cpp: Moved resource pixmap hash from qwebsettings.
     12        (earlyClearGraphics):
     13        (graphics):
     14        (loadResourcePixmap):
     15        (WebCore::Image::setPlatformResource):
     16
    1172011-11-17  Zeno Albisser  <zeno@webkit.org>
    218
  • trunk/Source/WebCore/platform/graphics/Image.h

    r100535 r100613  
    161161#endif
    162162
     163#if PLATFORM(QT)
     164    static void setPlatformResource(const char* name, const QPixmap&);
     165#endif
     166
    163167    virtual void drawPattern(GraphicsContext*, const FloatRect& srcRect, const AffineTransform& patternTransform,
    164168                             const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator, const FloatRect& destRect);
  • trunk/Source/WebCore/platform/graphics/qt/ImageQt.cpp

    r90406 r100613  
    4343#include "qwebsettings.h"
    4444
    45 #include <QPixmap>
    46 #include <QPainter>
     45#include <QApplication>
     46#include <QDebug>
    4747#include <QImage>
    4848#include <QImageReader>
     49#include <QPainter>
     50#include <QPixmap>
     51#include <QStyle>
    4952#include <QTransform>
    5053
    51 #include <QDebug>
    52 
    5354#include <math.h>
     55
     56typedef QHash<QByteArray, QPixmap> WebGraphicHash;
     57Q_GLOBAL_STATIC(WebGraphicHash, _graphics)
     58
     59static void earlyClearGraphics()
     60{
     61    _graphics()->clear();
     62}
     63
     64static WebGraphicHash* graphics()
     65{
     66    WebGraphicHash* hash = _graphics();
     67
     68    if (hash->isEmpty()) {
     69
     70        // prevent ~QPixmap running after ~QApplication (leaks native pixmaps)
     71        qAddPostRoutine(earlyClearGraphics);
     72
     73        // QWebSettings::MissingImageGraphic
     74        hash->insert("missingImage", QPixmap(QLatin1String(":webkit/resources/missingImage.png")));
     75        // QWebSettings::MissingPluginGraphic
     76        hash->insert("nullPlugin", QPixmap(QLatin1String(":webkit/resources/nullPlugin.png")));
     77        // QWebSettings::DefaultFrameIconGraphic
     78        hash->insert("urlIcon", QPixmap(QLatin1String(":webkit/resources/urlIcon.png")));
     79        // QWebSettings::TextAreaSizeGripCornerGraphic
     80        hash->insert("textAreaResizeCorner", QPixmap(QLatin1String(":webkit/resources/textAreaResizeCorner.png")));
     81        // QWebSettings::DeleteButtonGraphic
     82        hash->insert("deleteButton", QPixmap(QLatin1String(":webkit/resources/deleteButton.png")));
     83        // QWebSettings::InputSpeechButtonGraphic
     84        hash->insert("inputSpeech", QPixmap(QLatin1String(":webkit/resources/inputSpeech.png")));
     85        // QWebSettings::SearchCancelButtonGraphic
     86        hash->insert("searchCancelButton", QApplication::style()->standardPixmap(QStyle::SP_DialogCloseButton));
     87        // QWebSettings::SearchCancelButtonPressedGraphic
     88        hash->insert("searchCancelButtonPressed", QApplication::style()->standardPixmap(QStyle::SP_DialogCloseButton));
     89    }
     90
     91    return hash;
     92}
    5493
    5594// This function loads resources into WebKit
    5695static QPixmap loadResourcePixmap(const char *name)
    5796{
    58     QPixmap pixmap;
    59     if (qstrcmp(name, "missingImage") == 0)
    60         pixmap = QWebSettings::webGraphic(QWebSettings::MissingImageGraphic);
    61     else if (qstrcmp(name, "nullPlugin") == 0)
    62         pixmap = QWebSettings::webGraphic(QWebSettings::MissingPluginGraphic);
    63     else if (qstrcmp(name, "urlIcon") == 0)
    64         pixmap = QWebSettings::webGraphic(QWebSettings::DefaultFrameIconGraphic);
    65     else if (qstrcmp(name, "textAreaResizeCorner") == 0)
    66         pixmap = QWebSettings::webGraphic(QWebSettings::TextAreaSizeGripCornerGraphic);
    67     else if (qstrcmp(name, "deleteButton") == 0)
    68         pixmap = QWebSettings::webGraphic(QWebSettings::DeleteButtonGraphic);
    69     else if (!qstrcmp(name, "inputSpeech"))
    70         pixmap = QWebSettings::webGraphic(QWebSettings::InputSpeechButtonGraphic);
    71     else if (!qstrcmp(name, "searchCancelButton"))
    72         pixmap = QWebSettings::webGraphic(QWebSettings::SearchCancelButtonGraphic);
    73     else if (!qstrcmp(name, "searchCancelButtonPressed"))
    74         pixmap = QWebSettings::webGraphic(QWebSettings::SearchCancelButtonPressedGraphic);
    75 
    76     return pixmap;
     97    return graphics()->value(name);
    7798}
    7899
     
    100121{
    101122    return StillImage::create(loadResourcePixmap(name));
     123}
     124
     125void Image::setPlatformResource(const char* name, const QPixmap& pixmap)
     126{
     127    WebGraphicHash* h = graphics();
     128    if (pixmap.isNull())
     129        h->remove(name);
     130    else
     131        h->insert(name, pixmap);
    102132}
    103133
  • trunk/Source/WebKit/qt/Api/qwebsettings.cpp

    r98730 r100613  
    8888    WebCore::Settings* settings;
    8989};
    90 
    91 typedef QHash<int, QPixmap> WebGraphicHash;
    92 Q_GLOBAL_STATIC(WebGraphicHash, _graphics)
    93 
    94 static void earlyClearGraphics()
    95 {
    96     _graphics()->clear();
    97 }
    98 
    99 static WebGraphicHash* graphics()
    100 {
    101     WebGraphicHash* hash = _graphics();
    102 
    103     if (hash->isEmpty()) {
    104 
    105         // prevent ~QPixmap running after ~QApplication (leaks native pixmaps)
    106         qAddPostRoutine(earlyClearGraphics);
    107 
    108         hash->insert(QWebSettings::MissingImageGraphic, QPixmap(QLatin1String(":webkit/resources/missingImage.png")));
    109         hash->insert(QWebSettings::MissingPluginGraphic, QPixmap(QLatin1String(":webkit/resources/nullPlugin.png")));
    110         hash->insert(QWebSettings::DefaultFrameIconGraphic, QPixmap(QLatin1String(":webkit/resources/urlIcon.png")));
    111         hash->insert(QWebSettings::TextAreaSizeGripCornerGraphic, QPixmap(QLatin1String(":webkit/resources/textAreaResizeCorner.png")));
    112         hash->insert(QWebSettings::DeleteButtonGraphic, QPixmap(QLatin1String(":webkit/resources/deleteButton.png")));
    113         hash->insert(QWebSettings::InputSpeechButtonGraphic, QPixmap(QLatin1String(":webkit/resources/inputSpeech.png")));
    114         hash->insert(QWebSettings::SearchCancelButtonGraphic, QApplication::style()->standardPixmap(QStyle::SP_DialogCloseButton));
    115         hash->insert(QWebSettings::SearchCancelButtonPressedGraphic, QApplication::style()->standardPixmap(QStyle::SP_DialogCloseButton));
    116     }
    117 
    118     return hash;
    119 }
    12090
    12191Q_GLOBAL_STATIC(QList<QWebSettingsPrivate*>, allSettings);
     
    752722*/
    753723
     724static const char* resourceNameForWebGraphic(QWebSettings::WebGraphic type)
     725{
     726    switch (type) {
     727    case QWebSettings::MissingImageGraphic: return "missingImage";
     728    case QWebSettings::MissingPluginGraphic: return "nullPlugin";
     729    case QWebSettings::DefaultFrameIconGraphic: return "urlIcon";
     730    case QWebSettings::TextAreaSizeGripCornerGraphic: return "textAreaResizeCorner";
     731    case QWebSettings::DeleteButtonGraphic: return "deleteButton";
     732    case QWebSettings::InputSpeechButtonGraphic: return "inputSpeech";
     733    case QWebSettings::SearchCancelButtonGraphic: return "searchCancelButton";
     734    case QWebSettings::SearchCancelButtonPressedGraphic: return "searchCancelButtonPressed";
     735    }
     736    return 0;
     737}
     738
    754739/*!
    755740    Sets \a graphic to be drawn when QtWebKit needs to draw an image of the
     
    763748void QWebSettings::setWebGraphic(WebGraphic type, const QPixmap& graphic)
    764749{
    765     WebGraphicHash* h = graphics();
    766     if (graphic.isNull())
    767         h->remove(type);
    768     else
    769         h->insert(type, graphic);
     750    WebCore::Image::setPlatformResource(resourceNameForWebGraphic(type), graphic);
    770751}
    771752
     
    778759QPixmap QWebSettings::webGraphic(WebGraphic type)
    779760{
    780     return graphics()->value(type);
     761    RefPtr<WebCore::Image> img = WebCore::Image::loadPlatformResource(resourceNameForWebGraphic(type));
     762    if (!img)
     763        return QPixmap();
     764    QPixmap* pixmap = img->nativeImageForCurrentFrame();
     765    if (!pixmap)
     766        return QPixmap();
     767    return *pixmap;
    781768}
    782769
  • trunk/Source/WebKit/qt/ChangeLog

    r100602 r100613  
     12011-11-17  Simon Hausmann  <simon.hausmann@nokia.com>
     2
     3        [Qt] Layer violation: Image::loadPlatformResource uses QWebSettings::webGraphic
     4        https://bugs.webkit.org/show_bug.cgi?id=72594
     5
     6        Reviewed by Kenneth Rohde Christiansen.
     7
     8        Move resource pixmap cache into ImageQt.cpp.
     9
     10        * Api/qwebsettings.cpp:
     11        (resourceNameForWebGraphic): Helper function to translate between public API enums and
     12        resource names.
     13        (QWebSettings::setWebGraphic): Call the new ImageQt::setPlatformResource setter.
     14        (QWebSettings::webGraphic): Call Image::loadPlatformResource to read from the cache
     15        in WebCore.
     16
    1172011-11-17  Tor Arne Vestbø  <tor.arne.vestbo@nokia.com>
    218
Note: See TracChangeset for help on using the changeset viewer.