Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[cairo] Fix LayoutTests/fast/canvas/patternfill-repeat.html
https://bugs.webkit.org/show_bug.cgi?id=53085

Patch by Dominik Röttsches <dominik.rottsches@intel.com> on 2012-06-18
Reviewed by Martin Robinson.

Source/WebCore:

Clipping previously unlimited vertical and horizontal pattern repeats with
a clip rectangle similar to the Qt Graphics Context.

No new tests, this patch fixes
canvas/philip/tests/2d.pattern.paint.repeat* tests.

* platform/graphics/Pattern.h:
(WebCore::Pattern::getPatternSpaceTransform): Adding constant getter method to be able to map to pattern space externally, needed by PlatformContextCairo::clipForPatternFilling.
* platform/graphics/cairo/PlatformContextCairo.cpp:
(WebCore::PlatformContextCairo::prepareForFilling):
(WebCore::PlatformContextCairo::clipForPatternFilling): Clip pattern repeats if needed.
* platform/graphics/cairo/PlatformContextCairo.h:

LayoutTests:

canvas/philip/tests/2d.pattern.paint.repeat* tests now passing.

* platform/efl/Skipped:
* platform/gtk/TestExpectations:

Canonical link: https://commits.webkit.org/107210@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@120598 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Dominik Röttsches authored and webkit-commit-queue committed Jun 18, 2012
1 parent 81bd6ea commit f643a30
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 13 deletions.
12 changes: 12 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,15 @@
2012-06-18 Dominik Röttsches <dominik.rottsches@intel.com>

[cairo] Fix LayoutTests/fast/canvas/patternfill-repeat.html
https://bugs.webkit.org/show_bug.cgi?id=53085

Reviewed by Martin Robinson.

canvas/philip/tests/2d.pattern.paint.repeat* tests now passing.

* platform/efl/Skipped:
* platform/gtk/TestExpectations:

2012-06-18 Zan Dobersek <zandobersek@gmail.com>

Unreviewed GTK gardening, remove duplicates from the GTK WK2
Expand Down
7 changes: 0 additions & 7 deletions LayoutTests/platform/efl/Skipped
Expand Up @@ -389,13 +389,6 @@ canvas/philip/tests/2d.path.rect.selfintersect.html
# rectangle has zero height.
canvas/philip/tests/2d.path.rect.zero.6.html

# Repeat-x/-y doesn't work - not supported in Cairo, workaround needed
# https://bugs.webkit.org/show_bug.cgi?id=53085
canvas/philip/tests/2d.pattern.paint.repeatx.coord1.html
canvas/philip/tests/2d.pattern.paint.repeatx.outside.html
canvas/philip/tests/2d.pattern.paint.repeaty.coord1.html
canvas/philip/tests/2d.pattern.paint.repeaty.outside.html

# BUG: Bug in the test itself, as the input box can be big enough for the given coordinates to be inside it.
fast/forms/input-text-click-outside.html

Expand Down
6 changes: 0 additions & 6 deletions LayoutTests/platform/gtk/TestExpectations
Expand Up @@ -820,12 +820,6 @@ BUGWKGTK : canvas/philip/tests/2d.path.rect.selfintersect.html = TEXT
// rectangle has zero height.
BUGWKGTK : canvas/philip/tests/2d.path.rect.zero.6.html = TEXT

// Repeat-x/-y doesn't work - not supported in Cairo, workaround needed
BUGWK53085 : canvas/philip/tests/2d.pattern.paint.repeatx.coord1.html = TEXT
BUGWK53085 : canvas/philip/tests/2d.pattern.paint.repeatx.outside.html = TEXT
BUGWK53085 : canvas/philip/tests/2d.pattern.paint.repeaty.coord1.html = TEXT
BUGWK53085 : canvas/philip/tests/2d.pattern.paint.repeaty.outside.html = TEXT

// Tests that user modal dialogs fail in the DRT for some reason.
BUGWK53600 : fast/animation/request-animation-frame-during-modal.html = TEXT
BUGWK53600 : fast/events/show-modal-dialog-onblur-onfocus.html = TEXT
Expand Down
20 changes: 20 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,23 @@
2012-06-18 Dominik Röttsches <dominik.rottsches@intel.com>

[cairo] Fix LayoutTests/fast/canvas/patternfill-repeat.html
https://bugs.webkit.org/show_bug.cgi?id=53085

Reviewed by Martin Robinson.

Clipping previously unlimited vertical and horizontal pattern repeats with
a clip rectangle similar to the Qt Graphics Context.

No new tests, this patch fixes
canvas/philip/tests/2d.pattern.paint.repeat* tests.

* platform/graphics/Pattern.h:
(WebCore::Pattern::getPatternSpaceTransform): Adding constant getter method to be able to map to pattern space externally, needed by PlatformContextCairo::clipForPatternFilling.
* platform/graphics/cairo/PlatformContextCairo.cpp:
(WebCore::PlatformContextCairo::prepareForFilling):
(WebCore::PlatformContextCairo::clipForPatternFilling): Clip pattern repeats if needed.
* platform/graphics/cairo/PlatformContextCairo.h:

2012-06-18 Robert Kroeger <rjkroege@chromium.org>

Touch events with default actions should be handled.
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/platform/graphics/Pattern.h
Expand Up @@ -82,6 +82,7 @@ class Pattern : public RefCounted<Pattern> {
PlatformPatternPtr createPlatformPattern(const AffineTransform& userSpaceTransformation) const;
#endif
void setPatternSpaceTransform(const AffineTransform& patternSpaceTransformation);
const AffineTransform& getPatternSpaceTransform() { return m_patternSpaceTransformation; };
void setPlatformPatternSpaceTransform();

bool repeatX() const { return m_repeatX; }
Expand Down
42 changes: 42 additions & 0 deletions Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp
Expand Up @@ -251,6 +251,9 @@ void PlatformContextCairo::prepareForFilling(const GraphicsContextState& state,
state.fillGradient.get(),
state.fillColor,
patternAdjustment == AdjustPatternForGlobalAlpha ? globalAlpha() : 1);

if (state.fillPattern)
clipForPatternFilling(state);
}

void PlatformContextCairo::prepareForStroking(const GraphicsContextState& state, AlphaPreservation alphaPreservation)
Expand All @@ -262,4 +265,43 @@ void PlatformContextCairo::prepareForStroking(const GraphicsContextState& state,
alphaPreservation == PreserveAlpha ? globalAlpha() : 1);
}

void PlatformContextCairo::clipForPatternFilling(const GraphicsContextState& state)
{
ASSERT(state.fillPattern);

// Hold current cairo path in a variable for restoring it after configuring the pattern clip rectangle.
OwnPtr<cairo_path_t> currentPath = adoptPtr(cairo_copy_path(m_cr.get()));
cairo_new_path(m_cr.get());

// Initialize clipping extent from current cairo clip extents, then shrink if needed according to pattern.
// Inspired by GraphicsContextQt::drawRepeatPattern.
double x1, y1, x2, y2;
cairo_clip_extents(m_cr.get(), &x1, &y1, &x2, &y2);
FloatRect clipRect(x1, y1, x2 - x1, y2 - y1);

Image* patternImage = state.fillPattern->tileImage();
ASSERT(patternImage);
const AffineTransform& patternTransform = state.fillPattern->getPatternSpaceTransform();
FloatRect patternRect = patternTransform.mapRect(FloatRect(0, 0, patternImage->width(), patternImage->height()));

bool repeatX = state.fillPattern->repeatX();
bool repeatY = state.fillPattern->repeatY();

if (!repeatX) {
clipRect.setX(patternRect.x());
clipRect.setWidth(patternRect.width());
}
if (!repeatY) {
clipRect.setY(patternRect.y());
clipRect.setHeight(patternRect.height());
}
if (!repeatX || !repeatY) {
cairo_rectangle(m_cr.get(), clipRect.x(), clipRect.y(), clipRect.width(), clipRect.height());
cairo_clip(m_cr.get());
}

// Restoring cairo path.
cairo_append_path(m_cr.get(), currentPath.get());
}

} // namespace WebCore
2 changes: 2 additions & 0 deletions Source/WebCore/platform/graphics/cairo/PlatformContextCairo.h
Expand Up @@ -68,6 +68,8 @@ class PlatformContextCairo {
void prepareForStroking(const GraphicsContextState&, AlphaPreservation = PreserveAlpha);

private:
void clipForPatternFilling(const GraphicsContextState&);

RefPtr<cairo_t> m_cr;

class State;
Expand Down

0 comments on commit f643a30

Please sign in to comment.