Personal tools

Views

Flash Player:9:Update:Full-Screen Mode HW

From Adobe Labs

Table of contents
[edit]

Full-Screen mode with hardware scaling

[edit]

Introduction

Flash Player 9 Update 3 introduces a new property called fullScreenSourceRect on the Stage object. It is available in ActionScript 2.0 and ActionScript 3.0. This property allows developers to specify which part of a SWF is displayed in full-screen mode. This allows Flash Player to leverage hardware scaling which can significantly improve quality and performance.

The previous full-screen behavior works in the same was as if you maximized the window of a SWF playing in the standalone player. It enlarges the stage with the side effect that everything has to be re-rendered using a much higher resolution. Using this property the Flash Player will render the selected area on stage at 100% scale and then deliver the result to the OS where it is scaled up and displayed.

[edit]

ActionScript API

Let's take a look with a simple example in ActionScript 2.0. In case you have not worked with the full-screen feature yet, please consult Tracy's excellent overview first.


 function goFullScreen()
 {
 import flash.geom.*;
    Stage["fullScreenSourceRect"] = new Rectangle(0, 0, Stage.width, Stage.height);
    Stage["displayState"] = "fullScreen";
 }

In this example the current size of the stage is selected and scaled up. The rectangle can be anywhere, even outside the current stage coordinates and size. Of note: At this time the dot notation can not be used without compiler errors. This will be resolved when Adobe provides an updated class description for Adobe Flash CS3.

[edit]

Using the feature for video playback

If you use this feature for video playback, to improve performance there is something really important which needs to be taken into account: Do not scale the video on the stage. Always have it render at 100% scale if you use this feature. The easiest way to achieve this is to set the size of the video object to the size of the actual video. We can modify the above code to reflect this:

 import flash.geom.*;
 function goFullScreen()
 {
    // when going out of full screen mode 
    // we use these values
    myVideo.savedWidth = myVideo.width;
    myVideo.savedHeight = myVideo.height;
    myVideo.savedSmoothing = myVideo.smoothing;
    myVideo.savedDeblocking = myVideo.deblocking;
 
    // Set the size of the video object to the 
    // original size of the video stream
    myVideo.width = myVideo.videoWidth;
    myVideo.height = myVideo.videoHeight;
    myVideo.smoothing = false;
    myVideo.deblocking = 0;
 
    Stage["fullScreenSourceRect"] = new Rectangle(
       myVideo.x, myVideo.y, 
       myVideo.width, myVideo.height);
 
    Stage["displayState"] = "fullScreen";
 }

There are a few important changes which are added here. First the rectangle uses the area covered by the video object, dropping anything around it. Second, it makes sure that the video is rendered at 100% scale. Third, smoothing of the video is turned off. Not doing this results in a performance penalty since the Flash Player will go through a slower code path. Fourth, the deblocking is set to automatic mode. This is important if VP6 video is used as Flash Player 9 Update 3 now can make a much better judgment of when to use and not to use post processing.

[edit]

Updating playerglobal.swc for ActionScript 3.0

The above example are in ActionScript 2.0. In ActionScript 3.0 an updated playerglobal.swc needs to be installed for the fullScreenSourceRect property to be recognized. The new playerglobal.swc is included in the demo zip file. To install the new playerglobal.swc the updated version needs to be copied into the following locations:

For Adobe Flash CS3:

 Adobe Flash CS3\en\Configuration\ActionScript 3.0\Classes\

For Adobe Flex Builder:

 Flex Builder 2\Flex SDK 2\frameworks\libs
[edit]

Demo

Click here to view the demo in action. The file will take a little time to buffer before it starts to play.

Download a demo of the property in action (ZIP, 49.2 MB)

Don't forget to post links to the demos you create on the wiki here!

Retrieved from "http://labs.adobe.com/wiki/index.php/Flash_Player:9:Update:Full-Screen_Mode_HW"