예제 #1
0
static void Repaint(struct PepperState *mystate) {
  struct PP_Point topleft = PP_MakePoint(0, 0);
  struct PP_Rect rect = PP_MakeRectFromXYWH(0, 0,
                                            mystate->position.size.width,
                                            mystate->position.size.height);
  int show, render;

  /* Wait for previous rendering (if applicable) to finish */
  Earth_Sync();

  /* Double buffer - show previously rendered image. */
  show = mystate->which_image;
  mystate->graphics_2d_interface->PaintImageData(mystate->device_context,
                                                 mystate->image[show],
                                                 &topleft, &rect);
  int32_t ret;
  ret = mystate->graphics_2d_interface->Flush(mystate->device_context,
      PP_MakeCompletionCallback(&FlushCompletionCallback, mystate));

  /* Start Rendering into the other image while presenting. */
  render = (mystate->which_image + 1) % NUMBER_OF_IMAGES;

  Earth_Draw(mystate->image_data[render],
             mystate->position.size.width,
             mystate->position.size.height);

  /* In next callback, show what was rendered. */
  mystate->which_image = render;
}
예제 #2
0
void _gtk_widget_queue_draw(GtkWidget *widget){
	cairo_t *cr;
	struct PP_ImageDataDesc image_desc;
	unsigned char *surface_data, *image_data;
	int num_chars;
	struct PP_Size size;
	struct PP_Point point;
	struct PP_Rect rect;
	cr = cairo_create(widget->surface);
	
	widget->g_signal_list[DRAW].g_signal_callback(widget, cr, NULL);
	
	size.width = cairo_image_surface_get_width(widget->surface);
	size.height = cairo_image_surface_get_height(widget->surface);
	
	point.x = 0;
	point.y = 0;
	
	rect.point = point;
	rect.size = size;
	
	printf("size width:%d, height:%d\n", size.width, size.height);
	
	g_graphics_2d_interface->PaintImageData(graphics, widget->image, &point, &rect);
	g_graphics_2d_interface->Flush(graphics, PP_MakeCompletionCallback(&FlushCompletionCallback, NULL));
} 
예제 #3
0
void PostMessage(const char *str) {
  struct PP_CompletionCallback cb;

  if (NULL == str) return;
  if (NULL == ppb_messaging_interface) return;
  if (0 == g_Instance) return;

  if (strncmp(str, "ERR:", 4)) {
    fprintf(stderr, "%s\n", str);
    fflush(stderr);
  }
  else {
    fprintf(stdout, "%s\n", str);
    fflush(stdout);
  }

  /* If on Main Pepper thread, then call interface directly. */
  if (pthread_self() == g_PPAPIThread) {
    ppb_messaging_interface->PostMessage(g_Instance, CStrToVar(str));
    return;
  }

  /* Otherwise use call on main thread. */
  cb = PP_MakeCompletionCallback(PostCompletionCallback, strdup(str));
  ppb_core_interface->CallOnMainThread(0, cb, 0);
}
예제 #4
0
int32_t RunJob(MainThreadRunner *runner, MainThreadJob *job){
  JobEntry entry;

  // initialize the entry
  entry.runner = runner;
  entry.pepper_instance = runner->pepper_instance_;
  entry.job = job;

  bool in_main_thread = IsMainThread();
  // Must be off main thread, or on a pseudothread.
  assert(!in_main_thread || in_pseudo_thread_);

  // Thread type specific initialization.
  if (in_main_thread) {
    entry.pseudo_thread_job = true;
  } else {
    entry.pseudo_thread_job = false;
    // Init condition variable.
    entry.is_done = false;
    int ret = pthread_mutex_init(&entry.done_mutex, NULL);
    assert(!ret);
    ret = pthread_cond_init(&entry.done_cond, NULL);
    assert(!ret);
  }

  // put the job on the queue
  pthread_mutex_lock(&(runner->lock_));
  //job_queue_.push_back(&entry);
  //JobEntry_list_push_back(&entry, &(runner->job_queue_));
  runner->job_queue_[runner->qtail]=&entry;
  runner->qtail = (runner->qtail+1)%QSIZE;
  runner->size++;
  pthread_mutex_unlock(&(runner->lock_));

#ifdef USE_PEPPER
  // Schedule the job.
  //pp::Module::Get()->core()->CallOnMainThread(0,
  //    pp::CompletionCallback(&DoWorkShim, this), PP_OK);
  g_core_interface->CallOnMainThread(0,
      PP_MakeCompletionCallback(&DoWorkShim, runner), PP_OK);
#endif
  // Block differntly on the main thread.
  if (entry.pseudo_thread_job) {
    // block pseudothread until job is done
    PseudoThreadBlock();
  } else {
    // wait on condition until the job is done
    pthread_mutex_lock(&entry.done_mutex);
    while (!entry.is_done) {
      pthread_cond_wait(&entry.done_cond, &entry.done_mutex);
    }
    pthread_mutex_unlock(&entry.done_mutex);
    pthread_mutex_destroy(&entry.done_mutex);
    pthread_cond_destroy(&entry.done_cond);
  }
  // Cleanup.
  //delete job;
  free(job);
  return entry.result;
}
예제 #5
0
struct PP_Var
ppb_instance_private_execute_script(PP_Instance instance, struct PP_Var script,
                                    struct PP_Var *exception)
{
    if (script.type != PP_VARTYPE_STRING) {
        trace_error("%s, 'script' is not a string\n", __func__);
        // TODO: fill exception
        return PP_MakeUndefined();
    }

    struct pp_instance_s *pp_i = tables_get_pp_instance(instance);
    if (!pp_i) {
        trace_error("%s, bad instance\n", __func__);
        return PP_MakeUndefined();
    }

    struct execute_script_param_s p;
    p.script =  script;
    p.pp_i =    pp_i;
    p.m_loop =  ppb_message_loop_get_current();
    p.depth =   ppb_message_loop_get_depth(p.m_loop) + 1;

    ppb_var_add_ref(script);
    ppb_message_loop_post_work(p.m_loop, PP_MakeCompletionCallback(_execute_script_comt, &p), 0);
    ppb_message_loop_run_int(p.m_loop, 1);
    ppb_var_release(script);

    return p.result;
}
예제 #6
0
		static void OnReceiveMessage(ZL_WebSocketConnection_Impl* impl, int32_t result)
		{
			//ZL_LOG("NACLWSC", "ONRECEIVE - WS: %d - RESULT: %d - READYSTATE: %d - BUFFER: %d", impl->websocket, result, (int32_t)ppb_websocket_interface->GetReadyState(impl->websocket), (int32_t)ppb_websocket_interface->GetBufferedAmount(impl->websocket));
			if (result < 0) { impl->Disconnect(PP_WEBSOCKETSTATUSCODE_ABNORMAL_CLOSURE, NULL, 0); return; }
			HandleMessage(impl);
			const PP_CompletionCallback cc = PP_MakeCompletionCallback((PP_CompletionCallback_Func)&OnReceiveMessage, (void*)impl);
			while (ppb_websocket_interface->ReceiveMessage(impl->websocket, &impl->data, cc) == PP_OK) HandleMessage(impl);
		}
예제 #7
0
		static void OnConnect(ZL_WebSocketConnection_Impl* impl, int32_t result)
		{
			//ZL_LOG("NACLWSC", "ONCONNECT - WS: %d - RESULT: %d - READYSTATE: %d", impl->websocket, result, (int32_t)ppb_websocket_interface->GetReadyState(impl->websocket));
			if (result < 0) { impl->Disconnect(PP_WEBSOCKETSTATUSCODE_ABNORMAL_CLOSURE, NULL, 0); return; }
			impl->websocket_active = true;
			impl->sigConnected.call();
			if (ppb_websocket_interface->ReceiveMessage(impl->websocket, &impl->data, PP_MakeCompletionCallback((PP_CompletionCallback_Func)&OnReceiveMessage, impl)) == PP_OK)
				OnReceiveMessage(impl, PP_OK);
		}
예제 #8
0
/**
 * Called when the position, the size, or the clip rect of the element in the
 * browser that corresponds to this NaCl module has changed.
 * @param[in] instance The identifier of the instance representing this NaCl
 *     module.
 * @param[in] position The location on the page of this NaCl module. This is
 *     relative to the top left corner of the viewport, which changes as the
 *     page is scrolled.
 * @param[in] clip The visible region of the NaCl module. This is relative to
 *     the top left of the plugin's coordinate system (not the page).  If the
 *     plugin is invisible, @a clip will be (0, 0, 0, 0).
 */
static void Instance_DidChangeView(PP_Instance instance,
                                   PP_Resource view_resource) {
	struct PP_Rect pos;
    int bFirstCall = 0;

	psNaCLContext->psView->GetRect(view_resource, &pos);

	if (pos.size.width == 0 || pos.size.height == 0)
	{
		return;
	}

	psNaCLContext->i32PluginWidth = pos.size.width;
	psNaCLContext->i32PluginHeight = pos.size.height;

    if(psNaCLContext->hRenderContext == 0)
    {
        bFirstCall = 1;
    }

    if(psNaCLContext->hRenderContext == 0)
    {
	    int32_t attribs[] = {
	    PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8,
	    PP_GRAPHICS3DATTRIB_BLUE_SIZE, 8,
	    PP_GRAPHICS3DATTRIB_GREEN_SIZE, 8,
	    PP_GRAPHICS3DATTRIB_RED_SIZE, 8,
	    PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 16,
	    PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 0,
	    PP_GRAPHICS3DATTRIB_SAMPLES, 4,
	    PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS, 1,
	    PP_GRAPHICS3DATTRIB_WIDTH, psNaCLContext->i32PluginWidth,
	    PP_GRAPHICS3DATTRIB_HEIGHT, psNaCLContext->i32PluginHeight,
	    PP_GRAPHICS3DATTRIB_NONE,
	    };

	    psNaCLContext->hRenderContext = psNaCLContext->psG3D->Create(psNaCLContext->hModule, NULL, attribs);
	    psNaCLContext->psInstanceInterface->BindGraphics(psNaCLContext->hModule, psNaCLContext->hRenderContext);

        if(bFirstCall)
        {
	        DemoInit(psNaCLContext, psNaCLContext->i32PluginWidth, psNaCLContext->i32PluginHeight);
        }

        PP_CompletionCallback cc = PP_MakeCompletionCallback(DrawFrame, 0);
        psNaCLContext->psCore->CallOnMainThread(0, cc, PP_OK);
    }
    else
    {
        psNaCLContext->psG3D->ResizeBuffers(psNaCLContext->hRenderContext,
            psNaCLContext->i32PluginWidth,
            psNaCLContext->i32PluginHeight);

    }
}
예제 #9
0
void DrawFrame(void* user_data, int32_t result) 
{
    glSetCurrentContextPPAPI(psNaCLContext->hRenderContext);

    DemoRender(psNaCLContext);

    glSetCurrentContextPPAPI(0);

    PP_CompletionCallback cc = PP_MakeCompletionCallback(DrawFrame, 0);
    psNaCLContext->psG3D->SwapBuffers(psNaCLContext->hRenderContext, cc);
}
예제 #10
0
void ZL_WebSocketConnection_Impl::Connect()
{
	struct ZL_WebSocket_Callbacks
	{
		static void OnConnect(ZL_WebSocketConnection_Impl* impl, int32_t result)
		{
			//ZL_LOG("NACLWSC", "ONCONNECT - WS: %d - RESULT: %d - READYSTATE: %d", impl->websocket, result, (int32_t)ppb_websocket_interface->GetReadyState(impl->websocket));
			if (result < 0) { impl->Disconnect(PP_WEBSOCKETSTATUSCODE_ABNORMAL_CLOSURE, NULL, 0); return; }
			impl->websocket_active = true;
			impl->sigConnected.call();
			if (ppb_websocket_interface->ReceiveMessage(impl->websocket, &impl->data, PP_MakeCompletionCallback((PP_CompletionCallback_Func)&OnReceiveMessage, impl)) == PP_OK)
				OnReceiveMessage(impl, PP_OK);
		}
		static void OnReceiveMessage(ZL_WebSocketConnection_Impl* impl, int32_t result)
		{
			//ZL_LOG("NACLWSC", "ONRECEIVE - WS: %d - RESULT: %d - READYSTATE: %d - BUFFER: %d", impl->websocket, result, (int32_t)ppb_websocket_interface->GetReadyState(impl->websocket), (int32_t)ppb_websocket_interface->GetBufferedAmount(impl->websocket));
			if (result < 0) { impl->Disconnect(PP_WEBSOCKETSTATUSCODE_ABNORMAL_CLOSURE, NULL, 0); return; }
			HandleMessage(impl);
			const PP_CompletionCallback cc = PP_MakeCompletionCallback((PP_CompletionCallback_Func)&OnReceiveMessage, (void*)impl);
			while (ppb_websocket_interface->ReceiveMessage(impl->websocket, &impl->data, cc) == PP_OK) HandleMessage(impl);
		}
		static void HandleMessage(ZL_WebSocketConnection_Impl* impl)
		{
			//ZL_LOG("NACLWSC", "HANDLEMESSAGE - WS: %d - VALUE_ID: %d - READYSTATE: %d", impl->websocket, (int32_t)impl->data.value.as_id, (int32_t)ppb_websocket_interface->GetReadyState(impl->websocket));
			if (!impl->data.value.as_id) return;
			if (impl->data.type == PP_VARTYPE_STRING) 
			{
				uint32_t length;
				const char* data = ppb_var_interface->VarToUtf8(impl->data, &length);
				impl->sigReceivedText.call(ZL_String(data, length));
			}
			else if (impl->data.type == PP_VARTYPE_ARRAY_BUFFER)
			{
				uint32_t length;
				ppb_vararraybuffer_interface->ByteLength(impl->data, &length);
				const char* data = (const char*)ppb_vararraybuffer_interface->Map(impl->data);
				impl->sigReceivedBinary.call(data, length);
			}
			ppb_var_interface->Release(impl->data);
		}
	};
	websocket = ppb_websocket_interface->Create(instance_);
	ppb_websocket_interface->Connect(websocket, ZLStrToVar(url), NULL, 0, PP_MakeCompletionCallback((PP_CompletionCallback_Func)&ZL_WebSocket_Callbacks::OnConnect, this));
}
/* TODO(dspringer): We need to add a test that calls PostMessage directly from
 * HandleMessage to ensure that this is all asynchronous.
 */
void HandleMessage(PP_Instance instance, struct PP_Var message) {
  struct PPB_Core* ppb_core =
      (struct PPB_Core*)(*get_browser_interface_func)(PPB_CORE_INTERFACE);
  struct MessageInfo* message_to_send = malloc(sizeof(struct MessageInfo));
  message_to_send->instance = instance;
  message_to_send->message = message;

  if (message.type == PP_VARTYPE_STRING) {
    struct PPB_Var* ppb_var = GetPPB_Var();
    /* If the message is a string, add reference to go with the copy we did
     * above.
     */
    ppb_var->AddRef(message);
  }
  /* Echo message back to browser */
  ppb_core->CallOnMainThread(
      0,  /* I don't care about delay */
      PP_MakeCompletionCallback(SendOnMessageEventCallback, message_to_send),
      PP_OK);  /* Dummy value for result */
}
예제 #12
0
/* Read up to BUFFER_READ_SIZE bytes more from the URLLoader.
 * Allocate more space in the destination buffer if needed.
 */
void ReadSome(void* data) {
  while (ogg_file_alloced < ogg_file_size + BUFFER_READ_SIZE) {
    /* The buffer isn't big enough to hold BUFFER_READ_SIZE more bytes. */
    char* temp = (char*)malloc(ogg_file_alloced * 2);
    memcpy(temp, ogg_file_contents, ogg_file_size);
    free(ogg_file_contents);
    ogg_file_contents = temp;
    ogg_file_alloced *= 2;
  }

  struct PP_CompletionCallback cb =
      PP_MakeCompletionCallback(ReadCallback, data);
#ifndef NDEBUG
  int32_t read_ret =
#endif
      g_MyState.loader_interface->ReadResponseBody(
          (PP_Resource)data, ogg_file_contents + ogg_file_size,
          BUFFER_READ_SIZE, cb);
  assert(read_ret == PP_OK_COMPLETIONPENDING);
}
예제 #13
0
static PP_Bool Instance_DidCreate(PP_Instance instance,
                                  uint32_t argc,
                                  const char* argn[],
                                  const char* argv[]) {
  g_MyState.instance = instance;
  g_MyState.ready = 0;
  g_MyStateIsValid = 1;

  /* This sets up OpenAL with PPAPI info. */
  alSetPpapiInfo(instance, g_get_browser_interface);

  const ALCchar* devices = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
  setenv("ALSOFT_LOGLEVEL", "3", 0);
  printf("Audio devices available:\n");
  while (devices[0] != '\0') {
    printf("\t%s\n", devices);
    devices = devices + strlen(devices) + 1;
  }

  InitializeOpenAL();

  ogg_file_contents = (char*)malloc(BUFFER_READ_SIZE);
  ogg_file_alloced = BUFFER_READ_SIZE;

  PP_Resource request = g_MyState.request_interface->Create(instance);
  g_MyState.request_interface->SetProperty(
      request, PP_URLREQUESTPROPERTY_URL,
      g_MyState.var_interface->VarFromUtf8(OGG_FILE, strlen(OGG_FILE)));

  PP_Resource loader = g_MyState.loader_interface->Create(instance);
  struct PP_CompletionCallback cb =
      PP_MakeCompletionCallback(OpenCallback, (void*)loader);
  int32_t open_ret = g_MyState.loader_interface->Open(loader, request, cb);
  assert(open_ret == PP_OK_COMPLETIONPENDING);
  if (open_ret != PP_OK_COMPLETIONPENDING)
    return PP_FALSE;

  return PP_TRUE;
}
예제 #14
0
void Repaint(struct InstanceInfo* instance, const struct PP_Size* size) {
  PP_Resource image, graphics;
  struct PP_ImageDataDesc image_desc;
  uint32_t* image_data;
  int num_words, i;

  /* Create image data to paint into. */
  image = ih.g_image_data_interface->Create(
      instance->pp_instance, PP_IMAGEDATAFORMAT_BGRA_PREMUL, size, PP_TRUE);
  if (!image)
    return;
  ih.g_image_data_interface->Describe(image, &image_desc);

  /* Fill the image with blue. */
  image_data = (uint32_t*)ih.g_image_data_interface->Map(image);
  if (!image_data) {
    ih.g_core_interface->ReleaseResource(image);
    return;
  }
  num_words = image_desc.stride * size->height / 4;
  for (i = 0; i < num_words; i++)
    image_data[i] = 0xFF0000FF;

  /* Create the graphics 2d and paint the image to it. */
  graphics = MakeAndBindGraphics2D(instance->pp_instance, size);
  if (!graphics) {
    ih.g_core_interface->ReleaseResource(image);
    return;
  }

  ih.g_graphics_2d_interface->ReplaceContents(graphics, image);
  ih.g_graphics_2d_interface->Flush(graphics,
      PP_MakeCompletionCallback(&FlushCompletionCallback, NULL));

  ih.g_core_interface->ReleaseResource(graphics);
  ih.g_core_interface->ReleaseResource(image);
}
예제 #15
0
struct PP_Var
ppb_url_util_dev_get_document_url(PP_Instance instance, struct PP_URLComponents_Dev *components)
{
    reset_components(components);
    struct pp_instance_s *pp_i = tables_get_pp_instance(instance);
    if (!pp_i) {
        trace_error("%s, bad instance\n", __func__);
        return PP_MakeUndefined();
    }

    struct get_document_url_param_s p;
    p.npp = pp_i->npp;
    p.m_loop = ppb_message_loop_get_current();
    p.depth = ppb_message_loop_get_depth(p.m_loop) + 1;
    p.np_window_obj = pp_i->np_window_obj;

    ppb_message_loop_post_work(p.m_loop, PP_MakeCompletionCallback(_get_document_url_comt, &p), 0);
    ppb_message_loop_run_int(p.m_loop, 1);

    if (components)
        parse_url_string(ppb_var_var_to_utf8(p.result, NULL), components);

    return p.result;
}
예제 #16
0
void ZL_WebSocketConnection_Impl::Disconnect(unsigned short code, const char* buf, size_t len)
{
	if (!websocket) return;
	struct ZL_WebSocket_Callbacks { static void OnDisconnect(void*, int32_t) {} };
	ppb_websocket_interface->Close(websocket, code, (buf ? ppb_var_interface->VarFromUtf8(buf, len) : PP_MakeUndefined()), PP_MakeCompletionCallback(&ZL_WebSocket_Callbacks::OnDisconnect, NULL));
	websocket = 0;
	websocket_active = false;
	sigDisconnected.call();
}