michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "gfxGdkNativeRenderer.h" michael@0: #include "gfxContext.h" michael@0: #include "gfxPlatformGtk.h" michael@0: michael@0: #ifdef MOZ_X11 michael@0: #include michael@0: #include "cairo-xlib.h" michael@0: #include "gfxXlibSurface.h" michael@0: michael@0: #if (MOZ_WIDGET_GTK == 2) michael@0: nsresult michael@0: gfxGdkNativeRenderer::DrawWithXlib(cairo_surface_t* surface, michael@0: nsIntPoint offset, michael@0: nsIntRect* clipRects, uint32_t numClipRects) michael@0: { michael@0: GdkDrawable *drawable = gfxPlatformGtk::GetGdkDrawable(surface); michael@0: if (!drawable) { michael@0: int depth = cairo_xlib_surface_get_depth(surface); michael@0: GdkScreen* screen = gdk_colormap_get_screen(mColormap); michael@0: drawable = michael@0: gdk_pixmap_foreign_new_for_screen(screen, cairo_xlib_surface_get_drawable(surface), michael@0: cairo_xlib_surface_get_width(surface), michael@0: cairo_xlib_surface_get_height(surface), michael@0: depth); michael@0: if (!drawable) michael@0: return NS_ERROR_FAILURE; michael@0: michael@0: gdk_drawable_set_colormap(drawable, mColormap); michael@0: gfxPlatformGtk::SetGdkDrawable(surface, drawable); michael@0: g_object_unref(drawable); // The drawable now belongs to |surface|. michael@0: } michael@0: michael@0: GdkRectangle clipRect; michael@0: if (numClipRects) { michael@0: NS_ASSERTION(numClipRects == 1, "Too many clip rects"); michael@0: clipRect.x = clipRects[0].x; michael@0: clipRect.y = clipRects[0].y; michael@0: clipRect.width = clipRects[0].width; michael@0: clipRect.height = clipRects[0].height; michael@0: } michael@0: michael@0: return DrawWithGDK(drawable, offset.x, offset.y, michael@0: numClipRects ? &clipRect : nullptr, numClipRects); michael@0: } michael@0: michael@0: void michael@0: gfxGdkNativeRenderer::Draw(gfxContext* ctx, nsIntSize size, michael@0: uint32_t flags, GdkColormap* colormap) michael@0: { michael@0: mColormap = colormap; michael@0: michael@0: Visual* visual = michael@0: gdk_x11_visual_get_xvisual(gdk_colormap_get_visual(colormap)); michael@0: Screen* screen = michael@0: gdk_x11_screen_get_xscreen(gdk_colormap_get_screen(colormap)); michael@0: michael@0: gfxXlibNativeRenderer::Draw(ctx, size, flags, screen, visual); michael@0: } michael@0: michael@0: #else michael@0: // TODO GTK3 michael@0: #endif michael@0: michael@0: #endif