Title: [164859] trunk
Revision
164859
Author
za...@apple.com
Date
2014-02-28 07:24: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): unrelated cleanup.
(destroyWebViewAndOffscreenWindow): unrelated cleanup.
(dumpRenderTree):
(changeOffscreenWindowScaleIfNeeded):
(runTest):
* DumpRenderTree/mac/DumpRenderTreeWindow.h:
* DumpRenderTree/mac/DumpRenderTreeWindow.mm:
(-[DumpRenderTreeWindow initWithContentRect:styleMask:backing:defer:]): cleanup.
* WebKitTestRunner/PlatformWebView.h:
* WebKitTestRunner/TestInvocation.cpp:
(WTR::changeOffscreenWindowScaleIfNeeded):
(WTR::TestInvocation::invoke):
* WebKitTestRunner/mac/PlatformWebViewMac.mm:
(WTR::PlatformWebView::changeOffscreenWindowScaleIfNeeded):

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 (164858 => 164859)


--- trunk/LayoutTests/ChangeLog	2014-02-28 14:34:08 UTC (rev 164858)
+++ trunk/LayoutTests/ChangeLog	2014-02-28 15:24:18 UTC (rev 164859)
@@ -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  Mihnea Ovidenie  <mih...@adobe.com>
 
         [CSSRegions] ASSERTION FAILED: !m_regionsInvalidated in RenderFlowThread::regionAtBlockOffset

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


--- 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 15:24:18 UTC (rev 164859)
@@ -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 => 164859)


--- 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 15:24:18 UTC (rev 164859)
@@ -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 (164858 => 164859)


--- trunk/Tools/ChangeLog	2014-02-28 14:34:08 UTC (rev 164858)
+++ trunk/Tools/ChangeLog	2014-02-28 15:24:18 UTC (rev 164859)
@@ -1,3 +1,31 @@
+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): unrelated cleanup.
+        (destroyWebViewAndOffscreenWindow): unrelated cleanup.
+        (dumpRenderTree):
+        (changeOffscreenWindowScaleIfNeeded):
+        (runTest):
+        * DumpRenderTree/mac/DumpRenderTreeWindow.h:
+        * DumpRenderTree/mac/DumpRenderTreeWindow.mm:
+        (-[DumpRenderTreeWindow initWithContentRect:styleMask:backing:defer:]): cleanup.
+        * WebKitTestRunner/PlatformWebView.h:
+        * WebKitTestRunner/TestInvocation.cpp:
+        (WTR::changeOffscreenWindowScaleIfNeeded):
+        (WTR::TestInvocation::invoke):
+        * WebKitTestRunner/mac/PlatformWebViewMac.mm:
+        (WTR::PlatformWebView::changeOffscreenWindowScaleIfNeeded):
+
 2014-02-27  Brian Burg  <bb...@apple.com>
 
         Web Inspector: model tests should use a special Test.html inspector page

Modified: trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm (164858 => 164859)


--- trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm	2014-02-28 14:34:08 UTC (rev 164858)
+++ trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm	2014-02-28 15:24:18 UTC (rev 164859)
@@ -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>
@@ -771,10 +772,36 @@
         [uiWindow retain];
     }
 #endif
+    mainFrame = [webView mainFrame];
 
     return webView;
 }
 
+static void destroyWebViewAndOffscreenWindow()
+{
+    WebView *webView = [mainFrame webView];
+
+    [webView close];
+    mainFrame = nil;
+
+#if !PLATFORM(IOS)
+    NSWindow* window = [webView window];
+    // 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
@@ -1121,8 +1148,7 @@
     [NSSound _setAlertType:0];
 #endif
 
-    WebView *webView = createWebViewAndOffscreenWindow();
-    mainFrame = [webView mainFrame];
+    createWebViewAndOffscreenWindow();
 
     [[NSURLCache sharedURLCache] removeAllCachedResponses];
     [WebCache empty];
@@ -1148,28 +1174,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 +1443,20 @@
     printf("===============================================\n");
 }
 
+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];
+}
+
 static void sizeWebViewForCurrentTest()
 {
     // W3C SVG tests expect to be 480x360
@@ -1733,8 +1753,10 @@
         return;
     }
 
-    const string testURL([[url absoluteString] UTF8String]);
+    const char* testURL([[url absoluteString] UTF8String]);
     
+    changeWindowScaleIfNeeded(testURL);
+
     resetWebViewToConsistentStateBeforeTesting();
 
     gTestRunner = TestRunner::create(testURL, command.expectedPixelHash);

Modified: trunk/Tools/DumpRenderTree/mac/DumpRenderTreeWindow.h (164858 => 164859)


--- trunk/Tools/DumpRenderTree/mac/DumpRenderTreeWindow.h	2014-02-28 14:34:08 UTC (rev 164858)
+++ trunk/Tools/DumpRenderTree/mac/DumpRenderTreeWindow.h	2014-02-28 15:24:18 UTC (rev 164859)
@@ -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 (164858 => 164859)


--- trunk/Tools/DumpRenderTree/mac/DumpRenderTreeWindow.mm	2014-02-28 14:34:08 UTC (rev 164858)
+++ trunk/Tools/DumpRenderTree/mac/DumpRenderTreeWindow.mm	2014-02-28 15:24:18 UTC (rev 164859)
@@ -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 (164858 => 164859)


--- trunk/Tools/WebKitTestRunner/PlatformWebView.h	2014-02-28 14:34:08 UTC (rev 164858)
+++ trunk/Tools/WebKitTestRunner/PlatformWebView.h	2014-02-28 15:24:18 UTC (rev 164859)
@@ -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 (164858 => 164859)


--- trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2014-02-28 14:34:08 UTC (rev 164858)
+++ trunk/Tools/WebKitTestRunner/TestInvocation.cpp	2014-02-28 15:24:18 UTC (rev 164859)
@@ -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 (164858 => 164859)


--- trunk/Tools/WebKitTestRunner/efl/PlatformWebViewEfl.cpp	2014-02-28 14:34:08 UTC (rev 164858)
+++ trunk/Tools/WebKitTestRunner/efl/PlatformWebViewEfl.cpp	2014-02-28 15:24:18 UTC (rev 164859)
@@ -127,6 +127,10 @@
 {
 }
 
+void PlatformWebView::changeWindowScaleIfNeeded(float)
+{
+}
+
 WKRetainPtr<WKImageRef> PlatformWebView::windowSnapshotImage()
 {
     int width;

Modified: trunk/Tools/WebKitTestRunner/gtk/PlatformWebViewGtk.cpp (164858 => 164859)


--- trunk/Tools/WebKitTestRunner/gtk/PlatformWebViewGtk.cpp	2014-02-28 14:34:08 UTC (rev 164858)
+++ trunk/Tools/WebKitTestRunner/gtk/PlatformWebViewGtk.cpp	2014-02-28 15:24:18 UTC (rev 164859)
@@ -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 (164858 => 164859)


--- trunk/Tools/WebKitTestRunner/ios/PlatformWebViewIOS.mm	2014-02-28 14:34:08 UTC (rev 164858)
+++ trunk/Tools/WebKitTestRunner/ios/PlatformWebViewIOS.mm	2014-02-28 15:24:18 UTC (rev 164859)
@@ -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 (164858 => 164859)


--- trunk/Tools/WebKitTestRunner/mac/PlatformWebViewMac.mm	2014-02-28 14:34:08 UTC (rev 164858)
+++ trunk/Tools/WebKitTestRunner/mac/PlatformWebViewMac.mm	2014-02-28 15:24:18 UTC (rev 164859)
@@ -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