gfx/thebes/gfxGdkNativeRenderer.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/thebes/gfxGdkNativeRenderer.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,69 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "gfxGdkNativeRenderer.h"
    1.10 +#include "gfxContext.h"
    1.11 +#include "gfxPlatformGtk.h"
    1.12 +
    1.13 +#ifdef MOZ_X11
    1.14 +#include <gdk/gdkx.h>
    1.15 +#include "cairo-xlib.h"
    1.16 +#include "gfxXlibSurface.h"
    1.17 +
    1.18 +#if (MOZ_WIDGET_GTK == 2)
    1.19 +nsresult
    1.20 +gfxGdkNativeRenderer::DrawWithXlib(cairo_surface_t* surface,
    1.21 +                                   nsIntPoint offset,
    1.22 +                                   nsIntRect* clipRects, uint32_t numClipRects)
    1.23 +{
    1.24 +    GdkDrawable *drawable = gfxPlatformGtk::GetGdkDrawable(surface);
    1.25 +    if (!drawable) {
    1.26 +        int depth = cairo_xlib_surface_get_depth(surface);
    1.27 +        GdkScreen* screen = gdk_colormap_get_screen(mColormap);
    1.28 +        drawable =
    1.29 +            gdk_pixmap_foreign_new_for_screen(screen, cairo_xlib_surface_get_drawable(surface),
    1.30 +                                              cairo_xlib_surface_get_width(surface),
    1.31 +                                              cairo_xlib_surface_get_height(surface),
    1.32 +                                              depth);
    1.33 +        if (!drawable)
    1.34 +            return NS_ERROR_FAILURE;
    1.35 +
    1.36 +        gdk_drawable_set_colormap(drawable, mColormap);
    1.37 +        gfxPlatformGtk::SetGdkDrawable(surface, drawable);
    1.38 +        g_object_unref(drawable); // The drawable now belongs to |surface|.
    1.39 +    }
    1.40 +    
    1.41 +    GdkRectangle clipRect;
    1.42 +    if (numClipRects) {
    1.43 +        NS_ASSERTION(numClipRects == 1, "Too many clip rects");
    1.44 +        clipRect.x = clipRects[0].x;
    1.45 +        clipRect.y = clipRects[0].y;
    1.46 +        clipRect.width = clipRects[0].width;
    1.47 +        clipRect.height = clipRects[0].height;
    1.48 +    }
    1.49 +
    1.50 +    return DrawWithGDK(drawable, offset.x, offset.y,
    1.51 +                       numClipRects ? &clipRect : nullptr, numClipRects);
    1.52 +}
    1.53 +
    1.54 +void
    1.55 +gfxGdkNativeRenderer::Draw(gfxContext* ctx, nsIntSize size,
    1.56 +                           uint32_t flags, GdkColormap* colormap)
    1.57 +{
    1.58 +    mColormap = colormap;
    1.59 +
    1.60 +    Visual* visual =
    1.61 +        gdk_x11_visual_get_xvisual(gdk_colormap_get_visual(colormap));
    1.62 +    Screen* screen =
    1.63 +        gdk_x11_screen_get_xscreen(gdk_colormap_get_screen(colormap));
    1.64 +
    1.65 +    gfxXlibNativeRenderer::Draw(ctx, size, flags, screen, visual);
    1.66 +}
    1.67 +
    1.68 +#else
    1.69 +// TODO GTK3
    1.70 +#endif
    1.71 +
    1.72 +#endif

mercurial