gfx/layers/MacIOSurfaceImage.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: 2 -*-
     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 "MacIOSurfaceImage.h"
     7 #include "mozilla/layers/MacIOSurfaceTextureClientOGL.h"
     9 using namespace mozilla;
    10 using namespace mozilla::layers;
    12 TextureClient*
    13 MacIOSurfaceImage::GetTextureClient(CompositableClient* aClient)
    14 {
    15   if (!mTextureClient) {
    16     RefPtr<MacIOSurfaceTextureClientOGL> buffer =
    17       new MacIOSurfaceTextureClientOGL(TEXTURE_FLAGS_DEFAULT);
    18     buffer->InitWith(mSurface);
    19     mTextureClient = buffer;
    20   }
    21   return mTextureClient;
    22 }
    24 TemporaryRef<gfx::SourceSurface>
    25 MacIOSurfaceImage::GetAsSourceSurface()
    26 {
    27   mSurface->Lock();
    28   size_t bytesPerRow = mSurface->GetBytesPerRow();
    29   size_t ioWidth = mSurface->GetDevicePixelWidth();
    30   size_t ioHeight = mSurface->GetDevicePixelHeight();
    32   unsigned char* ioData = (unsigned char*)mSurface->GetBaseAddress();
    34   RefPtr<gfx::DataSourceSurface> dataSurface
    35     = gfx::Factory::CreateDataSourceSurface(gfx::IntSize(ioWidth, ioHeight), gfx::SurfaceFormat::B8G8R8A8);
    36   if (!dataSurface)
    37     return nullptr;
    39   gfx::DataSourceSurface::MappedSurface mappedSurface;
    40   if (!dataSurface->Map(gfx::DataSourceSurface::WRITE, &mappedSurface))
    41     return nullptr;
    43   for (size_t i = 0; i < ioHeight; ++i) {
    44     memcpy(mappedSurface.mData + i * mappedSurface.mStride,
    45            ioData + i * bytesPerRow,
    46            ioWidth * 4);
    47   }
    49   dataSurface->Unmap();
    50   mSurface->Unlock();
    52   return dataSurface;
    53 }

mercurial