diff --git a/Source/WebCore/platform/graphics/opengl/TextureMapperGL.cpp b/Source/WebCore/platform/graphics/opengl/TextureMapperGL.cpp index 0ff7022..50bfa97 100644 --- a/Source/WebCore/platform/graphics/opengl/TextureMapperGL.cpp +++ b/Source/WebCore/platform/graphics/opengl/TextureMapperGL.cpp @@ -347,6 +347,7 @@ public: void setTextureMapper(TextureMapperGL* texmap) { m_textureMapper = texmap; } void updateContents(PixelFormat, const IntRect&, void*); + void updateRawContents(const IntRect&, const void*); void pack() { // This is currently a stub. @@ -684,19 +685,6 @@ void BitmapTextureGL::endPaint() m_buffer.clear(); } -#ifdef TEXMAP_OPENGL_ES_2 -static void swizzleBGRAToRGBA(uint32_t* data, const IntSize& size) -{ - int width = size.width(); - int height = size.height(); - for (int y = 0; y < height; ++y) { - uint32_t* p = data + y * width; - for (int x = 0; x < width; ++x) - p[x] = ((p[x] << 16) & 0xff0000) | ((p[x] >> 16) & 0xff) | (p[x] & 0xff00ff00); - } -} -#endif - void BitmapTextureGL::updateContents(PixelFormat pixelFormat, const IntRect& rect, void* bits) { GL_CMD(glBindTexture(GL_TEXTURE_2D, m_id)) @@ -737,6 +725,13 @@ void BitmapTextureGL::updateContents(PixelFormat pixelFormat, const IntRect& rec GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(), rect.width(), rect.height(), glFormat, GL_UNSIGNED_BYTE, bits)) } +void BitmapTextureGL::updateRawContents(const IntRect& rect, const void* bits) +{ + GL_CMD(glBindTexture(GL_TEXTURE_2D, m_id)) + GLuint glFormat = isOpaque() ? GL_RGB : GL_RGBA; + GL_CMD(glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(), rect.width(), rect.height(), glFormat, GL_UNSIGNED_BYTE, bits)) +} + void BitmapTextureGL::setContentsToImage(Image* image) { ImageUID uid = image ? uidForImage(image) : 0; diff --git a/Source/WebCore/platform/graphics/qt/TextureMapperQt.cpp b/Source/WebCore/platform/graphics/qt/TextureMapperQt.cpp index f41a421..98cc827 100644 --- a/Source/WebCore/platform/graphics/qt/TextureMapperQt.cpp +++ b/Source/WebCore/platform/graphics/qt/TextureMapperQt.cpp @@ -76,7 +76,6 @@ void BitmapTextureQt::updateContents(PixelFormat pixelFormat, const IntRect& rec m_painter.end(); } - bool BitmapTextureQt::save(const String& path) { return m_pixmap.save(path, "PNG"); diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapper.h b/Source/WebCore/platform/graphics/texmap/TextureMapper.h index c1dcbbd..d66fe2f 100644 --- a/Source/WebCore/platform/graphics/texmap/TextureMapper.h +++ b/Source/WebCore/platform/graphics/texmap/TextureMapper.h @@ -71,6 +71,7 @@ public: // For performance reasons, BitmapTexture might modify the bits directly (swizzle). // Thus, this method is only recommended for buffer update, such as used by WebKit2. virtual void updateContents(PixelFormat, const IntRect&, void* bits) = 0; + virtual void updateRawContents(const IntRect&, const void* bits) { } virtual PlatformGraphicsContext* beginPaintMedia() { return beginPaint(IntRect(0, 0, size().width(), size().height())); diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp b/Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp index 217a955..ccf49bc 100644 --- a/Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp +++ b/Source/WebCore/platform/graphics/texmap/TextureMapperNode.cpp @@ -481,7 +481,7 @@ void TextureMapperNode::clearAllDirectlyCompositedImageTiles() } } -void TextureMapperNode::setContentsTileBackBuffer(int id, const IntRect& sourceRect, const IntRect& targetRect, void* bits, BitmapTexture::PixelFormat format) +void TextureMapperNode::setContentsTileBackBuffer(int id, const IntRect& sourceRect, const IntRect& targetRect, const void* bits) { ASSERT(m_textureMapper); @@ -498,7 +498,7 @@ void TextureMapperNode::setContentsTileBackBuffer(int id, const IntRect& sourceR if (!tile.backBuffer.texture) tile.backBuffer.texture = m_textureMapper->createTexture(); tile.backBuffer.texture->reset(sourceRect.size(), false); - tile.backBuffer.texture->updateContents(format, sourceRect, bits); + tile.backBuffer.texture->updateRawContents(sourceRect, bits); tile.isBackBufferUpdated = true; } diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperNode.h b/Source/WebCore/platform/graphics/texmap/TextureMapperNode.h index 27bff1d..fe4b14c 100644 --- a/Source/WebCore/platform/graphics/texmap/TextureMapperNode.h +++ b/Source/WebCore/platform/graphics/texmap/TextureMapperNode.h @@ -148,7 +148,7 @@ public: void setTileOwnership(TileOwnership ownership) { m_state.tileOwnership = ownership; } int createContentsTile(float scale); void removeContentsTile(int id); - void setContentsTileBackBuffer(int id, const IntRect& sourceRect, const IntRect& targetRect, void* bits, BitmapTexture::PixelFormat); + void setContentsTileBackBuffer(int id, const IntRect& sourceRect, const IntRect& targetRect, const void* bits); void setTileBackBufferTextureForDirectlyCompositedImage(int id, const IntRect& sourceRect, const FloatRect& targetRect, BitmapTexture*); void clearAllDirectlyCompositedImageTiles(); void purgeNodeTexturesRecursive(); diff --git a/Source/WebKit2/Shared/ShareableBitmap.h b/Source/WebKit2/Shared/ShareableBitmap.h index 12cd7ab..c78a14e 100644 --- a/Source/WebKit2/Shared/ShareableBitmap.h +++ b/Source/WebKit2/Shared/ShareableBitmap.h @@ -135,6 +135,7 @@ public: // This creates a QImage that directly references the shared bitmap data. // This is only safe to use when we know that the contents of the shareable bitmap won't change. QImage createQImage(); + void swizzleRGB(); #endif private: diff --git a/Source/WebKit2/Shared/qt/ShareableBitmapQt.cpp b/Source/WebKit2/Shared/qt/ShareableBitmapQt.cpp index b0ab2ec..d5e371d 100644 --- a/Source/WebKit2/Shared/qt/ShareableBitmapQt.cpp +++ b/Source/WebKit2/Shared/qt/ShareableBitmapQt.cpp @@ -70,4 +70,17 @@ void ShareableBitmap::paint(GraphicsContext& /*context*/, float /*scaleFactor*/, notImplemented(); } -} // namespace WebKit +void ShareableBitmap::swizzleRGB() +{ + uint32_t* data = reinterpret_cast(this->data()); + int width = size().width(); + int height = size().height(); + for (int y = 0; y < height; ++y) { + uint32_t* p = data + y * width; + for (int x = 0; x < width; ++x) + p[x] = ((p[x] << 16) & 0xff0000) | ((p[x] >> 16) & 0xff) | (p[x] & 0xff00ff00); + } +} + +} +// namespace WebKit diff --git a/Source/WebKit2/UIProcess/LayerTreeHostProxy.h b/Source/WebKit2/UIProcess/LayerTreeHostProxy.h index 46c4d14..004c280 100644 --- a/Source/WebKit2/UIProcess/LayerTreeHostProxy.h +++ b/Source/WebKit2/UIProcess/LayerTreeHostProxy.h @@ -110,8 +110,8 @@ protected: void syncLayerParameters(const WebLayerInfo&); void createTile(WebLayerID, int, float scale); void removeTile(WebLayerID, int); - void updateTile(WebLayerID, int, const WebCore::IntRect&, const WebCore::IntRect&, const QImage&); - void createImage(int64_t, const QImage&); + void updateTile(WebLayerID, int, const WebCore::IntRect&, const WebCore::IntRect&, ShareableBitmap*); + void createImage(int64_t, ShareableBitmap*); void destroyImage(int64_t); void assignImageToLayer(WebCore::GraphicsLayer*, int64_t imageID); void flushLayerChanges(); diff --git a/Source/WebKit2/UIProcess/qt/LayerTreeHostProxyQt.cpp b/Source/WebKit2/UIProcess/qt/LayerTreeHostProxyQt.cpp index 8c428d7..9405ab7 100644 --- a/Source/WebKit2/UIProcess/qt/LayerTreeHostProxyQt.cpp +++ b/Source/WebKit2/UIProcess/qt/LayerTreeHostProxyQt.cpp @@ -96,7 +96,7 @@ struct UpdateTileMessageData { int remoteTileID; IntRect sourceRect; IntRect targetRect; - QImage image; + RefPtr bitmap; }; struct RemoveTileMessageData { @@ -106,7 +106,7 @@ struct RemoveTileMessageData { struct CreateImageMessageData { int64_t imageID; - QImage image; + RefPtr bitmap; }; struct DestroyImageMessageData { @@ -350,7 +350,7 @@ void LayerTreeHostProxy::removeTile(WebLayerID layerID, int tileID) m_tileToNodeTile.remove(tileID); } -void LayerTreeHostProxy::updateTile(WebLayerID layerID, int tileID, const IntRect& sourceRect, const IntRect& targetRect, const QImage& image) +void LayerTreeHostProxy::updateTile(WebLayerID layerID, int tileID, const IntRect& sourceRect, const IntRect& targetRect, ShareableBitmap* bitmap) { ensureLayer(layerID); TextureMapperNode* node = toTextureMapperNode(layerByID(layerID)); @@ -361,15 +361,16 @@ void LayerTreeHostProxy::updateTile(WebLayerID layerID, int tileID, const IntRec if (!nodeTileID) return; - QImage imageRef(image); node->setTextureMapper(m_textureMapper.get()); - node->setContentsTileBackBuffer(nodeTileID, sourceRect, targetRect, imageRef.bits(), BitmapTexture::BGRAFormat); + QImage image = bitmap->createQImage(); + node->setContentsTileBackBuffer(nodeTileID, sourceRect, targetRect, image.constBits()); } -void LayerTreeHostProxy::createImage(int64_t imageID, const QImage& image) +void LayerTreeHostProxy::createImage(int64_t imageID, ShareableBitmap* bitmap) { TiledImage tiledImage; static const int TileDimension = 1024; + QImage image = bitmap->createQImage(); bool imageHasAlpha = image.hasAlphaChannel(); IntRect imageRect(0, 0, image.width(), image.height()); for (int y = 0; y < image.height(); y += TileDimension) { @@ -383,13 +384,12 @@ void LayerTreeHostProxy::createImage(int64_t imageID, const QImage& image) subImage = image.copy(rect); RefPtr texture = m_textureMapper->createTexture(); texture->reset(rect.size(), !imageHasAlpha); - texture->updateContents(imageHasAlpha ? BitmapTexture::BGRAFormat : BitmapTexture::BGRFormat, IntRect(IntPoint::zero(), rect.size()), subImage.bits()); + texture->updateRawContents(IntRect(IntPoint::zero(), rect.size()), subImage.constBits()); tiledImage.add(rect.location(), texture); } } - m_directlyCompositedImages.remove(imageID); - m_directlyCompositedImages.add(imageID, tiledImage); + m_directlyCompositedImages.set(imageID, tiledImage); } void LayerTreeHostProxy::destroyImage(int64_t imageID) @@ -490,18 +490,18 @@ void LayerTreeHostProxy::syncRemoteContent() case LayerTreeMessageToRenderer::UpdateTile: { const UpdateTileMessageData& data = static_cast(nextMessage.get())->data(); - updateTile(data.layerID, data.remoteTileID, data.sourceRect, data.targetRect, data.image); + updateTile(data.layerID, data.remoteTileID, data.sourceRect, data.targetRect, data.bitmap.get()); break; } case LayerTreeMessageToRenderer::CreateImage: { const CreateImageMessageData& data = static_cast(nextMessage.get())->data(); - createImage(data.imageID, data.image); + createImage(data.imageID, data.bitmap.get()); break; } case LayerTreeMessageToRenderer::DestroyImage: { - const CreateImageMessageData& data = static_cast(nextMessage.get())->data(); + const DestroyImageMessageData& data = static_cast(nextMessage.get())->data(); destroyImage(data.imageID); break; } @@ -534,8 +534,7 @@ void LayerTreeHostProxy::updateTileForLayer(int layerID, int tileID, const WebKi UpdateTileMessageData data; data.layerID = layerID; data.remoteTileID = tileID; - RefPtr bitmap = ShareableBitmap::create(updateInfo.bitmapHandle); - data.image = bitmap->createQImage().copy(); + data.bitmap = ShareableBitmap::create(updateInfo.bitmapHandle); data.sourceRect = IntRect(IntPoint::zero(), updateInfo.updateRectBounds.size()); data.targetRect = updateInfo.updateRectBounds; pushUpdateToQueue(UpdateTileMessage::create(data)); @@ -580,9 +579,8 @@ void LayerTreeHostProxy::didRenderFrame() void LayerTreeHostProxy::createDirectlyCompositedImage(int64_t key, const WebKit::ShareableBitmap::Handle& handle) { CreateImageMessageData data; - RefPtr bitmap = ShareableBitmap::create(handle); data.imageID = key; - data.image = bitmap->createQImage().copy(); + data.bitmap = ShareableBitmap::create(handle); pushUpdateToQueue(CreateImageMessage::create(data)); } @@ -613,7 +611,6 @@ void LayerTreeHostProxy::purgeGLResources() node->purgeNodeTexturesRecursive(); m_directlyCompositedImages.clear(); - m_textureMapper.clear(); m_drawingAreaProxy->page()->process()->send(Messages::LayerTreeHost::PurgeBackingStores(), m_drawingAreaProxy->page()->pageID()); diff --git a/Source/WebKit2/WebProcess/WebPage/TiledBackingStoreRemoteTile.cpp b/Source/WebKit2/WebProcess/WebPage/TiledBackingStoreRemoteTile.cpp index 4140e72..34003af 100644 --- a/Source/WebKit2/WebProcess/WebPage/TiledBackingStoreRemoteTile.cpp +++ b/Source/WebKit2/WebProcess/WebPage/TiledBackingStoreRemoteTile.cpp @@ -88,6 +88,10 @@ Vector TiledBackingStoreRemoteTile::updateBackBuffer() OwnPtr graphicsContext(bitmap->createGraphicsContext()); graphicsContext->drawImageBuffer(m_localBuffer.get(), ColorSpaceDeviceRGB, IntPoint(0, 0)); +#if PLATFORM(QT) + bitmap->swizzleRGB(); +#endif + UpdateInfo updateInfo; updateInfo.updateRectBounds = m_rect; updateInfo.updateScaleFactor = m_tiledBackingStore->contentsScale(); diff --git a/Source/WebKit2/WebProcess/WebPage/qt/LayerTreeHostQt.cpp b/Source/WebKit2/WebProcess/WebPage/qt/LayerTreeHostQt.cpp index 1c74fc8..5de20c2 100644 --- a/Source/WebKit2/WebProcess/WebPage/qt/LayerTreeHostQt.cpp +++ b/Source/WebKit2/WebProcess/WebPage/qt/LayerTreeHostQt.cpp @@ -321,6 +321,7 @@ int64_t LayerTreeHostQt::adoptImageBackingStore(Image* image) graphicsContext->drawImage(image, ColorSpaceDeviceRGB, IntPoint::zero()); } + bitmap->swizzleRGB(); ShareableBitmap::Handle handle; bitmap->createHandle(handle); m_webPage->send(Messages::LayerTreeHostProxy::CreateDirectlyCompositedImage(key, handle));