ErlendHL
1312 posts
|
|
|
|
Draco18s
6860 posts
|
Now the question is:
What is “a large number of calls”? 10? 50? 100?
|
|
|
BobTheCoolGuy
3754 posts
|
And also – does it only affect setPixel and setPixel32?
|
|
|
Draco18s
6860 posts
|
Originally posted by BobTheCoolGuy:
And also – does it only affect setPixel and setPixel32?
No, it effects any and all updates.
|
|
|
ErlendHL
1312 posts
|
Originally posted by Draco18s:
Now the question is:
What is “a large number of calls”? 10? 50? 100?
Yeah, that depends on how much performance the lock and unlock functions take. But well when I think about it, I think they just change a variable or something that the Bitmap (the one that’s assigned the BitmapData) checks before it draws the BitmapData, so maybe it’s efficient also when you don’t do quite so many calls, (but quite unnoticeable in performance).
Also, by calls, do they mean setPixel and setPixel32? If so, that would mean that calling lock and unlock before and after calling draw would increase the performance… but if so, it’s logical to think that functions like draw and copyPixels use lock and unlock by themselves. – Would be interesting to know!
Originally posted by BobTheCoolGuy:
And also – does it only affect setPixel and setPixel32?
By the explanation given I suspect it doesn’t change anything while actually calling those commands, but it stops the DisplayObject (Bitmap) from drawing everything that’s new. I don’t know quite how all this works at that level…
Edit: And don’t any functions in the BitmapData that change the pixels in any way use setPixel/setPixel32 after all?
|
|
|
ErlendHL
1312 posts
|
Found an article http://flexcomps.wordpress.com/2008/10/10/improve-performance-with-bitmapdatalock/
It seems my guesses were pretty much right.
So theoretically it may improve performance when only calling setPixel twice ^^ – but of course it’s totally unnoticeable and unnecessary.
What strucks my mind is that the model (BitmapData) is notifying the view (Bitmap). Using MVC I’ve never made the model know the view – because the model can have several view’s or none. but this is probably off topic
|
|
|
NineFiveThree
1370 posts
|
Originally posted by ErlendHL:
What strucks my mind is that the model (BitmapData) is notifying the view (Bitmap). Using MVC I’ve never made the model know the view – because the model can have several view’s or none. but this is probably off topic
Why do you think does the model have to know the view in order to make lock()/unlock() work?
The communication from model to view is always indirect, via observer, for example.
So when you call lock() on the BitmapData you are pretty much telling it to stop dispatching those CHANGE Events until you call unlock(). (I hope the analogy makes it more clear)
|
|
|
BobTheCoolGuy
3754 posts
|
Edit: And don’t any functions in the BitmapData that change the pixels in any way use setPixel/setPixel32 after all?
Not really – as far as I know, all the BitmapData methods are implemented natively, so they have much much better performance than calling setPixel methods.
|
|
|
ErlendHL
1312 posts
|
Thanks guys.
So does lock and unlock before and after a draw call increase the performance?
|
|
|
BobTheCoolGuy
3754 posts
|
Originally posted by ErlendHL:
Thanks guys.
So does lock and unlock before and after a draw call increase the performance?
Try testing it yourself I guess. Run lock, a thousand or so draws, an unlock, and compare the time that takes to not locking the BitmapData. I would think it might help some.
|
|
|
truefire
3011 posts
|
It should, AFAIK, only speed up if no bitmaps attached to the stage are pointed to the BMD.
|
|
|
ErlendHL
1312 posts
|
Originally posted by truefire:
It should, AFAIK, only speed up if no bitmaps attached to the stage are pointed to the BMD.
I don’t get it, doesn’t it stop updating the Bitmaps pointed to the BitmapData?
|
|
|
Lucidius
180 posts
|
The point of bitmapData.lock() and bitmapData.unlock() is simple if you are using a blitting system…
what I do is something along the lines of
//where canvasBitmapData is held by a Bitmap instance Canvas – which is my entire screen display…
canvasBitmapData.lock();
//then a bunch of copyPixels() operations…
renderWorld();
renderTeam();
renderEnemies();
renderSpells();
renderEffects();
canvasBitmapData.unlock();
The point of using lock is that when you change a bitmapData, the Bitmap that holds it will NOT reflect the change until unlock() is called. Otherwise it is drawing to the screen (rendering) every time it is changed. Thus the entire screen shows all change only once per frame – the essence of blitting.
from the doc:
lock():void
Locks an image so that any objects that reference the BitmapData object, such as Bitmap objects, are not updated when this BitmapData object changes.
unlock(changeRect:Rectangle = null):void
Unlocks an image so that any objects that reference the BitmapData object, such as Bitmap objects, are updated when this BitmapData object changes.
|