Flash Player 10.1 internal mechanism (Part 2)-variable runway for execution model

Source: Internet
Author: User
By Xiaowei
Lin
On limit L 7,
2010 AM
| No
Comments

Speaker: Lee Thomason (lthomaso@adobe.com)
Translation: Lin Xiaowei
Xwlin@adobe.com)

In the previous article, we introduced flash
How to integrate the player code library and its impact on the later development of the Flash Platform. In section 2, we will focus on the flash
The architecture of player and its impact on developers.

Understand the execution model

The execution model refers to flash
How can a player execute corresponding commands in each frame period. Flash
In fact, the player background runs n multithreading, but as does not provide developers with a multi-threaded programming model. This means that, in terms of concept, we need
As a single-threaded running entity, player has never argued about the advantages/disadvantages of this single-threaded programming model. I don't want to comment too much on this controversial question, but remember this fact.

Elastic
Racetrack)


The variable runway is flash.
The frame execution model of player, which describes how code execution and frame rendering work balance each other during a frame processing cycle. Flash Player
9. avm2 and avm2 made some improvements to this model. This information was summarized based on the study of the event mechanism and rendering model. The complete model has not yet been officially published.

The basic runway theory has not changed.
In the period in which the player executes a frame, the previous part of the time is used to execute the code, and the remaining time is used to render the objects in the display list. Each execution phase can increase the execution time to execute more code or perform more rendering based on actual needs, and the total length of the runway will also increase accordingly.




Based on the previous model, what changes are the appearance of each stage in a microcycle and how they form a frame.

Avm2
By flash
Controlled by a marshal-level component called marshal in player, Marshal is responsible for cutting time into flash
Here I want to clarify the basic time slice for player work.
The time slice of player has nothing to do with the frame rate when the SWF file is running. We will finally see the flash
Player combines these time slices into one frame. In Mac
In OS version Firefox, a SWF file compiled by Flex is executed. Marshal usually splits the time into a time slice of 19-20 milliseconds. The time slice size depends on the platform and browser.
For the convenience of our next discussion, we assume that the time slice size is 20 milliseconds, that is to say, there will be no more than 50 time slice every second, five steps in each time slice
Possible operations are performed in the following order:
 

  1. Player event scheduling-such as timer events, mouse events, enter_frame events, and urlloader events.
  2. User code execution-all code listening for the corresponding event in the previous step is executed.
  3. Render event scheduling-calling stage. invalidate () During User code execution triggers this special event.
  4. Last User code execution-the user code listening for the third-step special event is executed at this time.
  5. Player change display list.






Marshal
Execute a 20 ms time slice repeatedly and decide the next operation during running. All these operations performed in a time film are summarized into the above two-section runway (code execution, Image Rendering), that is, what we call
Frame. User code and invalidation operations are filled in the Code Execution area, and rendering operations are filled in the runway rendering area. It must be noted that related operations can only happen within the scheduled time of Marshal. If your user
The code is very short, so marshal will wait for a while after executing the user code and then enter the rendering stage.

In order to better illustrate how actions are executed and how the runway is created, refer to the following example to describe 5fps,
How the time slice is processed in SWF with a frame rate of 25 FPS and 50 FPS.





To
As shown in the preceding example, the variable runway in a frame cycle performs different operations at different frame rates. For example, for a SwF with a 5fps frame, each frame processes 10 user actions and 1 is invalid.
Action: One rendering action; SwF with a frame rate of 25 FPS. Two user actions are processed at each frame, one invalid action, and one rendering action.
50 fps swf, each frame can only process one user action, one invalid action, and one rendered action. It is important to note that some events can only happen.
In some specific time slices, for example, event. enter_frame events can only be scheduled in the initial time slices of a certain frame.

  1. The code and rendering parts in a time slice may be too long, resulting in a corresponding time slice larger than 20 milliseconds. This is the meaning of "variable, to ensure that the frame playing rate is still close to the frame rate set during SWF compilation, Marshal will discard some time slices.
  2. The playback speed of the SWF file cannot exceed the current flash
    PLAYER: Specifies the speed of time slice cutting. You can set the playback speed of FPS for the SWF file, but flash can play at most 50 frames (the specific value depends on the current system setting ).
  3. The Code Execution frequency may be higher than the frame rate of SwF. When playing a 1 fps swf file, the playback time of one frame is 1 second, that is, 50 time slices. However, in each time slice, there will be mouse trigger or timer events, although only the last time slice will be rendered, you can also choose to call the function updateafterevent ()
    Rendering in advance, but can only be called in mouse, timer, and keyboard event handler functions. In this case, Marshal considers that the current frame has ended and enters the next frame from the next time slice.
    Finally, if the appearance property of a Sprite, such as width and height, changes and the mouse is passed over the sprite, flash will force rendering.
  4. If the frame rate is not an integer factor of the number of time slices per second, the rendering interval of the platform will become unfixed. For example, the SWF with a frame rate of 20 FPS runs on the system with 50 time slices per second, flash
    Player will play two frames every five time slices, and the SWF rendering frequency will be 2-3-2-3-2-3 (time slice ).

Post from: http://blogs.adobe.com/xwlin/2010/04/flash_player_101_-_adobe_max_2009_1.html
Http://www.craftymind.com/2008/04/18/updated-elastic-racetrack-for-flash-9-and-avm2/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.