Debian Codegraph @

exp/app/debug/fps.go

raw symbols SCIP
1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 //go:build darwin || linux || windows
6
7 // Package debug provides GL-based debugging tools for apps.
8 package debugscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/
9
10 import (
11 "imagescip-go gomod github.com/golang/go/src go1.24.0 image/"
12 "image/colorscip-go gomod github.com/golang/go/src go1.24.0 `image/color`/"
13 "image/drawscip-go gomod github.com/golang/go/src go1.24.0 `image/draw`/"
14 "timescip-go gomod github.com/golang/go/src go1.24.0 time/"
15
16 "golang.org/x/mobile/event/sizescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/"
17 "golang.org/x/mobile/exp/gl/glutilscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/"
18 "golang.org/x/mobile/geomscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/geom`/"
19 )
20
21 // FPS draws a count of the frames rendered per second.
22 type FPSscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS# struct {
23 szscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS#sz. sizescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/.Eventscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#
24 imagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS#images. *glutilscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/.Imagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#
25 mscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS#m. *glutilscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/.Imagescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#
26 lastDrawscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS#lastDraw. timescip-go gomod github.com/golang/go/src go1.24.0 time/.Timescip-go gomod github.com/golang/go/src go1.24.0 time/Time#
27 // TODO: store *gl.Context
28 }
29
30 // NewFPS creates an FPS tied to the current GL context.
31 func NewFPSscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/NewFPS().(images *glutilscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/.Imagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#) *FPSscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS# {
32 return &FPSscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS#{
33 lastDrawscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS#lastDraw.: timescip-go gomod github.com/golang/go/src go1.24.0 time/.Nowscip-go gomod github.com/golang/go/src go1.24.0 time/Now().(),
34 imagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS#images.: images,
35 }
36 }
37
38 // Draw draws the per second framerate in the bottom-left of the screen.
39 func (p *FPSscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS#) Drawscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS#Draw().(sz sizescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/.Eventscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#) {
40 const imgW, imgH = 7*(fontWidthscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/fontWidth.+1) + 1, fontHeightscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/fontHeight. + 2
41
42 if sz.WidthPxscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#WidthPx. == 0 && sz.HeightPxscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#HeightPx. == 0 {
43 return
44 }
45 if p.szscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS#sz. != sz {
46 p.szscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS#sz. = sz
47 if p.mscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS#m. != nil {
48 p.mscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS#m..Releasescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#Release().()
49 }
50 p.mscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS#m. = p.imagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS#images..NewImagescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Images#NewImage().(imgW, imgH)
51 }
52
53 display := [7]byte{
54 4: 'F',
55 5: 'P',
56 6: 'S',
57 }
58 now := timescip-go gomod github.com/golang/go/src go1.24.0 time/.Nowscip-go gomod github.com/golang/go/src go1.24.0 time/Now().()
59 f := 0
60 if dur := now.Subscip-go gomod github.com/golang/go/src go1.24.0 time/Time#Sub().(p.lastDrawscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS#lastDraw.); dur > 0 {
61 f = int(timescip-go gomod github.com/golang/go/src go1.24.0 time/.Secondscip-go gomod github.com/golang/go/src go1.24.0 time/Second. / dur)
62 }
63 display[2] = '0' + byte((f/1e0)%10)
64 display[1] = '0' + byte((f/1e1)%10)
65 display[0] = '0' + byte((f/1e2)%10)
66 drawscip-go gomod github.com/golang/go/src go1.24.0 `image/draw`/.Drawscip-go gomod github.com/golang/go/src go1.24.0 `image/draw`/Draw().(p.mscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS#m..RGBAscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#RGBA., p.mscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS#m..RGBAscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#RGBA..Boundsscip-go gomod github.com/golang/go/src go1.24.0 image/RGBA#Bounds().(), imagescip-go gomod github.com/golang/go/src go1.24.0 image/.Whitescip-go gomod github.com/golang/go/src go1.24.0 image/White., imagescip-go gomod github.com/golang/go/src go1.24.0 image/.Pointscip-go gomod github.com/golang/go/src go1.24.0 image/Point#{}, drawscip-go gomod github.com/golang/go/src go1.24.0 `image/draw`/.Srcscip-go gomod github.com/golang/go/src go1.24.0 `image/draw`/Src.)
67 for i, c := range display {
68 glyph := glyphsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/glyphs.[c]
69 if len(glyph) != fontWidthscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/fontWidth.*fontHeightscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/fontHeight. {
70 continue
71 }
72 for y := 0; y < fontHeightscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/fontHeight.; y++ {
73 for x := 0; x < fontWidthscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/fontWidth.; x++ {
74 if glyph[fontWidthscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/fontWidth.*y+x] == ' ' {
75 continue
76 }
77 p.mscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS#m..RGBAscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#RGBA..SetRGBAscip-go gomod github.com/golang/go/src go1.24.0 image/RGBA#SetRGBA().((fontWidthscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/fontWidth.+1)*i+x+1, y+1, colorscip-go gomod github.com/golang/go/src go1.24.0 `image/color`/.RGBAscip-go gomod github.com/golang/go/src go1.24.0 `image/color`/RGBA#{Ascip-go gomod github.com/golang/go/src go1.24.0 `image/color`/RGBA#A.: 0xff})
78 }
79 }
80 }
81
82 p.mscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS#m..Uploadscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#Upload().()
83 p.mscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS#m..Drawscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#Draw().(
84 sz,
85 geomscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/geom`/.Pointscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/geom`/Point#{0, sz.HeightPtscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#HeightPt. - imgH},
86 geomscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/geom`/.Pointscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/geom`/Point#{imgW, sz.HeightPtscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#HeightPt. - imgH},
87 geomscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/geom`/.Pointscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/geom`/Point#{0, sz.HeightPtscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/event/size`/Event#HeightPt.},
88 p.mscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS#m..RGBAscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#RGBA..Boundsscip-go gomod github.com/golang/go/src go1.24.0 image/RGBA#Bounds().(),
89 )
90
91 p.lastDrawscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS#lastDraw. = now
92 }
93
94 func (f *FPSscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS#) Releasescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS#Release().() {
95 if f.mscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS#m. != nil {
96 f.mscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS#m..Releasescip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/gl/glutil`/Image#Release().()
97 f.mscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS#m. = nil
98 f.imagesscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/FPS#images. = nil
99 }
100 }
101
102 const (
103 fontWidthscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/fontWidth. = 5
104 fontHeightscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/fontHeight. = 7
105 )
106
107 // glyphs comes from the 6x10 fixed font from the plan9port:
108 // https://github.com/9fans/plan9port/tree/master/font/fixed
109 //
110 // 6x10 becomes 5x7 because each glyph has a 1-pixel margin plus space for
111 // descenders.
112 //
113 // Its README file says that those fonts were converted from XFree86, and are
114 // in the public domain.
115 var glyphsscip-go gomod golang.org/x/mobile . `golang.org/x/mobile/exp/app/debug`/glyphs. = [256]string{
116 '0': "" +
117 " X " +
118 " X X " +
119 "X X" +
120 "X X" +
121 "X X" +
122 " X X " +
123 " X ",
124 '1': "" +
125 " X " +
126 " XX " +
127 "X X " +
128 " X " +
129 " X " +
130 " X " +
131 "XXXXX",
132 '2': "" +
133 " XXX " +
134 "X X" +
135 " X" +
136 " XX " +
137 " X " +
138 "X " +
139 "XXXXX",
140 '3': "" +
141 "XXXXX" +
142 " X" +
143 " X " +
144 " XX " +
145 " X" +
146 "X X" +
147 " XXX ",
148 '4': "" +
149 " X " +
150 " XX " +
151 " X X " +
152 "X X " +
153 "XXXXX" +
154 " X " +
155 " X ",
156 '5': "" +
157 "XXXXX" +
158 "X " +
159 "X XX " +
160 "XX X" +
161 " X" +
162 "X X" +
163 " XXX ",
164 '6': "" +
165 " XX " +
166 " X " +
167 "X " +
168 "X XX " +
169 "XX X" +
170 "X X" +
171 " XXX ",
172 '7': "" +
173 "XXXXX" +
174 " X" +
175 " X " +
176 " X " +
177 " X " +
178 " X " +
179 " X ",
180 '8': "" +
181 " XXX " +
182 "X X" +
183 "X X" +
184 " XXX " +
185 "X X" +
186 "X X" +
187 " XXX ",
188 '9': "" +
189 " XXX " +
190 "X X" +
191 "X XX" +
192 " XX X" +
193 " X" +
194 " X " +
195 " XX ",
196 'F': "" +
197 "XXXXX" +
198 "X " +
199 "X " +
200 "XXXX " +
201 "X " +
202 "X " +
203 "X ",
204 'P': "" +
205 "XXXX " +
206 "X X" +
207 "X X" +
208 "XXXX " +
209 "X " +
210 "X " +
211 "X ",
212 'S': "" +
213 " XXX " +
214 "X X" +
215 "X " +
216 " XXX " +
217 " X" +
218 "X X" +
219 " XXX ",
220 }