[whatwg] <canvas> shadow compositing oddities

On Aug 4, 2008, at 2:29 PM, Eric Butler wrote:

> Philip Taylor wrote:
>> On Sun, Jul 27, 2008 at 8:06 PM, Eric Butler <ebutler at mozilla.com>  
>> wrote:
>>
>>> [...]
>>> However, following the spec's drawing model, there are a few  
>>> operators that
>>> behave rather unexpectedly if the shadow color is left at its  
>>> default value.
>>> For instance, since A in B always results in transparency if  
>>> either A or B
>>> is fully transparent, source-in will always simply clear the  
>>> clipping region
>>> to fully transparent no matter what the source and destination are.
>>>
>>
>> Oops - that does seem quite broken. (It's probably my fault - I  
>> didn't
>> notice that problem when I was looking at how shadows should work...
>
> The need to be able to disable shadows explicitly seems clear. But I  
> also believe that the spec should provide
> for a means to disable normal drawing and only draw shadows to  
> increase the usefulness of shadows.
>
> As it stands, if you draw with shadows, you'll end up getting some  
> of the shadows drawn on top of some of
> the actual shapes. But perhaps the developer wants to have all  
> shadows behind all shapes for a particular set
> of shapes. The only way to accomplish that would be to create a  
> second canvas, do all the drawing without
> shadows on that, then draw the canvas with its shadow back to the  
> original, which seems cumbersome
> to use and is terribly inefficient.

I think that'll cause problems as well -- for example, let's say you  
had two overlapping paths that you wanted to draw a shadow behind.   
The two paths are both solid and are supposed to be rendered as a  
single shape to the user.  If you drew them separately with shadows,  
as it stands now, the shadows would end up adding and would be denser  
in the overlap areas which isn't what the author would intend.  I  
would suggest:

- special case opacity 0, 0,0 offset, 0 blur radius as 'shadows off',  
as Oliver suggested to preserve current usage

- if shadows aren't off, draw them normally -- one shadow per drawing  
operation

- go the whole way and add beginLayer/endLayer, akin to  
CGContextBeginTransparencyLayer[WithRect]/EndTransparencyLayer.  Could  
also call it pushGroup/popGroup.  As a side benefit, this would  
provide a simple way to implement double-buffered rendering without  
needing to use two canvases.  (http://developer.apple.com/documentation/GraphicsImaging/Reference/CGContext/Reference/reference.html#/ 
/apple_ref/c/func/CGContextBeginTransparencyLayer)

    - Vlad

Received on Monday, 4 August 2008 16:27:33 UTC