Bug 16469

Summary: Device offset is not affected by scaling
Product: cairo Reporter: Michael Ventnor <ventnor.bugzilla>
Component: generalAssignee: Jeff Muizelaar <jmuizelaar>
Status: RESOLVED FIXED QA Contact: cairo-bugs mailing list <cairo-bugs>
Severity: normal    
Priority: medium    
Version: 1.6.5   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments: Testcase
Apply the device offset before the destination transform
cairo test for device offset with scale
New patch

Description Michael Ventnor 2008-06-22 18:55:06 UTC
While implementing a new CSS feature in Mozilla Gecko I stumbled across a bug regarding device offsets and scaling that make the feature quite glitchy.

Device offsets seem to be unaffected by scaling when painted onto a surface with scaling applied.

e.g. - surface A is scaled by 0.5, 0.5
- surface B has a device offset of -40, -40.
- draw a rectangle on surface A at X=40, Y=40, width=20, height=20. This means the actual size is 20, 20, 10, 10 due to scaling.
- draw a rectangle of exactly the same coordinates on surface B.
- mask or paint surface B onto surface A.

The result is that the rectangle on surface B is painted at half-size, but it is drawn at 40, 40, so the device offsets didn't allow the X or Y of B's rectangle to be scaled like A's.

Hopefully this can be fixed soon as this blocks a proper implementation of text-shadow and box-shadow in Gecko.
Comment 1 Michael Ventnor 2008-06-22 18:56:33 UTC
Created attachment 17310 [details]
Testcase

When compiled, this dumps the contents of an image surface to stdout. The result should be that the orange rectangle (on the device offset surface) completely covers the blue rectangle (the reference that is drawn directly on the scaled surface).
Comment 2 Behdad Esfahbod 2008-06-22 20:11:32 UTC
You are right.  This is a bug.
Comment 3 Behdad Esfahbod 2008-06-22 20:12:39 UTC
In the mean time you can avoid it by not using device offsets for this purpose.  Use the pattern matrix instead.
Comment 4 Behdad Esfahbod 2008-06-22 20:15:21 UTC
If you want to jump into fixing this, _cairo_pattern_acquire_surface_for_surface() is the place.
Comment 5 Jeff Muizelaar 2008-07-17 19:35:53 UTC
Created attachment 17737 [details] [review]
Apply the device offset before the destination transform

The attached patch seems to fix the problem.
Comment 6 Vladimir Vukicevic 2008-07-21 01:52:11 UTC
From reading the code, that patch looks right to me -- we presumably never ran into this because the device transform of things used as sources was always identity.  I'd push this patch upstream, and add a testcase to the test suite for src-with-dev-transform.
Comment 7 Jeff Muizelaar 2008-07-21 08:18:52 UTC
Created attachment 17797 [details] [review]
cairo test for device offset with scale
Comment 8 Jeff Muizelaar 2008-07-21 08:19:44 UTC
Created attachment 17798 [details] [review]
New patch
Comment 9 Vladimir Vukicevic 2008-07-21 16:33:16 UTC
Tests passed for me -- Jeff, can you commit and push this?  I'll pull it into Mozilla from there.
Comment 10 Jeff Muizelaar 2008-07-21 19:27:20 UTC
Committed.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.