Title: [100613] trunk/Source
Revision
100613
Author
hausm...@webkit.org
Date
2011-11-17 06:22:48 -0800 (Thu, 17 Nov 2011)

Log 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.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (100612 => 100613)


--- trunk/Source/WebCore/ChangeLog	2011-11-17 14:15:36 UTC (rev 100612)
+++ trunk/Source/WebCore/ChangeLog	2011-11-17 14:22:48 UTC (rev 100613)
@@ -1,3 +1,19 @@
+2011-11-17  Simon Hausmann  <simon.hausm...@nokia.com>
+
+        [Qt] Layer violation: Image::loadPlatformResource uses QWebSettings::webGraphic
+        https://bugs.webkit.org/show_bug.cgi?id=72594
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        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):
+
 2011-11-17  Zeno Albisser  <z...@webkit.org>
 
         [Qt][WK2] Touch/Mouse events are delivered with wrong coordinates.

Modified: trunk/Source/WebCore/platform/graphics/Image.h (100612 => 100613)


--- trunk/Source/WebCore/platform/graphics/Image.h	2011-11-17 14:15:36 UTC (rev 100612)
+++ trunk/Source/WebCore/platform/graphics/Image.h	2011-11-17 14:22:48 UTC (rev 100613)
@@ -160,6 +160,10 @@
     static PassRefPtr<Image> loadPlatformThemeIcon(const char* name, int size);
 #endif
 
+#if PLATFORM(QT)
+    static void setPlatformResource(const char* name, const QPixmap&);
+#endif
+
     virtual void drawPattern(GraphicsContext*, const FloatRect& srcRect, const AffineTransform& patternTransform,
                              const FloatPoint& phase, ColorSpace styleColorSpace, CompositeOperator, const FloatRect& destRect);
 

Modified: trunk/Source/WebCore/platform/graphics/qt/ImageQt.cpp (100612 => 100613)


--- trunk/Source/WebCore/platform/graphics/qt/ImageQt.cpp	2011-11-17 14:15:36 UTC (rev 100612)
+++ trunk/Source/WebCore/platform/graphics/qt/ImageQt.cpp	2011-11-17 14:22:48 UTC (rev 100613)
@@ -42,38 +42,59 @@
 #include "StillImageQt.h"
 #include "qwebsettings.h"
 
-#include <QPixmap>
-#include <QPainter>
+#include <QApplication>
+#include <QDebug>
 #include <QImage>
 #include <QImageReader>
+#include <QPainter>
+#include <QPixmap>
+#include <QStyle>
 #include <QTransform>
 
-#include <QDebug>
-
 #include <math.h>
 
+typedef QHash<QByteArray, QPixmap> WebGraphicHash;
+Q_GLOBAL_STATIC(WebGraphicHash, _graphics)
+
+static void earlyClearGraphics()
+{
+    _graphics()->clear();
+}
+
+static WebGraphicHash* graphics()
+{
+    WebGraphicHash* hash = _graphics();
+
+    if (hash->isEmpty()) {
+
+        // prevent ~QPixmap running after ~QApplication (leaks native pixmaps)
+        qAddPostRoutine(earlyClearGraphics);
+
+        // QWebSettings::MissingImageGraphic
+        hash->insert("missingImage", QPixmap(QLatin1String(":webkit/resources/missingImage.png")));
+        // QWebSettings::MissingPluginGraphic
+        hash->insert("nullPlugin", QPixmap(QLatin1String(":webkit/resources/nullPlugin.png")));
+        // QWebSettings::DefaultFrameIconGraphic
+        hash->insert("urlIcon", QPixmap(QLatin1String(":webkit/resources/urlIcon.png")));
+        // QWebSettings::TextAreaSizeGripCornerGraphic
+        hash->insert("textAreaResizeCorner", QPixmap(QLatin1String(":webkit/resources/textAreaResizeCorner.png")));
+        // QWebSettings::DeleteButtonGraphic
+        hash->insert("deleteButton", QPixmap(QLatin1String(":webkit/resources/deleteButton.png")));
+        // QWebSettings::InputSpeechButtonGraphic
+        hash->insert("inputSpeech", QPixmap(QLatin1String(":webkit/resources/inputSpeech.png")));
+        // QWebSettings::SearchCancelButtonGraphic
+        hash->insert("searchCancelButton", QApplication::style()->standardPixmap(QStyle::SP_DialogCloseButton));
+        // QWebSettings::SearchCancelButtonPressedGraphic
+        hash->insert("searchCancelButtonPressed", QApplication::style()->standardPixmap(QStyle::SP_DialogCloseButton));
+    }
+
+    return hash;
+}
+
 // This function loads resources into WebKit
 static QPixmap loadResourcePixmap(const char *name)
 {
-    QPixmap pixmap;
-    if (qstrcmp(name, "missingImage") == 0)
-        pixmap = QWebSettings::webGraphic(QWebSettings::MissingImageGraphic);
-    else if (qstrcmp(name, "nullPlugin") == 0)
-        pixmap = QWebSettings::webGraphic(QWebSettings::MissingPluginGraphic);
-    else if (qstrcmp(name, "urlIcon") == 0)
-        pixmap = QWebSettings::webGraphic(QWebSettings::DefaultFrameIconGraphic);
-    else if (qstrcmp(name, "textAreaResizeCorner") == 0)
-        pixmap = QWebSettings::webGraphic(QWebSettings::TextAreaSizeGripCornerGraphic);
-    else if (qstrcmp(name, "deleteButton") == 0)
-        pixmap = QWebSettings::webGraphic(QWebSettings::DeleteButtonGraphic);
-    else if (!qstrcmp(name, "inputSpeech"))
-        pixmap = QWebSettings::webGraphic(QWebSettings::InputSpeechButtonGraphic);
-    else if (!qstrcmp(name, "searchCancelButton"))
-        pixmap = QWebSettings::webGraphic(QWebSettings::SearchCancelButtonGraphic);
-    else if (!qstrcmp(name, "searchCancelButtonPressed"))
-        pixmap = QWebSettings::webGraphic(QWebSettings::SearchCancelButtonPressedGraphic);
-
-    return pixmap;
+    return graphics()->value(name);
 }
 
 namespace WebCore {
@@ -101,6 +122,15 @@
     return StillImage::create(loadResourcePixmap(name));
 }
 
+void Image::setPlatformResource(const char* name, const QPixmap& pixmap)
+{
+    WebGraphicHash* h = graphics();
+    if (pixmap.isNull())
+        h->remove(name);
+    else
+        h->insert(name, pixmap);
+}
+
 void Image::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const AffineTransform& patternTransform,
                         const FloatPoint& phase, ColorSpace, CompositeOperator op, const FloatRect& destRect)
 {

Modified: trunk/Source/WebKit/qt/Api/qwebsettings.cpp (100612 => 100613)


--- trunk/Source/WebKit/qt/Api/qwebsettings.cpp	2011-11-17 14:15:36 UTC (rev 100612)
+++ trunk/Source/WebKit/qt/Api/qwebsettings.cpp	2011-11-17 14:22:48 UTC (rev 100613)
@@ -88,36 +88,6 @@
     WebCore::Settings* settings;
 };
 
-typedef QHash<int, QPixmap> WebGraphicHash;
-Q_GLOBAL_STATIC(WebGraphicHash, _graphics)
-
-static void earlyClearGraphics()
-{
-    _graphics()->clear();
-}
-
-static WebGraphicHash* graphics()
-{
-    WebGraphicHash* hash = _graphics();
-
-    if (hash->isEmpty()) {
-
-        // prevent ~QPixmap running after ~QApplication (leaks native pixmaps)
-        qAddPostRoutine(earlyClearGraphics);
-
-        hash->insert(QWebSettings::MissingImageGraphic, QPixmap(QLatin1String(":webkit/resources/missingImage.png")));
-        hash->insert(QWebSettings::MissingPluginGraphic, QPixmap(QLatin1String(":webkit/resources/nullPlugin.png")));
-        hash->insert(QWebSettings::DefaultFrameIconGraphic, QPixmap(QLatin1String(":webkit/resources/urlIcon.png")));
-        hash->insert(QWebSettings::TextAreaSizeGripCornerGraphic, QPixmap(QLatin1String(":webkit/resources/textAreaResizeCorner.png")));
-        hash->insert(QWebSettings::DeleteButtonGraphic, QPixmap(QLatin1String(":webkit/resources/deleteButton.png")));
-        hash->insert(QWebSettings::InputSpeechButtonGraphic, QPixmap(QLatin1String(":webkit/resources/inputSpeech.png")));
-        hash->insert(QWebSettings::SearchCancelButtonGraphic, QApplication::style()->standardPixmap(QStyle::SP_DialogCloseButton));
-        hash->insert(QWebSettings::SearchCancelButtonPressedGraphic, QApplication::style()->standardPixmap(QStyle::SP_DialogCloseButton));
-    }
-
-    return hash;
-}
-
 Q_GLOBAL_STATIC(QList<QWebSettingsPrivate*>, allSettings);
 
 void QWebSettingsPrivate::apply()
@@ -751,6 +721,21 @@
 }
 */
 
+static const char* resourceNameForWebGraphic(QWebSettings::WebGraphic type)
+{
+    switch (type) {
+    case QWebSettings::MissingImageGraphic: return "missingImage";
+    case QWebSettings::MissingPluginGraphic: return "nullPlugin";
+    case QWebSettings::DefaultFrameIconGraphic: return "urlIcon";
+    case QWebSettings::TextAreaSizeGripCornerGraphic: return "textAreaResizeCorner";
+    case QWebSettings::DeleteButtonGraphic: return "deleteButton";
+    case QWebSettings::InputSpeechButtonGraphic: return "inputSpeech";
+    case QWebSettings::SearchCancelButtonGraphic: return "searchCancelButton";
+    case QWebSettings::SearchCancelButtonPressedGraphic: return "searchCancelButtonPressed";
+    }
+    return 0;
+}
+
 /*!
     Sets \a graphic to be drawn when QtWebKit needs to draw an image of the
     given \a type.
@@ -762,11 +747,7 @@
 */
 void QWebSettings::setWebGraphic(WebGraphic type, const QPixmap& graphic)
 {
-    WebGraphicHash* h = graphics();
-    if (graphic.isNull())
-        h->remove(type);
-    else
-        h->insert(type, graphic);
+    WebCore::Image::setPlatformResource(resourceNameForWebGraphic(type), graphic);
 }
 
 /*!
@@ -777,7 +758,13 @@
 */
 QPixmap QWebSettings::webGraphic(WebGraphic type)
 {
-    return graphics()->value(type);
+    RefPtr<WebCore::Image> img = WebCore::Image::loadPlatformResource(resourceNameForWebGraphic(type));
+    if (!img)
+        return QPixmap();
+    QPixmap* pixmap = img->nativeImageForCurrentFrame();
+    if (!pixmap)
+        return QPixmap();
+    return *pixmap;
 }
 
 /*!

Modified: trunk/Source/WebKit/qt/ChangeLog (100612 => 100613)


--- trunk/Source/WebKit/qt/ChangeLog	2011-11-17 14:15:36 UTC (rev 100612)
+++ trunk/Source/WebKit/qt/ChangeLog	2011-11-17 14:22:48 UTC (rev 100613)
@@ -1,3 +1,19 @@
+2011-11-17  Simon Hausmann  <simon.hausm...@nokia.com>
+
+        [Qt] Layer violation: Image::loadPlatformResource uses QWebSettings::webGraphic
+        https://bugs.webkit.org/show_bug.cgi?id=72594
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        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.
+
 2011-11-17  Tor Arne Vestbø  <tor.arne.ves...@nokia.com>
 
         [Qt] Move WebKit2 C++ APIs to private API and build QML extension plugin on top of that
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to