1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #include "gfxGdkNativeRenderer.h"
7 #include "gfxContext.h"
8 #include "gfxPlatformGtk.h"
9
10 #ifdef MOZ_X11
11 #include <gdk/gdkx.h>
12 #include "cairo-xlib.h"
13 #include "gfxXlibSurface.h"
14
15 #if (MOZ_WIDGET_GTK == 2)
16 nsresult
DrawWithXlib(cairo_surface_t * surface,nsIntPoint offset,mozilla::gfx::IntRect * clipRects,uint32_t numClipRects)17 gfxGdkNativeRenderer::DrawWithXlib(cairo_surface_t* surface,
18 nsIntPoint offset,
19 mozilla::gfx::IntRect* clipRects, uint32_t numClipRects)
20 {
21 GdkDrawable *drawable = gfxPlatformGtk::GetGdkDrawable(surface);
22 if (!drawable) {
23 int depth = cairo_xlib_surface_get_depth(surface);
24 GdkScreen* screen = gdk_colormap_get_screen(mColormap);
25 drawable =
26 gdk_pixmap_foreign_new_for_screen(screen, cairo_xlib_surface_get_drawable(surface),
27 cairo_xlib_surface_get_width(surface),
28 cairo_xlib_surface_get_height(surface),
29 depth);
30 if (!drawable)
31 return NS_ERROR_FAILURE;
32
33 gdk_drawable_set_colormap(drawable, mColormap);
34 gfxPlatformGtk::SetGdkDrawable(surface, drawable);
35 g_object_unref(drawable); // The drawable now belongs to |surface|.
36 }
37
38 GdkRectangle clipRect;
39 if (numClipRects) {
40 NS_ASSERTION(numClipRects == 1, "Too many clip rects");
41 clipRect.x = clipRects[0].x;
42 clipRect.y = clipRects[0].y;
43 clipRect.width = clipRects[0].width;
44 clipRect.height = clipRects[0].height;
45 }
46
47 return DrawWithGDK(drawable, offset.x, offset.y,
48 numClipRects ? &clipRect : nullptr, numClipRects);
49 }
50
51 void
Draw(gfxContext * ctx,mozilla::gfx::IntSize size,uint32_t flags,GdkColormap * colormap)52 gfxGdkNativeRenderer::Draw(gfxContext* ctx, mozilla::gfx::IntSize size,
53 uint32_t flags, GdkColormap* colormap)
54 {
55 mColormap = colormap;
56
57 Visual* visual =
58 gdk_x11_visual_get_xvisual(gdk_colormap_get_visual(colormap));
59 Screen* screen =
60 gdk_x11_screen_get_xscreen(gdk_colormap_get_screen(colormap));
61
62 gfxXlibNativeRenderer::Draw(ctx, size, flags, screen, visual);
63 }
64
65 #else
66 // TODO GTK3
67 #endif
68
69 #endif
70