コード例 #1
0
bool NetscapePlugin::platformPostInitializeWindowed(bool needsXEmbed, uint64_t windowID)
{
    m_npWindow.type = NPWindowTypeWindow;
    if (!needsXEmbed) {
        notImplemented();
        return false;
    }

    Display* display = x11HostDisplay();

#if PLATFORM(GTK)
    // It seems flash needs the socket to be in the same process,
    // I guess it uses gdk_window_lookup(), so we create a new socket here
    // containing a plug with the UI process socket embedded.
    m_platformPluginWidget = gtk_plug_new(static_cast<Window>(windowID));
    GtkWidget* socket = gtk_socket_new();
    // Do not show the plug widget until the socket is connected.
    g_signal_connect_swapped(socket, "plug-added", G_CALLBACK(gtk_widget_show), m_platformPluginWidget);
    g_signal_connect(socket, "plug-removed", G_CALLBACK(socketPlugRemovedCallback), nullptr);
    gtk_container_add(GTK_CONTAINER(m_platformPluginWidget), socket);
    gtk_widget_show(socket);

    m_npWindow.window = GINT_TO_POINTER(gtk_socket_get_id(GTK_SOCKET(socket)));
    GdkWindow* window = gtk_widget_get_window(socket);
    NPSetWindowCallbackStruct* callbackStruct = static_cast<NPSetWindowCallbackStruct*>(m_npWindow.ws_info);
    callbackStruct->display = GDK_WINDOW_XDISPLAY(window);
    callbackStruct->visual = GDK_VISUAL_XVISUAL(gdk_window_get_visual(window));
    callbackStruct->depth = gdk_visual_get_depth(gdk_window_get_visual(window));
    callbackStruct->colormap = XCreateColormap(display, GDK_ROOT_WINDOW(), callbackStruct->visual, AllocNone);
#else
    UNUSED_PARAM(windowID);
#endif

    XFlush(display);

    callSetWindow();

    return true;
}
コード例 #2
0
ファイル: na-tray-child.c プロジェクト: SESDE/SESDE
static void
na_tray_child_realize (GtkWidget *widget)
{
  NaTrayChild *child = NA_TRAY_CHILD (widget);
  GdkVisual *visual = gtk_widget_get_visual (widget);
  GdkWindow *window;

  GTK_WIDGET_CLASS (na_tray_child_parent_class)->realize (widget);

  window = gtk_widget_get_window (widget);

  if (child->has_alpha)
    {
      /* We have real transparency with an ARGB visual and the Composite
       * extension. */

      /* Set a transparent background */
      cairo_pattern_t *transparent = cairo_pattern_create_rgba (0, 0, 0, 0);
      gdk_window_set_background_pattern (window, transparent);
      gdk_window_set_composited (window, TRUE);
      cairo_pattern_destroy (transparent);

      child->parent_relative_bg = FALSE;
    }
  else if (visual == gdk_window_get_visual (gdk_window_get_parent (window)))
    {
      /* Otherwise, if the visual matches the visual of the parent window, we
       * can use a parent-relative background and fake transparency. */
      gdk_window_set_background_pattern (window, NULL);

      child->parent_relative_bg = TRUE;
    }
  else
    {
      /* Nothing to do; the icon will sit on top of an ugly gray box */
      child->parent_relative_bg = FALSE;
    }

  gdk_window_set_composited (window, child->composited);

  gtk_widget_set_app_paintable (GTK_WIDGET (child),
                                child->parent_relative_bg || child->has_alpha);

  /* Double-buffering will interfere with the parent-relative-background fake
   * transparency, since the double-buffer code doesn't know how to fill in the
   * background of the double-buffer correctly.
   */
  gtk_widget_set_double_buffered (GTK_WIDGET (child),
                                  child->parent_relative_bg);
}
コード例 #3
0
static GdkVisual* getVisual(Widget* widget)
{
    if (!widget)
        return 0;

    GtkWidget* container = GTK_WIDGET(widget->root()->hostWindow()->platformPageClient());
    if (!container) {
        GdkScreen* screen = gdk_screen_get_default();
        return screen ? gdk_screen_get_system_visual(screen) : 0;
    }

    if (!gtk_widget_get_realized(container))
        container = getToplevel(container);
    return container ? gdk_window_get_visual(gtk_widget_get_window(container)) : 0;
}
コード例 #4
0
static GdkVisual* getVisual(Widget* widget)
{
    if (!widget)
        return 0;

    GtkWidget* container = GTK_WIDGET(widget->root()->hostWindow()->platformPageClient());

    if (!container)
        return 0;

    if (!gtk_widget_get_realized(container)) {
        GtkWidget* toplevel = gtk_widget_get_toplevel(container);
        if (gtk_widget_is_toplevel(toplevel))
            container = toplevel;
        else
            return 0;
    }

    return gdk_window_get_visual(gtk_widget_get_window(container));
}
コード例 #5
0
ファイル: gdk.c プロジェクト: hedmo/compiz
cairo_surface_t *
create_native_surface_and_wrap (int        w,
                                int        h,
                                GtkWidget *parent_style_window)
{
    GdkWindow       *window;
    GdkVisual       *visual;
    cairo_surface_t *surface;
    Display         *display;
    Pixmap           pixmap;

    if (w <= 0 || h <= 0)
	abort ();

    display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
    window = gtk_widget_get_window (parent_style_window);
    visual = gdk_window_get_visual (window);
    pixmap = XCreatePixmap (display, GDK_WINDOW_XID (window), w, h, gdk_visual_get_depth (visual));
    surface = cairo_xlib_surface_create (display, pixmap, GDK_VISUAL_XVISUAL (visual), w, h);

    return surface;
}
コード例 #6
0
ファイル: bitmap.cpp プロジェクト: gitrider/wxsj2
wxBitmap wxBitmap::Rescale( int clipx, int clipy, int clipwidth, int clipheight, int newx, int newy )
{
    wxCHECK_MSG( Ok(), wxNullBitmap, wxT("invalid bitmap") );

    if (newy==M_BMPDATA->m_width && newy==M_BMPDATA->m_height)
        return *this;
    
    int width = wxMax(newx, 1);
    int height = wxMax(newy, 1);
    width = wxMin(width, clipwidth);
    height = wxMin(height, clipheight);
        
    wxBitmap bmp;

#ifdef __WXGTK20__
    if (HasPixbuf())
    {
        bmp.SetWidth(width);
        bmp.SetHeight(height);
        bmp.SetDepth(GetDepth());
        bmp.SetPixbuf(gdk_pixbuf_new(GDK_COLORSPACE_RGB,
                                     gdk_pixbuf_get_has_alpha(GetPixbuf()),
                                     8, width, height));
        gdk_pixbuf_scale(GetPixbuf(), bmp.GetPixbuf(),
                         0, 0, width, height,
                         clipx, clipy, 
                         (double)newx/GetWidth(), (double)newy/GetHeight(),
                         GDK_INTERP_BILINEAR);
    }
    else
#endif // __WXGTK20__
    {
        GdkImage *img = (GdkImage*) NULL;
        if (GetPixmap())
            img = gdk_image_get( GetPixmap(), 0, 0, GetWidth(), GetHeight() );
        else if (GetBitmap())
            img = gdk_image_get( GetBitmap(), 0, 0, GetWidth(), GetHeight() );
        else
            wxFAIL_MSG( wxT("Ill-formed bitmap") );

        wxCHECK_MSG( img, wxNullBitmap, wxT("couldn't create image") );

        int bpp = -1;

        
        GdkGC *gc = NULL;
        GdkPixmap *dstpix = NULL;
        if (GetPixmap())
        {
            GdkVisual *visual = gdk_window_get_visual( GetPixmap() );
            if (visual == NULL)
                visual = wxTheApp->GetGdkVisual();

            bpp = visual->depth;
            bmp = wxBitmap(width,height,bpp);
            dstpix = bmp.GetPixmap();
            gc = gdk_gc_new( dstpix );
        }

        char *dst = NULL;
        long dstbyteperline = 0;
        
        if (GetBitmap())
        {
            bpp = 1;
            dstbyteperline = width/8*M_BMPDATA->m_bpp;
            if (width*M_BMPDATA->m_bpp % 8 != 0)
                dstbyteperline++;
            dst = (char*) malloc(dstbyteperline*height);
        }
                 
        // be careful to use the right scaling factor
        float scx = (float)M_BMPDATA->m_width/(float)newx;
        float scy = (float)M_BMPDATA->m_height/(float)newy;
        // prepare accel-tables
        int *tablex = (int *)calloc(width,sizeof(int));
        int *tabley = (int *)calloc(height,sizeof(int));

        // accel table filled with clipped values
        for (int x = 0; x < width; x++)
            tablex[x] = (int) (scx * (x+clipx));
        for (int y = 0; y < height; y++)
            tabley[y] = (int) (scy * (y+clipy));

        // Main rescaling routine starts here
        for (int h = 0; h < height; h++)
        {
            char outbyte = 0;
            int old_x = -1;
            guint32 old_pixval = 0;

            for (int w = 0; w < width; w++)
            {
                guint32 pixval;
                int x = tablex[w];
                if (x == old_x)
                    pixval = old_pixval;
                else
                {
                    pixval = gdk_image_get_pixel( img, x, tabley[h] );
                    old_pixval = pixval;
                    old_x = x;
                }
                    
                if (bpp == 1)
                {
                    if (!pixval)
                    {
                        char bit=1;
                        char shift = bit << w % 8;
                        outbyte |= shift;
                    }
                    
                    if ((w+1)%8==0)
                    {
                        dst[h*dstbyteperline+w/8] = outbyte;
                        outbyte = 0;
                    }
                }
                else
                {
                    GdkColor col;
                    col.pixel = pixval;
                    gdk_gc_set_foreground( gc, &col );
                    gdk_draw_point( dstpix, gc, w, h);
                }
            }
        
            // do not forget the last byte
            if ((bpp == 1) && (width % 8 != 0))
                dst[h*dstbyteperline+width/8] = outbyte;
        }
        
        gdk_image_destroy( img );
        if (gc) gdk_gc_unref( gc );

        if (bpp == 1)
        {
            bmp = wxBitmap( (const char *)dst, width, height, 1 );
            free( dst );
        }
        
        if (GetMask())
        {
            dstbyteperline = width/8;
            if (width % 8 != 0)
                dstbyteperline++;
            dst = (char*) malloc(dstbyteperline*height);
            img = gdk_image_get( GetMask()->GetBitmap(), 0, 0, GetWidth(), GetHeight() );

            for (int h = 0; h < height; h++)
            {
                char outbyte = 0;
                int old_x = -1;
                guint32 old_pixval = 0;
        
                for (int w = 0; w < width; w++)
                {
                    guint32 pixval;
                    int x = tablex[w];
                    if (x == old_x)
                        pixval = old_pixval;
                    else
                    {
                        pixval = gdk_image_get_pixel( img, x, tabley[h] );
                        old_pixval = pixval;
                        old_x = x;
                    }
                    
                    if (pixval)
                    {
                        char bit=1;
                        char shift = bit << w % 8;
                        outbyte |= shift;
                    }
                    
                    if ((w+1)%8 == 0)
                    {
                        dst[h*dstbyteperline+w/8] = outbyte;
                        outbyte = 0;
                    }
                }
            
                // do not forget the last byte
                if (width % 8 != 0)
                    dst[h*dstbyteperline+width/8] = outbyte;
            }
            wxMask* mask = new wxMask;
            mask->m_bitmap = gdk_bitmap_create_from_data( wxGetRootWindow()->window, (gchar *) dst, width, height );
            bmp.SetMask(mask);

            free( dst );
            gdk_image_destroy( img );
        }

        free( tablex );
        free( tabley );
    }
    
    return bmp; 
}
コード例 #7
0
ファイル: gtk2xtbin.c プロジェクト: rn10950/RetroZilla
GtkWidget*
gtk_xtbin_new (GdkWindow *parent_window, String * f)
{
  GtkXtBin *xtbin;
  gpointer user_data;

  assert(parent_window != NULL);
  xtbin = gtk_type_new (GTK_TYPE_XTBIN);

  if (!xtbin)
    return (GtkWidget*)NULL;

  if (f)
    fallback = f;

  /* Initialize the Xt toolkit */
  xtbin->parent_window = parent_window;

  xt_client_init(&(xtbin->xtclient), 
      GDK_VISUAL_XVISUAL(gdk_window_get_visual(parent_window )),
      GDK_COLORMAP_XCOLORMAP(gdk_window_get_colormap(parent_window)),
      gdk_window_get_visual(parent_window )->depth);

  if (!xtbin->xtclient.xtdisplay) {
    /* If XtOpenDisplay failed, we can't go any further.
     *  Bail out.
     */
#ifdef DEBUG_XTBIN
    printf("gtk_xtbin_init: XtOpenDisplay() returned NULL.\n");
#endif
    g_free (xtbin);
    return (GtkWidget *)NULL;
  }

  /* If this is the first running widget, hook this display into the
     mainloop */
  if (0 == num_widgets) {
    int           cnumber;
    /*
     * hook Xt event loop into the glib event loop.
     */

    /* the assumption is that gtk_init has already been called */
    GSource* gs = g_source_new(&xt_event_funcs, sizeof(GSource));
      if (!gs) {
       return NULL;
      }
    
    g_source_set_priority(gs, GDK_PRIORITY_EVENTS);
    g_source_set_can_recurse(gs, TRUE);
    tag = g_source_attach(gs, (GMainContext*)NULL);
#ifdef VMS
    cnumber = XConnectionNumber(xtdisplay);
#else
    cnumber = ConnectionNumber(xtdisplay);
#endif
    xt_event_poll_fd.fd = cnumber;
    xt_event_poll_fd.events = G_IO_IN; 
    xt_event_poll_fd.revents = 0;    /* hmm... is this correct? */

    g_main_context_add_poll ((GMainContext*)NULL, 
                             &xt_event_poll_fd, 
                             G_PRIORITY_LOW);
    /* add a timer so that we can poll and process Xt timers */
    xt_polling_timer_id =
      gtk_timeout_add(25,
                      (GtkFunction)xt_event_polling_timer_callback,
                      xtdisplay);
  }

  /* Bump up our usage count */
  num_widgets++;

  /* Build the hierachy */
  xtbin->xtdisplay = xtbin->xtclient.xtdisplay;
  gtk_widget_set_parent_window(GTK_WIDGET(xtbin), parent_window);
  gdk_window_get_user_data(xtbin->parent_window, &user_data);
  if (user_data)
    gtk_container_add(GTK_CONTAINER(user_data), GTK_WIDGET(xtbin));

  return GTK_WIDGET (xtbin);
}
コード例 #8
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;
}
コード例 #9
0
RedirectedXCompositeWindow::RedirectedXCompositeWindow(GdkWindow* parentWindow, std::function<void()> damageNotify)
    : m_display(GDK_DISPLAY_XDISPLAY(gdk_window_get_display(parentWindow)))
    , m_window(0)
    , m_parentWindow(0)
    , m_pixmap(0)
    , m_damage(0)
    , m_needsNewPixmapAfterResize(false)
{
    Screen* screen = DefaultScreenOfDisplay(m_display);

    GdkVisual* visual = gdk_window_get_visual(parentWindow);
    Colormap colormap = XCreateColormap(m_display, RootWindowOfScreen(screen), GDK_VISUAL_XVISUAL(visual), AllocNone);

    // This is based on code from Chromium: src/content/common/gpu/image_transport_surface_linux.cc
    XSetWindowAttributes windowAttributes;
    windowAttributes.override_redirect = True;
    windowAttributes.colormap = colormap;

    // CWBorderPixel must be present when the depth doesn't match the parent's one.
    // See http://cgit.freedesktop.org/xorg/xserver/tree/dix/window.c?id=xorg-server-1.16.0#n703.
    windowAttributes.border_pixel = 0;

    m_parentWindow = XCreateWindow(m_display,
        RootWindowOfScreen(screen),
        WidthOfScreen(screen) + 1, 0, 1, 1,
        0,
        gdk_visual_get_depth(visual),
        InputOutput,
        GDK_VISUAL_XVISUAL(visual),
        CWOverrideRedirect | CWColormap | CWBorderPixel,
        &windowAttributes);
    XMapWindow(m_display, m_parentWindow);

    windowAttributes.event_mask = StructureNotifyMask;
    windowAttributes.override_redirect = False;
    // Create the window of at last 1x1 since X doesn't allow to create empty windows.
    m_window = XCreateWindow(m_display,
        m_parentWindow,
        0, 0,
        std::max(1, m_size.width()),
        std::max(1, m_size.height()),
        0,
        CopyFromParent,
        InputOutput,
        CopyFromParent,
        CWEventMask,
        &windowAttributes);
    XMapWindow(m_display, m_window);

    XFreeColormap(m_display, colormap);

    xDamageNotifier().add(m_window, WTF::move(damageNotify));

    while (1) {
        XEvent event;
        XWindowEvent(m_display, m_window, StructureNotifyMask, &event);
        if (event.type == MapNotify && event.xmap.window == m_window)
            break;
    }
    XSelectInput(m_display, m_window, NoEventMask);
    XCompositeRedirectWindow(m_display, m_window, CompositeRedirectManual);
    m_damage = XDamageCreate(m_display, m_window, XDamageReportNonEmpty);
}
コード例 #10
0
ファイル: utilsgtk.cpp プロジェクト: CobaltBlues/wxWidgets
int wxDisplayDepth()
{
    return gdk_window_get_visual( wxGetRootWindow()->window )->depth;
}
コード例 #11
0
static GdkPixmap *
create_text_pixmap(GtkWidget *drawing_area, FT_Face face)
{
    gint i, pixmap_width, pixmap_height, pos_y, textlen;
    GdkPixmap *pixmap = NULL;
    const gchar *text;
    Display *xdisplay;
    Drawable xdrawable;
    Visual *xvisual;
    Colormap xcolormap;
    XftDraw *draw;
    XftColor colour;
    XGlyphInfo extents;
    XftFont *font;
    gint *sizes = NULL, n_sizes, alpha_size;
    FcCharSet *charset = NULL;
    cairo_t *cr;
    GdkWindow *window = gtk_widget_get_window (drawing_area);

    text = pango_language_get_sample_string(NULL);
    if (! check_font_contain_text (face, text))
	{
	    pango_language_get_sample_string (pango_language_from_string ("en_US"));
	}

    textlen = strlen(text);

    /* create the XftDraw */
    xdisplay = GDK_PIXMAP_XDISPLAY(window);

	#if GTK_CHECK_VERSION(3, 0, 0)
		xvisual = GDK_VISUAL_XVISUAL(gdk_window_get_visual(window));
	#else
		xvisual = GDK_VISUAL_XVISUAL(gdk_drawable_get_visual(window));
	#endif

    xcolormap = GDK_COLORMAP_XCOLORMAP(gdk_drawable_get_colormap(window));
    XftColorAllocName(xdisplay, xvisual, xcolormap, "black", &colour);

    /* work out what sizes to render */
    if (FT_IS_SCALABLE(face)) {
	n_sizes = 8;
	sizes = g_new(gint, n_sizes);
	sizes[0] = 8;
	sizes[1] = 10;
	sizes[2] = 12;
	sizes[3] = 18;
	sizes[4] = 24;
	sizes[5] = 36;
	sizes[6] = 48;
	sizes[7] = 72;
	alpha_size = 24;
    } else {
	/* use fixed sizes */
	n_sizes = face->num_fixed_sizes;
	sizes = g_new(gint, n_sizes);
	alpha_size = 0;
	for (i = 0; i < face->num_fixed_sizes; i++) {
	    sizes[i] = face->available_sizes[i].height;

	    /* work out which font size to render */
	    if (face->available_sizes[i].height <= 24)
		alpha_size = face->available_sizes[i].height;
	}
    }

    /* calculate size of pixmap to use (with 4 pixels padding) ... */
    pixmap_width = 8;
    pixmap_height = 8;

    font = get_font(xdisplay, face, alpha_size, charset);
    charset = FcCharSetCopy (font->charset);
    XftTextExtentsUtf8(xdisplay, font,
		       (guchar *)lowercase_text, strlen(lowercase_text), &extents);
    pixmap_height += extents.height + 4;
    pixmap_width = MAX(pixmap_width, 8 + extents.width);
    XftTextExtentsUtf8(xdisplay, font,
		       (guchar *)uppercase_text, strlen(uppercase_text), &extents);
    pixmap_height += extents.height + 4;
    pixmap_width = MAX(pixmap_width, 8 + extents.width);
    XftTextExtentsUtf8(xdisplay, font,
		       (guchar *)punctuation_text, strlen(punctuation_text), &extents);
    pixmap_height += extents.height + 4;
    pixmap_width = MAX(pixmap_width, 8 + extents.width);
    XftFontClose(xdisplay, font);

    pixmap_height += 8;

    for (i = 0; i < n_sizes; i++) {
	font = get_font(xdisplay, face, sizes[i], charset);
	if (!font) continue;
	XftTextExtentsUtf8(xdisplay, font, (guchar *)text, textlen, &extents);
	pixmap_height += extents.height + 4;
	pixmap_width = MAX(pixmap_width, 8 + extents.width);
	XftFontClose(xdisplay, font);
    }

    /* create pixmap */
    gtk_widget_set_size_request(drawing_area, pixmap_width, pixmap_height);
    pixmap = gdk_pixmap_new(window,
			    pixmap_width, pixmap_height, -1);
    if (!pixmap)
	goto end;
    cr = gdk_cairo_create (pixmap);
    cairo_set_source_rgb (cr, 1, 1, 1);
    cairo_paint (cr);
    cairo_destroy (cr);

    xdrawable = GDK_DRAWABLE_XID(pixmap);
    draw = XftDrawCreate(xdisplay, xdrawable, xvisual, xcolormap);

    /* draw text */
    pos_y = 4;
    font = get_font(xdisplay, face, alpha_size, charset);
    draw_string(xdisplay, draw, font, &colour, lowercase_text, &pos_y);
    draw_string(xdisplay, draw, font, &colour, uppercase_text, &pos_y);
    draw_string(xdisplay, draw, font, &colour, punctuation_text, &pos_y);
    XftFontClose(xdisplay, font);

    pos_y += 8;
    for (i = 0; i < n_sizes; i++) {
	font = get_font(xdisplay, face, sizes[i], charset);
	if (!font) continue;
	draw_string(xdisplay, draw, font, &colour, text, &pos_y);
	XftFontClose(xdisplay, font);
    }

    g_signal_connect(drawing_area, "expose-event", G_CALLBACK(expose_event),
                     pixmap);

 end:
    g_free(sizes);
    FcCharSetDestroy (charset);
    return pixmap;
}
コード例 #12
0
RedirectedXCompositeWindow::RedirectedXCompositeWindow(WebPageProxy& webPage, const IntSize& initialSize, std::function<void()>&& damageNotify)
    : m_webPage(webPage)
    , m_display(GDK_DISPLAY_XDISPLAY(gdk_window_get_display(gtk_widget_get_parent_window(webPage.viewWidget()))))
    , m_size(initialSize)
{
    m_size.scale(m_webPage.deviceScaleFactor());

    ASSERT(downcast<PlatformDisplayX11>(PlatformDisplay::sharedDisplay()).native() == m_display);
    Screen* screen = DefaultScreenOfDisplay(m_display);

    GdkVisual* visual = gdk_window_get_visual(gtk_widget_get_parent_window(webPage.viewWidget()));
    XUniqueColormap colormap(XCreateColormap(m_display, RootWindowOfScreen(screen), GDK_VISUAL_XVISUAL(visual), AllocNone));

    // This is based on code from Chromium: src/content/common/gpu/image_transport_surface_linux.cc
    XSetWindowAttributes windowAttributes;
    windowAttributes.override_redirect = True;
    windowAttributes.colormap = colormap.get();

    // CWBorderPixel must be present when the depth doesn't match the parent's one.
    // See http://cgit.freedesktop.org/xorg/xserver/tree/dix/window.c?id=xorg-server-1.16.0#n703.
    windowAttributes.border_pixel = 0;

    m_parentWindow = XCreateWindow(m_display,
        RootWindowOfScreen(screen),
        WidthOfScreen(screen) + 1, 0, 1, 1,
        0,
        gdk_visual_get_depth(visual),
        InputOutput,
        GDK_VISUAL_XVISUAL(visual),
        CWOverrideRedirect | CWColormap | CWBorderPixel,
        &windowAttributes);
    XMapWindow(m_display, m_parentWindow.get());

    windowAttributes.event_mask = StructureNotifyMask;
    windowAttributes.override_redirect = False;
    // Create the window of at last 1x1 since X doesn't allow to create empty windows.
    m_window = XCreateWindow(m_display,
        m_parentWindow.get(),
        0, 0,
        std::max(1, m_size.width()),
        std::max(1, m_size.height()),
        0,
        CopyFromParent,
        InputOutput,
        CopyFromParent,
        CWEventMask,
        &windowAttributes);
    XMapWindow(m_display, m_window.get());

    xDamageNotifier().add(m_window.get(), WTFMove(damageNotify));

    while (1) {
        XEvent event;
        XWindowEvent(m_display, m_window.get(), StructureNotifyMask, &event);
        if (event.type == MapNotify && event.xmap.window == m_window.get())
            break;
    }
    XSelectInput(m_display, m_window.get(), NoEventMask);
    XCompositeRedirectWindow(m_display, m_window.get(), CompositeRedirectManual);
    if (!m_size.isEmpty())
        createNewPixampAndPixampSurface();
    m_damage = XDamageCreate(m_display, m_window.get(), XDamageReportNonEmpty);
}
コード例 #13
0
ファイル: gdkglcontext-wayland.c プロジェクト: Distrotech/gtk
static gboolean
find_eglconfig_for_window (GdkWindow  *window,
                           EGLConfig  *egl_config_out,
                           GError    **error)
{
  GdkDisplay *display = gdk_window_get_display (window);
  GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display);
  GdkVisual *visual = gdk_window_get_visual (window);
  EGLint attrs[MAX_EGL_ATTRS];
  EGLint count;
  EGLConfig *configs;
  gboolean use_rgba;

  int i = 0;

  attrs[i++] = EGL_SURFACE_TYPE;
  attrs[i++] = EGL_WINDOW_BIT;

  attrs[i++] = EGL_COLOR_BUFFER_TYPE;
  attrs[i++] = EGL_RGB_BUFFER;

  attrs[i++] = EGL_RED_SIZE;
  attrs[i++] = 1;
  attrs[i++] = EGL_GREEN_SIZE;
  attrs[i++] = 1;
  attrs[i++] = EGL_BLUE_SIZE;
  attrs[i++] = 1;

  use_rgba = (visual == gdk_screen_get_rgba_visual (gdk_display_get_default_screen (display)));

  if (use_rgba)
    {
      attrs[i++] = EGL_ALPHA_SIZE;
      attrs[i++] = 1;
    }
  else
    {
      attrs[i++] = EGL_ALPHA_SIZE;
      attrs[i++] = 0;
    }

  attrs[i++] = EGL_NONE;
  g_assert (i < MAX_EGL_ATTRS);

  if (!eglChooseConfig (display_wayland->egl_display, attrs, NULL, 0, &count) || count < 1)
    {
      g_set_error_literal (error, GDK_GL_ERROR,
                           GDK_GL_ERROR_UNSUPPORTED_FORMAT,
                           _("No available configurations for the given pixel format"));
      return FALSE;
    }

  configs = g_new (EGLConfig, count);

  if (!eglChooseConfig (display_wayland->egl_display, attrs, configs, count, &count) || count < 1)
    {
      g_set_error_literal (error, GDK_GL_ERROR,
                           GDK_GL_ERROR_UNSUPPORTED_FORMAT,
                           _("No available configurations for the given pixel format"));
      return FALSE;
    }

  /* Pick first valid configuration i guess? */

  if (egl_config_out != NULL)
    *egl_config_out = configs[0];

  g_free (configs);

  return TRUE;
}
コード例 #14
0
static GdkBitmap *
scale_bitmap (GdkWindow *window, GdkBitmap *bitmap, gdouble scale_x, gdouble scale_y)
{
  GdkGC *gc;
  GdkVisual *visual = NULL;
  GdkImage *image = NULL, *new_image = NULL;
  GdkBitmap *new_bitmap = NULL;
  gint x, y, width, height, new_width, new_height;
  GdkColor color;

  if(!bitmap) return NULL;
  if(!window) return NULL;

  gc = gdk_gc_new(bitmap);

  gdk_window_get_size(bitmap, &width, &height);

  if(scale_x == 1.0 && scale_y == 1.0){
    new_bitmap = gdk_pixmap_new(window, width, height, 1);
    color.pixel = 0;
    gdk_gc_set_foreground(gc, &color);
    gdk_draw_rectangle(new_bitmap, gc, TRUE, 0, 0, width, height);
    color.pixel = 1;
    gdk_gc_set_foreground(gc, &color);

    gdk_draw_pixmap(new_bitmap,
                    gc,
                    bitmap,
                    0, 0,
                    0, 0,
                    width, height);
    gdk_gc_unref(gc);
    return new_bitmap;
  }

  new_width = roundint(width * scale_x);
  new_height = roundint(height * scale_y);

  /* make a client side image of the bitmap, and
   * scale the data into a another client side image */
  visual = gdk_window_get_visual (bitmap);
  if(!visual) return NULL;
  new_image = gdk_image_new(GDK_IMAGE_FASTEST,visual,new_width,new_height);
  if(!new_image) return NULL;
  new_bitmap = gdk_pixmap_new(window, new_width, new_height, 1);

  image = gdk_drawable_get_image(bitmap,
                        0, 0,
                        width, height);

  color.pixel = 0;
  gdk_gc_set_foreground(gc, &color);
  gdk_draw_rectangle(new_bitmap, gc, TRUE, 0, 0, width, height);
  color.pixel = 1;
  gdk_gc_set_foreground(gc, &color);

  for(x = 0; x < new_width; x++){
    for(y = 0; y < new_height; y++){
      gint px, py;
      gulong pixel;

      px = MIN(roundint(x / scale_x), width - 1);
      py = MIN(roundint(y / scale_y), height - 1);

      pixel = gdk_image_get_pixel(image, px, py);
      gdk_image_put_pixel(new_image, x, y, pixel);
    }
  }

  /* draw the image into a new pixmap */
  gdk_draw_image(new_bitmap,gc,new_image,0,0,0,0,new_width,new_height);

  gdk_image_destroy(image);
  gdk_image_destroy(new_image);

  gdk_gc_unref(gc);

  return new_bitmap;
}