hyperandroid / CAAT

Canvas Advanced Animation Toolkit
hyperandroid.github.com/CAAT
MIT License
727 stars 117 forks source link

Invalidation mechanism #22

Closed ngryman closed 12 years ago

ngryman commented 12 years ago

Hi,

I am using CAAT (canvas implementation) on several platforms, including mobile devices. This is a really great framework :)

I just have a question. On desktop, clearing the whole canvas has no real impact on small canvases, but on mobile this is really a performance bottleneck. I would like to know if a kind of invalidation mechanism is planned for CAAT, in order to clear only areas that have to be redrawn (based on actor dirtiness).

Thanks a lot !

hyperandroid commented 12 years ago

Hi,

it's not been planned such a feature. I've always believed it to be counterproductive unless in very specific situations like few on-screen actors. For example, the need of tracking per actor on-screen coordinates, the need to union different affected areas, the need to set a clip rectangle to redraw only affected areas etc. make me think about that probably all that extra code complexity and its execution overhead is not worth the saved drawing time. sometimes surely i'm wrong, so please, proof me I am. ^^ will keep this issue open and think about it. Thanks for asking, best.

ngryman commented 12 years ago

Just for info, a little jsfiddle : http://jsfiddle.net/mgbUc/6/.

I have different results, very surprising results ...

Of course this is a a very basic example, there is no clipping algorithm, and just one square moving ^^ ... Clear operation is meant to be quite expensive on not accelerated device, but apparently some progress have been done in recent versions of iOS / Android.

I would like to test a very basic invalidation algorithm with CAAT to ... invalidate ^^ or validate if it can be useful or not. Can you tell me how do you build CAAT ? And where do you think is the best place to put this code ?

Thanks a lot :)

hyperandroid commented 12 years ago

Hey there,

I've made some code changes regarding coordinate clamping from float to integer. You should notice a performance improvement while in mobile canvas. Could you confirm it ? Despite I think in most situations is not worth it, I'm taking seriously the possibility of setting a dirty rectangle redraw mechanism which should be explicitly allowed by the developer. Unfortunately, I can't tell when. Thanks, -ibon

ngryman commented 12 years ago

Yeah that's a very cool improvement ;) I think this will improve performances on non-hardware accelerated devices (every mobile devices indeed). I will update CAAT and report any changes in perfs.

The solution of giving the programmer the ability to specify a list of dirty rectangles and apply it, is a great compromise. Anyone could adapt his own invalidation mechanism following his needs.

My test results are very strange, I would like to know if I get the same results in a much more complex scene using CAAT. So, this update will be very interesting for me ;)

Thanks a lot.

hyperandroid commented 12 years ago

Hey Nicholas,

have made some changes to CAAT and added an experimental dirty rectangles clearing procedure. To be enabled you must call director.setClear( CAAT.Director.CLEAR_DIRTY_RECTS ); Every actor which changes affine transformation, either position, rotation or scale, will automatically be invalidated. In you want any other actor to be explicitly invalidated, just call actor.invalidate();

Let me know how it works for you.

-ibon