Title: [164882] trunk
Revision
164882
Author
za...@apple.com
Date
2014-02-28 13:43:18 -0800 (Fri, 28 Feb 2014)

Log Message

Add hiDPI support to DumpRenderTree/WebKitTestRunner without the need of reloading the test case.
https://bugs.webkit.org/show_bug.cgi?id=129438

Reviewed by Simon Fraser.

'hidpi-' prefixed test cases now trigger 2x scale factor on the testing
offscreen window. It makes testing subpixel rendering and positioning possible.

Both the offscreen window's and WebKit's scaling are set accordingly.

Tools:

* DumpRenderTree/mac/DumpRenderTree.mm:
(createWebViewAndOffscreenWindow): cleanup
(destroyWebViewAndOffscreenWindow): cleanup
(dumpRenderTree):
(changeWindowScaleIfNeeded):
(runTest):
* DumpRenderTree/mac/DumpRenderTreeWindow.h:
* DumpRenderTree/mac/DumpRenderTreeWindow.mm:
(-[DumpRenderTreeWindow initWithContentRect:styleMask:backing:defer:]): cleanup
* WebKitTestRunner/PlatformWebView.h:
* WebKitTestRunner/TestInvocation.cpp:
(WTR::changeWindowScaleIfNeeded):
(WTR::TestInvocation::invoke):
* WebKitTestRunner/efl/PlatformWebViewEfl.cpp:
(WTR::PlatformWebView::changeWindowScaleIfNeeded):
* WebKitTestRunner/gtk/PlatformWebViewGtk.cpp:
(WTR::PlatformWebView::changeWindowScaleIfNeeded):
* WebKitTestRunner/ios/PlatformWebViewIOS.mm:
(WTR::PlatformWebView::changeWindowScaleIfNeeded):
* WebKitTestRunner/mac/PlatformWebViewMac.mm:
(WTR::PlatformWebView::changeWindowScaleIfNeeded):

LayoutTests:

* fast/borders/hidpi-simple-hairline-border-painting-expected.html: Added.
* fast/borders/hidpi-simple-hairline-border-painting.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (164881 => 164882)


--- trunk/LayoutTests/ChangeLog	2014-02-28 21:12:54 UTC (rev 164881)
+++ trunk/LayoutTests/ChangeLog	2014-02-28 21:43:18 UTC (rev 164882)
@@ -1,3 +1,18 @@
+2014-02-28  Zalan Bujtas  <za...@apple.com>
+
+        Add hiDPI support to DumpRenderTree/WebKitTestRunner without the need of reloading the test case.
+        https://bugs.webkit.org/show_bug.cgi?id=129438
+
+        Reviewed by Simon Fraser.
+
+        'hidpi-' prefixed test cases now trigger 2x scale factor on the testing
+        offscreen window. It makes testing subpixel rendering and positioning possible.
+
+        Both the offscreen window's and WebKit's scaling are set accordingly.
+
+        * fast/borders/hidpi-simple-hairline-border-painting-expected.html: Added.
+        * fast/borders/hidpi-simple-hairline-border-painting.html: Added.
+
 2014-02-28  Alexey Proskuryakov  <a...@apple.com>
 
         paragraphs with different directionality in textarea with unicode-bidi: plaintext are aligned the same

Added: trunk/LayoutTests/fast/borders/hidpi-simple-hairline-border-painting-expected.html (0 => 164882)


--- trunk/LayoutTests/fast/borders/hidpi-simple-hairline-border-painting-expected.html	                        (rev 0)
+++ trunk/LayoutTests/fast/borders/hidpi-simple-hairline-border-painting-expected.html	2014-02-28 21:43:18 UTC (rev 164882)
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<title>It tests if 0.5px borders get painted.</title>
+<style>
+  div {
+	width: 49px;
+	height: 49px;
+	border: 1px solid green;
+  }
+</style>
+<body>
+	<div></div>
+</body>

Added: trunk/LayoutTests/fast/borders/hidpi-simple-hairline-border-painting.html (0 => 164882)


--- trunk/LayoutTests/fast/borders/hidpi-simple-hairline-border-painting.html	                        (rev 0)
+++ trunk/LayoutTests/fast/borders/hidpi-simple-hairline-border-painting.html	2014-02-28 21:43:18 UTC (rev 164882)
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<title>It tests if 0.5px borders get painted.</title>
+<style>
+.outer {
+	width: 50px;
+	height: 50px;
+	border: 0.5px solid green;
+}
+.inner {
+	width: 49px;
+	height: 49px;
+	border: 0.5px solid green;
+}
+</style>
+<body>
+	<div class="outer"><div class="inner"></div></div>
+</body>

Modified: trunk/Tools/ChangeLog (164881 => 164882)


--- trunk/Tools/ChangeLog	2014-02-28 21:12:54 UTC (rev 164881)
+++ trunk/Tools/ChangeLog	2014-02-28 21:43:18 UTC (rev 164882)
@@ -1,3 +1,37 @@
+2014-02-28  Zalan Bujtas  <za...@apple.com>
+
+        Add hiDPI support to DumpRenderTree/WebKitTestRunner without the need of reloading the test case.
+        https://bugs.webkit.org/show_bug.cgi?id=129438
+
+        Reviewed by Simon Fraser.
+
+        'hidpi-' prefixed test cases now trigger 2x scale factor on the testing
+        offscreen window. It makes testing subpixel rendering and positioning possible.
+
+        Both the offscreen window's and WebKit's scaling are set accordingly.
+
+        * DumpRenderTree/mac/DumpRenderTree.mm:
+        (createWebViewAndOffscreenWindow): cleanup
+        (destroyWebViewAndOffscreenWindow): cleanup
+        (dumpRenderTree):
+        (changeWindowScaleIfNeeded):
+        (runTest):
+        * DumpRenderTree/mac/DumpRenderTreeWindow.h:
+        * DumpRenderTree/mac/DumpRenderTreeWindow.mm:
+        (-[DumpRenderTreeWindow initWithContentRect:styleMask:backing:defer:]): cleanup
+        * WebKitTestRunner/PlatformWebView.h:
+        * WebKitTestRunner/TestInvocation.cpp:
+        (WTR::changeWindowScaleIfNeeded):
+        (WTR::TestInvocation::invoke):
+        * WebKitTestRunner/efl/PlatformWebViewEfl.cpp:
+        (WTR::PlatformWebView::changeWindowScaleIfNeeded):
+        * WebKitTestRunner/gtk/PlatformWebViewGtk.cpp:
+        (WTR::PlatformWebView::changeWindowScaleIfNeeded):
+        * WebKitTestRunner/ios/PlatformWebViewIOS.mm:
+        (WTR::PlatformWebView::changeWindowScaleIfNeeded):
+        * WebKitTestRunner/mac/PlatformWebViewMac.mm:
+        (WTR::PlatformWebView::changeWindowScaleIfNeeded):
+
 2014-02-28  Anders Carlsson  <ander...@apple.com>
 
         Remove logging.

Modified: trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm (164881 => 164882)


--- trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm	2014-02-28 21:12:54 UTC (rev 164881)
+++ trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm	2014-02-28 21:43:18 UTC (rev 164882)
@@ -90,6 +90,7 @@
 #import <wtf/Threading.h>
 #import <wtf/ObjcRuntimeExtras.h>
 #import <wtf/OwnPtr.h>
+#import <wtf/text/WTFString.h>
 
 #if !PLATFORM(IOS)
 #import <Carbon/Carbon.h>
@@ -775,6 +776,32 @@
     return webView;
 }
 
+static void destroyWebViewAndOffscreenWindow()
+{
+    WebView *webView = [mainFrame webView];
+#if !PLATFORM(IOS)
+    NSWindow *window = [webView window];
+#endif
+    [webView close];
+    mainFrame = nil;
+
+#if !PLATFORM(IOS)
+    // Work around problem where registering drag types leaves an outstanding
+    // "perform selector" on the window, which retains the window. It's a bit
+    // inelegant and perhaps dangerous to just blow them all away, but in practice
+    // it probably won't cause any trouble (and this is just a test tool, after all).
+    [NSObject cancelPreviousPerformRequestsWithTarget:window];
+
+    [window close]; // releases when closed
+#else
+    UIWindow *uiWindow = [gWebBrowserView window];
+    [uiWindow removeFromSuperview];
+    [uiWindow release];
+#endif
+
+    [webView release];
+}
+
 static NSString *libraryPathForDumpRenderTree()
 {
     //FIXME: This may not be sufficient to prevent interactions/crashes
@@ -1148,28 +1175,8 @@
     if (threaded)
         stopJavaScriptThreads();
 
-#if !PLATFORM(IOS)
-    NSWindow *window = [webView window];
-#endif
-    [webView close];
-    mainFrame = nil;
-
-#if !PLATFORM(IOS)
-    // Work around problem where registering drag types leaves an outstanding
-    // "perform selector" on the window, which retains the window. It's a bit
-    // inelegant and perhaps dangerous to just blow them all away, but in practice
-    // it probably won't cause any trouble (and this is just a test tool, after all).
-    [NSObject cancelPreviousPerformRequestsWithTarget:window];
+    destroyWebViewAndOffscreenWindow();
     
-    [window close]; // releases when closed
-#else
-    UIWindow *uiWindow = [gWebBrowserView window];
-    [uiWindow removeFromSuperview];
-    [uiWindow release];
-#endif
-
-    [webView release];
-    
     releaseGlobalControllers();
     
 #if !PLATFORM(IOS)
@@ -1437,6 +1444,22 @@
     printf("===============================================\n");
 }
 
+#if !PLATFORM(IOS)
+static void changeWindowScaleIfNeeded(const char* testPathOrUR)
+{
+    bool hasHighDPIWindow = [[[mainFrame webView] window] backingScaleFactor] != 1;
+    WTF::String localPathOrUrl = String(testPathOrUR);
+    bool needsHighDPIWindow = localPathOrUrl.findIgnoringCase("hidpi-") != notFound;
+    if (hasHighDPIWindow == needsHighDPIWindow)
+        return;
+
+    CGFloat newScaleFactor = needsHighDPIWindow ? 2 : 1;
+    // When the new scale factor is set on the window first, WebView doesn't see it as a new scale and stops propagating the behavior change to WebCore::Page.
+    gTestRunner->setBackingScaleFactor(newScaleFactor);
+    [[[mainFrame webView] window] _setWindowResolution:newScaleFactor displayIfChanged:YES];
+}
+#endif
+
 static void sizeWebViewForCurrentTest()
 {
     // W3C SVG tests expect to be 480x360
@@ -1733,8 +1756,11 @@
         return;
     }
 
-    const string testURL([[url absoluteString] UTF8String]);
+    const char* testURL([[url absoluteString] UTF8String]);
     
+#if !PLATFORM(IOS)
+    changeWindowScaleIfNeeded(testURL);
+#endif
     resetWebViewToConsistentStateBeforeTesting();
 
     gTestRunner = TestRunner::create(testURL, command.expectedPixelHash);

Modified: trunk/Tools/DumpRenderTree/mac/DumpRenderTreeWindow.h (164881 => 164882)


--- trunk/Tools/DumpRenderTree/mac/DumpRenderTreeWindow.h	2014-02-28 21:12:54 UTC (rev 164881)
+++ trunk/Tools/DumpRenderTree/mac/DumpRenderTreeWindow.h	2014-02-28 21:43:18 UTC (rev 164882)
@@ -38,6 +38,12 @@
 
 @class WebView;
 
+@interface NSWindow (Details)
+
+- (void)_setWindowResolution:(CGFloat)resolution displayIfChanged:(BOOL)displayIfChanged;
+
+@end
+
 @interface DumpRenderTreeWindow : NSWindow
 {
 }

Modified: trunk/Tools/DumpRenderTree/mac/DumpRenderTreeWindow.mm (164881 => 164882)


--- trunk/Tools/DumpRenderTree/mac/DumpRenderTreeWindow.mm	2014-02-28 21:12:54 UTC (rev 164881)
+++ trunk/Tools/DumpRenderTree/mac/DumpRenderTreeWindow.mm	2014-02-28 21:43:18 UTC (rev 164882)
@@ -74,8 +74,9 @@
 #if !PLATFORM(IOS)
 - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation
 {
-    [self _addToOpenWindows];
-    return [super initWithContentRect:contentRect styleMask:styleMask backing:bufferingType defer:deferCreation];
+    if ((self = [super initWithContentRect:contentRect styleMask:styleMask backing:bufferingType defer:deferCreation]))
+        [self _addToOpenWindows];
+    return self;
 }
 #else
 - (id)initWithLayer:(CALayer *)layer

Modified: trunk/Tools/WebKitTestRunner/PlatformWebView.h (164881 => 164882)


--- trunk/Tools/WebKitTestRunner/PlatformWebView.h	2014-02-28 21:12:54 UTC (rev 164881)
+++ trunk/Tools/WebKitTestRunner/PlatformWebView.h	2014-02-28 21:43:18 UTC (rev 164882)
@@ -89,6 +89,8 @@
     WKRetainPtr<WKImageRef> windowSnapshotImage();
     WKDictionaryRef options() const { return m_options.get(); }
 
+    void changeWindowScaleIfNeeded(float newScale);
+
 private:
     PlatformWKView m_view;
     PlatformWindow m_window;

Modified: trunk/Tools/WebKitTestRunner/TestInvocation.cpp (164881 => 164882)


--- trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2014-02-28 21:12:54 UTC (rev 164881)
+++ trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2014-02-28 21:43:18 UTC (rev 164882)
@@ -127,6 +127,13 @@
         TestController::shared().mainWebView()->resizeTo(TestController::viewWidth, TestController::viewHeight);
 }
 
+static void changeWindowScaleIfNeeded(const char* pathOrURL)
+{
+    WTF::String localPathOrUrl = String(pathOrURL);
+    bool needsHighDPIWindow = localPathOrUrl.findIgnoringCase("hidpi-") != notFound;
+    TestController::shared().mainWebView()->changeWindowScaleIfNeeded(needsHighDPIWindow ? 2 : 1);
+}
+
 static bool shouldLogFrameLoadDelegates(const char* pathOrURL)
 {
     return strstr(pathOrURL, "loading/");
@@ -193,6 +200,7 @@
 void TestInvocation::invoke()
 {
     TestController::TimeoutDuration timeoutToUse = TestController::LongTimeout;
+    changeWindowScaleIfNeeded(m_pathOrURL.c_str());
     sizeWebViewForCurrentTest(m_pathOrURL.c_str());
     updateLayoutType(m_pathOrURL.c_str());
     updateThreadedScrollingForCurrentTest(m_pathOrURL.c_str());

Modified: trunk/Tools/WebKitTestRunner/efl/PlatformWebViewEfl.cpp (164881 => 164882)


--- trunk/Tools/WebKitTestRunner/efl/PlatformWebViewEfl.cpp	2014-02-28 21:12:54 UTC (rev 164881)
+++ trunk/Tools/WebKitTestRunner/efl/PlatformWebViewEfl.cpp	2014-02-28 21:43:18 UTC (rev 164882)
@@ -127,6 +127,10 @@
 {
 }
 
+void PlatformWebView::changeWindowScaleIfNeeded(float)
+{
+}
+
 WKRetainPtr<WKImageRef> PlatformWebView::windowSnapshotImage()
 {
     int width;

Modified: trunk/Tools/WebKitTestRunner/gtk/PlatformWebViewGtk.cpp (164881 => 164882)


--- trunk/Tools/WebKitTestRunner/gtk/PlatformWebViewGtk.cpp	2014-02-28 21:12:54 UTC (rev 164881)
+++ trunk/Tools/WebKitTestRunner/gtk/PlatformWebViewGtk.cpp	2014-02-28 21:43:18 UTC (rev 164882)
@@ -114,6 +114,10 @@
 {
 }
 
+void PlatformWebView::changeWindowScaleIfNeeded(float)
+{
+}
+
 WKRetainPtr<WKImageRef> PlatformWebView::windowSnapshotImage()
 {
     // FIXME: implement to capture pixels in the UI process,

Modified: trunk/Tools/WebKitTestRunner/ios/PlatformWebViewIOS.mm (164881 => 164882)


--- trunk/Tools/WebKitTestRunner/ios/PlatformWebViewIOS.mm	2014-02-28 21:12:54 UTC (rev 164881)
+++ trunk/Tools/WebKitTestRunner/ios/PlatformWebViewIOS.mm	2014-02-28 21:43:18 UTC (rev 164882)
@@ -207,6 +207,11 @@
 //    [m_window makeFirstResponder:m_view];
 }
 
+void PlatformWebView::changeWindowScaleIfNeeded(float)
+{
+    // Retina only surface.
+}
+
 WKRetainPtr<WKImageRef> PlatformWebView::windowSnapshotImage()
 {
     return 0; // FIXME for iOS?

Modified: trunk/Tools/WebKitTestRunner/mac/PlatformWebViewMac.mm (164881 => 164882)


--- trunk/Tools/WebKitTestRunner/mac/PlatformWebViewMac.mm	2014-02-28 21:12:54 UTC (rev 164881)
+++ trunk/Tools/WebKitTestRunner/mac/PlatformWebViewMac.mm	2014-02-28 21:43:18 UTC (rev 164882)
@@ -109,7 +109,12 @@
     NSRect currentFrame = [self frame];
     return NSMakeRect(_fakeOrigin.x, _fakeOrigin.y, currentFrame.size.width, currentFrame.size.height);
 }
+@end
 
+@interface NSWindow (Details)
+
+- (void)_setWindowResolution:(CGFloat)resolution displayIfChanged:(BOOL)displayIfChanged;
+
 @end
 
 namespace WTR {
@@ -242,4 +247,16 @@
     return useThreadedScrolling == [(TestRunnerWKView *)m_view useThreadedScrolling];
 }
 
+void PlatformWebView::changeWindowScaleIfNeeded(float newScale)
+{
+    CGFloat currentScale = [m_window backingScaleFactor];
+    if (currentScale == newScale)
+        return;
+    [m_window _setWindowResolution:newScale displayIfChanged:YES];
+    // Changing the scaling factor on the window does not trigger NSWindowDidChangeBackingPropertiesNotification. We need to send the notification manually.
+    RetainPtr<NSMutableDictionary> notificationUserInfo = [[NSMutableDictionary alloc] initWithCapacity:1];
+    [notificationUserInfo setObject:[NSNumber numberWithDouble:currentScale] forKey:NSBackingPropertyOldScaleFactorKey];
+    [[NSNotificationCenter defaultCenter] postNotificationName:NSWindowDidChangeBackingPropertiesNotification object:m_window userInfo:notificationUserInfo.get()];
+}
+
 } // namespace WTR
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to