Bug 72965

Summary: [chromium] Use blending on opaque non-axis-aligned layers.
Product: WebKit Reporter: Dana Jansens <danakj>
Component: New BugsAssignee: Dana Jansens <danakj>
Status: RESOLVED DUPLICATE    
Severity: Normal CC: backer, cc-bugs, enne, jamesr, nduca, piman, reveman, webkit.review.bot, wjmaclean
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on: 73040    
Bug Blocks: 73061    
Attachments:
Description Flags
Patch
none
use transformed quad to determine axis-aligned
none
use transformed quad to determine axis-aligned v2
none
Patch
none
Patch none

Description Dana Jansens 2011-11-22 09:53:41 PST
These layers will have non-orthogonal edges. If marked opaque, and not blended, they will have strongly aliased edges.
Comment 1 Dana Jansens 2011-11-22 10:12:44 PST
Created attachment 116239 [details]
Patch
Comment 2 W. James MacLean 2011-11-23 06:43:33 PST
(In reply to comment #1)
> Created an attachment (id=116239) [details]
> Patch

You might want to take a look at Dave Reveman's comment on https://bugs.webkit.org/show_bug.cgi?id=70533 about making the axis-align (and pixel-aligned) test more consistent with what is used elsewhere in the compositor.

He recommends:

> This also needs to snap to the pixel grid to be correct. Instead of analyzing the transform, I think we should use the same logic as the anti-aliasing code, which is: 
> transformedQuad.isRectilinear() && transformedQuad.boundingBox().isExpressibleAsIntRect()
Comment 3 Dana Jansens 2011-11-23 07:10:56 PST
(In reply to comment #2)
> (In reply to comment #1)
> > Created an attachment (id=116239) [details] [details]
> > Patch
> 
> You might want to take a look at Dave Reveman's comment on https://bugs.webkit.org/show_bug.cgi?id=70533 about making the axis-align (and pixel-aligned) test more consistent with what is used elsewhere in the compositor.
> 
> He recommends:
> 
> > This also needs to snap to the pixel grid to be correct. Instead of analyzing the transform, I think we should use the same logic as the anti-aliasing code, which is: 
> > transformedQuad.isRectilinear() && transformedQuad.boundingBox().isExpressibleAsIntRect()

If an opaque rect is half inside a pixel, but axis aligned, would it want blending?

It would be possible to apply the layer's drawTransform() to its visibleLayerRect() and see if the resulting quad passes the above test.

@reveman would this be preferable?
Comment 4 David Reveman 2011-11-23 11:05:36 PST
(In reply to comment #3)
> (In reply to comment #2)
> > (In reply to comment #1)
> > > Created an attachment (id=116239) [details] [details] [details]
> > > Patch
> > 
> > You might want to take a look at Dave Reveman's comment on https://bugs.webkit.org/show_bug.cgi?id=70533 about making the axis-align (and pixel-aligned) test more consistent with what is used elsewhere in the compositor.
> > 
> > He recommends:
> > 
> > > This also needs to snap to the pixel grid to be correct. Instead of analyzing the transform, I think we should use the same logic as the anti-aliasing code, which is: 
> > > transformedQuad.isRectilinear() && transformedQuad.boundingBox().isExpressibleAsIntRect()
> 
> If an opaque rect is half inside a pixel, but axis aligned, would it want blending?

Yes, we need blending enabled whenever an anti-aliasing shader is used.

> 
> It would be possible to apply the layer's drawTransform() to its visibleLayerRect() and see if the resulting quad passes the above test.
> 
> @reveman would this be preferable?

Yes, have a look at:

http://trac.webkit.org/browser/trunk/Source/WebCore/platform/graphics/chromium/cc/CCTiledLayerImpl.cpp#L115

this is exactly what we're doing there.
Comment 5 Dana Jansens 2011-11-23 14:02:14 PST
Created attachment 116421 [details]
use transformed quad to determine axis-aligned
Comment 6 Dana Jansens 2011-11-23 14:06:53 PST
Created attachment 116424 [details]
use transformed quad to determine axis-aligned v2
Comment 7 David Reveman 2011-11-23 14:48:48 PST
Comment on attachment 116424 [details]
use transformed quad to determine axis-aligned v2

This will fix the problem but we could do better for tiled layers. Only the tiles that have edges at the borders of the layer will need blending. The inner tiles don't.

Maybe we should move the disable blend code into CCLayerImpl::Draw?
Comment 8 W. James MacLean 2011-11-23 15:46:15 PST
(In reply to comment #7)
> (From update of attachment 116424 [details])
> This will fix the problem but we could do better for tiled layers. Only the tiles that have edges at the borders of the layer will need blending. The inner tiles don't.
> 
> Maybe we should move the disable blend code into CCLayerImpl::Draw?

Given that CCTileLayerImpl is about to be heavily refactored, I think we should defer blending just the edge-tiles until after that time. It can be marked as a FIXME in this patch.
Comment 9 David Reveman 2011-11-23 15:57:03 PST
(In reply to comment #8)
> (In reply to comment #7)
> > (From update of attachment 116424 [details] [details])
> > This will fix the problem but we could do better for tiled layers. Only the tiles that have edges at the borders of the layer will need blending. The inner tiles don't.
> > 
> > Maybe we should move the disable blend code into CCLayerImpl::Draw?
> 
> Given that CCTileLayerImpl is about to be heavily refactored, I think we should defer blending just the edge-tiles until after that time. It can be marked as a FIXME in this patch.

That's fine with me. Please create another bugzilla entry for this and have it depend on the CCTileLayerImpl refactoring changes.
Comment 10 Dana Jansens 2011-11-23 16:41:35 PST
Created attachment 116453 [details]
Patch
Comment 11 Dana Jansens 2011-11-23 16:43:49 PST
Pushed the decision to blend off to CCLayerImpl. This way CCTiledLayerImpl can override the behavior, but have access to the CCLayerImpl versions of the functions to help make consistent decisions on a per-tile basis.
Comment 12 Dana Jansens 2011-12-09 15:06:29 PST
Created attachment 118650 [details]
Patch

Put the blending decision behind a single public function: bool drawWithBlending().

Made protected methods to decide blending based on the contents of the layer (i.e. are all pixels opaque), and the edges of the layer (i.e. is it rectilinear or does it require anti-aliasing for the edges).
Comment 13 Adrienne Walker 2011-12-09 15:38:39 PST
(In reply to comment #12)
> Created an attachment (id=118650) [details]
> Patch
> 
> Put the blending decision behind a single public function: bool drawWithBlending().
> 
> Made protected methods to decide blending based on the contents of the layer (i.e. are all pixels opaque), and the edges of the layer (i.e. is it rectilinear or does it require anti-aliasing for the edges).

Not all layer types have antialiased edges.  Don't we want to draw any opaque layer without antialiased edges with blending off, regardless of whether it lines up on integer coordinates?

(I think https://bugs.webkit.org/show_bug.cgi?id=73059 might do some of this?)
Comment 14 Dana Jansens 2011-12-09 16:09:14 PST
Yes, 73059 is going to do exactly the right thing I think :) Hooray.

*** This bug has been marked as a duplicate of bug 73059 ***
Comment 15 Eric Seidel (no email) 2011-12-19 11:10:33 PST
Comment on attachment 118650 [details]
Patch

How can we test this?
Comment 16 Eric Seidel (no email) 2011-12-19 11:24:09 PST
Comment on attachment 118650 [details]
Patch

Cleared review? from attachment 118650 [details] so that this bug does not appear in http://webkit.org/pending-review.  If you would like this patch reviewed, please attach it to a new bug (or re-open this bug before marking it for review again).