void CodeGenWorkItem::RecordNativeCodeSize(Func *func, size_t bytes, ushort pdataCount, ushort xdataSize)
{
    BYTE *buffer;
#if defined(_M_ARM32_OR_ARM64)
    bool canAllocInPreReservedHeapPageSegment = false;
#else
    bool canAllocInPreReservedHeapPageSegment = func->CanAllocInPreReservedHeapPageSegment();
#endif
    EmitBufferAllocation *allocation = func->GetEmitBufferManager()->AllocateBuffer(bytes, &buffer, pdataCount, xdataSize, canAllocInPreReservedHeapPageSegment, true);

#if DBG
    MEMORY_BASIC_INFORMATION memBasicInfo;
    size_t resultBytes = VirtualQuery(allocation->allocation->address, &memBasicInfo, sizeof(memBasicInfo));
    Assert(resultBytes != 0 && memBasicInfo.Protect == PAGE_EXECUTE);
#endif

    Assert(allocation != nullptr);
    if (buffer == nullptr)
        Js::Throw::OutOfMemory();

    SetCodeAddress((size_t)buffer);
    SetCodeSize(bytes);
    SetPdataCount(pdataCount);
    SetXdataSize(xdataSize);
    SetAllocation(allocation);
}
Beispiel #2
0
void Widget::RequestResize() {
	m_requisition = CalculateRequisition();

	if( m_custom_requisition ) {
		if( m_custom_requisition->x > 0.f ) {
			m_requisition.x = std::max( m_custom_requisition->x, m_requisition.x );
		}

		if( m_custom_requisition->y > 0.f ) {
			m_requisition.y = std::max( m_custom_requisition->y, m_requisition.y );
		}
	}

	HandleRequisitionChange();

	auto parent = m_parent.lock();

	// Notify observers.
	GetSignals().Emit( OnSizeRequest );

	if( parent ) {
		parent->RequestResize();
	}
	else {
		sf::FloatRect allocation(
			GetAllocation().left,
			GetAllocation().top,
			std::max( GetAllocation().width, m_requisition.x ),
			std::max( GetAllocation().height, m_requisition.y )
		);

		SetAllocation( allocation );
	}
}
nsresult nsPluginNativeWindowGtk2::CreateXEmbedWindow() {
  if(!mGtkSocket) {
    GdkWindow *win = gdk_window_lookup((XID)window);
    mGtkSocket = gtk_socket_new();

    //attach the socket to the container widget
    gtk_widget_set_parent_window(mGtkSocket, win);

    // Make sure to handle the plug_removed signal.  If we don't the
    // socket will automatically be destroyed when the plug is
    // removed, which means we're destroying it more than once.
    // SYNTAX ERROR.
    g_signal_connect(mGtkSocket, "plug_removed",
                     G_CALLBACK(plug_removed_cb), NULL);

    gpointer user_data = NULL;
    gdk_window_get_user_data(win, &user_data);

    GtkContainer *container = GTK_CONTAINER(user_data);
    gtk_container_add(container, mGtkSocket);
    gtk_widget_realize(mGtkSocket);

    // Resize before we show
    SetAllocation();

    gtk_widget_show(mGtkSocket);

    gdk_flush();
    window = (nsPluginPort *)gtk_socket_get_id(GTK_SOCKET(mGtkSocket));
  }

  return NS_OK;
}
nsresult nsPluginNativeWindowGtk2::CallSetWindow(nsCOMPtr<nsIPluginInstance> &aPluginInstance)
{
  if(aPluginInstance) {
    nsresult rv;
    PRBool val = PR_FALSE;
    if(!mGtkSocket) {
      if (CanGetValueFromPlugin(aPluginInstance))
        rv = aPluginInstance->GetValue
               ((nsPluginInstanceVariable)NPPVpluginNeedsXEmbed, &val);
    }
#ifdef DEBUG
    printf("nsPluginNativeWindowGtk2: NPPVpluginNeedsXEmbed=%d\n", val);
#endif
    if(val) {
      CreateXEmbedWindow();
    }

    if(mGtkSocket) {
      // Make sure to resize and re-place the window if required
      SetAllocation();
      window = (nsPluginPort *)gtk_socket_get_id(GTK_SOCKET(mGtkSocket));
    }
#ifdef DEBUG
    printf("nsPluginNativeWindowGtk2: call SetWindow with xid=%p\n", (void *)window);
#endif
    aPluginInstance->SetWindow(this);
  }
  else if (mPluginInstance)
    mPluginInstance->SetWindow(nsnull);

  SetPluginInstance(aPluginInstance);
  return NS_OK;
}
Beispiel #5
0
void Alignment::UpdateChild() {
	auto child = GetChild();

	if( !child ) {
		return;
	}

	sf::FloatRect allocation( GetAllocation() );

	sf::Vector2f spare_space( allocation.width, allocation.height );
	spare_space -= child->GetRequisition();
	spare_space.x *= 1.f - GetScale().x;
	spare_space.y *= 1.f - GetScale().y;

	if( ( spare_space.x < 0 ) || ( spare_space.y < 0 ) ) {
#if defined( SFGUI_DEBUG )
		std::cerr << "SFGUI warning: Alignment got a smaller allocation than it requested.\n";
		return;
#endif
	}

	allocation.left = spare_space.x * GetAlignment().x;
	allocation.top = spare_space.y * GetAlignment().y;
	allocation.width -= spare_space.x;
	allocation.height -= spare_space.y;

	child->SetAllocation( allocation );
}
nsresult nsPluginNativeWindowGtk2::CreateXEmbedWindow() {
  NS_ASSERTION(!mSocketWidget,"Already created a socket widget!");

  GdkWindow *parent_win = gdk_window_lookup((XID)window);
  mSocketWidget = gtk_socket_new();

  //attach the socket to the container widget
  gtk_widget_set_parent_window(mSocketWidget, parent_win);

  // Make sure to handle the plug_removed signal.  If we don't the
  // socket will automatically be destroyed when the plug is
  // removed, which means we're destroying it more than once.
  // SYNTAX ERROR.
  g_signal_connect(mSocketWidget, "plug_removed",
                   G_CALLBACK(plug_removed_cb), NULL);

  g_signal_connect(mSocketWidget, "unrealize",
                   G_CALLBACK(socket_unrealize_cb), NULL);

  g_signal_connect(mSocketWidget, "destroy",
                   G_CALLBACK(gtk_widget_destroyed), &mSocketWidget);

  gpointer user_data = NULL;
  gdk_window_get_user_data(parent_win, &user_data);

  GtkContainer *container = GTK_CONTAINER(user_data);
  gtk_container_add(container, mSocketWidget);
  gtk_widget_realize(mSocketWidget);

  // The GtkSocket has a visible window, but the plugin's XEmbed plug will
  // cover this window.  Normally GtkSockets let the X server paint their
  // background and this would happen immediately (before the plug is
  // created).  Setting the background to None prevents the server from
  // painting this window, avoiding flicker.
  gdk_window_set_back_pixmap(mSocketWidget->window, NULL, FALSE);

  // Resize before we show
  SetAllocation();

  gtk_widget_show(mSocketWidget);

  gdk_flush();
  window = (void*)gtk_socket_get_id(GTK_SOCKET(mSocketWidget));

  // Fill out the ws_info structure.
  // (The windowless case is done in nsObjectFrame.cpp.)
  GdkWindow *gdkWindow = gdk_window_lookup((XID)window);
  if(!gdkWindow)
    return NS_ERROR_FAILURE;

  mWsInfo.display = GDK_WINDOW_XDISPLAY(gdkWindow);
  mWsInfo.colormap = GDK_COLORMAP_XCOLORMAP(gdk_drawable_get_colormap(gdkWindow));
  GdkVisual* gdkVisual = gdk_drawable_get_visual(gdkWindow);
  mWsInfo.visual = GDK_VISUAL_XVISUAL(gdkVisual);
  mWsInfo.depth = gdkVisual->depth;

  return NS_OK;
}
Beispiel #7
0
void Window::HandleAdd( Widget::Ptr child ) {
	Bin::HandleAdd( child );

	if( GetChild() ) {
		// Reset allocation so the window will be as large as required.
		SetAllocation( sf::FloatRect( GetAllocation().left, GetAllocation().top, 1.f, 1.f ) );
		RequestResize();
	}
}
nsresult nsPluginNativeWindowGtk2::CallSetWindow(nsRefPtr<nsNPAPIPluginInstance> &aPluginInstance)
{
  if (aPluginInstance) {
    if (type == NPWindowTypeWindow) {
      if (!mSocketWidget) {
        nsresult rv;

        PRBool needXEmbed = PR_FALSE;
        rv = aPluginInstance->GetValueFromPlugin(NPPVpluginNeedsXEmbed, &needXEmbed);
        // If the call returned an error code make sure we still use our default value.
        if (NS_FAILED(rv)) {
          needXEmbed = PR_FALSE;
        }
#ifdef DEBUG
        printf("nsPluginNativeWindowGtk2: NPPVpluginNeedsXEmbed=%d\n", needXEmbed);
#endif

        if (needXEmbed) {
          rv = CreateXEmbedWindow();
        }
        else {
          rv = CreateXtWindow();
        }

        if (NS_FAILED(rv)) {
          return NS_ERROR_FAILURE;
        }
      }

      if (!mSocketWidget) {
        return NS_ERROR_FAILURE;
      }

      // Make sure to resize and re-place the window if required.
      // Need to reset "window" each time as nsObjectFrame::DidReflow sets it
      // to the ancestor window.
      if (GTK_IS_XTBIN(mSocketWidget)) {
        gtk_xtbin_resize(mSocketWidget, width, height);
        // Point the NPWindow structures window to the actual X window
        window = (void*)GTK_XTBIN(mSocketWidget)->xtwindow;
      }
      else { // XEmbed
        SetAllocation();
        window = (void*)gtk_socket_get_id(GTK_SOCKET(mSocketWidget));
      }
#ifdef DEBUG
      printf("nsPluginNativeWindowGtk2: call SetWindow with xid=%p\n", (void *)window);
#endif
    } // NPWindowTypeWindow
    aPluginInstance->SetWindow(this);
  }
  else if (mPluginInstance)
    mPluginInstance->SetWindow(nsnull);

  SetPluginInstance(aPluginInstance);
  return NS_OK;
}
nsresult nsPluginNativeWindowGtk2::CallSetWindow(nsCOMPtr<nsIPluginInstance> &aPluginInstance)
{
  if(aPluginInstance) {
    if (type == nsPluginWindowType_Window) {
      nsresult rv;
      if(!mSocketWidget) {
        PRBool needXEmbed = PR_FALSE;
        if (CanGetValueFromPlugin(aPluginInstance)) {
          rv = aPluginInstance->GetValue
            ((nsPluginInstanceVariable)NPPVpluginNeedsXEmbed, &needXEmbed);
#ifdef DEBUG
          printf("nsPluginNativeWindowGtk2: NPPVpluginNeedsXEmbed=%d\n", needXEmbed);
#endif
        }
        nsresult rv;
        if(needXEmbed) {
#ifdef MOZ_COMPOSITED_PLUGINS
          rv = CreateXCompositedWindow();
#else
          rv = CreateXEmbedWindow();
#endif
        }
        else {
          rv = CreateXtWindow();
        }
        if(NS_FAILED(rv))
          return NS_ERROR_FAILURE;
      }

      if(!mSocketWidget)
        return NS_ERROR_FAILURE;

      // Make sure to resize and re-place the window if required.
      // Need to reset "window" each time as nsObjectFrame::DidReflow sets it
      // to the ancestor window.
      if(GTK_IS_XTBIN(mSocketWidget)) {
        gtk_xtbin_resize(mSocketWidget, width, height);
        // Point the NPWindow structures window to the actual X window
        window = (nsPluginPort *)GTK_XTBIN(mSocketWidget)->xtwindow;
      }
      else { // XEmbed
        SetAllocation();
        window = (nsPluginPort *)gtk_socket_get_id(GTK_SOCKET(mSocketWidget));
      }
#ifdef DEBUG
      printf("nsPluginNativeWindowGtk2: call SetWindow with xid=%p\n", (void *)window);
#endif
    } // nsPluginWindowType_Window
    aPluginInstance->SetWindow(this);
  }
  else if (mPluginInstance)
    mPluginInstance->SetWindow(nsnull);

  SetPluginInstance(aPluginInstance);
  return NS_OK;
}
Beispiel #10
0
bool Window::HandleAdd( Widget::Ptr child ) {
	if( !Bin::HandleAdd( child ) ) {
		return false;
	}

	// Reset allocation so the window will be as large as required.
	SetAllocation( sf::FloatRect( GetAllocation().left, GetAllocation().top, 1.f, 1.f ) );
	RequestResize();

	return true;
}
Beispiel #11
0
void Window::HandleMouseMoveEvent( int x, int y ) {
	if( ( x == std::numeric_limits<int>::min() ) || ( y == std::numeric_limits<int>::min() ) ) {
		return;
	}

	if( m_dragging ) {
		SetPosition(
			sf::Vector2f(
				static_cast<float>( x ) - m_drag_offset.x,
				static_cast<float>( y ) - m_drag_offset.y
			)
		);
	}
	else if( m_resizing && (GetStyle() & RESIZE) == RESIZE ) {
		SetAllocation(
			sf::FloatRect(
				GetAllocation().left,
				GetAllocation().top,
				std::max( GetRequisition().x, static_cast<float>( x ) + m_drag_offset.x - GetAllocation().left ),
				std::max( GetRequisition().y, static_cast<float>( y ) + m_drag_offset.y - GetAllocation().top )
			)
		);
	}
}
Beispiel #12
0
void Button::AllocateChild() {
	auto child = GetChild();

	if( !child ) {
		return;
	}

	float padding( Context::Get().GetEngine().GetProperty<float>( "Padding", shared_from_this() ) );
	float border_width( Context::Get().GetEngine().GetProperty<float>( "BorderWidth", shared_from_this() ) );

	sf::FloatRect allocation( GetAllocation() );

	allocation.left = padding + border_width;
	allocation.top = padding + border_width;
	allocation.width = child->GetRequisition().x;
	allocation.height -= border_width * 2.f + padding * 2.f;

	if( GetState() == State::ACTIVE ) {
		allocation.left += border_width;
		allocation.top += border_width;
	}

	child->SetAllocation( allocation );
}
Beispiel #13
0
nsresult nsPluginNativeWindowGtk::CallSetWindow(nsRefPtr<nsNPAPIPluginInstance> &aPluginInstance)
{
    if (aPluginInstance) {
        if (type == NPWindowTypeWindow) {
            if (!mSocketWidget) {
                nsresult rv;

                // The documentation on the types for many variables in NP(N|P)_GetValue
                // is vague.  Often boolean values are NPBool (1 byte), but
                // https://developer.mozilla.org/en/XEmbed_Extension_for_Mozilla_Plugins
                // treats NPPVpluginNeedsXEmbed as PRBool (int), and
                // on x86/32-bit, flash stores to this using |movl 0x1,&needsXEmbed|.
                // thus we can't use NPBool for needsXEmbed, or the three bytes above
                // it on the stack would get clobbered. so protect with the larger bool.
                int needsXEmbed = 0;
                rv = aPluginInstance->GetValueFromPlugin(NPPVpluginNeedsXEmbed, &needsXEmbed);
                // If the call returned an error code make sure we still use our default value.
                if (NS_FAILED(rv)) {
                    needsXEmbed = 0;
                }
#ifdef DEBUG
                printf("nsPluginNativeWindowGtk: NPPVpluginNeedsXEmbed=%d\n", needsXEmbed);
#endif

                bool isOOPPlugin = aPluginInstance->GetPlugin()->GetLibrary()->IsOOP();
                if (needsXEmbed || isOOPPlugin) {
                    bool enableXtFocus = !needsXEmbed;
                    rv = CreateXEmbedWindow(enableXtFocus);
                }
                else {
#if (MOZ_WIDGET_GTK == 2)
                    rv = CreateXtWindow();
#else
                    return NS_ERROR_FAILURE;
#endif
                }

                if (NS_FAILED(rv)) {
                    return NS_ERROR_FAILURE;
                }
            }

            if (!mSocketWidget) {
                return NS_ERROR_FAILURE;
            }

            // Make sure to resize and re-place the window if required.
            SetAllocation();
            // Need to reset "window" each time as nsPluginFrame::DidReflow sets it
            // to the ancestor window.
#if (MOZ_WIDGET_GTK == 2)
            if (GTK_IS_XTBIN(mSocketWidget)) {
                // Point the NPWindow structures window to the actual X window
                SetWindow(GTK_XTBIN(mSocketWidget)->xtwindow);
            }
            else { // XEmbed or OOP&Xt
                SetWindow(gtk_socket_get_id(GTK_SOCKET(mSocketWidget)));
            }
#else
            // Gtk3 supports only OOP by GtkSocket
            SetWindow(gtk_socket_get_id(GTK_SOCKET(mSocketWidget)));
#endif

#ifdef DEBUG
            printf("nsPluginNativeWindowGtk: call SetWindow with xid=%p\n", (void *)window);
#endif
        } // NPWindowTypeWindow
        aPluginInstance->SetWindow(this);
    }
    else if (mPluginInstance)
        mPluginInstance->SetWindow(nullptr);

    SetPluginInstance(aPluginInstance);
    return NS_OK;
}
Beispiel #14
0
nsresult nsPluginNativeWindowGtk::CreateXEmbedWindow(bool aEnableXtFocus) {
    NS_ASSERTION(!mSocketWidget,"Already created a socket widget!");
    GdkDisplay *display = gdk_display_get_default();
    GdkWindow *parent_win = gdk_x11_window_lookup_for_display(display, GetWindow());
    mSocketWidget = gtk_socket_new();

    //attach the socket to the container widget
    gtk_widget_set_parent_window(mSocketWidget, parent_win);

    // enable/disable focus event handlers,
    // see plugin_window_filter_func() for details
    g_object_set_data(G_OBJECT(mSocketWidget), "enable-xt-focus", (void *)aEnableXtFocus);

    // Make sure to handle the plug_removed signal.  If we don't the
    // socket will automatically be destroyed when the plug is
    // removed, which means we're destroying it more than once.
    // SYNTAX ERROR.
    g_signal_connect(mSocketWidget, "plug_removed",
                     G_CALLBACK(plug_removed_cb), nullptr);

    g_signal_connect(mSocketWidget, "unrealize",
                     G_CALLBACK(socket_unrealize_cb), nullptr);

    g_signal_connect(mSocketWidget, "destroy",
                     G_CALLBACK(gtk_widget_destroyed), &mSocketWidget);

    gpointer user_data = nullptr;
    gdk_window_get_user_data(parent_win, &user_data);

    GtkContainer *container = GTK_CONTAINER(user_data);
    gtk_container_add(container, mSocketWidget);
    gtk_widget_realize(mSocketWidget);

    // The GtkSocket has a visible window, but the plugin's XEmbed plug will
    // cover this window.  Normally GtkSockets let the X server paint their
    // background and this would happen immediately (before the plug is
    // created).  Setting the background to None prevents the server from
    // painting this window, avoiding flicker.
    // TODO GTK3
#if (MOZ_WIDGET_GTK == 2)
    gdk_window_set_back_pixmap(gtk_widget_get_window(mSocketWidget), nullptr, FALSE);
#endif

    // Resize before we show
    SetAllocation();

    gtk_widget_show(mSocketWidget);

    gdk_flush();
    SetWindow(gtk_socket_get_id(GTK_SOCKET(mSocketWidget)));

    // Fill out the ws_info structure.
    // (The windowless case is done in nsPluginFrame.cpp.)
    GdkWindow *gdkWindow = gdk_x11_window_lookup_for_display(display, GetWindow());
    if(!gdkWindow)
        return NS_ERROR_FAILURE;

    mWsInfo.display = GDK_WINDOW_XDISPLAY(gdkWindow);
#if (MOZ_WIDGET_GTK == 2)
    mWsInfo.colormap = GDK_COLORMAP_XCOLORMAP(gdk_drawable_get_colormap(gdkWindow));
    GdkVisual* gdkVisual = gdk_drawable_get_visual(gdkWindow);
    mWsInfo.depth = gdkVisual->depth;
#else
    mWsInfo.colormap = None;
    GdkVisual* gdkVisual = gdk_window_get_visual(gdkWindow);
    mWsInfo.depth = gdk_visual_get_depth(gdkVisual);
#endif
    mWsInfo.visual = GDK_VISUAL_XVISUAL(gdkVisual);

    return NS_OK;
}
nsresult nsPluginNativeWindowGtk2::CreateXCompositedWindow() {
  NS_ASSERTION(!mSocketWidget,"Already created a socket widget!");

  mParentWindow = gtk_window_new(GTK_WINDOW_POPUP);
  mSocketWidget = gtk_socket_new();
  GdkWindow *parent_win = mParentWindow->window;

  //attach the socket to the container widget
  gtk_widget_set_parent_window(mSocketWidget, parent_win);

  // Make sure to handle the plug_removed signal.  If we don't the
  // socket will automatically be destroyed when the plug is
  // removed, which means we're destroying it more than once.
  // SYNTAX ERROR.
  g_signal_connect(mSocketWidget, "plug_removed",
                   G_CALLBACK(plug_removed_cb), NULL);

  g_signal_connect(mSocketWidget, "destroy",
                   G_CALLBACK(gtk_widget_destroyed), &mSocketWidget);

  /*gpointer user_data = NULL;
  gdk_window_get_user_data(parent_win, &user_data);
  */
  GtkContainer *container = GTK_CONTAINER(mParentWindow);
  gtk_container_add(container, mSocketWidget);
  gtk_widget_realize(mSocketWidget);

  // Resize before we show
  SetAllocation();
  gtk_widget_set_size_request (mSocketWidget, width, height);
  /* move offscreen */
  gtk_window_move (GTK_WINDOW(mParentWindow), width+1000, height+1000);


  gtk_widget_show(mSocketWidget);
  gtk_widget_show_all(mParentWindow);

  /* store away a reference to the socketwidget */
  mPlugWindow = (mSocketWidget);

  gdk_flush();
  window = (nsPluginPort *)gtk_socket_get_id(GTK_SOCKET(mSocketWidget));

  /* This is useful if we still have the plugin window inline
   * i.e. firefox vs. fennec */
  // gdk_window_set_composited(mSocketWidget->window, TRUE);

  if (!mDamage) {
    /* we install a general handler instead of one specific to a particular window
     * because we don't have a GdkWindow for the plugin window */
    gdk_window_add_filter (parent_win, plugin_composite_filter_func, this);

    int junk;
    if (!XDamageQueryExtension (GDK_DISPLAY (), &xdamage_event_base, &junk))
      printf ("This requires the XDamage extension");

    mDamage = XDamageCreate(GDK_DISPLAY(), (Drawable)window, XDamageReportNonEmpty);
    XCompositeRedirectWindow (GDK_DISPLAY(),
        (Drawable)window,
        CompositeRedirectManual);

    /* this is a hack to avoid having flash causing a crash when it is unloaded.
     * libplayback sets up dbus_connection_filters. When flash is unloaded it takes
     * libplayback with it, however the connection filters are not removed
     * which causes a crash when dbus tries to execute them. dlopening libplayback
     * ensures that those functions stay around even after flash is gone. */
    static void *libplayback_handle;
    if (!libplayback_handle) {
      libplayback_handle = dlopen("libplayback-1.so.0", RTLD_NOW);
    }

  }

  // Fill out the ws_info structure.
  // (The windowless case is done in nsObjectFrame.cpp.)
  GdkWindow *gdkWindow = gdk_window_lookup((XID)window);
  mWsInfo.display = GDK_WINDOW_XDISPLAY(gdkWindow);
  mWsInfo.colormap = GDK_COLORMAP_XCOLORMAP(gdk_drawable_get_colormap(gdkWindow));
  GdkVisual* gdkVisual = gdk_drawable_get_visual(gdkWindow);
  mWsInfo.visual = GDK_VISUAL_XVISUAL(gdkVisual);
  mWsInfo.depth = gdkVisual->depth;

  return NS_OK;
}