Mercurial > hg > orthanc-stone
comparison Platforms/Wasm/Defaults.cpp @ 918:d6c029d15aaa
Merged am-dev into default
author | Alain Mazy <am@osimis.io> |
---|---|
date | Fri, 19 Jul 2019 15:15:13 +0200 |
parents | 8f7930f589ef |
children | 92a043b8e431 |
comparison
equal
deleted
inserted
replaced
914:4d1f57773b5b | 918:d6c029d15aaa |
---|---|
38 } | 38 } |
39 | 39 |
40 #ifdef __cplusplus | 40 #ifdef __cplusplus |
41 extern "C" { | 41 extern "C" { |
42 #endif | 42 #endif |
43 | |
44 #if 0 | |
45 // rewrite malloc/free in order to monitor allocations. We actually only monitor large allocations (like images ...) | |
46 | |
47 size_t bigChunksTotalSize = 0; | |
48 std::map<void*, size_t> allocatedBigChunks; | |
49 | |
50 extern void* emscripten_builtin_malloc(size_t bytes); | |
51 extern void emscripten_builtin_free(void* mem); | |
52 | |
53 void * __attribute__((noinline)) malloc(size_t size) | |
54 { | |
55 void *ptr = emscripten_builtin_malloc(size); | |
56 if (size > 100000) | |
57 { | |
58 bigChunksTotalSize += size; | |
59 printf("++ Allocated %zu bytes, got %p. (%zu MB consumed by big chunks)\n", size, ptr, bigChunksTotalSize/(1024*1024)); | |
60 allocatedBigChunks[ptr] = size; | |
61 } | |
62 return ptr; | |
63 } | |
64 | |
65 void __attribute__((noinline)) free(void *ptr) | |
66 { | |
67 emscripten_builtin_free(ptr); | |
68 | |
69 std::map<void*, size_t>::iterator it = allocatedBigChunks.find(ptr); | |
70 if (it != allocatedBigChunks.end()) | |
71 { | |
72 bigChunksTotalSize -= it->second; | |
73 printf("-- Freed %zu bytes at %p. (%zu MB consumed by big chunks)\n", it->second, ptr, bigChunksTotalSize/(1024*1024)); | |
74 allocatedBigChunks.erase(it); | |
75 } | |
76 } | |
77 #endif // 0 | |
43 | 78 |
44 using namespace OrthancStone; | 79 using namespace OrthancStone; |
45 | 80 |
46 // when WASM needs a C++ viewport | 81 // when WASM needs a C++ viewport |
47 ViewportHandle EMSCRIPTEN_KEEPALIVE CreateCppViewport() { | 82 ViewportHandle EMSCRIPTEN_KEEPALIVE CreateCppViewport() { |
273 float x1, | 308 float x1, |
274 float y1, | 309 float y1, |
275 float x2, | 310 float x2, |
276 float y2) | 311 float y2) |
277 { | 312 { |
278 printf("touch start with %d touches\n", touchCount); | 313 // printf("touch start with %d touches\n", touchCount); |
279 | 314 |
280 std::vector<Deprecated::Touch> touches; | 315 std::vector<Deprecated::Touch> touches; |
281 GetTouchVector(touches, touchCount, x0, y0, x1, y1, x2, y2); | 316 GetTouchVector(touches, touchCount, x0, y0, x1, y1, x2, y2); |
282 viewport->TouchStart(touches); | 317 viewport->TouchStart(touches); |
283 } | 318 } |
289 float x1, | 324 float x1, |
290 float y1, | 325 float y1, |
291 float x2, | 326 float x2, |
292 float y2) | 327 float y2) |
293 { | 328 { |
294 printf("touch move with %d touches\n", touchCount); | 329 // printf("touch move with %d touches\n", touchCount); |
295 | 330 |
296 std::vector<Deprecated::Touch> touches; | 331 std::vector<Deprecated::Touch> touches; |
297 GetTouchVector(touches, touchCount, x0, y0, x1, y1, x2, y2); | 332 GetTouchVector(touches, touchCount, x0, y0, x1, y1, x2, y2); |
298 viewport->TouchMove(touches); | 333 viewport->TouchMove(touches); |
299 } | 334 } |
305 float x1, | 340 float x1, |
306 float y1, | 341 float y1, |
307 float x2, | 342 float x2, |
308 float y2) | 343 float y2) |
309 { | 344 { |
310 printf("touch end with %d touches remaining\n", touchCount); | 345 // printf("touch end with %d touches remaining\n", touchCount); |
311 | 346 |
312 std::vector<Deprecated::Touch> touches; | 347 std::vector<Deprecated::Touch> touches; |
313 GetTouchVector(touches, touchCount, x0, y0, x1, y1, x2, y2); | 348 GetTouchVector(touches, touchCount, x0, y0, x1, y1, x2, y2); |
314 viewport->TouchEnd(touches); | 349 viewport->TouchEnd(touches); |
315 } | 350 } |
360 | 395 |
361 const char* EMSCRIPTEN_KEEPALIVE SendSerializedMessageToStoneApplication(const char* message) | 396 const char* EMSCRIPTEN_KEEPALIVE SendSerializedMessageToStoneApplication(const char* message) |
362 { | 397 { |
363 static std::string output; // we don't want the string to be deallocated when we return to JS code so we always use the same string (this is fine since JS is single-thread) | 398 static std::string output; // we don't want the string to be deallocated when we return to JS code so we always use the same string (this is fine since JS is single-thread) |
364 | 399 |
365 printf("SendSerializedMessageToStoneApplication\n"); | 400 //printf("SendSerializedMessageToStoneApplication\n"); |
366 printf("%s", message); | 401 //printf("%s", message); |
367 | 402 |
368 if (applicationWasmAdapter.get() != NULL) { | 403 if (applicationWasmAdapter.get() != NULL) { |
369 applicationWasmAdapter->HandleSerializedMessageFromWeb(output, std::string(message)); | 404 applicationWasmAdapter->HandleSerializedMessageFromWeb(output, std::string(message)); |
370 return output.c_str(); | 405 return output.c_str(); |
371 } | 406 } |
372 printf("This Stone application does not have a Web Adapter"); | 407 printf("This Stone application does not have a Web Adapter, unable to send messages"); |
373 return NULL; | 408 return NULL; |
374 } | 409 } |
375 | 410 |
376 #ifdef __cplusplus | 411 #ifdef __cplusplus |
377 } | 412 } |