gfx/thebes/gfxD2DSurface.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

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.

     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/. */
     6 #include "gfxD2DSurface.h"
     7 #include "cairo.h"
     8 #include "cairo-win32.h"
     9 #include "gfxWindowsPlatform.h"
    11 gfxD2DSurface::gfxD2DSurface(HWND aWnd, gfxContentType aContent)
    12 {
    13     Init(cairo_d2d_surface_create_for_hwnd(
    14         gfxWindowsPlatform::GetPlatform()->GetD2DDevice(),
    15         aWnd,
    16         (cairo_content_t)(int)aContent));
    17 }
    19 gfxD2DSurface::gfxD2DSurface(HANDLE handle, gfxContentType aContent)
    20 {
    21     Init(cairo_d2d_surface_create_for_handle(
    22         gfxWindowsPlatform::GetPlatform()->GetD2DDevice(),
    23         handle,
    24 	(cairo_content_t)(int)aContent));
    25 }
    27 gfxD2DSurface::gfxD2DSurface(ID3D10Texture2D *texture, gfxContentType aContent)
    28 {
    29     Init(cairo_d2d_surface_create_for_texture(
    30         gfxWindowsPlatform::GetPlatform()->GetD2DDevice(),
    31         texture,
    32 	(cairo_content_t)(int)aContent));
    33 }
    35 gfxD2DSurface::gfxD2DSurface(cairo_surface_t *csurf)
    36 {
    37     Init(csurf, true);
    38 }
    40 gfxD2DSurface::gfxD2DSurface(const gfxIntSize& size,
    41                              gfxImageFormat imageFormat)
    42 {
    43     Init(cairo_d2d_surface_create(
    44         gfxWindowsPlatform::GetPlatform()->GetD2DDevice(),
    45         (cairo_format_t)(int)imageFormat,
    46         size.width, size.height));
    47 }
    49 gfxD2DSurface::~gfxD2DSurface()
    50 {
    51 }
    53 void
    54 gfxD2DSurface::Present()
    55 {
    56     cairo_d2d_present_backbuffer(CairoSurface());
    57 }
    59 void
    60 gfxD2DSurface::Scroll(const nsIntPoint &aDelta, const nsIntRect &aClip)
    61 {
    62     cairo_rectangle_t rect;
    63     rect.x = aClip.x;
    64     rect.y = aClip.y;
    65     rect.width = aClip.width;
    66     rect.height = aClip.height;
    67     cairo_d2d_scroll(CairoSurface(), aDelta.x, aDelta.y, &rect);
    68 }
    70 ID3D10Texture2D*
    71 gfxD2DSurface::GetTexture()
    72 {
    73   return cairo_d2d_surface_get_texture(CairoSurface());
    74 }
    76 HDC
    77 gfxD2DSurface::GetDC(bool aRetainContents)
    78 {
    79     return cairo_d2d_get_dc(CairoSurface(), aRetainContents);
    80 }
    82 void
    83 gfxD2DSurface::ReleaseDC(const nsIntRect *aUpdatedRect)
    84 {
    85     if (!aUpdatedRect) {
    86         return cairo_d2d_release_dc(CairoSurface(), nullptr);
    87     }
    89     cairo_rectangle_int_t rect;
    90     rect.x = aUpdatedRect->x;
    91     rect.y = aUpdatedRect->y;
    92     rect.width = aUpdatedRect->width;
    93     rect.height = aUpdatedRect->height;
    94     cairo_d2d_release_dc(CairoSurface(), &rect);
    95 }
    97 const gfxIntSize gfxD2DSurface::GetSize() const
    98 { 
    99     return gfxIntSize(cairo_d2d_surface_get_width(mSurface),
   100                       cairo_d2d_surface_get_height(mSurface));
   101 }

mercurial