From 9c8d462eac59a99409f7fe32882202fa082b55a7 Mon Sep 17 00:00:00 2001 From: "Owen W. Taylor" Date: Tue, 18 Feb 2014 13:40:05 -0500 Subject: [PATCH] [GTK][WK2] Implement hi-dpi support for accelerated compositing Source/WebCore * platform/graphics/texmap/TextureMapperLayer.h: Add a deviceScaleFactor argument to paint() to scale the overall matrix and painting up by that factor. * platform/graphics/texmap/TextureMapperTiledBackingStore.cpp * platform/graphics/texmap/TextureMapperTiledBackingStore.h * platform/graphics/texmap/GraphicsLayerTextureMapper.cpp; When painting a layer with a device scale factor, enlarge the backing store appropriately to keep a full-resolution version of the layer contents. Remove the redundant size argument to updateContents() since we can get that information from the GraphicsLayer. * platform/graphics/texmap/TextureMapper.cpp: Handle device scale appropriately in updateContents. * platform/gtk/RedirectedXCompositeWindow.cpp * platform/gtk/RedirectedXCompositeWindow.h: Add the notion of device scale factor to the redirected X composite window; the size of the created window is multiplied by the scale factor, and the scale factor is set on the Cairo surface. Source/WebKit * WebCoreSupport/AcceleratedCompositingContextGL.cpp: * WebCoreSupport/AcceleratedCompositingContextGL.h: Add deviceScaleFactorChanged(), and use the scale factor from the webView for the redirected window and when painting. * WebCoreSupport/ChromeClientGtk.cpp: Call deviceScaleFactorChanged() on the AcceleratedCompositingContext when necessary. Source/WebKit2 * UIProcess/API/gtk/WebKitWebViewBase.cpp Set the device scale factor on the RedirectedXCompositeWindow * WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp * WebProcess/WebPage/gtk/LayerTreeHostGtk.h: Implement deviceScaleFactor() override and pass the scale factor to the TextureMappingLayer when painting. --- Source/WebCore/ChangeLog | 23 +++++++++++++++++++++ .../graphics/texmap/GraphicsLayerTextureMapper.cpp | 2 +- .../platform/graphics/texmap/TextureMapper.cpp | 12 ++++++++--- .../graphics/texmap/TextureMapperLayer.cpp | 3 ++- .../platform/graphics/texmap/TextureMapperLayer.h | 2 +- .../texmap/TextureMapperTiledBackingStore.cpp | 24 ++++++++++++++-------- .../texmap/TextureMapperTiledBackingStore.h | 7 ++++--- .../platform/gtk/RedirectedXCompositeWindow.cpp | 24 +++++++++++++++++----- .../platform/gtk/RedirectedXCompositeWindow.h | 6 ++++-- Source/WebKit/gtk/ChangeLog | 10 +++++++++ .../WebCoreSupport/AcceleratedCompositingContext.h | 2 ++ .../AcceleratedCompositingContextGL.cpp | 22 +++++++++++++++++--- .../WebKit/gtk/WebCoreSupport/ChromeClientGtk.cpp | 15 ++++++++------ Source/WebKit2/ChangeLog | 10 +++++++++ .../UIProcess/API/gtk/WebKitWebViewBase.cpp | 12 +++++++---- .../WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp | 7 ++++++- .../WebProcess/WebPage/gtk/LayerTreeHostGtk.h | 1 + 17 files changed, 144 insertions(+), 38 deletions(-) diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index a560007..83dba09 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,26 @@ +2014-02-18 Owen Taylor + + * platform/graphics/texmap/TextureMapperLayer.h: Add a deviceScaleFactor + argument to paint() to scale the overall matrix and painting up by that + factor. + + * platform/graphics/texmap/TextureMapperTiledBackingStore.cpp + * platform/graphics/texmap/TextureMapperTiledBackingStore.h + * platform/graphics/texmap/GraphicsLayerTextureMapper.cpp; + When painting a layer with a device scale factor, enlarge the backing + store appropriately to keep a full-resolution version of the layer + contents. Remove the redundant size argument to updateContents() + since we can get that information from the GraphicsLayer. + + * platform/graphics/texmap/TextureMapper.cpp: Handle device scale + appropriately in updateContents. + + * platform/gtk/RedirectedXCompositeWindow.cpp + * platform/gtk/RedirectedXCompositeWindow.h: + Add the notion of device scale factor to the redirected X composite window; + the size of the created window is multiplied by the scale factor, and + the scale factor is set on the Cairo surface. + 2014-02-13 Owen Taylor Add deviceScaleFactor support to cairo/WidgetBackingStore diff --git a/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.cpp b/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.cpp index 1b87ee6..1bb35f2 100644 --- a/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.cpp +++ b/Source/WebCore/platform/graphics/texmap/GraphicsLayerTextureMapper.cpp @@ -611,7 +611,7 @@ void GraphicsLayerTextureMapper::updateBackingStoreIfNeeded() TextureMapperTiledBackingStore* backingStore = static_cast(m_backingStore.get()); - backingStore->updateContents(textureMapper, this, m_size, dirtyRect, BitmapTexture::UpdateCanModifyOriginalImageData); + backingStore->updateContents(textureMapper, this, dirtyRect, BitmapTexture::UpdateCanModifyOriginalImageData); m_needsDisplay = false; m_needsDisplayRect = IntRect(); diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapper.cpp b/Source/WebCore/platform/graphics/texmap/TextureMapper.cpp index 4cf4462..b91639b 100644 --- a/Source/WebCore/platform/graphics/texmap/TextureMapper.cpp +++ b/Source/WebCore/platform/graphics/texmap/TextureMapper.cpp @@ -155,10 +155,16 @@ void BitmapTexture::updateContents(TextureMapper* textureMapper, GraphicsLayer* context->setImageInterpolationQuality(textureMapper->imageInterpolationQuality()); context->setTextDrawingMode(textureMapper->textDrawingMode()); - IntRect sourceRect(targetRect); + float deviceScaleFactor = sourceLayer->deviceScaleFactor(); + + FloatRect sourceRect(targetRect); sourceRect.setLocation(offset); - context->translate(-offset.x(), -offset.y()); - sourceLayer->paintGraphicsLayerContents(*context, sourceRect); + sourceRect.scale(1 / deviceScaleFactor); + + context->scale(FloatSize(deviceScaleFactor, deviceScaleFactor)); + context->translate(-sourceRect.x(), -sourceRect.y()); + + sourceLayer->paintGraphicsLayerContents(*context, enclosingIntRect(sourceRect)); RefPtr image = imageBuffer->copyImage(DontCopyBackingStore); diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp b/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp index 86592c6..3d53eb5 100644 --- a/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp +++ b/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp @@ -82,13 +82,14 @@ void TextureMapperLayer::computeTransformsRecursive() sortByZOrder(m_children); } -void TextureMapperLayer::paint() +void TextureMapperLayer::paint(float deviceScaleFactor) { computeTransformsRecursive(); TextureMapperPaintOptions options; options.textureMapper = m_textureMapper; options.textureMapper->bindSurface(0); + options.transform.scale(deviceScaleFactor); paintRecursive(options); } diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.h b/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.h index 9046aa5..d014e99 100644 --- a/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.h +++ b/Source/WebCore/platform/graphics/texmap/TextureMapperLayer.h @@ -126,7 +126,7 @@ public: void syncAnimations(); bool descendantsOrSelfHaveRunningAnimations() const; - void paint(); + void paint(float deviceScaleFactor); void setScrollPositionDeltaIfNeeded(const FloatSize&); diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperTiledBackingStore.cpp b/Source/WebCore/platform/graphics/texmap/TextureMapperTiledBackingStore.cpp index b81b89f..6154904 100644 --- a/Source/WebCore/platform/graphics/texmap/TextureMapperTiledBackingStore.cpp +++ b/Source/WebCore/platform/graphics/texmap/TextureMapperTiledBackingStore.cpp @@ -22,6 +22,7 @@ #if USE(TEXTURE_MAPPER) #include "TextureMapperTiledBackingStore.h" +#include "GraphicsLayer.h" #include "ImageBuffer.h" #include "TextureMapper.h" @@ -69,12 +70,16 @@ void TextureMapperTiledBackingStore::drawRepaintCounter(TextureMapper* textureMa textureMapper->drawNumber(repaintCount, borderColor, m_tiles[i].rect().location(), adjustedTransform); } -void TextureMapperTiledBackingStore::createOrDestroyTilesIfNeeded(const FloatSize& size, const IntSize& tileSize, bool hasAlpha) +void TextureMapperTiledBackingStore::createOrDestroyTilesIfNeeded(const FloatSize& size, float deviceScaleFactor, const IntSize& tileSize, bool hasAlpha) { - if (size == m_size) + if (size == m_size && deviceScaleFactor == m_deviceScaleFactor) return; m_size = size; + m_deviceScaleFactor = deviceScaleFactor; + + FloatSize scaledSize = m_size; + scaledSize.scale(deviceScaleFactor); Vector tileRectsToAdd; Vector tileIndicesToRemove; @@ -82,8 +87,8 @@ void TextureMapperTiledBackingStore::createOrDestroyTilesIfNeeded(const FloatSiz // This method recycles tiles. We check which tiles we need to add, which to remove, and use as many // removable tiles as replacement for new tiles when possible. - for (float y = 0; y < m_size.height(); y += tileSize.height()) { - for (float x = 0; x < m_size.width(); x += tileSize.width()) { + for (float y = 0; y < scaledSize.height(); y += tileSize.height()) { + for (float x = 0; x < scaledSize.width(); x += tileSize.width()) { FloatRect tileRect(x, y, tileSize.width(), tileSize.height()); tileRect.intersect(rect()); tileRectsToAdd.append(tileRect); @@ -135,16 +140,19 @@ void TextureMapperTiledBackingStore::createOrDestroyTilesIfNeeded(const FloatSiz void TextureMapperTiledBackingStore::updateContents(TextureMapper* textureMapper, Image* image, const FloatSize& totalSize, const IntRect& dirtyRect, BitmapTexture::UpdateContentsFlag updateContentsFlag) { - createOrDestroyTilesIfNeeded(totalSize, textureMapper->maxTextureSize(), !image->currentFrameKnownToBeOpaque()); + createOrDestroyTilesIfNeeded(totalSize, 1, textureMapper->maxTextureSize(), !image->currentFrameKnownToBeOpaque()); for (size_t i = 0; i < m_tiles.size(); ++i) m_tiles[i].updateContents(textureMapper, image, dirtyRect, updateContentsFlag); } -void TextureMapperTiledBackingStore::updateContents(TextureMapper* textureMapper, GraphicsLayer* sourceLayer, const FloatSize& totalSize, const IntRect& dirtyRect, BitmapTexture::UpdateContentsFlag updateContentsFlag) +void TextureMapperTiledBackingStore::updateContents(TextureMapper* textureMapper, GraphicsLayer* sourceLayer, const IntRect& dirtyRect, BitmapTexture::UpdateContentsFlag updateContentsFlag) { - createOrDestroyTilesIfNeeded(totalSize, textureMapper->maxTextureSize(), true); + createOrDestroyTilesIfNeeded(sourceLayer->size(), sourceLayer->deviceScaleFactor(), textureMapper->maxTextureSize(), true); + + IntRect scaledDirtyRect = dirtyRect; + scaledDirtyRect.scale(sourceLayer->deviceScaleFactor()); for (size_t i = 0; i < m_tiles.size(); ++i) - m_tiles[i].updateContents(textureMapper, sourceLayer, dirtyRect, updateContentsFlag); + m_tiles[i].updateContents(textureMapper, sourceLayer, scaledDirtyRect, updateContentsFlag); } PassRefPtr TextureMapperTiledBackingStore::texture() const diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperTiledBackingStore.h b/Source/WebCore/platform/graphics/texmap/TextureMapperTiledBackingStore.h index 2f792dc..0e83cc3 100644 --- a/Source/WebCore/platform/graphics/texmap/TextureMapperTiledBackingStore.h +++ b/Source/WebCore/platform/graphics/texmap/TextureMapperTiledBackingStore.h @@ -42,19 +42,20 @@ public: virtual void drawBorder(TextureMapper*, const Color&, float borderWidth, const FloatRect&, const TransformationMatrix&) override; virtual void drawRepaintCounter(TextureMapper*, int repaintCount, const Color&, const FloatRect&, const TransformationMatrix&) override; void updateContents(TextureMapper*, Image*, const FloatSize&, const IntRect&, BitmapTexture::UpdateContentsFlag); - void updateContents(TextureMapper*, GraphicsLayer*, const FloatSize&, const IntRect&, BitmapTexture::UpdateContentsFlag); + void updateContents(TextureMapper*, GraphicsLayer*, const IntRect&, BitmapTexture::UpdateContentsFlag); void setContentsToImage(Image* image) { m_image = image; } private: TextureMapperTiledBackingStore(); - void createOrDestroyTilesIfNeeded(const FloatSize& backingStoreSize, const IntSize& tileSize, bool hasAlpha); + void createOrDestroyTilesIfNeeded(const FloatSize& backingStoreSize, float deviceScaleFactor, const IntSize& tileSize, bool hasAlpha); void updateContentsFromImageIfNeeded(TextureMapper*); TransformationMatrix adjustedTransformForRect(const FloatRect&); - inline FloatRect rect() const { return FloatRect(FloatPoint::zero(), m_size); } + inline FloatRect rect() const { return FloatRect(0, 0, m_size.width() * m_deviceScaleFactor, m_size.height() * m_deviceScaleFactor); } Vector m_tiles; FloatSize m_size; + float m_deviceScaleFactor; RefPtr m_image; }; diff --git a/Source/WebCore/platform/gtk/RedirectedXCompositeWindow.cpp b/Source/WebCore/platform/gtk/RedirectedXCompositeWindow.cpp index c8e81e4..8fb7a9b 100644 --- a/Source/WebCore/platform/gtk/RedirectedXCompositeWindow.cpp +++ b/Source/WebCore/platform/gtk/RedirectedXCompositeWindow.cpp @@ -36,6 +36,7 @@ #include #include #include +#include "CairoUtilities.h" namespace WebCore { @@ -93,13 +94,14 @@ static bool supportsXDamageAndXComposite() return true; } -PassOwnPtr RedirectedXCompositeWindow::create(const IntSize& size, GLContextNeeded needsContext) +PassOwnPtr RedirectedXCompositeWindow::create(const IntSize& size, float deviceScaleFactor, GLContextNeeded needsContext) { - return supportsXDamageAndXComposite() ? adoptPtr(new RedirectedXCompositeWindow(size, needsContext)) : nullptr; + return supportsXDamageAndXComposite() ? adoptPtr(new RedirectedXCompositeWindow(size, deviceScaleFactor, needsContext)) : nullptr; } -RedirectedXCompositeWindow::RedirectedXCompositeWindow(const IntSize& size, GLContextNeeded needsContext) +RedirectedXCompositeWindow::RedirectedXCompositeWindow(const IntSize& size, float deviceScaleFactor, GLContextNeeded needsContext) : m_size(size) + , m_deviceScaleFactor(deviceScaleFactor) , m_window(0) , m_parentWindow(0) , m_pixmap(0) @@ -175,7 +177,9 @@ RedirectedXCompositeWindow::~RedirectedXCompositeWindow() void RedirectedXCompositeWindow::resize(const IntSize& size) { Display* display = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); - XResizeWindow(display, m_window, size.width(), size.height()); + IntSize scaledSize = size; + scaledSize.scale(m_deviceScaleFactor); + XResizeWindow(display, m_window, scaledSize.width(), scaledSize.height()); XFlush(display); @@ -191,6 +195,12 @@ void RedirectedXCompositeWindow::resize(const IntSize& size) m_needsNewPixmapAfterResize = true; } +void RedirectedXCompositeWindow::setDeviceScaleFactor(float deviceScaleFactor) +{ + m_deviceScaleFactor = deviceScaleFactor; + resize(m_size); +} + GLContext* RedirectedXCompositeWindow::context() { ASSERT(m_needsContext == CreateGLContext); @@ -236,9 +246,13 @@ cairo_surface_t* RedirectedXCompositeWindow::cairoSurfaceForWidget(GtkWidget* wi return 0; } + IntSize scaledSize = m_size; + scaledSize.scale(m_deviceScaleFactor); + RefPtr newSurface = adoptRef(cairo_xlib_surface_create(newPixmapDisplay, newPixmap, windowAttributes.visual, - m_size.width(), m_size.height())); + scaledSize.width(), scaledSize.height())); + cairoSurfaceSetDeviceScale(newSurface.get(), m_deviceScaleFactor, m_deviceScaleFactor); // Nvidia drivers seem to prepare their redirected window pixmap asynchronously, so for a few fractions // of a second after each resize, while doing continuous resizing (which constantly destroys and creates diff --git a/Source/WebCore/platform/gtk/RedirectedXCompositeWindow.h b/Source/WebCore/platform/gtk/RedirectedXCompositeWindow.h index 01a5490..dde42b5 100644 --- a/Source/WebCore/platform/gtk/RedirectedXCompositeWindow.h +++ b/Source/WebCore/platform/gtk/RedirectedXCompositeWindow.h @@ -43,11 +43,12 @@ namespace WebCore { class RedirectedXCompositeWindow { public: enum GLContextNeeded { CreateGLContext, DoNotCreateGLContext }; - static PassOwnPtr create(const IntSize&, GLContextNeeded = CreateGLContext); + static PassOwnPtr create(const IntSize&, float, GLContextNeeded = CreateGLContext); virtual ~RedirectedXCompositeWindow(); const IntSize& size() { return m_size; } void resize(const IntSize& newSize); + void setDeviceScaleFactor(float deviceScaleFactor); GLContext* context(); cairo_surface_t* cairoSurfaceForWidget(GtkWidget*); Window windowId() { return m_window; } @@ -60,10 +61,11 @@ public: } private: - RedirectedXCompositeWindow(const IntSize&, GLContextNeeded); + RedirectedXCompositeWindow(const IntSize&, float, GLContextNeeded); void cleanupPixmapAndPixmapSurface(); IntSize m_size; + float m_deviceScaleFactor; Window m_window; Window m_parentWindow; Pixmap m_pixmap; diff --git a/Source/WebKit/gtk/ChangeLog b/Source/WebKit/gtk/ChangeLog index 649aaef..0b57cb4 100644 --- a/Source/WebKit/gtk/ChangeLog +++ b/Source/WebKit/gtk/ChangeLog @@ -1,3 +1,13 @@ +2014-02-18 Owen Taylor + + * WebCoreSupport/AcceleratedCompositingContextGL.cpp: + * WebCoreSupport/AcceleratedCompositingContextGL.h: Add + deviceScaleFactorChanged(), and use the scale factor from the + webView for the redirected window and when painting. + + * WebCoreSupport/ChromeClientGtk.cpp: Call deviceScaleFactorChanged() + on the AcceleratedCompositingContext when necessary. + 2014-02-13 Owen Taylor Implement hi-dpi support diff --git a/Source/WebKit/gtk/WebCoreSupport/AcceleratedCompositingContext.h b/Source/WebKit/gtk/WebCoreSupport/AcceleratedCompositingContext.h index 5d4e848..0381205 100644 --- a/Source/WebKit/gtk/WebCoreSupport/AcceleratedCompositingContext.h +++ b/Source/WebKit/gtk/WebCoreSupport/AcceleratedCompositingContext.h @@ -52,6 +52,7 @@ public: void setNonCompositedContentsNeedDisplay(const WebCore::IntRect&); void scheduleLayerFlush(); void resizeRootLayer(const WebCore::IntSize&); + void deviceScaleFactorChanged(); bool renderLayersToWindow(cairo_t*, const WebCore::IntRect& clipRect); bool enabled(); @@ -59,6 +60,7 @@ public: virtual void notifyAnimationStarted(const WebCore::GraphicsLayer*, double time); virtual void notifyFlushRequired(const WebCore::GraphicsLayer*); virtual void paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, WebCore::GraphicsLayerPaintingPhase, const WebCore::IntRect& rectToPaint); + virtual float deviceScaleFactor() const override; void initialize(); diff --git a/Source/WebKit/gtk/WebCoreSupport/AcceleratedCompositingContextGL.cpp b/Source/WebKit/gtk/WebCoreSupport/AcceleratedCompositingContextGL.cpp index 4535686..0915105 100644 --- a/Source/WebKit/gtk/WebCoreSupport/AcceleratedCompositingContextGL.cpp +++ b/Source/WebKit/gtk/WebCoreSupport/AcceleratedCompositingContextGL.cpp @@ -92,8 +92,10 @@ void AcceleratedCompositingContext::initialize() IntSize pageSize = getWebViewSize(m_webView); if (!m_redirectedWindow) { - if (m_redirectedWindow = RedirectedXCompositeWindow::create(pageSize)) + if (m_redirectedWindow = RedirectedXCompositeWindow::create(pageSize, 1)) { m_redirectedWindow->setDamageNotifyCallback(redirectedWindowDamagedCallback, m_webView); + m_redirectedWindow->setDeviceScaleFactor(deviceScaleFactor()); + } } else m_redirectedWindow->resize(pageSize); @@ -197,7 +199,8 @@ void AcceleratedCompositingContext::compositeLayersToContext(CompositePurpose pu return; const IntSize& windowSize = m_redirectedWindow->size(); - glViewport(0, 0, windowSize.width(), windowSize.height()); + float scaleFactor = deviceScaleFactor(); + glViewport(0, 0, scaleFactor * windowSize.width(), scaleFactor * windowSize.height()); if (purpose == ForResize) { glClearColor(1, 1, 1, 0); @@ -205,7 +208,9 @@ void AcceleratedCompositingContext::compositeLayersToContext(CompositePurpose pu } m_textureMapper->beginPainting(); - toTextureMapperLayer(m_rootLayer.get())->paint(); + + toTextureMapperLayer(m_rootLayer.get())->paint(deviceScaleFactor()); + m_fpsCounter.updateFPSAndDisplay(m_textureMapper.get()); m_textureMapper->endPainting(); @@ -314,6 +319,12 @@ void AcceleratedCompositingContext::resizeRootLayer(const IntSize& newSize) scheduleLayerFlush(); } +void AcceleratedCompositingContext::deviceScaleFactorChanged() +{ + if (m_redirectedWindow) + m_redirectedWindow->setDeviceScaleFactor(deviceScaleFactor()); +} + void AcceleratedCompositingContext::scrollNonCompositedContents(const IntRect& scrollRect, const IntSize& scrollOffset) { m_nonCompositedContentLayer->setNeedsDisplayInRect(scrollRect); @@ -404,6 +415,11 @@ void AcceleratedCompositingContext::paintContents(const GraphicsLayer*, Graphics context.restore(); } +float AcceleratedCompositingContext::deviceScaleFactor() const +{ + return gtk_widget_get_scale_factor(GTK_WIDGET(m_webView)); +} + } // namespace WebKit #endif // USE(TEXTURE_MAPPER_GL) diff --git a/Source/WebKit/gtk/WebCoreSupport/ChromeClientGtk.cpp b/Source/WebKit/gtk/WebCoreSupport/ChromeClientGtk.cpp index 9865f0b..9fa186f 100644 --- a/Source/WebKit/gtk/WebCoreSupport/ChromeClientGtk.cpp +++ b/Source/WebKit/gtk/WebCoreSupport/ChromeClientGtk.cpp @@ -519,16 +519,19 @@ void ChromeClient::widgetSizeChanged(const IntSize& oldWidgetSize, IntSize newSi void ChromeClient::deviceScaleFactorChanged() { - if (m_webView->priv->backingStore) { + AcceleratedCompositingContext* compositingContext = m_webView->priv->acceleratedCompositingContext.get(); + /* When compositing is enabled, we just have a dummy backing store */ + if (!compositingContext->enabled() && m_webView->priv->backingStore) { int scaleFactor = gtk_widget_get_scale_factor(GTK_WIDGET(m_webView)); float oldScaleFactor = m_webView->priv->backingStore->deviceScaleFactor(); - if (scaleFactor == oldScaleFactor) - return; - - m_webView->priv->backingStore = 0; - widgetSizeChanged(IntSize(0, 0), getWebViewRect(m_webView).size()); + if (scaleFactor != oldScaleFactor) { + m_webView->priv->backingStore = 0; + widgetSizeChanged(IntSize(0, 0), getWebViewRect(m_webView).size()); + } } + + m_webView->priv->acceleratedCompositingContext->deviceScaleFactorChanged(); } static void coalesceRectsIfPossible(const IntRect& clipRect, Vector& rects) diff --git a/Source/WebKit2/ChangeLog b/Source/WebKit2/ChangeLog index b788a76..0f17476 100644 --- a/Source/WebKit2/ChangeLog +++ b/Source/WebKit2/ChangeLog @@ -1,3 +1,13 @@ +2014-02-18 Owen Taylor + + * UIProcess/API/gtk/WebKitWebViewBase.cpp + Set the device scale factor on the RedirectedXCompositeWindow + + * WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp + * WebProcess/WebPage/gtk/LayerTreeHostGtk.h: + Implement deviceScaleFactor() override and pass the scale factor + to the TextureMappingLayer when painting. + 2014-02-13 Owen Taylor Implement hi-dpi support for GTK+ diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp index 3c6589a5..bc6815e 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp @@ -397,10 +397,13 @@ static void scaleFactorChanged(GObject *object, GParamSpec *pspec) { WebKitWebViewBasePrivate* priv = WEBKIT_WEB_VIEW_BASE(object)->priv; - if (priv->pageProxy) { - int scaleFactor = gtk_widget_get_scale_factor(GTK_WIDGET(object)); + int scaleFactor = gtk_widget_get_scale_factor(GTK_WIDGET(object)); + + if (priv->pageProxy) priv->pageProxy->setIntrinsicDeviceScaleFactor(scaleFactor); - } + + if (priv->redirectedWindow) + priv->redirectedWindow->setDeviceScaleFactor(scaleFactor); } #endif /* HAVE_GTK_SCALE_FACTOR */ @@ -421,7 +424,8 @@ static void webkitWebViewBaseConstructed(GObject* object) #if USE(TEXTURE_MAPPER_GL) && defined(GDK_WINDOWING_X11) GdkDisplay* display = gdk_display_manager_get_default_display(gdk_display_manager_get()); if (GDK_IS_X11_DISPLAY(display)) { - priv->redirectedWindow = RedirectedXCompositeWindow::create(IntSize(1, 1), RedirectedXCompositeWindow::DoNotCreateGLContext); + int scaleFactor = gtk_widget_get_scale_factor(viewWidget); + priv->redirectedWindow = RedirectedXCompositeWindow::create(IntSize(1, 1), scaleFactor, RedirectedXCompositeWindow::DoNotCreateGLContext); if (priv->redirectedWindow) priv->redirectedWindow->setDamageNotifyCallback(redirectedWindowDamagedCallback, object); } diff --git a/Source/WebKit2/WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp b/Source/WebKit2/WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp index 70f6c83..9f9356f 100644 --- a/Source/WebKit2/WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp +++ b/Source/WebKit2/WebProcess/WebPage/gtk/LayerTreeHostGtk.cpp @@ -287,6 +287,11 @@ void LayerTreeHostGtk::paintContents(const GraphicsLayer* graphicsLayer, Graphic } } +float LayerTreeHostGtk::deviceScaleFactor() const +{ + return m_webPage->deviceScaleFactor(); +} + gboolean LayerTreeHostGtk::layerFlushTimerFiredCallback(LayerTreeHostGtk* layerTreeHost) { layerTreeHost->layerFlushTimerFired(); @@ -338,7 +343,7 @@ void LayerTreeHostGtk::compositeLayersToContext(CompositePurpose purpose) } m_textureMapper->beginPainting(); - toTextureMapperLayer(m_rootLayer.get())->paint(); + toTextureMapperLayer(m_rootLayer.get())->paint(deviceScaleFactor()); m_textureMapper->endPainting(); context->swapBuffers(); diff --git a/Source/WebKit2/WebProcess/WebPage/gtk/LayerTreeHostGtk.h b/Source/WebKit2/WebProcess/WebPage/gtk/LayerTreeHostGtk.h index bb30b09..b381aa4 100644 --- a/Source/WebKit2/WebProcess/WebPage/gtk/LayerTreeHostGtk.h +++ b/Source/WebKit2/WebProcess/WebPage/gtk/LayerTreeHostGtk.h @@ -81,6 +81,7 @@ private: virtual void notifyFlushRequired(const WebCore::GraphicsLayer*); virtual void paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, WebCore::GraphicsLayerPaintingPhase, const WebCore::IntRect& clipRect); virtual void didCommitChangesForLayer(const WebCore::GraphicsLayer*) const { } + virtual float deviceScaleFactor() const override; void createPageOverlayLayer(PageOverlay*); void destroyPageOverlayLayer(PageOverlay*); -- 1.8.5.3