[Cuis-dev] Clipping operation

Juan Vuletich juan at jvuletich.org
Thu Apr 30 11:49:14 PDT 2020


Hi Folks,

(inline)

On 4/30/2020 6:03 AM, Thierry Goubier via Cuis-dev wrote:
> Le jeu. 30 avr. 2020 à 10:45, Hilaire Fernandes via Cuis-dev
> <cuis-dev at lists.cuis.st>  a écrit :
>> Hi Thierry,
>>
>> Yes, it was looking odd to me. Thanks to confirm what I understood.
> Then you didn't need me much :)
>
> I hit that when starting to port from Pharo to Cuis.
>
>> I guess the rationnal behind this paradigm is to optimize drawing operation?!

Let me tell you how this came to be.

Before, please remember that Cuis can and must evolve, and you are all 
very much welcome to discuss needs and opinions. We already agree that 
we want Cuis to be simple, reasonably easy to understand, useful, etc. 
But when we get to the details, there are tons of small decisions that 
need to be done and don't have an obvious answer. Nothing here is carved 
on stone, and we are free to correct past mistakes, or past decisions we 
don't like anymore.

In Morphic, when we have a single coordinate space, and when all morphs 
are rectangular, clipping submorphs is trivial: all that is needed is to 
set the clippingRect in the Canvas. But Morph rotation, and Morphs with 
arbitrary shapes, make clipping much harder. Squeak includes a way to 
clip to arbitrary shapes by asking the clipping morph to draw itself on 
a 1-bit Form that is later used as a mask. This works, but it is very 
expensive. Additionally this same "morph shadow" technique is used to 
tell if a Morph occupies some pixel position, for knowing which Morph 
the Hand is grabbing. (The alternative is having each Morph know its 
shape and geometry twice: once for drawing, and in another method, to 
check for a pixel position. Needless to say I don't like this solution, 
that puts the burden on the developer. That should be solved by the 
framework.)

In Morphic3 / VectorCanvas I wanted to have Morphs with arbitrary shapes 
perform as well as rectangular Morphs. One thing I included is a buffer 
with the same dimensions as the Display that holds an id for the last 
morph drawn there (i.e. the Morph that the Hand will pick). I also found 
a way to use that same information to do correct clipping, but only for 
the first submorph drawn. The reason is that sibling Morphs drawn before 
us will overwrite that information, so the check to clip or not would 
have to consider the id of several Morphs, and I didn't like that extra 
complexity. I was able to tweak all the existing tools so each Morph 
needed to clip at most one single submorph. I wasn't really happy, and 
wasn't sure if this would be good enough for all possible applications. 
This was maybe 8 years ago.

> Maybe. But I wonder how much you gain (unless you are on a device
> where setting up clipping is expensive). The way it is done also means
> that you can't customize morph tree traversal for drawing (i.e. have a
> morph that for example cache its submorphs for faster drawing) unless
> you subclass the canvas . And even if you do that, is there a point
> where, on a draw operation, you can catch the canvas and replace it
> with your variant? I don't know.
>
> In truth, I'd be interested to see drawing optimisations by
> manipulating the morph tree.
>
> Thierry
>
>> Hilaire

Having a single clipped submorph was not only an optimization, but an 
enabler of an implementation detail for the future VectorEngine.

Dr. Geo is the first application brought to Cuis that does the kind of 
things Morphic3 / VectorCanvas should really shine at. This is a great 
time to rethink all this, and improve it.

I wasn't sure how to end this email, so instead of sending it, I went to 
think for a couple of hours. I came up with a design that, quite 
cheaply, can do nested clipping morphs, where each clipping morph will 
clip all its submorphs, at any arbitrary shape. I plan to add this to 
VectorCanvas and VectorEngine.

So, for our regular BitBltCanvas and BitBltCanvasEngine we can introduce 
back clipping for all submorphs, even if only for Display aligned 
Rectangles. VectorCanvas will implement whatever protocol we come with, 
but for true arbitrary Morph shape.

Thanks,

-- 
Juan Vuletich
www.cuis-smalltalk.org
https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev
https://github.com/jvuletich
https://www.linkedin.com/in/juan-vuletich-75611b3
@JuanVuletich



More information about the Cuis-dev mailing list