diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-06-10 07:08:30 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-06-10 07:08:30 +0300 |
commit | 99044467586a5a37c796a7786834359dfaf30a2c (patch) | |
tree | 629905f08c354049172101ff83de96976c2bba4e /src/media.c | |
parent | fdfd11b8a1a2d00c850039c8237208010236f765 (diff) |
Media: Estimate memory use
In-memory images, audio, and downloads are included in RAM usage in Debug Information.
Diffstat (limited to 'src/media.c')
-rw-r--r-- | src/media.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/media.c b/src/media.c index 180c28e6..eb4a8311 100644 --- a/src/media.c +++ b/src/media.c | |||
@@ -24,6 +24,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | |||
24 | #include "gmdocument.h" | 24 | #include "gmdocument.h" |
25 | #include "gmrequest.h" | 25 | #include "gmrequest.h" |
26 | #include "ui/window.h" | 26 | #include "ui/window.h" |
27 | #include "ui/paint.h" /* size_SDLTexture */ | ||
27 | #include "audio/player.h" | 28 | #include "audio/player.h" |
28 | #include "app.h" | 29 | #include "app.h" |
29 | #include "stb_image.h" | 30 | #include "stb_image.h" |
@@ -262,8 +263,28 @@ void clear_Media(iMedia *d) { | |||
262 | } | 263 | } |
263 | 264 | ||
264 | size_t memorySize_Media(const iMedia *d) { | 265 | size_t memorySize_Media(const iMedia *d) { |
265 | /* TODO: Calculate the actual memory use. */ | 266 | size_t memSize = 0; |
266 | return 0; | 267 | iConstForEach(PtrArray, i, &d->images) { |
268 | const iGmImage *img = i.ptr; | ||
269 | if (img->texture) { | ||
270 | const iInt2 texSize = size_SDLTexture(img->texture); | ||
271 | memSize += 4 * texSize.x * texSize.y; /* RGBA */ | ||
272 | } | ||
273 | else { | ||
274 | memSize += size_Block(&img->partialData); | ||
275 | } | ||
276 | } | ||
277 | iConstForEach(PtrArray, a, &d->audio) { | ||
278 | const iGmAudio *audio = a.ptr; | ||
279 | if (audio->player) { | ||
280 | memSize += sourceDataSize_Player(audio->player); | ||
281 | } | ||
282 | } | ||
283 | iConstForEach(PtrArray, n, &d->downloads) { | ||
284 | const iGmDownload *down = n.ptr; | ||
285 | memSize += down->numBytes; | ||
286 | } | ||
287 | return memSize; | ||
267 | } | 288 | } |
268 | 289 | ||
269 | iBool setDownloadUrl_Media(iMedia *d, iGmLinkId linkId, const iString *url) { | 290 | iBool setDownloadUrl_Media(iMedia *d, iGmLinkId linkId, const iString *url) { |