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