Question

With flash player 11 came 3D GPU acceleration but not every video card can do the job and when there is unsupported video card acceleration is switched to software. Can I check if hardware acceleration is available in order to customize my application.

Was it helpful?

Solution

You must obtain a Context3D to view it's driverInfo:

trace("3d mode: " + context3D.driverInfo);

For me, this indicates:

context3d

Easiest to test for software rendering, hardware accelerated GPU would be indicated by DirectX or OpenGL.

This could be implemented as such:

package
{
    import flash.display.Sprite;
    import flash.display.Stage3D;
    import flash.display3D.Context3D;
    import flash.display3D.Context3DRenderMode;
    import flash.events.Event;
    import flash.system.ApplicationDomain;
    import flash.system.Capabilities;

    public class X extends Sprite
    {
        public function X()
        {
            super();

            if (ApplicationDomain.currentDomain.hasDefinition("flash.display.Stage3D"))
            {
                stage.stage3Ds[0].addEventListener(Event.CONTEXT3D_CREATE, onContext3DCreate);
                stage.stage3Ds[0].requestContext3D();
            }
        }

        private function onContext3DCreate(event:Event):void
        {
            // obtain context
            var t:Stage3D = event.target as Stage3D;
            var context3D:Context3D = t.context3D;

            // detect software mode
            if ((context3D.driverInfo == Context3DRenderMode.SOFTWARE)
                || (context3D.driverInfo.indexOf('oftware') > -1))
            {
                trace("Software mode detected!");
            }

            trace("Flash Version: " + Capabilities.version);
            trace("3D mode: " + context3D.driverInfo);
        }

    }
}

For GPU accelerated StageVideo, you listen for StageVideoAvailabilityEvent to confirm StageVideoAvailability.AVAILABLE.

This could be implemented as:

package
{
    import flash.display.Sprite;
    import flash.events.StageVideoAvailabilityEvent;
    import flash.media.StageVideoAvailability;

    public class X extends Sprite
    {
        public function X()
        {
            super();
            stage.addEventListener(StageVideoAvailabilityEvent.STAGE_VIDEO_AVAILABILITY, onStageVideoState);
        }

        private function onStageVideoState(event:StageVideoAvailabilityEvent):void
        {
            if (event.availability == StageVideoAvailability.AVAILABLE)
                trace("available");
        }

    }
}

Once you have a StageVideo, render state is indicated by StageVideoEvent.RENDER_STATE.

var stageVideo = stage.stageVideos[0];
stageVideo.addEventListener(StageVideoEvent.RENDER_STATE, stageVideoStateChange);

function stageVideoStateChange(event:StageVideoEvent):void
{   
    trace("Render State: " + event.status);
}

Render state is derived by StageVideoEvent.status and includes:

  • VideoStatus.ACCELERATED - Decoding and presentation both occur in hardware. (Best performance.)
  • VideoStatus.SOFTWARE - Presentation in hardware, decoding in software. (Acceptable performance.)
  • VideoStatus.UNAVAILABLE - No GPU resources are available to handle video, and nothing is displayed. Fall back to a Video object.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top