diff options
Diffstat (limited to 'Source/WebCore')
17 files changed, 251 insertions, 68 deletions
diff --git a/Source/WebCore/PlatformQt.cmake b/Source/WebCore/PlatformQt.cmake index 3f839b0dd..a6a807fce 100644 --- a/Source/WebCore/PlatformQt.cmake +++ b/Source/WebCore/PlatformQt.cmake @@ -43,6 +43,7 @@ list(APPEND WebCore_INCLUDE_DIRECTORIES "${WEBCORE_DIR}/platform/network/qt" "${WEBCORE_DIR}/platform/text/qt" "${WEBCORE_DIR}/platform/win" + "${WEBCORE_DIR}/platform/graphics/x11" "${WTF_DIR}" ) @@ -69,6 +70,7 @@ list(APPEND WebCore_SOURCES platform/audio/qt/AudioBusQt.cpp platform/graphics/ImageSource.cpp + platform/graphics/PlatformDisplay.cpp platform/graphics/WOFFFileFormat.cpp platform/graphics/texmap/BitmapTextureImageBuffer.cpp @@ -102,6 +104,9 @@ list(APPEND WebCore_SOURCES platform/graphics/surfaces/qt/GraphicsSurfaceQt.cpp + platform/graphics/x11/PlatformDisplayX11.cpp + platform/graphics/x11/XUniqueResource.cpp + platform/network/NetworkStorageSessionStub.cpp platform/network/MIMESniffing.cpp @@ -186,21 +191,32 @@ if (ENABLE_GRAPHICS_CONTEXT_3D) ) endif () -if (ENABLE_NETSCAPE_PLUGIN_API AND WIN32) - set(WebCore_FORWARDING_HEADERS_FILES - platform/graphics/win/LocalWindowsContext.h - platform/win/BitmapInfo.h - platform/win/WebCoreInstanceHandle.h - ) - list(APPEND WebCore_SOURCES - platform/graphics/win/TransformationMatrixWin.cpp - platform/win/BitmapInfo.cpp - platform/win/WebCoreInstanceHandle.cpp - ) - list(APPEND WebCore_LIBRARIES - Shlwapi - version - ) +if (ENABLE_NETSCAPE_PLUGIN_API) + if (WIN32) + set(WebCore_FORWARDING_HEADERS_FILES + platform/graphics/win/LocalWindowsContext.h + + platform/win/BitmapInfo.h + platform/win/WebCoreInstanceHandle.h + ) + list(APPEND WebCore_SOURCES + platform/graphics/win/TransformationMatrixWin.cpp + + platform/win/BitmapInfo.cpp + platform/win/WebCoreInstanceHandle.cpp + ) + list(APPEND WebCore_LIBRARIES + Shlwapi + version + ) + elseif (PLUGIN_BACKEND_XLIB) + set(WebCore_FORWARDING_HEADERS_FILES + plugins/qt/QtX11ImageConversion.h + ) + list(APPEND WebCore_SOURCES + plugins/qt/QtX11ImageConversion.cpp + ) + endif () endif () if (ENABLE_SMOOTH_SCROLLING) @@ -247,6 +263,7 @@ list(APPEND WebCore_LIBRARIES ${Qt5Network_LIBRARIES} ${Qt5Sensors_LIBRARIES} ${SQLITE_LIBRARIES} + ${X11_X11_LIB} ${ZLIB_LIBRARIES} ) @@ -399,36 +416,6 @@ if (WIN32) ) endif () -if (MSVC) - list(APPEND WebCore_INCLUDE_DIRECTORIES - "${CMAKE_BINARY_DIR}/../include/private" - "${CMAKE_BINARY_DIR}/../include/private/JavaScriptCore" - "${DERIVED_SOURCES_DIR}/ForwardingHeaders/ANGLE" - "${DERIVED_SOURCES_DIR}/ForwardingHeaders/ANGLE/include/KHR" - "${DERIVED_SOURCES_DIR}/ForwardingHeaders/JavaScriptCore" - "${DERIVED_SOURCES_DIR}/ForwardingHeaders/JavaScriptCore/ForwardingHeaders" - "${DERIVED_SOURCES_DIR}/ForwardingHeaders/JavaScriptCore/API" - "${DERIVED_SOURCES_DIR}/ForwardingHeaders/JavaScriptCore/assembler" - "${DERIVED_SOURCES_DIR}/ForwardingHeaders/JavaScriptCore/builtins" - "${DERIVED_SOURCES_DIR}/ForwardingHeaders/JavaScriptCore/bytecode" - "${DERIVED_SOURCES_DIR}/ForwardingHeaders/JavaScriptCore/bytecompiler" - "${DERIVED_SOURCES_DIR}/ForwardingHeaders/JavaScriptCore/dfg" - "${DERIVED_SOURCES_DIR}/ForwardingHeaders/JavaScriptCore/disassembler" - "${DERIVED_SOURCES_DIR}/ForwardingHeaders/JavaScriptCore/heap" - "${DERIVED_SOURCES_DIR}/ForwardingHeaders/JavaScriptCore/debugger" - "${DERIVED_SOURCES_DIR}/ForwardingHeaders/JavaScriptCore/interpreter" - "${DERIVED_SOURCES_DIR}/ForwardingHeaders/JavaScriptCore/jit" - "${DERIVED_SOURCES_DIR}/ForwardingHeaders/JavaScriptCore/llint" - "${DERIVED_SOURCES_DIR}/ForwardingHeaders/JavaScriptCore/parser" - "${DERIVED_SOURCES_DIR}/ForwardingHeaders/JavaScriptCore/profiler" - "${DERIVED_SOURCES_DIR}/ForwardingHeaders/JavaScriptCore/runtime" - "${DERIVED_SOURCES_DIR}/ForwardingHeaders/JavaScriptCore/yarr" - "${DERIVED_SOURCES_DIR}/ForwardingHeaders/WTF" - "${WEBCORE_DIR}/ForwardingHeaders" - "${WEBCORE_DIR}/platform/win" - ) -endif () - if (APPLE) list(APPEND WebCore_SOURCES platform/VNodeTracker.cpp diff --git a/Source/WebCore/page/FrameView.cpp b/Source/WebCore/page/FrameView.cpp index 4bae77613..bf35cf8b2 100644 --- a/Source/WebCore/page/FrameView.cpp +++ b/Source/WebCore/page/FrameView.cpp @@ -4592,6 +4592,7 @@ void FrameView::removeChild(Widget& widget) bool FrameView::wheelEvent(const PlatformWheelEvent& wheelEvent) { +#if !PLATFORM(QT) // Note that to allow for rubber-band over-scroll behavior, even non-scrollable views // should handle wheel events. #if !ENABLE(RUBBER_BANDING) @@ -4609,6 +4610,7 @@ bool FrameView::wheelEvent(const PlatformWheelEvent& wheelEvent) } return true; } +#endif // We don't allow mouse wheeling to happen in a ScrollView that has had its scrollbars explicitly disabled. if (!canHaveScrollbars()) diff --git a/Source/WebCore/platform/PlatformTouchEvent.h b/Source/WebCore/platform/PlatformTouchEvent.h index 7af33d75d..21e306dd5 100644 --- a/Source/WebCore/platform/PlatformTouchEvent.h +++ b/Source/WebCore/platform/PlatformTouchEvent.h @@ -26,12 +26,6 @@ #if ENABLE(TOUCH_EVENTS) -#if PLATFORM(QT) -QT_BEGIN_NAMESPACE -class QTouchEvent; -QT_END_NAMESPACE -#endif - namespace WebCore { diff --git a/Source/WebCore/platform/ScrollView.cpp b/Source/WebCore/platform/ScrollView.cpp index c06450945..33792b6cc 100644 --- a/Source/WebCore/platform/ScrollView.cpp +++ b/Source/WebCore/platform/ScrollView.cpp @@ -574,8 +574,13 @@ void ScrollView::updateScrollbars(const ScrollPosition& desiredPosition) { LOG_WITH_STREAM(Scrolling, stream << "ScrollView::updateScrollbars " << desiredPosition); +#if PLATFORM(QT) + if (m_inUpdateScrollbars || prohibitsScrolling() || platformWidget()) + return; +#else if (m_inUpdateScrollbars || prohibitsScrolling() || platformWidget() || delegatesScrolling()) return; +#endif bool hasOverlayScrollbars = (!m_horizontalScrollbar || m_horizontalScrollbar->isOverlayScrollbar()) && (!m_verticalScrollbar || m_verticalScrollbar->isOverlayScrollbar()); diff --git a/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.cpp b/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.cpp index 812980a28..b6eccf711 100644 --- a/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.cpp +++ b/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.cpp @@ -26,7 +26,7 @@ #include "TextureMapperAnimation.h" #include <wtf/CurrentTime.h> -#if !USE(COORDINATED_GRAPHICS) +#if !USE(COORDINATED_GRAPHICS) || PLATFORM(QT) namespace WebCore { diff --git a/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.h b/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.h index 74f6cea8b..121a54600 100644 --- a/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.h +++ b/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.h @@ -20,7 +20,7 @@ #ifndef GraphicsLayerTextureMapper_h #define GraphicsLayerTextureMapper_h -#if !USE(COORDINATED_GRAPHICS) +#if !USE(COORDINATED_GRAPHICS) || PLATFORM(QT) #include "GraphicsLayer.h" #include "GraphicsLayerClient.h" diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp b/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp index 895d37f39..fc0dafab1 100644 --- a/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp +++ b/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp @@ -451,7 +451,7 @@ TextureMapperLayer::~TextureMapperLayer() } } -#if !USE(COORDINATED_GRAPHICS) +#if !USE(COORDINATED_GRAPHICS) || PLATFORM(QT) void TextureMapperLayer::setChildren(const Vector<GraphicsLayer*>& newChildren) { removeAllChildren(); diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.h b/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.h index 34c399af2..4fdb55263 100644 --- a/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.h +++ b/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.h @@ -76,7 +76,7 @@ public: TextureMapper* textureMapper() const { return rootLayer().m_textureMapper; } void setTextureMapper(TextureMapper* texmap) { m_textureMapper = texmap; } -#if !USE(COORDINATED_GRAPHICS) +#if !USE(COORDINATED_GRAPHICS) || PLATFORM(QT) void setChildren(const Vector<GraphicsLayer*>&); #endif void setChildren(const Vector<TextureMapperLayer*>&); diff --git a/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp b/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp index 7de531692..67d9ceae5 100644 --- a/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp +++ b/Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedGraphicsLayer.cpp @@ -42,6 +42,7 @@ namespace WebCore { +#if !PLATFORM(QT) std::unique_ptr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerFactory* factory, GraphicsLayerClient& client, Type layerType) { if (!factory) @@ -49,6 +50,7 @@ std::unique_ptr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerFactory* facto return factory->createGraphicsLayer(layerType, client); } +#endif static CoordinatedLayerID toCoordinatedLayerID(GraphicsLayer* layer) { diff --git a/Source/WebCore/platform/network/ResourceHandle.cpp b/Source/WebCore/platform/network/ResourceHandle.cpp index 44c007a66..4f1651294 100644 --- a/Source/WebCore/platform/network/ResourceHandle.cpp +++ b/Source/WebCore/platform/network/ResourceHandle.cpp @@ -153,7 +153,7 @@ void ResourceHandle::clearClient() d->m_client = nullptr; } -#if !PLATFORM(COCOA) && !USE(CFNETWORK) && !USE(SOUP) +#if !PLATFORM(COCOA) && !USE(CFNETWORK) && !USE(SOUP) && !PLATFORM(QT) // ResourceHandle never uses async client calls on these platforms yet. void ResourceHandle::continueWillSendRequest(const ResourceRequest&) { diff --git a/Source/WebCore/platform/network/qt/CookieJarQt.cpp b/Source/WebCore/platform/network/qt/CookieJarQt.cpp index 020727cc7..3b08c06cd 100644 --- a/Source/WebCore/platform/network/qt/CookieJarQt.cpp +++ b/Source/WebCore/platform/network/qt/CookieJarQt.cpp @@ -32,6 +32,7 @@ #include "Cookie.h" #include "URL.h" #include "NetworkingContext.h" +#include "NotImplemented.h" #include "PlatformCookieJar.h" #include "SQLiteStatement.h" #include "SQLiteTransaction.h" @@ -114,8 +115,7 @@ String cookieRequestHeaderFieldValue(const NetworkStorageSession& session, const bool cookiesEnabled(const NetworkStorageSession& session, const URL& /*firstParty*/, const URL& /*url*/) { - QNetworkCookieJar* jar = session.context() ? session.context()->networkAccessManager()->cookieJar() : SharedCookieJarQt::shared(); - return !!jar; + return true; } bool getRawCookies(const NetworkStorageSession& session, const URL& /*firstParty*/, const URL& /*url*/, Vector<Cookie>& rawCookies) @@ -138,12 +138,12 @@ void getHostnamesWithCookies(const NetworkStorageSession& session, HashSet<Strin jar->getHostnamesWithCookies(hostnames); } -void deleteCookiesForHostname(const NetworkStorageSession& session, const String& hostname) +void deleteCookiesForHostnames(const NetworkStorageSession& session, const Vector<String>& hostNames) { ASSERT_UNUSED(session, !session.context()); // Not yet implemented for cookie jars other than the shared one. SharedCookieJarQt* jar = SharedCookieJarQt::shared(); if (jar) - jar->deleteCookiesForHostname(hostname); + jar->deleteCookiesForHostnames(hostNames); } void deleteAllCookies(const NetworkStorageSession& session) @@ -154,6 +154,14 @@ void deleteAllCookies(const NetworkStorageSession& session) jar->deleteAllCookies(); } +void deleteAllCookiesModifiedSince(const NetworkStorageSession& session, std::chrono::system_clock::time_point time) +{ + ASSERT_UNUSED(session, !session.context()); // Not yet implemented for cookie jars other than the shared one. + SharedCookieJarQt* jar = SharedCookieJarQt::shared(); + if (jar) + jar->deleteAllCookiesModifiedSince(time); +} + SharedCookieJarQt* SharedCookieJarQt::shared() { return s_sharedCookieJarQt; @@ -203,6 +211,13 @@ bool SharedCookieJarQt::deleteCookie(const QNetworkCookie& cookie) return true; } +void SharedCookieJarQt::deleteCookiesForHostnames(const Vector<WTF::String>& hostNames) +{ + // QTFIXME: Implement as one statement or transaction + for (auto& hostname : hostNames) + deleteCookiesForHostname(hostname); +} + void SharedCookieJarQt::deleteCookiesForHostname(const String& hostname) { if (!m_database.isOpen()) @@ -245,6 +260,12 @@ void SharedCookieJarQt::deleteAllCookies() setAllCookies(QList<QNetworkCookie>()); } +void SharedCookieJarQt::deleteAllCookiesModifiedSince(std::chrono::system_clock::time_point) +{ + // QTFIXME + notImplemented(); +} + SharedCookieJarQt::SharedCookieJarQt(const String& cookieStorageDirectory) { if (!m_database.open(cookieStorageDirectory + ASCIILiteral("/cookies.db"))) { diff --git a/Source/WebCore/platform/network/qt/CookieJarQt.h b/Source/WebCore/platform/network/qt/CookieJarQt.h index 0f7b6abef..fb0e1a7c8 100644 --- a/Source/WebCore/platform/network/qt/CookieJarQt.h +++ b/Source/WebCore/platform/network/qt/CookieJarQt.h @@ -40,8 +40,9 @@ public: void getHostnamesWithCookies(HashSet<String>&); bool deleteCookie(const QNetworkCookie&) final; - void deleteCookiesForHostname(const String&); + void deleteCookiesForHostnames(const Vector<String>&); void deleteAllCookies(); + void deleteAllCookiesModifiedSince(std::chrono::system_clock::time_point); bool setCookiesFromUrl(const QList<QNetworkCookie>&, const QUrl&) final; void loadCookies(); @@ -49,6 +50,7 @@ private: SharedCookieJarQt(const String&); ~SharedCookieJarQt(); bool ensureDatabaseTable(); + void deleteCookiesForHostname(const String&); SQLiteDatabase m_database; }; diff --git a/Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp b/Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp index 951873190..cd096bfe7 100644 --- a/Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp +++ b/Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp @@ -563,6 +563,7 @@ void QNetworkReplyHandler::timerEvent(QTimerEvent* timerEvent) void QNetworkReplyHandler::sendResponseIfNeeded() { ASSERT(m_replyWrapper && m_replyWrapper->reply() && !wasAborted()); + ASSERT(!m_queue.deferSignals()); if (m_replyWrapper->reply()->error() && m_replyWrapper->reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).isNull()) return; @@ -585,7 +586,11 @@ void QNetworkReplyHandler::sendResponseIfNeeded() m_replyWrapper->encoding()); if (url.isLocalFile()) { - client->didReceiveResponse(m_resourceHandle, response); + if (client->usesAsyncCallbacks()) { + setLoadingDeferred(true); + client->didReceiveResponseAsync(m_resourceHandle, response); + } else + client->didReceiveResponse(m_resourceHandle, response); return; } @@ -607,11 +612,41 @@ void QNetworkReplyHandler::sendResponseIfNeeded() return; } - client->didReceiveResponse(m_resourceHandle, response); + if (client->usesAsyncCallbacks()) { + setLoadingDeferred(true); + client->didReceiveResponseAsync(m_resourceHandle, response); + } else + client->didReceiveResponse(m_resourceHandle, response); +} + +void QNetworkReplyHandler::continueAfterWillSendRequest(const ResourceRequest& newRequest) +{ + if (wasAborted()) // Network error cancelled the request. + return; + + m_request = newRequest.toNetworkRequest(m_resourceHandle->getInternal()->m_context.get()); +} + +void QNetworkReplyHandler::continueWillSendRequest(const ResourceRequest& newRequest) +{ + ASSERT(!m_resourceHandle->client() || m_resourceHandle->client()->usesAsyncCallbacks()); + ASSERT(m_queue.deferSignals()); + setLoadingDeferred(false); + + continueAfterWillSendRequest(newRequest); +} + +void QNetworkReplyHandler::continueDidReceiveResponse() +{ + ASSERT(!m_resourceHandle->client() || m_resourceHandle->client()->usesAsyncCallbacks()); + ASSERT(m_queue.deferSignals()); + setLoadingDeferred(false); } void QNetworkReplyHandler::redirect(ResourceResponse& response, const QUrl& redirection) { + ASSERT(!m_queue.deferSignals()); + QUrl newUrl = m_replyWrapper->reply()->url().resolved(redirection); ResourceHandleClient* client = m_resourceHandle->client(); @@ -644,11 +679,13 @@ void QNetworkReplyHandler::redirect(ResourceResponse& response, const QUrl& redi if (!newRequest.url().protocolIs("https") && protocolIs(newRequest.httpReferrer(), "https") && m_resourceHandle->context()->shouldClearReferrerOnHTTPSToHTTPRedirect()) newRequest.clearHTTPReferrer(); - client->willSendRequest(m_resourceHandle, newRequest, response); - if (wasAborted()) // Network error cancelled the request. - return; - - m_request = newRequest.toNetworkRequest(m_resourceHandle->getInternal()->m_context.get()); + if (client->usesAsyncCallbacks()) { + setLoadingDeferred(true); + client->willSendRequestAsync(m_resourceHandle, newRequest, response); + } else { + client->willSendRequest(m_resourceHandle, newRequest, response); + continueAfterWillSendRequest(newRequest); + } } void QNetworkReplyHandler::forwardData() @@ -663,6 +700,15 @@ void QNetworkReplyHandler::forwardData() if (!client) return; + // We have to use didReceiveBuffer instead of didReceiveData + // See https://bugs.webkit.org/show_bug.cgi?id=118598 + // and https://bugs.webkit.org/show_bug.cgi?id=118448#c32 + // NetworkResourceLoader implements only didReceiveBuffer and sends it over IPC to WebProcess + + // See also https://codereview.qt-project.org/#/c/79565/ + // + // FIXME: We need API to get unflattened array of data segments to convert it to non-contiguous SharedBuffer + qint64 bytesAvailable = m_replyWrapper->reply()->bytesAvailable(); Vector<char> buffer(8128); // smaller than 8192 to fit within 8k including overhead. while (bytesAvailable > 0 && !m_queue.deferSignals()) { diff --git a/Source/WebCore/platform/network/qt/QNetworkReplyHandler.h b/Source/WebCore/platform/network/qt/QNetworkReplyHandler.h index 4619e4857..22bf18ed8 100644 --- a/Source/WebCore/platform/network/qt/QNetworkReplyHandler.h +++ b/Source/WebCore/platform/network/qt/QNetworkReplyHandler.h @@ -137,6 +137,9 @@ public: void forwardData(); void sendResponseIfNeeded(); + void continueWillSendRequest(const ResourceRequest&); + void continueDidReceiveResponse(); + static ResourceError errorForReply(QNetworkReply*); private Q_SLOTS: @@ -145,6 +148,7 @@ private Q_SLOTS: private: void start(); String httpMethod() const; + void continueAfterWillSendRequest(const ResourceRequest&); void redirect(ResourceResponse&, const QUrl&); bool wasAborted() const { return !m_resourceHandle; } QNetworkReply* sendNetworkRequest(QNetworkAccessManager*, const ResourceRequest&); diff --git a/Source/WebCore/platform/network/qt/ResourceHandleQt.cpp b/Source/WebCore/platform/network/qt/ResourceHandleQt.cpp index 64c5e47e8..b850e2327 100644 --- a/Source/WebCore/platform/network/qt/ResourceHandleQt.cpp +++ b/Source/WebCore/platform/network/qt/ResourceHandleQt.cpp @@ -135,6 +135,20 @@ void ResourceHandle::cancel() } } +void ResourceHandle::continueWillSendRequest(const ResourceRequest& request) +{ + ASSERT(!client() || client()->usesAsyncCallbacks()); + ASSERT(d->m_job); + d->m_job->continueWillSendRequest(request); +} + +void ResourceHandle::continueDidReceiveResponse() +{ + ASSERT(!client() || client()->usesAsyncCallbacks()); + ASSERT(d->m_job); + d->m_job->continueDidReceiveResponse(); +} + void ResourceHandle::platformLoadResourceSynchronously(NetworkingContext* context, const ResourceRequest& request, StoredCredentials /*storedCredentials*/, ResourceError& error, ResourceResponse& response, Vector<char>& data) { WebCoreSynchronousLoader syncLoader(error, response, data); diff --git a/Source/WebCore/plugins/qt/QtX11ImageConversion.cpp b/Source/WebCore/plugins/qt/QtX11ImageConversion.cpp new file mode 100644 index 000000000..0a76fe239 --- /dev/null +++ b/Source/WebCore/plugins/qt/QtX11ImageConversion.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this program; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#include "config.h" +#include "QtX11ImageConversion.h" + +namespace WebCore { + +QImage qimageFromXImage(XImage* xi) +{ + QImage::Format format = QImage::Format_ARGB32_Premultiplied; + if (xi->depth == 24) + format = QImage::Format_RGB32; + else if (xi->depth == 16) + format = QImage::Format_RGB16; + + QImage image = QImage(reinterpret_cast<uchar*>(xi->data), xi->width, xi->height, xi->bytes_per_line, format).copy(); + + // we may have to swap the byte order + if ((QSysInfo::ByteOrder == QSysInfo::LittleEndian && xi->byte_order == MSBFirst) + || (QSysInfo::ByteOrder == QSysInfo::BigEndian && xi->byte_order == LSBFirst)) { + + for (int i = 0; i < image.height(); i++) { + if (xi->depth == 16) { + ushort* p = reinterpret_cast<ushort*>(image.scanLine(i)); + ushort* end = p + image.width(); + while (p < end) { + *p = ((*p << 8) & 0xff00) | ((*p >> 8) & 0x00ff); + p++; + } + } else { + uint* p = reinterpret_cast<uint*>(image.scanLine(i)); + uint* end = p + image.width(); + while (p < end) { + *p = ((*p << 24) & 0xff000000) | ((*p << 8) & 0x00ff0000) + | ((*p >> 8) & 0x0000ff00) | ((*p >> 24) & 0x000000ff); + p++; + } + } + } + } + + // fix-up alpha channel + if (format == QImage::Format_RGB32) { + QRgb* p = reinterpret_cast<QRgb*>(image.bits()); + for (int y = 0; y < xi->height; ++y) { + for (int x = 0; x < xi->width; ++x) + p[x] |= 0xff000000; + p += xi->bytes_per_line / 4; + } + } + + return image; +} + +} // namespace WebKit diff --git a/Source/WebCore/plugins/qt/QtX11ImageConversion.h b/Source/WebCore/plugins/qt/QtX11ImageConversion.h new file mode 100644 index 000000000..1a999a4ca --- /dev/null +++ b/Source/WebCore/plugins/qt/QtX11ImageConversion.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this program; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef QtX11ImageConversion_h +#define QtX11ImageConversion_h + +#include <QImage> +#include <X11/Xlib.h> + +namespace WebCore { + +QImage qimageFromXImage(XImage*); + +} + +#endif |