int main() { time_elapsed = emscripten_get_now(); http* http1 = new http("https://github.com",http::REQUEST_GET,"emscripten_master.zip"); http1->runRequest("/kripken/emscripten/archive/master.zip",http::ASSYNC_THREAD); http* http2 = new http("https://github.com",http::REQUEST_GET,"wolfviking_master.zip"); http2->runRequest("/wolfviking0/image.js/archive/master.zip",http::ASSYNC_THREAD); http2->abortRequest(); http* http3 = new http("https://raw.github.com",http::REQUEST_GET); http3->runRequest("/kripken/emscripten/master/LICENSE",http::ASSYNC_THREAD); num_request ++; emscripten_async_call(wait_http,http1,500); num_request ++; emscripten_async_call(wait_http,http2,500); num_request ++; emscripten_async_call(wait_http,http3,500); /* Http* http4 = new Http("http://www.---.com",Http::REQUEST_POST); http4->addValue("app","123"); http4->runRequest("/test.php",Http::ASSYNC_THREAD); num_request ++; emscripten_async_call(wait_http,http4,500); */ emscripten_set_main_loop(wait_https, 0, 0); }
void iter() { printf("frame: %d\n", ++counter); emscripten_async_call(acall, 0, counter % 2); // 0 or 1 millis, try to execute this *before* the sync callback finishes, which would be bad // ensure we don't 'recurse' with the main loop sending is back in before the synchronous operation callback finishes the rest of this trace assert(nesting == 0); nesting++; emscripten_sleep(500); assert(nesting == 1); nesting = 2; if (counter % 3 == 2) { // second sleep every 3rd frame, to test sleep when returning from a sleep printf(" (second sleep)\n"); assert(nesting == 2); nesting = 3; emscripten_sleep(1000); assert(nesting == 3); }; nesting = 0; if (counter == 10) { assert(acall_counter == 9 /* the tenth is about to execute, but not yet! */ ); finish(121); // if we got here without hitting any assertions, all is well emscripten_cancel_main_loop(); } }
int main() { SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER); darea = SDL_SetVideoMode(800, 600, 32, SDL_HWSURFACE); TTF_Init(); printf("main1\n"); emscripten_async_call(main_2, NULL, 500); // avoid startup delays and intermittent errors return 0; }
int main() { SDL_Init(0); last = SDL_GetTicks(); printf("frist! %d\n", last); atexit(never); // should never be called - it is wrong to exit the runtime orderly if we have async calls! emscripten_async_call(second, (void*)0, 500); return 1; }
int main() { SDL_Init(SDL_INIT_VIDEO); SDL_Surface *screen = SDL_SetVideoMode(600, 450, 32, SDL_HWSURFACE); SDL_Rect rect = { 0, 0, 600, 450 }; SDL_FillRect(screen, &rect, 0x2244ffff); emscripten_async_call(main_2, NULL, 3000); // avoid startup delays and intermittent errors return 0; }
int main() { SDL_Init(SDL_INIT_VIDEO); SDL_Window *window; SDL_Renderer *renderer; SDL_CreateWindowAndRenderer(600, 450, 0, &window, &renderer); SDL_SetRenderDrawColor(renderer, 0xFF, 0x00, 0x00, 0xFF ); SDL_Rect rect = { 0, 0, 600, 450 }; SDL_RenderFillRect(renderer, &rect); emscripten_async_call(main_2, NULL, 3000); // avoid startup delays and intermittent errors return 0; }
void mainey() { static int counter = 0; printf("mainey: %d\n", counter++); if (counter == 20) { emscripten_pause_main_loop(); emscripten_async_call(five, (void*)55, 1000); } else if (counter == 22) { // very soon after 20, so without pausing we fail assert(fived); emscripten_push_main_loop_blocker(pre1, (void*)123); emscripten_push_main_loop_blocker(pre2, (void*)98); } else if (counter == 23) { assert(pre1ed); assert(pre2ed); printf("Good!\n"); emscripten_cancel_main_loop(); emscripten_set_main_loop_arg(argey, (void*)17, 0, 0); } }
void PollThreadExit(void *) { if (!emscripten_atomic_load_u32(&threadRunning)) { EmscriptenWebGLContextAttributes attr; emscripten_webgl_init_context_attributes(&attr); #ifdef TEST_MAIN_THREAD_EXPLICIT_COMMIT attr.explicitSwapControl = EM_TRUE; #endif ctx = emscripten_webgl_create_context(0, &attr); emscripten_webgl_make_context_current(ctx); printf("Main thread rendering. You should see the WebGL canvas fade from black to green.\n"); emscripten_set_main_loop(MainThreadRender, 0, 0); } else { emscripten_async_call(PollThreadExit, 0, 1000); } }
/** * Resolve this address into a socket * @param family the type of 'protocol' (IPv4, IPv6) * @param socktype the type of socket (TCP, UDP, etc) * @param flags the flags to send to getaddrinfo * @param sockets the list of sockets to add the sockets to * @param func the inner working while looping over the address info * @return the resolved socket or INVALID_SOCKET. */ SOCKET NetworkAddress::Resolve(int family, int socktype, int flags, SocketList *sockets, LoopProc func) { if (func != ConnectLoopProc) { return INVALID_SOCKET; } else { SOCKET sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (sock == INVALID_SOCKET) { throw "Unable to connect"; } if (!SetNoDelay(sock)) { DEBUG(net, 1, "setting TCP_NODELAY failed"); } printf("schedule connect: %d\n", sock); emscripten_async_call(async_connect, (void *)sock, 10000); return sock; } }
void wait_http(void* request) { http* req = reinterpret_cast<http*>(request); if (req != 0) { if (req->getStatus() == http::ST_PENDING) { if ((int)req->getProgress()>0) { printf("Progress Request n°%d : %d\n",req->getId(),(int)req->getProgress()); } emscripten_async_call(wait_http,request,500); } else { if (req->getStatus() == http::ST_OK) { printf("Success Request n°%d : %s\n",req->getId(),req->getContent()); } else if (req->getStatus() == http::ST_ABORTED) { printf("Aborted Request n°%d", req->getId()); } else { printf("Error Request n°%d : %s\n",req->getId(), req->getError()); } num_request --; } } else { num_request --; } }
int main() { SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK); SDL_Surface *screen = SDL_SetVideoMode(600, 450, 32, SDL_HWSURFACE); emscripten_async_call(main_2, NULL, 3000); // avoid startup delays and intermittent errors return 0; }
int main() { ALCdevice* device = alcOpenDevice(NULL); ALCcontext* context = alcCreateContext(device, NULL); alcMakeContextCurrent(context); ALfloat listenerPos[] = {0.0, 0.0, 0.0}; ALfloat listenerVel[] = {0.0, 0.0, 0.0}; ALfloat listenerOri[] = {0.0, 0.0, -1.0, 0.0, 1.0, 0.0}; alListenerfv(AL_POSITION, listenerPos); alListenerfv(AL_VELOCITY, listenerVel); alListenerfv(AL_ORIENTATION, listenerOri); ALuint buffers[1]; alGenBuffers(1, buffers); FILE* source = fopen("audio.wav", "rb"); fseek(source, 0, SEEK_END); int size = ftell(source); fseek(source, 0, SEEK_SET); unsigned char* buffer = (unsigned char*) malloc(size); fread(buffer, size, 1, source); unsigned offset = 12; // ignore the RIFF header offset += 8; // ignore the fmt header offset += 2; // ignore the format type unsigned channels = buffer[offset + 1] << 8; channels |= buffer[offset]; offset += 2; printf("Channels: %u\n", channels); unsigned frequency = buffer[offset + 3] << 24; frequency |= buffer[offset + 2] << 16; frequency |= buffer[offset + 1] << 8; frequency |= buffer[offset]; offset += 4; printf("Frequency: %u\n", frequency); offset += 6; // ignore block size and bps unsigned bits = buffer[offset + 1] << 8; bits |= buffer[offset]; offset += 2; printf("Bits: %u\n", bits); ALenum format = 0; if(bits == 8) { if(channels == 1) format = AL_FORMAT_MONO8; else if(channels == 2) format = AL_FORMAT_STEREO8; } else if(bits == 16) { if(channels == 1) format = AL_FORMAT_MONO16; else if(channels == 2) format = AL_FORMAT_STEREO16; } offset += 8; // ignore the data chunk printf("Start offset: %d\n", offset); alBufferData(buffers[0], format, &buffer[offset], size - offset, frequency); ALuint sources[1]; alGenSources(1, sources); alSourcei(sources[0], AL_BUFFER, buffers[0]); ALint state; alGetSourcei(sources[0], AL_SOURCE_STATE, &state); assert(state == AL_INITIAL); alSourcePlay(sources[0]); alGetSourcei(sources[0], AL_SOURCE_STATE, &state); assert(state == AL_PLAYING); emscripten_async_call(playSource, reinterpret_cast<void*>(sources[0]), 700); return 0; }
int main(int argc, char *argv[]) { /* Check command line arguments */ argv += get_video_args(argv, &w, &h, &bpp, &flags); /* Initialize SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); return(1); } /* Initialize the display, always use hardware palette */ screen = SDL_SetVideoMode(w, h, bpp, flags | SDL_HWPALETTE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set %dx%d video mode: %s\n", w, h, SDL_GetError()); quit(1); } /* Set the window manager title bar */ SDL_WM_SetCaption("SDL gamma test", "testgamma"); /* Set the desired gamma, if any */ gamma = 1.0f; if ( *argv ) { gamma = (float)atof(*argv); } if ( SDL_SetGamma(gamma, gamma, gamma) < 0 ) { fprintf(stderr, "Unable to set gamma: %s\n", SDL_GetError()); quit(1); } #if 0 /* This isn't supported. Integrating the gamma ramps isn't exact */ /* See what gamma was actually set */ float real[3]; if ( SDL_GetGamma(&real[0], &real[1], &real[2]) < 0 ) { printf("Couldn't get gamma: %s\n", SDL_GetError()); } else { printf("Set gamma values: R=%2.2f, G=%2.2f, B=%2.2f\n", real[0], real[1], real[2]); } #endif /* Do all the drawing work */ image = SDL_LoadBMP("sample.bmp"); if ( image ) { SDL_Rect dst; dst.x = (screen->w - image->w)/2; dst.y = (screen->h - image->h)/2; dst.w = image->w; dst.h = image->h; SDL_BlitSurface(image, NULL, screen, &dst); SDL_UpdateRects(screen, 1, &dst); } /* Wait a bit, handling events */ then = SDL_GetTicks(); timeout = (5*1000); #ifndef EMSCRIPTEN while ( (SDL_GetTicks()-then) < timeout ) { #else emscripten_set_main_loop(&main_loop, 0, 1); } void main_loop() { if ( (SDL_GetTicks()-then) < timeout ) { #endif SDL_Event event; while ( SDL_PollEvent(&event) ) { switch (event.type) { case SDL_QUIT: /* Quit now */ timeout = 0; break; case SDL_KEYDOWN: switch (event.key.keysym.sym) { case SDLK_SPACE: /* Go longer.. */ timeout += (5*1000); break; case SDLK_UP: gamma += 0.2f; SDL_SetGamma(gamma, gamma, gamma); break; case SDLK_DOWN: gamma -= 0.2f; SDL_SetGamma(gamma, gamma, gamma); break; case SDLK_ESCAPE: timeout = 0; break; default: break; } break; } } } #ifdef EMSCRIPTEN else { #endif /* Perform a gamma flash to red using color ramps */ while ( gamma < 10.0 ) { /* Increase the red gamma and decrease everything else... */ gamma += 0.1f; CalculateGamma(gamma, red_ramp); CalculateGamma(1.0/gamma, ramp); SDL_SetGammaRamp(red_ramp, ramp, ramp); } /* Finish completely red */ memset(red_ramp, 255, sizeof(red_ramp)); memset(ramp, 0, sizeof(ramp)); SDL_SetGammaRamp(red_ramp, ramp, ramp); /* Now fade out to black */ for ( i=(red_ramp[0] >> 8); i >= 0; --i ) { memset(red_ramp, i, sizeof(red_ramp)); SDL_SetGammaRamp(red_ramp, NULL, NULL); } #ifndef EMSCRIPTEN SDL_Delay(1*1000); #else emscripten_pause_main_loop(); emscripten_async_call(&end_main, 0, 1*1000); } } void end_main() { #endif SDL_Quit(); #ifndef EMSCRIPTEN return(0); #else exit(0); #endif }
void __attribute__((used)) third() { int now = SDL_GetTicks(); printf("thard! %d\n", now); assert(fabs(now - last - 1000) < 500); emscripten_async_call(four, (void*)43, -1); // triggers requestAnimationFrame }
int main() { int major, minor; alcGetIntegerv(NULL, ALC_MAJOR_VERSION, 1, &major); alcGetIntegerv(NULL, ALC_MAJOR_VERSION, 1, &minor); assert(major == 1); printf("ALC version: %i.%i\n", major, minor); printf("Default device: %s\n", alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER)); ALCdevice* device = alcOpenDevice(NULL); ALCcontext* context = alcCreateContext(device, NULL); alcMakeContextCurrent(context); assert(alGetString(AL_VERSION)); printf("OpenAL version: %s\n", alGetString(AL_VERSION)); printf("OpenAL vendor: %s\n", alGetString(AL_VENDOR)); printf("OpenAL renderer: %s\n", alGetString(AL_RENDERER)); ALfloat listenerPos[] = {0.0, 0.0, 0.0}; ALfloat listenerVel[] = {0.0, 0.0, 0.0}; ALfloat listenerOri[] = {0.0, 0.0, -1.0, 0.0, 1.0, 0.0}; alListenerfv(AL_POSITION, listenerPos); alListenerfv(AL_VELOCITY, listenerVel); alListenerfv(AL_ORIENTATION, listenerOri); // check getting and setting global gain ALfloat volume; alGetListenerf(AL_GAIN, &volume); assert(volume == 1.0); alListenerf(AL_GAIN, 0.0); alGetListenerf(AL_GAIN, &volume); assert(volume == 0.0); alListenerf(AL_GAIN, 1.0); // reset gain to default ALuint buffers[1]; alGenBuffers(1, buffers); #ifdef __EMSCRIPTEN__ FILE* source = fopen("audio.wav", "rb"); #else FILE* source = fopen("sounds/audio.wav", "rb"); #endif fseek(source, 0, SEEK_END); int size = ftell(source); fseek(source, 0, SEEK_SET); unsigned char* buffer = (unsigned char*) malloc(size); fread(buffer, size, 1, source); unsigned offset = 12; // ignore the RIFF header offset += 8; // ignore the fmt header offset += 2; // ignore the format type unsigned channels = buffer[offset + 1] << 8; channels |= buffer[offset]; offset += 2; printf("Channels: %u\n", channels); unsigned frequency = buffer[offset + 3] << 24; frequency |= buffer[offset + 2] << 16; frequency |= buffer[offset + 1] << 8; frequency |= buffer[offset]; offset += 4; printf("Frequency: %u\n", frequency); offset += 6; // ignore block size and bps unsigned bits = buffer[offset + 1] << 8; bits |= buffer[offset]; offset += 2; printf("Bits: %u\n", bits); ALenum format = 0; if(bits == 8) { if(channels == 1) format = AL_FORMAT_MONO8; else if(channels == 2) format = AL_FORMAT_STEREO8; } else if(bits == 16) { if(channels == 1) format = AL_FORMAT_MONO16; else if(channels == 2) format = AL_FORMAT_STEREO16; } offset += 8; // ignore the data chunk printf("Start offset: %d\n", offset); alBufferData(buffers[0], format, &buffer[offset], size - offset, frequency); ALint val; alGetBufferi(buffers[0], AL_FREQUENCY, &val); assert(val == frequency); alGetBufferi(buffers[0], AL_SIZE, &val); assert(val == size - offset); alGetBufferi(buffers[0], AL_BITS, &val); assert(val == bits); alGetBufferi(buffers[0], AL_CHANNELS, &val); assert(val == channels); ALuint sources[1]; alGenSources(1, sources); assert(alIsSource(sources[0])); alSourcei(sources[0], AL_BUFFER, buffers[0]); ALint state; alGetSourcei(sources[0], AL_SOURCE_STATE, &state); assert(state == AL_INITIAL); alSourcePlay(sources[0]); alGetSourcei(sources[0], AL_SOURCE_STATE, &state); assert(state == AL_PLAYING); #ifdef __EMSCRIPTEN__ emscripten_async_call(playSource, reinterpret_cast<void*>(sources[0]), 700); #else usleep(700000); playSource(reinterpret_cast<void*>(sources[0])); #endif return 0; }
void ChromeClientJS::widgetSizeChanged(const IntSize& oldWidgetSize, IntSize newSize) { webkitTrace(); MainFrame& frame = (m_view->m_private->mainFrame->coreFrame()->mainFrame()); if(frame.view()) { frame.view()->resize(newSize.width(),newSize.height()); frame.view()->adjustViewSize(); if(frame.view()->needsLayout()) frame.view()->layout(); } if (m_view->m_private->acceleratedContext && m_view->m_private->acceleratedContext->enabled()) { m_view->m_private->acceleratedContext->resizeRootLayer(newSize); return; } if (m_view->m_private->backingStore && oldWidgetSize == newSize) return; if (m_view->m_private->backingStore) { const IntSize& oldSize = m_view->m_private->backingStore->size(); if (newSize.width() > oldSize.width()) newSize.setWidth(std::max(newSize.width(), static_cast<int>(oldSize.width() * 1.5))); if (newSize.height() > oldSize.height()) newSize.setHeight(std::max(newSize.height(), static_cast<int>(oldSize.height() * 1.5))); } // If we did not have a backing store before or if the backing store is growing, we need // to reallocate a new one and set it up so that we don't see artifacts while resizing. if (!m_view->m_private->backingStore || newSize.width() > m_view->m_private->backingStore->size().width() || newSize.height() > m_view->m_private->backingStore->size().height()) { SDL_Surface *surface = SDL_CreateRGBSurface(SDL_SWSURFACE, newSize.width(), newSize.height(), 32, //SDL_HWSURFACE | SDL_HWPALETTE 0x00FF0000, /* Rmask */ 0x0000FF00, /* Gmask */ 0x000000FF, /* Bmask */ 0xFF000000); /* Amask */ PassOwnPtr<WidgetBackingStore> newBackingStore = WebCore::WidgetBackingStoreCairo::create(surface, newSize); RefPtr<cairo_t> cr = adoptRef(cairo_create(newBackingStore->cairoSurface())); clearEverywhereInBackingStore(m_view, cr.get()); // Now we copy the old backing store image over the new cleared surface to prevent // annoying flashing as the widget grows. We do the "real" paint in a timeout // since we don't want to block resizing too long. if (m_view->m_private->backingStore) { cairo_set_source_surface(cr.get(), m_view->m_private->backingStore->cairoSurface(), 0, 0); cairo_rectangle(cr.get(), 0, 0, m_view->m_private->backingStore->size().width(), m_view->m_private->backingStore->size().height()); cairo_fill(cr.get()); } m_view->m_private->backingStore = newBackingStore; } else if (oldWidgetSize.width() < newSize.width() || oldWidgetSize.height() < newSize.height()) { // The widget is growing, but we did not need to create a new backing store. // We should clear any old data outside of the old widget region. RefPtr<cairo_t> cr = adoptRef(cairo_create(m_view->m_private->backingStore->cairoSurface())); clipOutOldWidgetArea(cr.get(), oldWidgetSize, newSize); clearEverywhereInBackingStore(m_view, cr.get()); } // We need to force a redraw and ignore the framerate cap. m_lastDisplayTime = 0; m_dirtyRegion.unite(IntRect(IntPoint(), m_view->m_private->backingStore->size())); // WebCore timers by default have a lower priority which leads to more artifacts when opaque // resize is on emscripten_async_call((void (*)(void *))(&repaintEverythingSoonTimeout), this, 0); }