flash player 11检查GPU加速

时间:2012-07-18 22:53:55

标签: flash 3d hardware-acceleration flash-player-11

随着闪存播放器11的3D GPU加速,但不是每个显卡都可以完成这项工作,当不支持的视频卡加速切换到软件时。我可以检查硬件加速是否可用,以便自定义我的应用程序。

1 个答案:

答案 0 :(得分:8)

您必须获取Context3D才能查看driverInfo

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

对我来说,这表明:

context3d

最容易测试软件渲染,硬件加速GPU将由DirectX或OpenGL指示。

这可以这样实现:

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);
        }

    }
}

对于GPU加速的StageVideo,您需要监听StageVideoAvailabilityEvent以确认StageVideoAvailability.AVAILABLE

这可以实现为:

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");
        }

    }
}

拥有StageVideo后,渲染状态由StageVideoEvent.RENDER_STATE表示。

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

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

渲染状态由StageVideoEvent.status派生,包括:

  • VideoStatus.ACCELERATED - 解码和呈现都发生在硬件中。 (最佳表现。)
  • VideoStatus.SOFTWARE - 硬件演示,软件解码。 (可接受的表现。)
  • VideoStatus.UNAVAILABLE - 没有可用于处理视频的GPU资源,也没有显示任何内容。回到视频对象。