bool SvgWindow::initTexture (SvgSource *source, SvgTexture &texture, CompSize size) { Display *dpy = screen->dpy (); texture.size = size; texture.pixmap = None; texture.cr = NULL; if (size.width () && size.height ()) { cairo_surface_t *surface; XWindowAttributes attr; XGetWindowAttributes (dpy, window->id (), &attr); texture.pixmap = XCreatePixmap (dpy, screen->root (), size.width (), size.height (), attr.depth); texture.textures = GLTexture::bindPixmapToTexture (texture.pixmap, size.width (), size.height (), attr.depth); if (texture.textures.empty ()) { compLogMessage ("svg", CompLogLevelInfo, "Couldn't bind pixmap 0x%x to texture", (int) texture.pixmap); XFreePixmap (dpy, texture.pixmap); return false; } surface = cairo_xlib_surface_create (dpy, texture.pixmap, attr.visual, size.width (), size.height ()); texture.cr = cairo_create (surface); cairo_surface_destroy (surface); } return true; }
static void allocate_pixmap (cairo_5c_surface_t *c5s) { Pixmap pixmap; cairo_5c_gui_t *gui = c5s->u.window.gui; Display *dpy = gui->global->dpy; GC gc = gui->gc; int width = gui->new_width; int height = gui->new_height; int depth = gui->depth; c5s->width = width; c5s->height = height; if (!width) width = 1; if (!height) height = 1; pixmap = XCreatePixmap (dpy, gui->root, width, height, depth); XFillRectangle (dpy, pixmap, gc, 0, 0, width, height); if (gui->pixmap) { XCopyArea (dpy, gui->pixmap, pixmap, gc, 0, 0, width, height, 0, 0); XFreePixmap (dpy, gui->pixmap); } gui->pixmap = pixmap; if (c5s->surface) { cairo_xlib_surface_set_drawable (c5s->surface, pixmap, width, height); } else { c5s->surface = cairo_xlib_surface_create (dpy, pixmap, DefaultVisual (dpy, DefaultScreen (dpy)), width, height); } }
VKWindow* CreateVKWindow(FcitxVKState* vkstate) { XSetWindowAttributes attrib; unsigned long attribmask; char strWindowName[] = "Fcitx VK Window"; Colormap cmap; Visual * vs; int depth; VKWindow* vkWindow = fcitx_utils_new(VKWindow); vkWindow->owner = vkstate; LoadVKImage(vkWindow); vs = VKFindARGBVisual(vkstate); VKInitWindowAttribute(vkstate, &vs, &cmap, &attrib, &attribmask, &depth); vkWindow->dpy = InvokeVaArgs(vkstate->owner, FCITX_X11, GETDISPLAY); vkWindow->fontSize = 12; vkWindow->defaultFont = strdup("sans"); #ifndef _ENABLE_PANGO GetValidFont("zh", &vkWindow->defaultFont); #endif vkWindow->window = XCreateWindow(vkWindow->dpy, DefaultRootWindow(vkWindow->dpy), 0, 0, VK_WINDOW_WIDTH, VK_WINDOW_HEIGHT, 0, depth, InputOutput, vs, attribmask, &attrib); if (vkWindow->window == (Window) None) return NULL; vkWindow->surface = cairo_xlib_surface_create(vkWindow->dpy, vkWindow->window, vs, VK_WINDOW_WIDTH, VK_WINDOW_HEIGHT); XSelectInput(vkWindow->dpy, vkWindow->window, ExposureMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask); VKSetWindowProperty(vkstate, vkWindow->window, FCITX_WINDOW_DOCK, strWindowName); InvokeVaArgs(vkstate->owner, FCITX_X11, ADDXEVENTHANDLER, VKWindowEventHandler, vkWindow); return vkWindow; }
cairo_surface_t* RedirectedXCompositeWindow::surface() { // This should never be called with an empty size (not in Accelerated Compositing mode). ASSERT(!m_size.isEmpty()); if (!m_needsNewPixmapAfterResize && m_surface) return m_surface.get(); m_needsNewPixmapAfterResize = false; Pixmap newPixmap = XCompositeNameWindowPixmap(m_display, m_window); if (!newPixmap) { cleanupPixmapAndPixmapSurface(); return nullptr; } XWindowAttributes windowAttributes; if (!XGetWindowAttributes(m_display, m_window, &windowAttributes)) { cleanupPixmapAndPixmapSurface(); XFreePixmap(m_display, newPixmap); return nullptr; } RefPtr<cairo_surface_t> newSurface = adoptRef(cairo_xlib_surface_create(m_display, newPixmap, windowAttributes.visual, m_size.width(), m_size.height())); // Nvidia drivers seem to prepare their redirected window pixmap asynchronously, so for a few fractions // of a second after each resize, while doing continuous resizing (which constantly destroys and creates // pixmap window-backings), the pixmap memory is uninitialized. To work around this issue, paint the old // pixmap to the new one to properly initialize it. if (m_surface) { RefPtr<cairo_t> cr = adoptRef(cairo_create(newSurface.get())); cairo_set_source_rgb(cr.get(), 1, 1, 1); cairo_paint(cr.get()); cairo_set_source_surface(cr.get(), m_surface.get(), 0, 0); cairo_paint(cr.get()); } cleanupPixmapAndPixmapSurface(); m_pixmap = newPixmap; m_surface = newSurface; return m_surface.get(); }
UrlBar::UrlBar(Display* display, Window parent, XContext context, BrowserControl* control, WKRect size, std::string url) : VisualComponent(display, control, size) , m_isFocused(false) , m_url(url) , m_copiedText(url) , m_cursorPosition(0) , m_textOffset(0) , m_loadProgress(0.0) { createXWindow(parent, context); m_surface = cairo_xlib_surface_create(display, m_window, DefaultVisual(display, 0), m_size.size.width, m_size.size.height); m_cairo = cairo_create(m_surface); cairo_select_font_face(m_cairo, "Verdana", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size(m_cairo, 14); XDefineCursor(display, m_window, XCreateFontCursor(display, XC_xterm)); m_clipboardAtom = XInternAtom(m_display, "CLIPBOARD", True); }
void FlashPlayerWidget::prepareSurface() { // cairo surface if ( d->surface ) cairo_surface_destroy( d->surface ); d->backingPixmap = QPixmap(width(),height()); // TODO - Find a way to get correct screen, visual rather // than just the default ones Display* display = d->backingPixmap.x11Display(); int screen = d->backingPixmap.x11Screen(); void* visual = d->backingPixmap.x11Visual(); d->surface = cairo_xlib_surface_create( display , d->backingPixmap.handle(), (Visual*)visual, width(), height() ); }
static void pens(const char *cmd) { cairo_surface_t *buf, *cbuf, *t; cairo_t *ctx; char str[CURSOR_STRING_MAX]; Theme q; sscanf(cmd, "%*s %lf %lf %lf %lf %lf %s\n", &q.R, &q.G, &q.B, &q.A, &q.e, str); XWarpPointer(dpy, None, wshow, 0, 0, 0, 0, sw/2, sh/2); /* create duplicate buffers */ t = cairo_xlib_surface_create(dpy, wshow, vis, sw, sh); buf = cairo_surface_create_similar(t, CAIRO_CONTENT_COLOR, sw, sh); cbuf = cairo_surface_create_similar(t, CAIRO_CONTENT_COLOR, sw, sh); ctx = cairo_create(cbuf); cairo_set_source_surface(ctx, t, 0, 0); cairo_paint(ctx); cairo_destroy(ctx); ctx = cairo_create(buf); cairo_set_source_surface(ctx, t, 0, 0); cairo_paint(ctx); cairo_surface_destroy(t); /* set drawing parameters */ cairo_set_line_join(ctx, CAIRO_LINE_JOIN_ROUND); cairo_set_line_cap(ctx, CAIRO_LINE_CAP_ROUND); cairo_set_source_rgba(ctx, q.R, q.G, q.B, q.A); cairo_set_line_width(ctx, q.e); // set font cairo_set_font_size(ctx, q.e); grab_mouse(); /* call appropriate sub function */ cairo_move_to(ctx, sw/2, sh/2); if (strncasecmp(cmd,"pen",3)==0) pen(ctx, buf, cbuf, &q); else if (strncasecmp(cmd,"dot",3)==0) dot(ctx, buf, cbuf, &q); else if (strncasecmp(cmd,"cust",4)==0) custom(ctx, buf, cbuf, &q, str); else if (strncasecmp(cmd,"zoom",4)==0) zoom(ctx, buf, cbuf, &q); /* clean up */ XUngrabPointer(dpy, CurrentTime); cairo_surface_destroy(buf); cairo_surface_destroy(cbuf); cairo_destroy(ctx); XDefineCursor(dpy, wshow, invisible_cursor); }
void ui_init_cairo(int canvas_width, int canvas_height, const char *font) { struct point p; ui->w[ui->cur].cs = cairo_xlib_surface_create(ui->dpy, ui->w[ui->cur].canvas, ui->vinfo.visual, canvas_width, canvas_height); ui->w[ui->cur].c = cairo_create(ui->w[ui->cur].cs); /* * pango-font-description-from-string() interprets the size without * a suffix as "points". If "px" is added, it will be read as pixels. */ ui->w[ui->cur].pangolayout = pango_cairo_create_layout(ui->w[ui->cur].c); ui->w[ui->cur].pangofont = pango_font_description_from_string(font); p = ui_get_text_size("abcfghjklABC", font); ui->font_height_actual = p.y; }
void RedirectedXCompositeWindow::createNewPixampAndPixampSurface() { // This should never be called with an empty size (not in Accelerated Compositing mode). ASSERT(!m_size.isEmpty()); XUniquePixmap newPixmap(XCompositeNameWindowPixmap(m_display, m_window.get())); if (!newPixmap) { cleanupPixmapAndPixmapSurface(); return; } XWindowAttributes windowAttributes; if (!XGetWindowAttributes(m_display, m_window.get(), &windowAttributes)) { cleanupPixmapAndPixmapSurface(); return; } RefPtr<cairo_surface_t> newSurface = adoptRef(cairo_xlib_surface_create(m_display, newPixmap.get(), windowAttributes.visual, m_size.width(), m_size.height())); cairoSurfaceSetDeviceScale(newSurface.get(), m_webPage.deviceScaleFactor(), m_webPage.deviceScaleFactor()); RefPtr<cairo_t> cr = adoptRef(cairo_create(newSurface.get())); if (!m_webPage.drawsBackground()) cairo_set_operator(cr.get(), CAIRO_OPERATOR_CLEAR); else setSourceRGBAFromColor(cr.get(), m_webPage.backgroundColor()); cairo_paint(cr.get()); // Nvidia drivers seem to prepare their redirected window pixmap asynchronously, so for a few fractions // of a second after each resize, while doing continuous resizing (which constantly destroys and creates // pixmap window-backings), the pixmap memory is uninitialized. To work around this issue, paint the old // pixmap to the new one to properly initialize it. if (m_surface) { cairo_set_operator(cr.get(), CAIRO_OPERATOR_OVER); cairo_set_source_surface(cr.get(), m_surface.get(), 0, 0); cairo_paint(cr.get()); } cleanupPixmapAndPixmapSurface(); m_pixmap = WTFMove(newPixmap); m_surface = WTFMove(newSurface); }
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; }
void draw(Area *a) { if (a->pix) { XFreePixmap(server.display, a->pix); if (a->pix_by_state[a->has_mouse_over_effect ? a->mouse_state : 0] != a->pix) XFreePixmap(server.display, a->pix_by_state[a->has_mouse_over_effect ? a->mouse_state : 0]); } a->pix = XCreatePixmap(server.display, server.root_win, a->width, a->height, server.depth); a->pix_by_state[a->has_mouse_over_effect ? a->mouse_state : 0] = a->pix; if (!a->_clear) { // Add layer of root pixmap (or clear pixmap if real_transparency==true) if (server.real_transparency) clear_pixmap(a->pix, 0, 0, a->width, a->height); XCopyArea(server.display, ((Panel *)a->panel)->temp_pmap, a->pix, server.gc, a->posx, a->posy, a->width, a->height, 0, 0); } else { a->_clear(a); } cairo_surface_t *cs = cairo_xlib_surface_create(server.display, a->pix, server.visual, a->width, a->height); cairo_t *c = cairo_create(cs); draw_background(a, c); if (a->_draw_foreground) a->_draw_foreground(a, c); cairo_destroy(c); cairo_surface_destroy(cs); }
void get_text_size(PangoFontDescription *font, int *height_ink, int *height, int panel_height, char *text, int len) { PangoRectangle rect_ink, rect; Pixmap pmap = XCreatePixmap (server.dsp, server.root_win, panel_height, panel_height, server.depth); cairo_surface_t *cs = cairo_xlib_surface_create (server.dsp, pmap, server.visual, panel_height, panel_height); cairo_t *c = cairo_create (cs); PangoLayout *layout = pango_cairo_create_layout (c); pango_layout_set_font_description (layout, font); pango_layout_set_text (layout, text, len); pango_layout_get_pixel_extents(layout, &rect_ink, &rect); *height_ink = rect_ink.height; *height = rect.height; //printf("dimension : %d - %d\n", rect_ink.height, rect.height); g_object_unref (layout); cairo_destroy (c); cairo_surface_destroy (cs); XFreePixmap (server.dsp, pmap); }
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; }
Pixmap ShadowHelper::createPixmap( const Cairo::Surface& surface, int opacity ) const { assert( surface.isValid() ); int width(0); int height(0); cairo_surface_get_size( surface, width, height ); GdkScreen* screen = gdk_screen_get_default(); Display* display( GDK_DISPLAY_XDISPLAY( gdk_screen_get_display( screen ) ) ); Window root( GDK_WINDOW_XID( gdk_screen_get_root_window( screen ) ) ); Pixmap pixmap = XCreatePixmap( display, root, width, height, 32 ); // create surface for pixmap { Cairo::Surface dest( cairo_xlib_surface_create( display, pixmap, GDK_VISUAL_XVISUAL( gdk_screen_get_rgba_visual( screen ) ), width, height ) ); Cairo::Context context( dest ); cairo_set_operator( context, CAIRO_OPERATOR_SOURCE ); cairo_rectangle( context, 0, 0, width, height ); cairo_set_source_surface( context, surface, 0, 0 ); cairo_fill( context ); if( opacity < 255 ) { cairo_set_operator( context, CAIRO_OPERATOR_DEST_IN ); cairo_set_source( context, ColorUtils::Rgba( 0, 0, 0, double(opacity)/255 ) ); cairo_rectangle( context, 0, 0, width, height ); cairo_fill( context ); } } return pixmap; }
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; }
Window *render_create_sorter(Window win) { int i; PopplerPage *page; double pdfw, pdfh, scale; cairo_surface_t *pix_s; cairo_t *pix_c; XSetWindowAttributes wa; wa.backing_store = Always; wa.event_mask = ButtonPress | ExposureMask | PointerMotionMask; Window *wins = malloc((_pdf[0].npage + 1) * sizeof(Window)); Pixmap pix; int ww, wh; for (i = 0; i < _pdf[0].npage; ++i) { page = poppler_document_get_page(_pdf[0].doc, i); poppler_page_get_size(page, &pdfw, &pdfh); scale = get_d(presH) / (6 * pdfh); ww = scale * pdfw; wh = scale * pdfh; wins[i] = XCreateWindow(dpy, win, 0, 0, ww, wh, 1, DefaultDepth(dpy,scr), InputOutput, DefaultVisual(dpy,scr), CWBackingStore | CWEventMask, &wa); XDefineCursor(dpy, wins[i], XCreateFontCursor(dpy, 68)); pix = XCreatePixmap(dpy, wins[i], ww, wh, DefaultDepth(dpy,scr)); pix_s = cairo_xlib_surface_create(dpy, pix, DefaultVisual(dpy,scr), ww, wh); pix_c = cairo_create(pix_s); cairo_surface_destroy(pix_s); cairo_set_source_rgb(pix_c, 1, 1, 1); cairo_paint(pix_c); cairo_scale(pix_c, scale, scale); poppler_page_render(page, pix_c); cairo_destroy(pix_c); XSetWindowBackgroundPixmap(dpy, wins[i], pix); XFreePixmap(dpy, pix); g_object_unref(page); } wins[_pdf[0].npage] = None; return wins; }
// // redraw // void root_window_redraw(XExposeEvent *e, Display *d, int screen, StateMachine *state) { // NOTE: if you wish t use `e` you MUST check if it is not NULL first if (!is_init) { // init freetype font the first time init_font(&font, ROOT_WINDOW_FONT_PATH); is_init = True; } // required properties and structs for redraw Window root = RootWindow(d, screen); int width = DisplayWidth(d, screen); int height = DisplayHeight(d, screen); Visual *visual = DefaultVisual(d, screen); // create surface cairo_surface_t *surface=cairo_xlib_surface_create(d, root, visual, width, height); cairo_t *cr = cairo_create(surface); // clear surface with a solid colour cairo_set_source_rgb(cr, ROOT_WINDOW_BG_RGB); cairo_rectangle(cr, 0, 0, width, height); cairo_fill(cr); // draw product name and version on desktop cairo_set_source_rgb(cr, ROOT_WINDOW_FG_RGB); cairo_set_font_face(cr, font.cairo_font); cairo_set_font_size(cr, ROOT_WINDOW_FONT_SIZE); cairo_move_to(cr, LAYOUT_MARGIN, height-(2*LAYOUT_MARGIN)); cairo_show_text(cr, PRODUCT_NAME_AND_VERSION); cairo_destroy(cr); cairo_surface_destroy(surface); }
void draw (Area *a) { if (a->pix) XFreePixmap (server.dsp, a->pix); a->pix = XCreatePixmap (server.dsp, server.root_win, a->width, a->height, server.depth); // add layer of root pixmap (or clear pixmap if real_transparency==true) if (server.real_transparency) clear_pixmap(a->pix, 0 ,0, a->width, a->height); XCopyArea (server.dsp, ((Panel *)a->panel)->temp_pmap, a->pix, server.gc, a->posx, a->posy, a->width, a->height, 0, 0); cairo_surface_t *cs; cairo_t *c; cs = cairo_xlib_surface_create (server.dsp, a->pix, server.visual, a->width, a->height); c = cairo_create (cs); draw_background (a, c); if (a->_draw_foreground) a->_draw_foreground(a, c); cairo_destroy (c); cairo_surface_destroy (cs); }
Surface(Scene& scene, int width = 0, int height = 0) : scene(scene), width(width), height(height), rendered(false) { Drawable da; Screen *scr; int screen; cairo_surface_t *sfc; if ((dsp = XOpenDisplay(NULL)) == NULL) { exit(1); } screen = DefaultScreen(dsp); scr = DefaultScreenOfDisplay(dsp); if (width == 0) { width = WidthOfScreen(scr), height = HeightOfScreen(scr); } da = XCreateSimpleWindow(dsp, DefaultRootWindow(dsp), 0, 0, width, height, 0, 0, 0); XSelectInput(dsp, da, ExposureMask | KeyPressMask | ButtonPressMask | StructureNotifyMask); XMapWindow(dsp, da); sfc = cairo_xlib_surface_create(dsp, da, DefaultVisual(dsp, screen), width, height); cairo_xlib_surface_set_size(sfc, width, height); cairo_surface = sfc; cr = cairo_create(sfc); render(); }
int main() { std::cout << "Hello, world!" << std::endl; DataSource *src = new DataSource(); std::cout << src->GetValues()[0] << std::endl; return 1; // Open a display. Display *d = XOpenDisplay(0); if ( d ) { // Create the window Window w = XCreateWindow( d, // Display DefaultRootWindow(d), // Parent 0, 0, // x, y 200, 600, // width, height 0, // border width CopyFromParent, // depth CopyFromParent, // class CopyFromParent, // visual 0, // valuemask 0 // attributes ); // Show the window XMapWindow(d, w); XFlush(d); // Test Widget cairo_surface_t *cs = cairo_xlib_surface_create( d, // X11 display w, // Drawable surface, in this case the window DefaultVisual(d, 0), 200, 600 ); cairo_t *cr = cairo_create(cs); XSelectInput(d, w, ExposureMask); // --------------------------------------------------------- // Setup Widget VertLayoutWidget *wid = new VertLayoutWidget(); wid->set_size(new Size(0, 0, 200, 600)); wid->set_margin(new Box(10)); wid->set_padding(new Box(8)); wid->set_spacing(8); wid->HonorChildSizes = true; // start simple // Add a child Widget *chld = new Widget(); chld->set_background_color(new Color(1, 0, 0, 1)); chld->set_border_color(new Color(0, 1, 0, 1)); chld->set_margin(new Box(0)); chld->set_requested_size(new Size(-1, -1, -1, -1)); // 1st Child wid->add_child(chld); // 2nd wid->add_child(new Widget(*chld)); // 3rd wid->add_child(new Widget(*chld)); //chld->set_requested_size(new Size(-1, -1, 500, 100)); wid->Draw(cr); // ---------------------------------------------------------- XEvent ev; while (1) { XNextEvent(d, &ev); std::cout << "Event!" << std::endl; if (ev.type == Expose) { wid->Draw(cr); } } cairo_destroy(cr); cairo_surface_destroy(cs); XCloseDisplay(d); return 0; } }
void custom_graphics(ValueType vt, float val,int W,int H) { int x0,y0,i; int _w, _h; float x,y,p; custom_graph_dimensions(vt, _w, _h); x0 = W / 2 - (_w / 2); y0 = H; switch(vt) { case VC_FilterVelocitySense: { p = powf(8.0f,(64.0f-(int)val)/64.0f); /* Grid */ grid(x0,y0,_w,_h, 4); /*Function curve*/ fl_color(FL_BLUE); if ((int)val == 127) { // in this case velF will always return 1.0 y = y0 - _h; fl_line(x0, y, x0 + _w, y); } else { fl_begin_line(); for(i = 0; i < _w; i++) { x = (float)i / (float)_w; y = powf(x,p) * _h; fl_vertex((float)x0 + i, (float)y0 - y); } fl_end_line(); } break; } case VC_FormFilterClearness: { p = powf(10.0f, (val - 32.0f) / 48.0f); //clearness param grid(x0,y0,_w,_h,10); fl_color(FL_BLUE); fl_begin_line(); x = 0; float frac = 1.0f / (float)_w; for(i = 0; i < _w; i++) { y = (atanf((x * 2.0f - 1.0f) * p) / atanf(p) + 1.0f) * 0.5f * _h; fl_vertex((float)x0 + i, (float)y0 - y); x += frac; } fl_end_line(); break; } case VC_SubBandwidthScale: { /* The scale centers around the factor 1 vertically and is logarithmic in both dimensions. */ int margin = 28; _h -= margin; _w -= margin * 2; x0 += margin * 1.25; y0 -= margin * 0.75; float cy = y0 - _h / 2; int j = 1; const float lg1020 = log10(20); /* Lower bound = 20hz*/ const float rx = _w / (log10(20000) - lg1020); /* log. width ratio */ const float ry = (_h / 2) / log10(100000); string hzMarkers[] = {"20", "100", "1k", "10k"}; string xMarkers[] = {"x10","x100","x1k","x10k","10%","1%","0.1%","0.01%"}; /* Scale lines */ fl_font(fl_font(),8); fl_line_style(0); for(i = 0; i < 4; i++) /* 10x / 10%, 100x / 1% ... */ { y = ry * (i + 1); fl_color(169,169,169); fl_line(x0, cy - y, x0 + _w, cy - y); fl_line(x0, cy + y, x0 + _w, cy + y); fl_color(0,0,0); fl_draw(xMarkers[i].c_str(), x0 - 28, (cy - y - 4), 24, 12, Fl_Align(FL_ALIGN_RIGHT)); fl_draw(xMarkers[i + 4].c_str(), x0 - 28, (cy + y - 4), 24, 12, Fl_Align(FL_ALIGN_RIGHT)); } /* Hz lines */ fl_color(196,196,196); /* Lighter inner lines*/ for(i = 10;i != 0; i *= 10) { for(j = 2; j < 10; j++) { x = x0 + rx * (log10(i * j) - lg1020) + 1; fl_line(x, y0, x, y0 - _h); if(i * j >= 20000) { i = 0; break; } } } fl_font(fl_font(),10); for(i = 0; i < 4; i++) /* 20, 100, 1k, 10k */ { x = x0 + (i == 0 ? 0 : ((float)i + 1 - lg1020) * rx); fl_color(127,127,127); /* Darker boundary lines */ fl_line(x, y0, x, y0 - _h); fl_color(FL_BLACK); fl_draw(hzMarkers[i].c_str(), x - 20, y0 + 4, 40, 12, Fl_Align(FL_ALIGN_CENTER)); } /* Unit marker at the lower right of the graph */ fl_draw("Hz", x0 + _w, y0 + 4, 20, 12, Fl_Align(FL_ALIGN_LEFT)); /* Vertical center line */ fl_color(64,64,64); fl_line(x0 - margin, cy, x0 + _w, cy); /* Function curve */ fl_color(FL_BLUE); if((int)val == 0) { fl_line(x0, cy, x0 + _w, cy); } else { const float p = ((int)val / 64.0f) * 3.0; /* Cairo not necessary, but makes it easier to read the graph */ cairo_t *cr; cairo_surface_t* Xsurface = cairo_xlib_surface_create (fl_display, fl_window, fl_visual->visual, Fl_Window::current()->w(), Fl_Window::current()->h()); cr = cairo_create (Xsurface); cairo_set_source_rgb(cr, 1, 0, 0); cairo_set_line_width(cr, 1.5); cairo_move_to(cr, x0, cy - ry * log10(powf(50, p))); cairo_line_to(cr, x0 + _w, cy - ry * log10(powf(0.05, p))); cairo_stroke(cr); cairo_surface_destroy(Xsurface); cairo_destroy(cr); } break; } default: break; } }
static gchar *_make_screenshot (gboolean bActiveWindow, const gchar *cFolder, const gchar *cFileName) { // create a surface that points on the root window. Display *display = gdk_x11_get_default_xdisplay (); Screen *screen = XDefaultScreenOfDisplay (display); Visual *visual = DefaultVisualOfScreen (screen); int w, h; Window Xid; if (bActiveWindow) { GldiWindowActor *pActiveWindow = gldi_windows_get_active (); Xid = gldi_window_get_id (pActiveWindow); // cairo_dock_get_active_xwindow () Window root_return; int x_return=1, y_return=1; unsigned int width_return, height_return, border_width_return, depth_return; XGetGeometry (display, Xid, &root_return, &x_return, &y_return, &width_return, &height_return, &border_width_return, &depth_return); // we can't use the data from the WindowActor, because it takes into account the window border. w = width_return; h = height_return; } else { Xid = DefaultRootWindow (display); w = g_desktopGeometry.Xscreen.width; h = g_desktopGeometry.Xscreen.height; } cairo_surface_t *s = cairo_xlib_surface_create (display, Xid, visual, w, h); gchar *cName = NULL; if (s) { // save the surface on the disk cName = _make_image_name (cFolder, cFileName); cairo_surface_write_to_png (s, cName); // apply the surface on the icon, with a transition. int iWidth, iHeight; CD_APPLET_GET_MY_ICON_EXTENT (&iWidth, &iHeight); cairo_dock_free_image_buffer (myData.pCurrentImage); myData.pCurrentImage = g_new0 (CairoDockImageBuffer, 1); double ratio = MIN ((double)iWidth / w, (double)iHeight / h); // keep ratio. int w0 = w * ratio; int h0 = h * ratio; cairo_surface_t *pSurface = cairo_dock_duplicate_surface (s, w, h, w0, h0); // we must duplicate the surface, because it's an Xlib surface, not a data surface (plus it's way too large anyway). cairo_dock_load_image_buffer_from_surface (myData.pCurrentImage, pSurface, w0, h0); cairo_dock_free_image_buffer (myData.pOldImage); myData.pOldImage = cairo_dock_create_image_buffer (myIcon->cFileName, iWidth, iHeight, 0); // maybe we could use the current icon image ... CD_APPLET_SET_TRANSITION_ON_MY_ICON (_render_step_cairo, _render_step_opengl, g_bUseOpenGL, // bFastPace : vite si opengl, lent si cairo. 2000, // 2s transition TRUE); // bRemoveWhenFinished cairo_surface_destroy (s); } return cName; }
void NetscapePlugin::platformPaint(GraphicsContext* context, const IntRect& dirtyRect, bool /*isSnapshot*/) { if (m_isWindowed) return; if (!m_isStarted) { // FIXME: we should paint a missing plugin icon. return; } if (context->paintingDisabled() || !m_drawable) return; XEvent xevent; memset(&xevent, 0, sizeof(XEvent)); XGraphicsExposeEvent& exposeEvent = xevent.xgraphicsexpose; exposeEvent.type = GraphicsExpose; exposeEvent.display = x11HostDisplay(); exposeEvent.drawable = m_drawable; IntRect exposedRect(dirtyRect); exposeEvent.x = exposedRect.x(); exposeEvent.y = exposedRect.y(); // Note: in transparent mode Flash thinks width is the right and height is the bottom. // We should take it into account if we want to support transparency. exposeEvent.width = exposedRect.width(); exposeEvent.height = exposedRect.height(); NPP_HandleEvent(&xevent); if (m_pluginDisplay != x11HostDisplay()) XSync(m_pluginDisplay, false); #if PLATFORM(QT) XImage* xImage = XGetImage(NetscapePlugin::x11HostDisplay(), m_drawable, exposedRect.x(), exposedRect.y(), exposedRect.width(), exposedRect.height(), ULONG_MAX, ZPixmap); QPainter* painter = context->platformContext(); painter->drawImage(QPoint(exposedRect.x(), exposedRect.y()), qimageFromXImage(xImage), exposedRect); XDestroyImage(xImage); #elif PLATFORM(GTK) RefPtr<cairo_surface_t> drawableSurface = adoptRef(cairo_xlib_surface_create(m_pluginDisplay, m_drawable, static_cast<NPSetWindowCallbackStruct*>(m_npWindow.ws_info)->visual, m_pluginSize.width(), m_pluginSize.height())); cairo_t* cr = context->platformContext()->cr(); cairo_save(cr); cairo_set_source_surface(cr, drawableSurface.get(), 0, 0); cairo_rectangle(cr, exposedRect.x(), exposedRect.y(), exposedRect.width(), exposedRect.height()); cairo_clip(cr); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_paint(cr); cairo_restore(cr); #else notImplemented(); #endif }
/* * draw_border_shape * Returns: void * Description: Draws a slight border around the decoration */ static void draw_border_shape (Display *xdisplay, Pixmap pixmap, Picture picture, int width, int height, decor_context_t *c, void *closure) { static XRenderColor white = { 0xffff, 0xffff, 0xffff, 0xffff }; decor_t d; decor_shadow_info_t *info = (decor_shadow_info_t *) closure; double save_decoration_alpha; GdkScreen *screen; memset (&d, 0, sizeof (d)); if (info) { gwd_decor_frame_ref (info->frame); d.frame = info->frame; d.state = info->state; d.actions = info->active; } else { d.frame = gwd_get_decor_frame ("normal"); d.state = 0; d.active = TRUE; } screen = gdk_screen_get_default (); d.surface = cairo_xlib_surface_create (GDK_SCREEN_XDISPLAY (screen), pixmap, GDK_VISUAL_XVISUAL (gdk_screen_get_rgba_visual (screen)), width, height); d.width = width; d.height = height; d.active = TRUE; d.draw = theme_draw_window_decoration; d.picture = picture; d.context = c; /* we use closure argument if maximized */ if (info) d.state = info->state; else d.state = 0; decor_get_default_layout (c, 1, 1, &d.border_layout); /* create shadow from opaque decoration * FIXME: Should not modify settings value * like this */ save_decoration_alpha = decoration_alpha; decoration_alpha = 1.0; (*d.draw) (&d); decoration_alpha = save_decoration_alpha; XRenderFillRectangle (xdisplay, PictOpSrc, picture, &white, c->left_space, c->top_space, width - c->left_space - c->right_space, height - c->top_space - c->bottom_space); if (!info) gwd_decor_frame_unref (d.frame); cairo_surface_destroy (d.surface); }
void *render_threaded(void *arg) { Show *show = (Show *) arg; int i, j, n, x, y, grid = 0; int sw = show->w, sh = show->h; Pixmap thumb = 0x0; /* open pdf and create Show */ PopplerDocument *pdf = poppler_document_new_from_file(show->uri,NULL,NULL); if (!pdf) die("\"%s\" is not a pdf file\n",show->uri); show->count = poppler_document_get_n_pages(pdf); show->slide = (Pixmap *) calloc(show->count, sizeof(Pixmap)); show->flag = (int *) calloc(show->count, sizeof(int)); /* scaling calculations */ double pdfw, pdfh; PopplerPage *page = poppler_document_get_page(pdf,0); poppler_page_get_size(page,&pdfw,&pdfh); float hsc = show->w/pdfw, vsc = show->h/pdfh; if (hsc > vsc) { show->scale = vsc; show->w = pdfw * show->scale; show->x = (sw - show->w)/2; } else { show->scale = hsc; show->h = pdfh * show->scale; show->y = (sh - show->h)/2; } /* create sorter */ if (show->sorter) { /* scaling calculations sorter */ show->sorter->count = 1; show->sorter->slide = (Pixmap *) calloc(1, sizeof(Pixmap)); show->sorter->flag = (int *) calloc(1,sizeof(int)); grid = (int) ceil(sqrt(show->count)) ; vsc = ( (sh-10)/grid - 10) / pdfh; hsc = ( (sw-10)/grid - 10) / pdfw; show->sorter->flag[0] = grid; show->sorter->scale = (vsc > hsc ? hsc : vsc); show->sorter->h = pdfh * show->sorter->scale; show->sorter->w = pdfw * show->sorter->scale; show->sorter->x = (sw - (show->sorter->w+10)*grid + 10)/2; show->sorter->y = (sh - (show->sorter->h+10)*grid + 10)/2; /* create empty sorter frame */ thumb = XCreatePixmap(dpy,root,show->sorter->w, show->sorter->h,DefaultDepth(dpy,scr)); show->sorter->slide[0] = XCreatePixmap(dpy,root,sw,sh, DefaultDepth(dpy,scr)); XFillRectangle(dpy,show->sorter->slide[0],bgc,0,0,sw,sh); n = 0; y = show->sorter->y; for (i = 0; i < grid; i++, y += show->sorter->h + 10) { x = show->sorter->x; for (j = 0; j < grid; j++, x+= show->sorter->w + 10) { if (++n > show->count) break; XFillRectangle(dpy,show->sorter->slide[0],egc,x+2,y+2, show->sorter->w-5,show->sorter->h-5); } } } /* render pages */ cairo_surface_t *target; cairo_t *cairo; n = 0; x = (show->sorter ? show->sorter->x : 0); y = (show->sorter ? show->sorter->y : 0); for (i = 0; i < show->count && !(show->flag[0] & STOP_RENDER); i++) { show->slide[i] = XCreatePixmap(dpy,root,show->w,show->h, DefaultDepth(dpy,scr)); XFillRectangle(dpy,show->slide[i],sgc,0,0,show->w,show->h); page = poppler_document_get_page(pdf,i); target = cairo_xlib_surface_create(dpy,show->slide[i], DefaultVisual(dpy,scr),show->w,show->h); cairo = cairo_create(target); cairo_scale(cairo,show->scale,show->scale); poppler_page_render(page,cairo); cairo_surface_destroy(target); cairo_destroy(cairo); show->flag[i] |= RENDERED; if (show->sorter) { XFillRectangle(dpy,thumb,sgc,0,0,show->sorter->w,show->sorter->h); target = cairo_xlib_surface_create(dpy,thumb,DefaultVisual(dpy,scr), show->sorter->w,show->sorter->h); cairo = cairo_create(target); cairo_scale(cairo,show->sorter->scale,show->sorter->scale); poppler_page_render(page,cairo); cairo_surface_destroy(target); XCopyArea(dpy,thumb,show->sorter->slide[0],sgc,0,0,show->sorter->w, show->sorter->h,x,y); x += show->sorter->w + 10; if (++n == grid) { n = 0; x = show->sorter->x; y += show->sorter->h + 10; } } } if (show->sorter) XFreePixmap(dpy,thumb); return NULL; }
int main(void) { XEvent xevent; int pxmp_flag = 1; cairo_surface_t *surface; cairo_t *cr; char *data; display = XOpenDisplay(getenv("DISPLAY")); screen_num = DefaultScreen(display); win = XCreateSimpleWindow(display, RootWindow(display, screen_num), 0, 0, 200, 200, 0, BlackPixel(display, screen_num), WhitePixel(display, screen_num)); pxmp1 = XCreatePixmap(display, win, 200, 200, DefaultDepth(display,DefaultScreen(display))); pxmp2 = XCreatePixmap(display, win, 200, 200, DefaultDepth(display,DefaultScreen(display))); XClearWindow(display,win); ximg = XCreateImage(display, DefaultVisual(disp,screen_num), 24, XYBitmap, 0, NULL, 640, 480, 8, 0); #if 0 #if 1 surface = cairo_xlib_surface_create(display, pxmp1, DefaultVisual(display, 0), 200, 200); cr = cairo_create(surface); cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0); cairo_rectangle(cr, 0, 0, 200, 200); cairo_fill(cr); cairo_set_source_rgba(cr, 0.0, 1.0, 0.0, 1.0); cairo_rectangle(cr, 10, 10, 100, 100); cairo_fill(cr); cairo_surface_destroy(surface); #endif surface = cairo_xlib_surface_create(display, pxmp2, DefaultVisual(display, 0), 200, 200); cr = cairo_create(surface); cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0); cairo_rectangle(cr, 0, 0, 200, 200); cairo_fill(cr); cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 1.0); cairo_rectangle(cr, 10, 10, 100, 100); cairo_fill(cr); cairo_surface_destroy(surface); #endif XSetWindowBackgroundPixmap(display,win,pxmp1); XSelectInput(display, win, ExposureMask|ButtonPressMask); XMapWindow(display, win); XSync(display, True); while ( 1 ) { XNextEvent(display, &xevent); if ( xevent.type == ButtonPress ) { fprintf(stderr,"Switching pixmap\n"); if ( pxmp_flag == 1 ) { XSetWindowBackgroundPixmap(display, win, pxmp2); pxmp_flag = 2; } else { XSetWindowBackgroundPixmap(display, win, pxmp1); pxmp_flag = 1; } XClearWindow(display, win); } } XFreePixmap(display, pxmp1); XFreePixmap(display, pxmp2); XCloseDisplay(display); return 0; }
static cairo_test_status_t do_test (const cairo_test_context_t *ctx, Display *dpy, unsigned char *reference_data, unsigned char *test_data, unsigned char *diff_data, cairo_bool_t use_pixmap, cairo_bool_t set_size, cairo_bool_t offscreen) { cairo_surface_t *surface; cairo_surface_t *test_surface; cairo_t *test_cr; buffer_diff_result_t result; Drawable drawable; int screen = DefaultScreen (dpy); if (use_pixmap && offscreen) return CAIRO_TEST_SUCCESS; if (use_pixmap) { drawable = XCreatePixmap (dpy, DefaultRootWindow (dpy), SIZE, SIZE, DefaultDepth (dpy, screen)); } else { XSetWindowAttributes xwa; int x, y; xwa.override_redirect = True; if (offscreen) { x = - OFFSCREEN_OFFSET; y = - OFFSCREEN_OFFSET; } else { x = 0; y = 0; } drawable = XCreateWindow (dpy, DefaultRootWindow (dpy), x, y, SIZE, SIZE, 0, DefaultDepth (dpy, screen), InputOutput, DefaultVisual (dpy, screen), CWOverrideRedirect, &xwa); XMapWindow (dpy, drawable); } surface = cairo_xlib_surface_create (dpy, drawable, DefaultVisual (dpy, screen), SIZE, SIZE); if (! surface_compare_visual_and_format (surface)) return CAIRO_TEST_FAILURE; if (set_size) { cairo_xlib_surface_set_size (surface, SIZE, SIZE); if (cairo_xlib_surface_get_width (surface) != SIZE || cairo_xlib_surface_get_height (surface) != SIZE) return CAIRO_TEST_FAILURE; } if (! check_similar_visual_and_format (surface)) return CAIRO_TEST_FAILURE; draw_pattern (surface); test_surface = cairo_image_surface_create_for_data (test_data, CAIRO_FORMAT_RGB24, SIZE, SIZE, SIZE * 4); test_cr = cairo_create (test_surface); cairo_set_source_surface (test_cr, surface, 0, 0); cairo_paint (test_cr); cairo_destroy (test_cr); cairo_surface_destroy (test_surface); /* We erase the surface to black in case we get the same * memory back again for the pixmap case. */ erase_pattern (surface); cairo_surface_destroy (surface); if (use_pixmap) XFreePixmap (dpy, drawable); else XDestroyWindow (dpy, drawable); if (offscreen) { size_t offset = 4 * (SIZE * OFFSCREEN_OFFSET + OFFSCREEN_OFFSET); buffer_diff_noalpha (reference_data + offset, test_data + offset, diff_data + offset, SIZE - OFFSCREEN_OFFSET, SIZE - OFFSCREEN_OFFSET, 4 * SIZE, &result); } else { buffer_diff_noalpha (reference_data, test_data, diff_data, SIZE, SIZE, 4 * SIZE, &result); } cairo_test_log (ctx, "xlib-surface: %s, %s, %s: %s\n", set_size ? " size" : "no-size", use_pixmap ? "pixmap" : "window", use_pixmap ? " " : (offscreen ? ", offscreen" : ", onscreen"), image_diff_is_failure (&result, 0) ? "FAIL" : "PASS"); if (image_diff_is_failure (&result, 0)) return CAIRO_TEST_FAILURE; else return CAIRO_TEST_SUCCESS; }
int main(int argc, char *argv[]) { int i; int screen; int win_x, win_y; unsigned int width, height; unsigned int depth; unsigned int border_width; unsigned int win_id; double y_all_extents = 0.0; double x, y; Display *display; Visual *visual; Window RootWindow; Window win; cairo_text_extents_t extents; cairo_surface_t *surface; cairo_t *cr; display = XOpenDisplay(NULL); if(display == NULL) { fprintf(stderr, "Cannot open display.\n"); exit(1); } screen = DefaultScreen(display); sscanf(argv[1], "%x", &win_id); win = win_id; XGetGeometry(display, win, &RootWindow, &win_x, &win_y, &width, &height, &border_width, &depth ); visual = DefaultVisual(display, screen); surface = cairo_xlib_surface_create (display, win, visual, width, height ); cr = cairo_create (surface); cairo_select_font_face (cr, "Arial", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size (cr, 32.0); cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); for (i = 2; i < argc ; i++) { cairo_text_extents(cr, argv[i], &extents); y_all_extents += (extents.height/2 + extents.y_bearing*2); } y_all_extents = y_all_extents/2.0; cairo_text_extents(cr, argv[1], &extents); x = width/2 - (extents.width/2 + extents.x_bearing); y = height/2 - (extents.height/2 + extents.y_bearing); y += y_all_extents; cairo_move_to(cr, x, y ); XClearWindow(display, win); for (i = 2; i < argc ; i++) { cairo_text_extents(cr, argv[i], &extents); x = width/2 - (extents.width/2 + extents.x_bearing); cairo_move_to (cr, x, y ); cairo_show_text (cr, argv[i]); y -= (extents.height/2 + extents.y_bearing*2 ); } XCloseDisplay(display); return 0; }
cairo_surface_t * x11_window_create(struct config *config, int *width, int *height) { Display *dpy; Window win; int screen; cairo_surface_t *surface; XSetWindowAttributes attr; struct x11_window *priv; int x, y, w, h; dpy = XOpenDisplay(NULL); if (dpy == NULL) return NULL; screen = DefaultScreen(dpy); XSetErrorHandler(noop); x11_position(dpy, *width, *height, config, &x, &y, &w, &h); attr.override_redirect = True; win = XCreateWindow(dpy, DefaultRootWindow(dpy), x, y, w, h, 0, DefaultDepth(dpy, screen), InputOutput, DefaultVisual(dpy, screen), CWOverrideRedirect, &attr); surface = cairo_xlib_surface_create(dpy, win, DefaultVisual (dpy, screen), w, h); if (cairo_surface_status(surface)) goto err_win; priv = malloc(sizeof(*priv)); if (priv == NULL) goto err_surface; if (prefer_image(config)) priv->base.surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, w, h); else priv->base.surface = cairo_surface_create_similar(surface, CAIRO_CONTENT_COLOR, w, h); if (cairo_surface_status(priv->base.surface)) goto err_priv; priv->base.show = x11_window_show; priv->base.hide = x11_window_hide; priv->dpy = dpy; priv->win = win; priv->front = surface; priv->visible = false; priv->width = w; priv->height = h; cairo_surface_set_user_data(priv->base.surface, &overlay_key, priv, x11_window_destroy); *width = w; *height = h; return priv->base.surface; err_priv: free(priv); err_surface: cairo_surface_destroy(surface); err_win: XDestroyWindow(dpy, win); XCloseDisplay(dpy); return NULL; }
void PluginView::paint(GraphicsContext* context, const IntRect& rect) { if (!m_isStarted || m_status != PluginStatusLoadedSuccessfully) { paintMissingPluginIcon(context, rect); return; } if (context->paintingDisabled()) return; setNPWindowIfNeeded(); if (m_isWindowed) return; if (!m_drawable) return; Display* display = getPluginDisplay(nullptr); const bool syncX = m_pluginDisplay && m_pluginDisplay != display; IntRect exposedRect(rect); exposedRect.intersect(frameRect()); exposedRect.move(-frameRect().x(), -frameRect().y()); RefPtr<cairo_surface_t> drawableSurface = adoptRef(cairo_xlib_surface_create(display, m_drawable, m_visual, m_windowRect.width(), m_windowRect.height())); if (m_isTransparent) { // If we have a 32 bit drawable and the plugin wants transparency, // we'll clear the exposed area to transparent first. Otherwise, // we'd end up with junk in there from the last paint, or, worse, // uninitialized data. RefPtr<cairo_t> cr = adoptRef(cairo_create(drawableSurface.get())); if (!(cairo_surface_get_content(drawableSurface.get()) & CAIRO_CONTENT_ALPHA)) { // Attempt to fake it when we don't have an alpha channel on our // pixmap. If that's not possible, at least clear the window to // avoid drawing artifacts. // This Would not work without double buffering, but we always use it. cairo_set_source_surface(cr.get(), cairo_get_group_target(context->platformContext()->cr()), -m_windowRect.x(), -m_windowRect.y()); cairo_set_operator(cr.get(), CAIRO_OPERATOR_SOURCE); } else cairo_set_operator(cr.get(), CAIRO_OPERATOR_CLEAR); cairo_rectangle(cr.get(), exposedRect.x(), exposedRect.y(), exposedRect.width(), exposedRect.height()); cairo_fill(cr.get()); } XEvent xevent; memset(&xevent, 0, sizeof(XEvent)); XGraphicsExposeEvent& exposeEvent = xevent.xgraphicsexpose; exposeEvent.type = GraphicsExpose; exposeEvent.display = display; exposeEvent.drawable = m_drawable; exposeEvent.x = exposedRect.x(); exposeEvent.y = exposedRect.y(); exposeEvent.width = exposedRect.x() + exposedRect.width(); // flash bug? it thinks width is the right in transparent mode exposeEvent.height = exposedRect.y() + exposedRect.height(); // flash bug? it thinks height is the bottom in transparent mode dispatchNPEvent(xevent); if (syncX) XSync(m_pluginDisplay, false); // sync changes by plugin cairo_t* cr = context->platformContext()->cr(); cairo_save(cr); cairo_set_source_surface(cr, drawableSurface.get(), frameRect().x(), frameRect().y()); cairo_rectangle(cr, frameRect().x() + exposedRect.x(), frameRect().y() + exposedRect.y(), exposedRect.width(), exposedRect.height()); cairo_clip(cr); if (m_isTransparent) cairo_set_operator(cr, CAIRO_OPERATOR_OVER); else cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_paint(cr); cairo_restore(cr); }