NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

fpsmonitor.py (9809B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\modules\fpsmonitor.py
      2 import blue
      3 import trinity
      4 import uthread
      5 import carbonui.const as uiconst
      6 from carbonui.control.window import Window
      7 from carbonui.primitives.containerAutoSize import ContainerAutoSize
      8 from carbonui.primitives.flowcontainer import FlowContainer
      9 from carbonui.primitives.gridcontainer import GridContainer
     10 from carbonui.primitives.base import Base
     11 from carbonui.primitives.container import Container
     12 from carbonui.primitives.line import Line
     13 from carbonui.text.custom import TextCustom
     14 from carbonui.text.styles import TextHeader, TextDetail
     15 from eve.client.script.ui import eveColor
     16 import evegraphics.settings as gfxsettings
     17 from carbonui.uiconst import PickState
     18 COLOR = eveColor.LIME_GREEN
     19 COLOR_HEX = eveColor.LIME_GREEN_HEX
     20 COLOR_SECONDARY = eveColor.LEAFY_GREEN
     21 COLOR_SECONDARY_HEX = eveColor.LEAFY_GREEN_HEX
     22 COLOR_TERTIARY = eveColor.COPPER_OXIDE_GREEN
     23 COLOR_TERTIARY_HEX = eveColor.COPPER_OXIDE_GREEN_HEX
     24 
     25 class GraphRenderer(Base):
     26     __renderObject__ = trinity.Tr2Sprite2dRenderJob
     27     default_state = uiconst.UI_PICKCHILDREN
     28     default_pickState = PickState.CHILDREN
     29 
     30     def ApplyAttributes(self, attributes):
     31         Base.ApplyAttributes(self, attributes)
     32         self.viewport = trinity.TriViewport()
     33         self.linegraph = trinity.Tr2LineGraph()
     34         self.linegraphSize = 0
     35         self.linegraph.name = 'FPS'
     36         self.linegraph.color = COLOR
     37         blue.statistics.SetAccumulator(self.linegraph.name, self.linegraph)
     38         self.generatedLinegraph = trinity.Tr2LineGraph()
     39         self.generatedLinegraph.name = 'Trinity/smoothedGeneratedFrames'
     40         self.generatedLinegraph.color = COLOR_TERTIARY
     41         blue.statistics.SetAccumulator(self.generatedLinegraph.name, self.generatedLinegraph)
     42         self.renderJob = trinity.CreateRenderJob('Graphs')
     43         self.renderObject.renderJob = self.renderJob
     44         self.renderJob.PythonCB(self.AdjustViewport)
     45         self.renderJob.SetViewport(self.viewport)
     46         self.renderJob.SetStdRndStates(trinity.RM_SPRITE2D)
     47         self.renderer = self.renderJob.RenderLineGraph()
     48         self.renderer.showLegend = False
     49         self.renderer.lineGraphs.append(self.linegraph)
     50 
     51     def Close(self):
     52         Base.Close(self)
     53         self.renderer.scaleChangeCallback = None
     54 
     55     def AdjustViewport(self):
     56         l, t = self.displayX, self.displayY
     57         parent = self.GetParent()
     58         while parent:
     59             l += parent.displayX
     60             t += parent.displayY
     61             parent = parent.GetParent()
     62 
     63         self.viewport.x = l
     64         self.viewport.y = t
     65         self.viewport.width = self._displayWidth
     66         self.viewport.height = self._displayHeight
     67         if self.linegraphSize != self._displayWidth:
     68             self.linegraph.SetSize(self._displayWidth)
     69             self.generatedLinegraph.SetSize(self._displayWidth)
     70             self.linegraphSize = self._displayWidth
     71 
     72     def SetShowGeneratedFrames(self, show):
     73         if not show:
     74             self.renderer.lineGraphs.remove(self.generatedLinegraph)
     75         elif show:
     76             self.renderer.lineGraphs.append(self.generatedLinegraph)
     77 
     78 
     79 class ExtraInfoLabel(ContainerAutoSize):
     80     default_align = uiconst.NOALIGN
     81 
     82     def ApplyAttributes(self, attributes):
     83         super(ExtraInfoLabel, self).ApplyAttributes(attributes)
     84         self.isAutoSizeEnabled = 'width' not in attributes
     85         self.label = TextCustom(parent=self, align=uiconst.TOPLEFT)
     86         self.caption = attributes.caption
     87         self.value = attributes.value
     88         self.ApplyText()
     89 
     90     def ApplyText(self):
     91         text = "<fontsize=12><color='{}'>{}: </color></fontsize><color='{}'>{}</color>".format(COLOR_SECONDARY_HEX, self.caption, COLOR_HEX, self.value)
     92         self.label.SetText(text)
     93 
     94     def SetValue(self, value):
     95         self.value = value
     96         self.ApplyText()
     97 
     98 
     99 class FpsMonitor(Window):
    100     default_caption = 'FPS Monitor'
    101     default_windowID = 'fpsMonitor2'
    102     default_width = 360
    103     default_height = 180
    104     __notifyevents__ = ['OnGraphicSettingsChanged']
    105 
    106     def ApplyAttributes(self, attributes):
    107         super(FpsMonitor, self).ApplyAttributes(attributes)
    108         self.fpsStat = blue.statistics.Find('FPS')
    109         self.gfpsStat = blue.statistics.Find('Trinity/smoothedGeneratedFrames')
    110         self.frameTimeStat = blue.statistics.Find('Trinity/SmoothedFrameTime')
    111         self.upscalingLabel = None
    112         self.hasUpscaling = False
    113         self.hasFrameGen = False
    114         self.gr = None
    115         self.extraInfoCont = FlowContainer(name='extraInfoCont', parent=self.sr.main, align=uiconst.TOBOTTOM, state=uiconst.UI_NORMAL, contentSpacing=(12, 2), padding=4)
    116         self.graphContainer = Container(parent=self.sr.main, align=uiconst.TOALL, padding=(4, 9, 4, 0))
    117         self.legendContainer = GridContainer(parent=self.graphContainer, align=uiconst.TORIGHT, width=24, columns=1, padLeft=4, top=-7)
    118         self.ConstructLegend()
    119         self.ConstructGraphRenderer()
    120         self.labelContainer = Container(parent=self.graphContainer, align=uiconst.TOBOTTOM, height=20)
    121         self.fpsLabel = TextCustom(name='fpsLabel', parent=self.labelContainer, bold=True, color=COLOR, pickState=PickState.ON, align=uiconst.TOLEFT)
    122         self.fpsLabel.hint = 'FPS'
    123         self.msLabel = TextCustom(name='fpsLabel', parent=self.labelContainer, color=COLOR_SECONDARY, pickState=PickState.ON, align=uiconst.TOLEFT)
    124         self.msLabel.hint = 'Frame time (ms)'
    125         self.genFpsLabel = TextCustom(name='genFpsLabel', parent=self.labelContainer, bold=True, color=COLOR_TERTIARY, align=uiconst.TORIGHT, pickState=PickState.ON)
    126         self.genFpsLabel.display = False
    127         self.genFpsLabel.hint = 'Generated FPS'
    128         self.ConstructExtraInfoLabels()
    129         uthread.new(self.UpdateLabelsThread)
    130 
    131     def ConstructExtraInfoLabels(self):
    132         adapterInfo = trinity.adapters.GetAdapterInfo(trinity.device.adapter)
    133         ExtraInfoLabel(parent=self.extraInfoCont, caption='Shader Model', value=trinity.GetShaderModel())
    134         ExtraInfoLabel(parent=self.extraInfoCont, caption='Platform', value=trinity.platform)
    135         ExtraInfoLabel(parent=self.extraInfoCont, caption='GPU', value=adapterInfo.description)
    136         self.throttlingLabel = ExtraInfoLabel(parent=self.extraInfoCont, caption='FPS Throttling')
    137         self.RefreshUpscalingLabel()
    138 
    139     def RefreshUpscalingLabel(self):
    140         upscalingInfo = trinity.device.GetUpscalingInfo()
    141         if self.hasUpscaling != upscalingInfo['technique'] == trinity.UPSCALING_TECHNIQUE.NONE or self.hasFrameGen == upscalingInfo['frameGeneration']:
    142             return
    143         self.hasUpscaling = upscalingInfo['technique'] != trinity.UPSCALING_TECHNIQUE.NONE
    144         self.hasFrameGen = upscalingInfo['frameGeneration']
    145         if self.upscalingLabel is None:
    146             self.upscalingLabel = ExtraInfoLabel(parent=self.extraInfoCont, caption='Upscaling', value='')
    147         techniqueName = upscalingInfo['techniqueName']
    148         settingName = upscalingInfo['settingName']
    149         labelText = '%s (%s) %s' % (techniqueName, settingName, 'Frame Gen' if self.hasFrameGen else '')
    150         self.upscalingLabel.SetValue(labelText)
    151         self.upscalingLabel.display = self.hasUpscaling
    152         self.upscalingLabel.AutoFitToContent()
    153         self.genFpsLabel.display = self.hasFrameGen
    154         self.gr.SetShowGeneratedFrames(self.hasFrameGen)
    155 
    156     def ConstructGraphRenderer(self):
    157         self.gr = GraphRenderer(parent=self.graphContainer, align=uiconst.TOALL)
    158         self.renderer = self.gr.renderer
    159         self.renderer.scaleChangeCallback = self.ScaleChangeHandler
    160         for i in xrange(4):
    161             cont = Container(parent=self.graphContainer, align=uiconst.TOTOP_PROP, height=0.25)
    162             Line(parent=cont, align=uiconst.TOTOP, color=COLOR, opacity=0.05)
    163             if i == 3:
    164                 Line(parent=cont, align=uiconst.TOBOTTOM, color=COLOR, opacity=0.075)
    165 
    166     def ConstructLegend(self):
    167         self.legendLabels = []
    168         for i in xrange(4):
    169             label = TextDetail(parent=self.legendContainer, align=uiconst.TOTOP, width=20, color=COLOR_SECONDARY)
    170             self.legendLabels.append(label)
    171 
    172     def ScaleChangeHandler(self):
    173         numLabels = len(self.legendLabels)
    174         label = 1.0
    175         labelStep = 1.0 / float(numLabels)
    176         for i in xrange(numLabels):
    177             labelValue = int((label / self.renderer.scale * self.renderer.legendScale + 0.5) / 100)
    178             self.legendLabels[i].SetText(str(labelValue))
    179             label -= labelStep
    180 
    181     def UpdateLabelsThread(self):
    182         while not self.destroyed:
    183             self.RefreshUpscalingLabel()
    184             if self.hasFrameGen:
    185                 self.genFpsLabel.text = '%.2f' % (self.gfpsStat.value / 100.0)
    186             self.fpsLabel.text = '%.2f' % (self.fpsStat.value / 100.0)
    187             self.msLabel.text = '(%.1fms)' % (self.frameTimeStat.value * 1000.0)
    188             value = self._GetThrottlingLabelText()
    189             self.throttlingLabel.SetValue(value)
    190             blue.synchro.SleepWallclock(500)
    191 
    192     def _GetThrottlingLabelText(self):
    193         if trinity.device.allowThrottling:
    194             t = trinity.device.throttlingState
    195         else:
    196             t = 0
    197         reasons = {1: 'Not focused',
    198          2: 'Window hidden',
    199          4: 'Thermal',
    200          -8: 'Other'}
    201         if t == 0:
    202             value = 'None'
    203         else:
    204             value = ' + '.join((v for k, v in reasons.items() if t & k != 0))
    205         return value
    206 
    207     def OnGraphicSettingsChanged(self, changes):
    208         if gfxsettings.GFX_UPSCALING_TECHNIQUE in changes or gfxsettings.GFX_UPSCALING_SETTING in changes or gfxsettings.GFX_FRAMEGENERATION_ENABLED in changes:
    209             self.RefreshUpscalingLabel()