Skip to content
Permalink
Browse files
2010-07-15 Shinichiro Hamaji <hamaji@chromium.org>
        Reviewed by Darin Adler.

        Printing test results differ between machines, we should use ImageDiff instead
        https://bugs.webkit.org/show_bug.cgi?id=20011

        Added printing/setPrinting.html to check there is the page boundary.

        Enabled printing/composite-layer-printing.html with setPrinting.

        The result of printing/media-queries-print.html shrunk because of
        PrintingMinimumShrinkFactor in PrintContext::begin().

        * platform/mac/Skipped:
        * platform/mac/printing/compositing-layer-printing-expected.checksum: Added.
        * platform/mac/printing/compositing-layer-printing-expected.png: Added.
        * platform/mac/printing/compositing-layer-printing-expected.txt: Added.
        * platform/mac/printing/media-queries-print-expected.checksum:
        * platform/mac/printing/media-queries-print-expected.png:
        * platform/mac/printing/setPrinting-expected.checksum: Added.
        * platform/mac/printing/setPrinting-expected.png: Added.
        * platform/mac/printing/setPrinting-expected.txt: Added.
        * printing/compositing-layer-printing.html:
        * printing/setPrinting.html: Added.
2010-07-15  Shinichiro Hamaji  <hamaji@chromium.org>

        Reviewed by Darin Adler.

        Printing test results differ between machines, we should use ImageDiff instead
        https://bugs.webkit.org/show_bug.cgi?id=20011

        Added spoolAllPagesWithBoundaries into PrintContext.

        Test: printing/setPrinting.html

        * WebCore.base.exp:
        * page/PrintContext.cpp:
        (WebCore::PrintContext::spoolAllPagesWithBoundaries):
        * page/PrintContext.h:
2010-07-15  Shinichiro Hamaji  <hamaji@chromium.org>

        Reviewed by Darin Adler.

        Printing test results differ between machines, we should use ImageDiff instead
        https://bugs.webkit.org/show_bug.cgi?id=20011

        * Misc/WebCoreStatistics.h:
        * Misc/WebCoreStatistics.mm:
        (-[WebFrame printToCGContext:cgContext:pageWidthInPixels:]):
2010-07-15  Shinichiro Hamaji  <hamaji@chromium.org>

        Reviewed by Darin Adler.

        Printing test results differ between machines, we should use ImageDiff instead
        https://bugs.webkit.org/show_bug.cgi?id=20011

        * DumpRenderTree/PixelDumpSupport.cpp:
        (dumpWebViewAsPixelsAndCompareWithExpected):
        * DumpRenderTree/PixelDumpSupport.h:
        * DumpRenderTree/mac/PixelDumpSupportMac.mm:
        (createBitmapContext): This function was added to share bitmap context creation code.
        (createBitmapContextFromWebView):
        (createPagedBitmapContext):

Canonical link: https://commits.webkit.org/54361@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@63521 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Shinichiro Hamaji committed Jul 16, 2010
1 parent 76c411b commit 3a898c6f3d9f0e19211199911db120f5d9e73b02
Showing 26 changed files with 228 additions and 20 deletions.
@@ -1,3 +1,29 @@
2010-07-15 Shinichiro Hamaji <hamaji@chromium.org>

Reviewed by Darin Adler.

Printing test results differ between machines, we should use ImageDiff instead
https://bugs.webkit.org/show_bug.cgi?id=20011

Added printing/setPrinting.html to check there is the page boundary.

Enabled printing/composite-layer-printing.html with setPrinting.

The result of printing/media-queries-print.html shrunk because of
PrintingMinimumShrinkFactor in PrintContext::begin().

* platform/mac/Skipped:
* platform/mac/printing/compositing-layer-printing-expected.checksum: Added.
* platform/mac/printing/compositing-layer-printing-expected.png: Added.
* platform/mac/printing/compositing-layer-printing-expected.txt: Added.
* platform/mac/printing/media-queries-print-expected.checksum:
* platform/mac/printing/media-queries-print-expected.png:
* platform/mac/printing/setPrinting-expected.checksum: Added.
* platform/mac/printing/setPrinting-expected.png: Added.
* platform/mac/printing/setPrinting-expected.txt: Added.
* printing/compositing-layer-printing.html:
* printing/setPrinting.html: Added.

2010-07-15 MORITA Hajime <morrita@google.com>

Unrviewed, added missing expectations.
@@ -5861,3 +5861,6 @@ http/tests/loading/preload-slow-loading.php

# Directory upload is not enabled.
fast/forms/input-file-directory-upload.html

# Need setPrinting. See https://bugs.webkit.org/show_bug.cgi?id=20011
printing/setPrinting.html
@@ -35,9 +35,6 @@ fast/events/attempt-scroll-with-no-scrollbars.html
# see bug <rdar://problem/5646437> REGRESSION (r28015): svg/batik/text/smallFonts fails
svg/batik/text/smallFonts.svg

# see bug https://bugs.webkit.org/show_bug.cgi?id=20011 -- Printing tests should use ImageDiff
printing/compositing-layer-printing.html

# Skip because fix for https://bugs.webkit.org/show_bug.cgi?id=26770 was reverted
compositing/animation/animated-composited-inside-hidden.html

@@ -0,0 +1 @@
590ebb52f9258d18c8e95839d2823f84
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,11 @@
layer at (0,0) size 1000x270
RenderView at (0,0) size 1000x270
layer at (0,0) size 1000x270
RenderBlock {HTML} at (0,0) size 1000x270
RenderBody {BODY} at (8,16) size 984x244
RenderBlock {P} at (0,0) size 984x18
RenderText {#text} at (0,0) size 454x18
text run at (0,0) width 454: "You should see two green squares below on screen, and when printed."
RenderBlock {DIV} at (10,34) size 100x100 [bgcolor=#008000]
layer at (18,160) size 100x100
RenderBlock {DIV} at (10,144) size 100x100 [bgcolor=#008000]
@@ -1 +1 @@
6090d2b0a19649aba8a379f982a345d3
9ea3bf56e7033cfee8a2beb3a800d85f
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1 @@
acb402590109e72d730b68ed674c8708
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,12 @@
layer at (0,0) size 982x785
RenderView at (0,0) size 982x785
layer at (0,0) size 982x785
RenderBlock {HTML} at (0,0) size 982x785
RenderBody {BODY} at (0,0) size 982x785
RenderBlock {DIV} at (0,0) size 800x749 [bgcolor=#008000]
RenderText {#text} at (0,0) size 237x18
text run at (0,0) width 237: "This test case should output 2 pages."
RenderBlock (anonymous) at (0,749) size 982x36
RenderText {#text} at (0,0) size 972x36
text run at (0,0) width 972: "There should be a blue line above this test. This line is the boundary of 2 pages. As the height of green box is shorter than the height of a page by one"
text run at (0,18) width 485: "pixel, there should be a white line between the green box and the blue line."
@@ -5463,3 +5463,6 @@ inspector/timeline-recalculate-styles.html

# Directory upload is not enabled.
fast/forms/input-file-directory-upload.html

# Need setPrinting. See https://bugs.webkit.org/show_bug.cgi?id=20011
printing/setPrinting.html
@@ -956,3 +956,6 @@ userscripts/user-style-top-frame-only.html

# Directory upload is not enabled.
fast/forms/input-file-directory-upload.html

# Need setPrinting. See https://bugs.webkit.org/show_bug.cgi?id=20011
printing/setPrinting.html
@@ -13,7 +13,7 @@
</style>
<script>
if (window.layoutTestController)
layoutTestController.printToPDF();
layoutTestController.setPrinting();
</script>
</head>
<body>
@@ -0,0 +1,19 @@
<html>
<head>
<script>
if (window.layoutTestController)
layoutTestController.setPrinting();
</script>
</head>

<body style="margin: 0px;">
<div style="width: 800px; height: 749px; background-color: green;">
This test case should output 2 pages.
</div>
There should be a blue line above this test.
This line is the boundary of 2 pages.
As the height of green box is shorter than the height of a page by one pixel,
there should be a white line between the green box and the blue line.
</div>
</body>
</html>
@@ -1,3 +1,19 @@
2010-07-15 Shinichiro Hamaji <hamaji@chromium.org>

Reviewed by Darin Adler.

Printing test results differ between machines, we should use ImageDiff instead
https://bugs.webkit.org/show_bug.cgi?id=20011

Added spoolAllPagesWithBoundaries into PrintContext.

Test: printing/setPrinting.html

* WebCore.base.exp:
* page/PrintContext.cpp:
(WebCore::PrintContext::spoolAllPagesWithBoundaries):
* page/PrintContext.h:

2010-07-15 Kent Tamura <tkent@chromium.org>

Unreviewed, small style fixes.
@@ -255,6 +255,7 @@ __ZN7WebCore12PrintContext13numberOfPagesEPNS_5FrameERKNS_9FloatSizeE
__ZN7WebCore12PrintContext16isPageBoxVisibleEPNS_5FrameEi
__ZN7WebCore12PrintContext20pageNumberForElementEPNS_7ElementERKNS_9FloatSizeE
__ZN7WebCore12PrintContext26pageSizeAndMarginsInPixelsEPNS_5FrameEiiiiiii
__ZN7WebCore12PrintContext27spoolAllPagesWithBoundariesEPNS_5FrameERNS_15GraphicsContextERKNS_9FloatSizeE
__ZN7WebCore12PrintContext28computePageRectsWithPageSizeERKNS_9FloatSizeEb
__ZN7WebCore12PrintContextC1EPNS_5FrameE
__ZN7WebCore12PrintContextD1Ev
@@ -244,4 +244,52 @@ int PrintContext::numberOfPages(Frame* frame, const FloatSize& pageSizeInPixels)
return printContext.pageCount();
}

void PrintContext::spoolAllPagesWithBoundaries(Frame* frame, GraphicsContext& graphicsContext, const FloatSize& pageSizeInPixels)
{
if (!frame->document() || !frame->view() || !frame->document()->renderer())
return;

frame->document()->updateLayout();

PrintContext printContext(frame);
printContext.begin(pageSizeInPixels.width());

float pageHeight;
printContext.computePageRects(FloatRect(FloatPoint(0, 0), pageSizeInPixels), 0, 0, 1, pageHeight);

const float pageWidth = pageSizeInPixels.width();
const Vector<IntRect>& pageRects = printContext.pageRects();
int totalHeight = pageRects.size() * (pageSizeInPixels.height() + 1) - 1;

// Fill the whole background by white.
graphicsContext.setFillColor(Color(255, 255, 255), DeviceColorSpace);
graphicsContext.fillRect(FloatRect(0, 0, pageWidth, totalHeight));

graphicsContext.save();
graphicsContext.translate(0, totalHeight);
graphicsContext.scale(FloatSize(1, -1));

int currentHeight = 0;
for (size_t pageIndex = 0; pageIndex < pageRects.size(); pageIndex++) {
// Draw a line for a page boundary if this isn't the first page.
if (pageIndex > 0) {
graphicsContext.save();
graphicsContext.setStrokeColor(Color(0, 0, 255), DeviceColorSpace);
graphicsContext.setFillColor(Color(0, 0, 255), DeviceColorSpace);
graphicsContext.drawLine(IntPoint(0, currentHeight),
IntPoint(pageWidth, currentHeight));
graphicsContext.restore();
}

graphicsContext.save();
graphicsContext.translate(0, currentHeight);
printContext.spoolPage(graphicsContext, pageIndex, pageWidth);
graphicsContext.restore();

currentHeight += pageSizeInPixels.height() + 1;
}

graphicsContext.restore();
}

}
@@ -59,6 +59,10 @@ class PrintContext {
static bool isPageBoxVisible(Frame* frame, int pageNumber);
static String pageSizeAndMarginsInPixels(Frame* frame, int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft);
static int numberOfPages(Frame*, const FloatSize& pageSizeInPixels);
// Draw all pages into a graphics context with lines which mean page boundaries.
// The height of the graphics context should be
// (pageSizeInPixels.height() + 1) * number-of-pages - 1
static void spoolAllPagesWithBoundaries(Frame*, GraphicsContext&, const FloatSize& pageSizeInPixels);

protected:
Frame* m_frame;
@@ -1,3 +1,14 @@
2010-07-15 Shinichiro Hamaji <hamaji@chromium.org>

Reviewed by Darin Adler.

Printing test results differ between machines, we should use ImageDiff instead
https://bugs.webkit.org/show_bug.cgi?id=20011

* Misc/WebCoreStatistics.h:
* Misc/WebCoreStatistics.mm:
(-[WebFrame printToCGContext:cgContext:pageWidthInPixels:]):

2010-07-15 Daniel Bates <dbates@rim.com>

Reviewed by Darin Adler.
@@ -90,4 +90,5 @@
- (NSString *)pageProperty:(const char*)propertyName:(int)pageNumber;
- (bool)isPageBoxVisible:(int)pageNumber;
- (NSString *)pageSizeAndMarginsInPixels:(int)pageNumber:(int)width:(int)height:(int)marginTop:(int)marginRight:(int)marginBottom:(int)marginLeft;
- (void)printToCGContext:(CGContextRef)cgContext:(float)pageWidthInPixels:(float)pageHeightInPixels;
@end
@@ -37,6 +37,7 @@
#import <WebCore/Frame.h>
#import <WebCore/GCController.h>
#import <WebCore/GlyphPageTreeNode.h>
#import <WebCore/GraphicsContext.h>
#import <WebCore/IconDatabase.h>
#import <WebCore/JSDOMWindow.h>
#import <WebCore/PageCache.h>
@@ -289,4 +290,15 @@ - (NSString *)pageSizeAndMarginsInPixels:(int)pageNumber:(int)width:(int)height:
{
return PrintContext::pageSizeAndMarginsInPixels(_private->coreFrame, pageNumber, width, height, marginTop, marginRight, marginBottom, marginLeft);
}

- (void)printToCGContext:(CGContextRef)cgContext:(float)pageWidthInPixels:(float)pageHeightInPixels
{
Frame* coreFrame = _private->coreFrame;
if (!coreFrame)
return;

GraphicsContext graphicsContext(cgContext);
PrintContext::spoolAllPagesWithBoundaries(coreFrame, graphicsContext, FloatSize(pageWidthInPixels, pageHeightInPixels));
}

@end
@@ -1,3 +1,18 @@
2010-07-15 Shinichiro Hamaji <hamaji@chromium.org>

Reviewed by Darin Adler.

Printing test results differ between machines, we should use ImageDiff instead
https://bugs.webkit.org/show_bug.cgi?id=20011

* DumpRenderTree/PixelDumpSupport.cpp:
(dumpWebViewAsPixelsAndCompareWithExpected):
* DumpRenderTree/PixelDumpSupport.h:
* DumpRenderTree/mac/PixelDumpSupportMac.mm:
(createBitmapContext): This function was added to share bitmap context creation code.
(createBitmapContextFromWebView):
(createPagedBitmapContext):

2010-07-15 Yuta Kitamura <yutak@chromium.org>

Reviewed by Kent Tamura.
@@ -42,7 +42,11 @@

void dumpWebViewAsPixelsAndCompareWithExpected(const std::string& expectedHash)
{
RefPtr<BitmapContext> context = createBitmapContextFromWebView(gLayoutTestController->testOnscreen(), gLayoutTestController->testRepaint(), gLayoutTestController->testRepaintSweepHorizontally(), gLayoutTestController->dumpSelectionRect());
RefPtr<BitmapContext> context;
if (gLayoutTestController->isPrinting())
context = createPagedBitmapContext();
else
context = createBitmapContextFromWebView(gLayoutTestController->testOnscreen(), gLayoutTestController->testRepaint(), gLayoutTestController->testRepaintSweepHorizontally(), gLayoutTestController->dumpSelectionRect());
ASSERT(context);

// Compute the hash of the bitmap context pixels
@@ -36,6 +36,7 @@
class BitmapContext;

void computeMD5HashStringForBitmapContext(BitmapContext*, char hashString[33]);
PassRefPtr<BitmapContext> createPagedBitmapContext();
PassRefPtr<BitmapContext> createBitmapContextFromWebView(bool onscreen, bool incrementalRepaint, bool sweepHorizontally, bool drawSelectionRect);
void dumpBitmap(BitmapContext*);
void dumpWebViewAsPixelsAndCompareWithExpected(const std::string& expectedHash);
@@ -38,6 +38,7 @@
#include <wtf/Assertions.h>
#include <wtf/RefPtr.h>

#import <WebKit/WebCoreStatistics.h>
#import <WebKit/WebDocumentPrivate.h>
#import <WebKit/WebHTMLViewPrivate.h>
#import <WebKit/WebKit.h>
@@ -104,18 +105,8 @@ void setupMainDisplayColorProfile()
signal(SIGTERM, restoreMainDisplayColorProfile);
}

PassRefPtr<BitmapContext> createBitmapContextFromWebView(bool onscreen, bool incrementalRepaint, bool sweepHorizontally, bool drawSelectionRect)
static PassRefPtr<BitmapContext> createBitmapContext(size_t pixelsWide, size_t pixelsHigh)
{
WebView* view = [mainFrame webView];

// If the WebHTMLView uses accelerated compositing, we need for force the on-screen capture path
// and also force Core Animation to start its animations with -display since the DRT window has autodisplay disabled.
if ([view _isUsingAcceleratedCompositing])
onscreen = YES;

NSSize webViewSize = [view frame].size;
size_t pixelsWide = static_cast<size_t>(webViewSize.width);
size_t pixelsHigh = static_cast<size_t>(webViewSize.height);
size_t rowBytes = (4 * pixelsWide + 63) & ~63; // Use a multiple of 64 bytes to improve CG performance

void *buffer = calloc(pixelsHigh, rowBytes);
@@ -140,9 +131,26 @@ void setupMainDisplayColorProfile()
return 0;
}

// The BitmapContext keeps the CGContextRef and the pixel buffer alive
RefPtr<BitmapContext> bitmapContext = BitmapContext::createByAdoptingBitmapAndContext(buffer, context);

return BitmapContext::createByAdoptingBitmapAndContext(buffer, context);
}

PassRefPtr<BitmapContext> createBitmapContextFromWebView(bool onscreen, bool incrementalRepaint, bool sweepHorizontally, bool drawSelectionRect)
{
WebView* view = [mainFrame webView];

// If the WebHTMLView uses accelerated compositing, we need for force the on-screen capture path
// and also force Core Animation to start its animations with -display since the DRT window has autodisplay disabled.
if ([view _isUsingAcceleratedCompositing])
onscreen = YES;

NSSize webViewSize = [view frame].size;
size_t pixelsWide = static_cast<size_t>(webViewSize.width);
size_t pixelsHigh = static_cast<size_t>(webViewSize.height);
RefPtr<BitmapContext> bitmapContext = createBitmapContext(pixelsWide, pixelsHigh);
if (!bitmapContext)
return 0;
CGContextRef context = bitmapContext->cgContext();

NSGraphicsContext *nsContext = [NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO];
ASSERT(nsContext);

@@ -254,3 +262,14 @@ void setupMainDisplayColorProfile()

return bitmapContext.release();
}

PassRefPtr<BitmapContext> createPagedBitmapContext()
{
int pageWidthInPixels = LayoutTestController::maxViewWidth;
int pageHeightInPixels = LayoutTestController::maxViewHeight;
int numberOfPages = [mainFrame numberOfPages:pageWidthInPixels:pageHeightInPixels];

RefPtr<BitmapContext> bitmapContext = createBitmapContext(pageWidthInPixels, numberOfPages * (pageHeightInPixels + 1) - 1);
[mainFrame printToCGContext:bitmapContext->cgContext():pageWidthInPixels:pageHeightInPixels];
return bitmapContext.release();
}

0 comments on commit 3a898c6

Please sign in to comment.