3

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.

Sam
  • 7,252
  • 16
  • 46
  • 65
Yovo
  • 629
  • 3
  • 8
  • 16

1 Answers1

8

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.
Jason Sturges
  • 15,855
  • 14
  • 59
  • 80
  • You can't use `stage` in the `Sprite` constructor, you're [missing a step](http://stackoverflow.com/a/13444450/238419). – BlueRaja - Danny Pflughoeft Mar 17 '14 at 22:54
  • @BlueRaja-DannyPflughoeft It's an isolated example where `stage` is present as this class is the root view of the application; not convoluted by the standard lifecycle of `Event.ADDED_TO_STAGE` handlers required by descendent display objects. – Jason Sturges Mar 18 '14 at 02:30