Exemplo n.º 1
0
static Picture
gdk_x11_drawable_get_picture (GdkDrawable *drawable)
{
  GdkDrawableImplX11 *impl = GDK_DRAWABLE_IMPL_X11 (drawable);
  
  if (!impl->picture)
    {
      Display *xdisplay = GDK_SCREEN_XDISPLAY (impl->screen);
      XRenderPictFormat *format;
      
      GdkVisual *visual = gdk_drawable_get_visual (GDK_DRAWABLE_IMPL_X11 (drawable)->wrapper);
      if (!visual)
	return None;

      format = XRenderFindVisualFormat (xdisplay, GDK_VISUAL_XVISUAL (visual));
      if (format)
	{
	  XRenderPictureAttributes attributes;
	  attributes.graphics_exposures = False;
	  
	  impl->picture = XRenderCreatePicture (xdisplay, impl->xid, format,
						CPGraphicsExposure, &attributes);
	}
    }
  
  return impl->picture;
}
Exemplo n.º 2
0
Renderer*
GtkOvgGlue::createRenderHandler()
{
    GNASH_REPORT_FUNCTION;

    if (!_drawing_area) {
        log_error("No area to draw in!");
        return 0;
    }
    
    GdkVisual* wvisual = gdk_drawable_get_visual(_drawing_area->window);
    GdkImage* tmpimage = gdk_image_new (GDK_IMAGE_FASTEST, wvisual, 1, 1);
    // const GdkVisual* visual = tmpimage->visual;
    gdk_image_destroy(tmpimage);

    _renderer.reset(reinterpret_cast<renderer::openvg::Renderer_ovg *>
                    (renderer::openvg::create_handler(0)));
    if (!_renderer) {
        boost::format fmt = boost::format(
            _("Could not create OPENVG renderer"));
        throw GnashException(fmt.str());
    }

    return reinterpret_cast<Renderer *>(_renderer.get());
}
Exemplo n.º 3
0
Renderer*
GtkAggGlue::createRenderHandler()
{
    GdkVisual* wvisual = gdk_drawable_get_visual(_drawing_area->window);

    GdkImage* tmpimage = gdk_image_new (GDK_IMAGE_FASTEST, wvisual, 1, 1);

    const GdkVisual* visual = tmpimage->visual;

    // FIXME: we use bpp instead of depth, because depth doesn't appear to
    // include the padding byte(s) the GdkImage actually has.
    const char *pixelformat = agg_detect_pixel_format(
        visual->red_shift, visual->red_prec,
        visual->green_shift, visual->green_prec,
        visual->blue_shift, visual->blue_prec,
        tmpimage->bpp * 8);

    gdk_image_destroy(tmpimage);

    _agg_renderer = create_Renderer_agg(pixelformat);
    if (! _agg_renderer) {
        boost::format fmt = boost::format(
            _("Could not create AGG renderer with pixelformat %s")
            ) % pixelformat;
        throw GnashException(fmt.str());
    }

    return _agg_renderer;
}
static void
init_graphics2d_as_renderable (struct graphics2d *gr)
{
  Drawable draw;
  Display * dpy;
  Visual * vis;
  
  g_assert (gr != NULL);
  g_assert (gr->drawable != NULL);

  gr->drawbuf = NULL;
  
  if (gr->debug) printf ("initializing graphics2d as renderable\n");
  draw = gdk_x11_drawable_get_xid (gr->drawable);
  
  dpy = gdk_x11_drawable_get_xdisplay (gr->drawable);
  g_assert (dpy != NULL);
  
  vis = gdk_x11_visual_get_xvisual (gdk_drawable_get_visual (gr->drawable));
  g_assert (vis != NULL);
  
  gr->surface = cairo_xlib_surface_create (dpy, draw, vis, 
					   CAIRO_FORMAT_ARGB32,
					   DefaultColormap (dpy, DefaultScreen (dpy)));
  g_assert (gr->surface != NULL);
  g_assert (gr->cr != NULL);
  cairo_set_target_surface (gr->cr, gr->surface);
}
Exemplo n.º 5
0
void
GtkAggGlue::setRenderHandlerSize(int width, int height)
{
    assert(width > 0);
    assert(height > 0);
    assert(_agg_renderer != NULL);
    
    if (_offscreenbuf && _offscreenbuf->width == width &&
        _offscreenbuf->height == height) {
        return; 
    }

    if (_offscreenbuf) {
        gdk_image_destroy(_offscreenbuf);
    }

    GdkVisual* visual = gdk_drawable_get_visual(_drawing_area->window);

    _offscreenbuf = gdk_image_new (GDK_IMAGE_FASTEST, visual, width,
                                   height);

   	static_cast<Renderer_agg_base *>(_agg_renderer)->init_buffer(
        (unsigned char*) _offscreenbuf->mem,
        _offscreenbuf->bpl * _offscreenbuf->height,
        _offscreenbuf->width,
        _offscreenbuf->height,
        _offscreenbuf->bpl); 
}
Exemplo n.º 6
0
static cairo_t *
gdk_cairo_create (GdkDrawable *drawable)
{
    int width, height;
    cairo_t *cr = NULL;
    cairo_surface_t *surface = NULL;
    GdkVisual *visual = gdk_drawable_get_visual (drawable);

    gdk_drawable_get_size (drawable, &width, &height);
    if (visual)
	surface = cairo_xlib_surface_create (GDK_DRAWABLE_XDISPLAY (drawable),
					     GDK_DRAWABLE_XID (drawable),
					     GDK_VISUAL_XVISUAL (visual),
					     width, height);
    else if (gdk_drawable_get_depth (drawable) == 1)
	surface = cairo_xlib_surface_create_for_bitmap
	    (GDK_PIXMAP_XDISPLAY (drawable),
	     GDK_PIXMAP_XID (drawable),
	     GDK_SCREEN_XSCREEN (gdk_drawable_get_screen (drawable)),
	     width, height);
    else {
	g_warning ("Using Cairo rendering requires the drawable argument to\n"
		   "have a specified colormap. All windows have a colormap,\n"
		   "however, pixmaps only have colormap by default if they\n"
		   "were created with a non-NULL window argument. Otherwise\n"
		   "a colormap must be set on them with "
		   "gdk_drawable_set_colormap");
	return NULL;
    }
    if (surface) {
	cr = cairo_create (surface);
	cairo_surface_destroy (surface);
    }
    return cr;
}
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;
}
Exemplo n.º 8
0
int screenDepthPerComponent(Widget* widget)
{
    GtkWidget* container = GTK_WIDGET(widget->root()->hostWindow()->platformWindow());
    if (!container)
        return 8;

    GdkVisual* visual = gdk_drawable_get_visual(GDK_DRAWABLE(GTK_WIDGET(widget->root()->hostWindow()->platformWindow())->window));
    return visual->bits_per_rgb;
}
Exemplo n.º 9
0
static gboolean
gdk_gl_pixmap_impl_x11_make_context_current (GdkGLDrawable *draw,
                                             GdkGLDrawable *read,
                                             GdkGLContext  *glcontext)
{
  GdkGLConfig *glconfig;
  GLXPixmap glxpixmap;
  GLXContext glxcontext;

  g_return_val_if_fail (GDK_IS_GL_PIXMAP_IMPL_X11 (draw), FALSE);
  g_return_val_if_fail (GDK_IS_GL_CONTEXT_IMPL_X11 (glcontext), FALSE);

  glconfig = GDK_GL_PIXMAP_IMPL_X11 (draw)->glconfig;
  glxpixmap = GDK_GL_PIXMAP_IMPL_X11 (draw)->glxpixmap;
  glxcontext = GDK_GL_CONTEXT_GLXCONTEXT (glcontext);

  if (glxpixmap == None || glxcontext == NULL)
    return FALSE;

#ifdef GDKGLEXT_MULTIHEAD_SUPPORT
  GDK_GL_NOTE (MISC,
    g_message (" -- Pixmap: screen number = %d",
      GDK_SCREEN_XNUMBER (gdk_drawable_get_screen (GDK_DRAWABLE (draw)))));
#endif /* GDKGLEXT_MULTIHEAD_SUPPORT */
  GDK_GL_NOTE (MISC,
    g_message (" -- Pixmap: visual id = 0x%lx",
      GDK_VISUAL_XVISUAL (gdk_drawable_get_visual (GDK_DRAWABLE (draw)))->visualid));

  GDK_GL_NOTE_FUNC_IMPL ("glXMakeCurrent");

  if (!glXMakeCurrent (GDK_GL_CONFIG_XDISPLAY (glconfig), glxpixmap, glxcontext))
    {
      g_warning ("glXMakeCurrent() failed");
      _gdk_gl_context_set_gl_drawable (glcontext, NULL);
      /* currently unused. */
      /* _gdk_gl_context_set_gl_drawable_read (glcontext, NULL); */
      return FALSE;
    }

  _gdk_gl_context_set_gl_drawable (glcontext, draw);
  /* currently unused. */
  /* _gdk_gl_context_set_gl_drawable_read (glcontext, read); */

  if (_GDK_GL_CONFIG_AS_SINGLE_MODE (glconfig))
    {
      /* We do this because we are treating a double-buffered frame
         buffer as a single-buffered frame buffer because the system
         does not appear to export any suitable single-buffered
         visuals (in which the following are necessary). */
      glDrawBuffer (GL_FRONT);
      glReadBuffer (GL_FRONT);
    }

  GDK_GL_NOTE (MISC, _gdk_gl_print_gl_info ());

  return TRUE;
}
Exemplo n.º 10
0
int screenDepth(Widget* widget)
{
    GtkWidget* container = GTK_WIDGET(widget->containingWindow());
    if (!container)
        return 24;

    GdkVisual* visual = gdk_drawable_get_visual(GDK_DRAWABLE(GTK_WIDGET(widget->containingWindow())->window));
    return visual->depth;
}
Exemplo n.º 11
0
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 */
      GdkColor transparent = { 0, 0, 0, 0 }; /* only pixel=0 matters */
      gdk_window_set_background (window, &transparent);
      gdk_window_set_composited (window, TRUE);

      child->parent_relative_bg = FALSE;
	}
	#if GTK_CHECK_VERSION(3, 0, 0)
		else if (visual == gdk_window_get_visual(gdk_window_get_parent(window)))
	#else
		else if (visual == gdk_drawable_get_visual(GDK_DRAWABLE(gdk_window_get_parent(window))))
	#endif
	{
      /* Otherwise, if the visual matches the visual of the parent window, we
       * can use a parent-relative background and fake transparency. */
      gdk_window_set_back_pixmap (window, NULL, TRUE);

      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);
}
Exemplo n.º 12
0
Arquivo: image.c Projeto: pts/pts-qiv
static void setup_imlib_for_drawable(GdkDrawable * d)
{
  imlib_context_set_dither(1); /* dither for depths < 24bpp */
  imlib_context_set_display(
    gdk_x11_drawable_get_xdisplay(d));
  imlib_context_set_visual(
    gdk_x11_visual_get_xvisual(gdk_drawable_get_visual(d)));
  imlib_context_set_colormap(
    gdk_x11_colormap_get_xcolormap(gdk_drawable_get_colormap(d)));
  imlib_context_set_drawable(
    gdk_x11_drawable_get_xid(d));
}
Exemplo n.º 13
0
GdkVisual *wxApp::GetGdkVisual()
{
    GdkVisual *visual = NULL;

    if (m_glVisualInfo)
        visual = gdkx_visual_get( ((XVisualInfo *) m_glVisualInfo)->visualid );
    else
        visual = gdk_drawable_get_visual( wxGetRootWindow()->window );

    wxASSERT( visual );

    return visual;
}
Exemplo n.º 14
0
gboolean
gdk_gl_window_make_context_current (GdkGLDrawable *draw, GdkGLContext *glcontext)
{
  GdkGLDrawable *read = draw;
  GdkGLConfig *glconfig;
  Window glxwindow;
  GLXContext glxcontext;

  g_return_val_if_fail (GDK_IS_GL_WINDOW (draw), FALSE);
  g_return_val_if_fail (GDK_IS_GL_CONTEXT_IMPL_X11 (glcontext), FALSE);

  glconfig = GDK_GL_WINDOW (draw)->glconfig;
  glxwindow = GDK_GL_WINDOW (draw)->glxwindow;
  glxcontext = GDK_GL_CONTEXT_GLXCONTEXT (glcontext);

  if (glxwindow == None || glxcontext == NULL)
    return FALSE;

  GDK_GL_NOTE (MISC, g_message (" -- Window: screen number = %d", GDK_SCREEN_XNUMBER (gdk_drawable_get_screen (GDK_DRAWABLE (draw)))));
  GDK_GL_NOTE (MISC, g_message (" -- Window: visual id = 0x%lx", GDK_VISUAL_XVISUAL (gdk_drawable_get_visual (GDK_DRAWABLE (draw)))->visualid));

  GDK_GL_NOTE_FUNC_IMPL ("glXMakeCurrent");

  if (!glXMakeCurrent (GDK_GL_CONFIG_XDISPLAY (glconfig), glxwindow, glxcontext))
    {
      g_warning ("glXMakeCurrent() failed");
      _gdk_gl_context_set_gl_drawable (glcontext, NULL);
      return FALSE;
    }

  _gdk_gl_context_set_gl_drawable (glcontext, draw);

  if (_GDK_GL_CONFIG_AS_SINGLE_MODE (glconfig))
    {
      /* We do this because we are treating a double-buffered frame
         buffer as a single-buffered frame buffer because the system
         does not appear to export any suitable single-buffered
         visuals (in which the following are necessary). */
      glDrawBuffer (GL_FRONT);
      glReadBuffer (GL_FRONT);
    }

  GDK_GL_NOTE (MISC, _gdk_gl_print_gl_info ());

  return TRUE;
}
Exemplo n.º 15
0
void
GtkOvgGlue::setRenderHandlerSize(int width, int height)
{
    GNASH_REPORT_FUNCTION;

    assert(width > 0);
    assert(height > 0);
    assert(_renderer != NULL);
    
#ifdef ENABLE_EGL_OFFSCREEN
    if (_offscreenbuf && _offscreenbuf->width == width &&
        _offscreenbuf->height == height) {
        return; 
    }

    if (_offscreenbuf) {
        gdk_image_destroy(_offscreenbuf);
    }

    GdkVisual* visual = gdk_drawable_get_visual(_drawing_area->window);
    _offscreenbuf = gdk_image_new (GDK_IMAGE_FASTEST, visual, width,
                                   height);
#endif

#if 1
    // if (_renderer) {
    //     vgScale(width, height);
    // }
#else
    // Attach the window to the low level device
    long xid = GDK_WINDOW_XID(gtk_widget_get_window(_drawing_area));
    _device->attachWindow(static_cast<renderer::GnashDevice::native_window_t>
                          (xid));

    vgLoadIdentity();

    // Allow drawing everywhere by default
    InvalidatedRanges ranges;
    ranges.setWorld();
    _renderer->set_invalidated_regions(ranges);    

    renderer::EGLDevice *egl = (renderer::EGLDevice*)_device.get();
    egl->swapBuffers();
#endif    
}
Exemplo n.º 16
0
int screenDepth(Widget* widget)
{
    GtkWidget* container = GTK_WIDGET(widget->root()->hostWindow()->platformWindow());

    if (!container)
        return 24;

    if (!GTK_WIDGET_REALIZED(container)) {
        GtkWidget* toplevel = gtk_widget_get_toplevel(container);
        if (GTK_WIDGET_TOPLEVEL(toplevel))
            container = toplevel;
        else
            return 24;
    }


    GdkVisual* visual = gdk_drawable_get_visual(GDK_DRAWABLE(container->window));
    return visual->depth;
}
static GdkVisual* getVisual(Widget* widget)
{
    if (!widget)
        return 0;

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

    if (!container)
        return 0;

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


    return gdk_drawable_get_visual(GDK_DRAWABLE(container->window));
}
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_drawable_get_visual(GDK_DRAWABLE(gtk_widget_get_window(container)));
}
Exemplo n.º 19
0
static cairo_t *
get_cairo_context (gamine_t *cb)
{
    Display *dpy;
    Drawable xid;
    Visual *visual;
    GdkDrawable *drawable;
    gint x_offset, y_offset;
    gint width, height;
    cairo_surface_t *surface;
    cairo_t *context;
    if (cb->is_cairo)
        return cb->cr;
    //if (GDK_IS_WINDOW (window)) {
    gdk_window_get_internal_paint_info ((cb->da)->window, &drawable,&x_offset,
            &y_offset);
    //} else {
    //    drawable = window;
    //};
    dpy = gdk_x11_drawable_get_xdisplay (drawable);
    xid = gdk_x11_drawable_get_xid (drawable);
    gdk_drawable_get_size (drawable, &width, &height);
    visual = GDK_VISUAL_XVISUAL(gdk_drawable_get_visual (drawable));
    //create an xlib surface 
    surface = cairo_xlib_surface_create (dpy, xid, visual,
        width, height);
    //create context
    context = cairo_create (surface);
    //cairo_surface_destroy (surface);
    
    //if (GDK_IS_WINDOW (window))
    cairo_translate (context, -x_offset, -y_offset);
    cb->is_cairo = TRUE;
    cb->cr = context;
    cb->surface = surface;
    return context;
}
Exemplo n.º 20
0
static cairo_t *_mt_cairo_begin(MT_TOOLKIT *mt, MT_WINDOW *win, MT_RECTANGLE *area, int x, int y, int width, int height)
{
   GdkWindow *window = (GdkWindow *)win;
   GdkDrawable *drawable;
   cairo_t *cr;
   gint xoff, yoff;
   gint w, h;

   /* revert to rendering to GdkPixbuf (needed for Gecko based applications): */
   if (!window || !GDK_IS_WINDOW(window)) {
      return _mt_cairo_begin_pixbuf(mt, win, area, x, y, width, height);
   }

   gdk_window_get_internal_paint_info(window, &drawable, &xoff, &yoff);

   if (!drawable) {
      return _mt_cairo_begin_pixbuf(mt, win, area, x, y, width, height);
   }

   gdk_drawable_get_size(drawable, &w, &h);
   _cairo_surface = cairo_xlib_surface_create(gdk_x11_drawable_get_xdisplay(drawable),
                                              gdk_x11_drawable_get_xid(drawable),
                                              gdk_x11_visual_get_xvisual(gdk_drawable_get_visual(drawable)),
                                              w, h);
   cr = cairo_create(_cairo_surface);
   
   cairo_translate(cr, -xoff + x, -yoff + y);

   if (area) {
      cairo_rectangle(cr, area->x - x, area->y - y, area->width, area->height);
      cairo_clip(cr);
      cairo_rectangle(cr, 0, 0, width, height);
      cairo_clip(cr);
   }

   return cr;
}
Exemplo n.º 21
0
static GdkVisual*
gdk_quartz_get_visual (GdkDrawable *drawable)
{
  return gdk_drawable_get_visual (GDK_DRAWABLE_IMPL_QUARTZ (drawable)->wrapper);
}
Exemplo n.º 22
0
int wxDisplayDepth()
{
    return gdk_drawable_get_visual( wxGetRootWindow()->window )->depth;
}
/*
 * This is identical to nsCanvasRenderingContext2D::Render, we just don't
 * have a good place to put it; though maybe I want a CanvasContextImpl that
 * all this stuff can derive from?
 */
NS_METHOD 
compzillaRenderingContext::Render (nsIRenderingContext *rc)
{
    DEBUG ("Render\n");

    nsresult rv = NS_OK;

#ifdef MOZ_CAIRO_GFX

    DEBUG ("thebes\n");

    gfxContext* ctx = (gfxContext*) rc->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT);
    nsRefPtr<gfxPattern> pat = new gfxPattern(mThebesSurface);

    // XXX I don't want to use PixelSnapped here, but layout doesn't guarantee
    // pixel alignment for this stuff!
    ctx->NewPath();
    ctx->PixelSnappedRectangleAndSetPattern(gfxRect(0, 0, mWidth, mHeight), pat);
    ctx->Fill();
#else
    DEBUG ("non-thebes\n");

    // non-Thebes; this becomes exciting
    cairo_surface_t *dest = nsnull;
    cairo_t *dest_cr = nsnull;

    GdkDrawable *gdkdraw = nsnull;
#ifdef MOZILLA_1_8_BRANCH
    rv = rc->RetrieveCurrentNativeGraphicData((void**) &gdkdraw);
    if (NS_FAILED(rv) || !gdkdraw)
        return NS_ERROR_FAILURE;
#else
    gdkdraw = (GdkDrawable*) rc->GetNativeGraphicData(nsIRenderingContext::NATIVE_GDK_DRAWABLE);
    if (!gdkdraw)
        return NS_ERROR_FAILURE;
#endif

    gint w, h;
    gdk_drawable_get_size (gdkdraw, &w, &h);
    dest = cairo_xlib_surface_create (GDK_DRAWABLE_XDISPLAY(gdkdraw),
                                      GDK_DRAWABLE_XID(gdkdraw),
                                      GDK_VISUAL_XVISUAL(gdk_drawable_get_visual(gdkdraw)),
                                      w, h);
    dest_cr = cairo_create (dest);

    nsTransform2D *tx = nsnull;
    rc->GetCurrentTransform(tx);

    nsCOMPtr<nsIDeviceContext> dctx;
    rc->GetDeviceContext(*getter_AddRefs(dctx));

    float x0 = 0.0, y0 = 0.0;
    float sx = 1.0, sy = 1.0;
    if (tx->GetType() & MG_2DTRANSLATION) {
        tx->Transform(&x0, &y0);
    }

    if (tx->GetType() & MG_2DSCALE) {
        sx = sy = dctx->DevUnitsToTwips();
        tx->TransformNoXLate(&sx, &sy);
    }

    cairo_translate (dest_cr, NSToIntRound(x0), NSToIntRound(y0));
    if (sx != 1.0 || sy != 1.0)
        cairo_scale (dest_cr, sx, sy);

    cairo_rectangle (dest_cr, 0, 0, mWidth, mHeight);
    cairo_clip (dest_cr);

    cairo_set_source_surface (dest_cr, mSurface, 0, 0);
    cairo_paint (dest_cr);

    if (dest_cr)
        cairo_destroy (dest_cr);
    if (dest)
        cairo_surface_destroy (dest);
#endif

    return rv;
}
Exemplo n.º 24
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;
}
Exemplo n.º 25
0
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;
}
Exemplo n.º 26
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;
}
Exemplo n.º 27
0
void GtkViewWidget::repaint()	{
	GtkPaintContext &gtkContext = (GtkPaintContext&)view()->context();
	Angle angle = rotation();
	bool isRotated = (angle == DEGREES90) || (angle == DEGREES270);
	int w = isRotated ? myArea->allocation.height : myArea->allocation.width;
	int h = isRotated ? myArea->allocation.width : myArea->allocation.height;
	gtkContext.updatePixmap(myArea, w, h);
	view()->paint();
	switch (angle) {
		default:
			cleanOriginalPixbuf();
			cleanRotatedPixbuf();
			gdk_draw_pixmap(myArea->window, myArea->style->white_gc, gtkContext.pixmap(),
											0, 0, 0, 0, myArea->allocation.width, myArea->allocation.height);
			break;
		case DEGREES180:
			cleanRotatedPixbuf();
			if ((myOriginalPixbuf != 0) &&
					((gdk_pixbuf_get_width(myOriginalPixbuf) != w) ||
					 (gdk_pixbuf_get_height(myOriginalPixbuf) != h))) {
				cleanOriginalPixbuf();
			}
			if (myOriginalPixbuf == 0) {
				myOriginalPixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, false, 8, w, h);
				myImage = gdk_image_new(GDK_IMAGE_FASTEST, gdk_drawable_get_visual(gtkContext.pixmap()), w, h);
			}
			gdk_drawable_copy_to_image(gtkContext.pixmap(), myImage, 0, 0, 0, 0, w, h);
			gdk_pixbuf_get_from_image(myOriginalPixbuf, myImage, gdk_drawable_get_colormap(gtkContext.pixmap()),
																0, 0, 0, 0, w, h);
			::rotate180(myOriginalPixbuf);
			gdk_draw_pixbuf(myArea->window, myArea->style->white_gc, myOriginalPixbuf,
											0, 0, 0, 0, w, h, GDK_RGB_DITHER_NONE, 0, 0);
			break;
		case DEGREES90:
		case DEGREES270:
			if ((myOriginalPixbuf != 0) &&
					((gdk_pixbuf_get_width(myOriginalPixbuf) != w) ||
					 (gdk_pixbuf_get_height(myOriginalPixbuf) != h))) {
				cleanOriginalPixbuf();
			}
			if ((myRotatedPixbuf != 0) &&
					((gdk_pixbuf_get_width(myRotatedPixbuf) != h) ||
					 (gdk_pixbuf_get_height(myRotatedPixbuf) != w))) {
				cleanRotatedPixbuf();
			}
			if (myOriginalPixbuf == 0) {
				myOriginalPixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, false, 8, w, h);
				myImage = gdk_image_new(GDK_IMAGE_FASTEST, gdk_drawable_get_visual(gtkContext.pixmap()), w, h);
			}
			if (myRotatedPixbuf == 0) {
				myRotatedPixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, false, 8, h, w);
			}
			gdk_drawable_copy_to_image(gtkContext.pixmap(), myImage, 0, 0, 0, 0, w, h);
			gdk_pixbuf_get_from_image(myOriginalPixbuf, myImage, gdk_drawable_get_colormap(gtkContext.pixmap()),
																0, 0, 0, 0, w, h);
			::rotate90(myRotatedPixbuf, myOriginalPixbuf, angle == DEGREES90);
			gdk_draw_pixbuf(myArea->window, myArea->style->white_gc, myRotatedPixbuf,
											0, 0, 0, 0, h, w, GDK_RGB_DITHER_NONE, 0, 0);
			break;
	}
}