MCPcopy Create free account
hub / github.com/DaedalusX64/daedalus / TextureHandler

Function TextureHandler

Source/HLEGraphics/TextureCacheWebDebug.cpp:14–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12
13#ifdef DAEDALUS_DEBUG_DISPLAYLIST
14static void TextureHandler(void * arg, WebDebugConnection * connection)
15{
16 const char * params = connection->GetQueryString();
17 if (!params)
18 return;
19
20 // Yes, this is pretty dodgy. Any random pointer can be passed in so we
21 // validated ptr against the list of textures below.
22 void * ptr {};
23 if (sscanf(params, "ptr=%p", &ptr) != 1)
24 {
25 printf("Couldn't parse pointer: %s\n", params);
26 return;
27 }
28
29 // NB: maintain a lock for as long as we have a ref to any textures.
30 // If we delete textures on this thread, we'll crash OpenGL.
31 {
32 MutexLock lock(CTextureCache::Get()->GetDebugMutex());
33 CRefPtr<CNativeTexture> texture;
34 {
35 std::vector<CTextureCache::STextureInfoSnapshot> textures;
36 CTextureCache::Get()->Snapshot(lock, textures);
37 for (size_t i {}; i < textures.size(); ++i)
38 {
39 CTextureCache::STextureInfoSnapshot & snap = textures[i];
40 if ((CNativeTexture*)snap.Texture == ptr)
41 {
42 texture = snap.Texture;
43 break;
44 }
45 }
46 }
47
48 // Return a 404 if not found
49 if (!texture)
50 {
51 printf("Couldn't find texture %p\n", ptr);
52 return;
53 }
54
55 connection->BeginResponse(200, -1, "image/png");
56 PngSaveImage(connection, texture);
57 }
58
59 connection->EndResponse();
60}
61#endif // DAEDALUS_DEBUG_DISPLAYLIST
62
63

Callers

nothing calls this directly

Calls 7

PngSaveImageFunction · 0.85
GetQueryStringMethod · 0.80
GetDebugMutexMethod · 0.80
SnapshotMethod · 0.80
sizeMethod · 0.80
BeginResponseMethod · 0.80
EndResponseMethod · 0.80

Tested by

no test coverage detected