gfx/thebes/gfxReusableImageSurfaceWrapper.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 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     3  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #include "gfxReusableImageSurfaceWrapper.h"
     6 #include "gfxImageSurface.h"
     8 gfxReusableImageSurfaceWrapper::gfxReusableImageSurfaceWrapper(gfxImageSurface* aSurface)
     9   : mSurface(aSurface)
    10 {
    11   MOZ_COUNT_CTOR(gfxReusableImageSurfaceWrapper);
    12 }
    14 gfxReusableImageSurfaceWrapper::~gfxReusableImageSurfaceWrapper()
    15 {
    16   MOZ_COUNT_DTOR(gfxReusableImageSurfaceWrapper);
    17 }
    19 void
    20 gfxReusableImageSurfaceWrapper::ReadLock()
    21 {
    22   NS_ASSERT_OWNINGTHREAD(gfxReusableImageSurfaceWrapper);
    23   AddRef();
    24 }
    26 void
    27 gfxReusableImageSurfaceWrapper::ReadUnlock()
    28 {
    29   Release();
    30 }
    32 gfxReusableSurfaceWrapper*
    33 gfxReusableImageSurfaceWrapper::GetWritable(gfxImageSurface** aSurface)
    34 {
    35   NS_ASSERT_OWNINGTHREAD(gfxReusableImageSurfaceWrapper);
    37   if (mRefCnt == 1) {
    38     *aSurface = mSurface;
    39     return this;
    40   }
    42   // Something else is reading the surface, copy it
    43   gfxImageSurface* copySurface = new gfxImageSurface(mSurface->GetSize(), mSurface->Format(), false);
    44   copySurface->CopyFrom(mSurface);
    45   *aSurface = copySurface;
    47   return new gfxReusableImageSurfaceWrapper(copySurface);
    48 }
    50 const unsigned char*
    51 gfxReusableImageSurfaceWrapper::GetReadOnlyData() const
    52 {
    53   return mSurface->Data();
    54 }
    56 gfxImageFormat
    57 gfxReusableImageSurfaceWrapper::Format()
    58 {
    59   return mSurface->Format();
    60 }

mercurial