gfx/ipc/SharedDIBSurface.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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 "SharedDIBSurface.h"
michael@0 7
michael@0 8 #include "cairo.h"
michael@0 9
michael@0 10 namespace mozilla {
michael@0 11 namespace gfx {
michael@0 12
michael@0 13 static const cairo_user_data_key_t SHAREDDIB_KEY = {0};
michael@0 14
michael@0 15 static const long kBytesPerPixel = 4;
michael@0 16
michael@0 17 bool
michael@0 18 SharedDIBSurface::Create(HDC adc, uint32_t aWidth, uint32_t aHeight,
michael@0 19 bool aTransparent)
michael@0 20 {
michael@0 21 nsresult rv = mSharedDIB.Create(adc, aWidth, aHeight, aTransparent);
michael@0 22 if (NS_FAILED(rv) || !mSharedDIB.IsValid())
michael@0 23 return false;
michael@0 24
michael@0 25 InitSurface(aWidth, aHeight, aTransparent);
michael@0 26 return true;
michael@0 27 }
michael@0 28
michael@0 29 bool
michael@0 30 SharedDIBSurface::Attach(Handle aHandle, uint32_t aWidth, uint32_t aHeight,
michael@0 31 bool aTransparent)
michael@0 32 {
michael@0 33 nsresult rv = mSharedDIB.Attach(aHandle, aWidth, aHeight, aTransparent);
michael@0 34 if (NS_FAILED(rv) || !mSharedDIB.IsValid())
michael@0 35 return false;
michael@0 36
michael@0 37 InitSurface(aWidth, aHeight, aTransparent);
michael@0 38 return true;
michael@0 39 }
michael@0 40
michael@0 41 void
michael@0 42 SharedDIBSurface::InitSurface(uint32_t aWidth, uint32_t aHeight,
michael@0 43 bool aTransparent)
michael@0 44 {
michael@0 45 long stride = long(aWidth * kBytesPerPixel);
michael@0 46 unsigned char* data = reinterpret_cast<unsigned char*>(mSharedDIB.GetBits());
michael@0 47
michael@0 48 gfxImageFormat format = aTransparent ? gfxImageFormat::ARGB32 : gfxImageFormat::RGB24;
michael@0 49
michael@0 50 gfxImageSurface::InitWithData(data, gfxIntSize(aWidth, aHeight),
michael@0 51 stride, format);
michael@0 52
michael@0 53 cairo_surface_set_user_data(mSurface, &SHAREDDIB_KEY, this, nullptr);
michael@0 54 }
michael@0 55
michael@0 56 bool
michael@0 57 SharedDIBSurface::IsSharedDIBSurface(gfxASurface* aSurface)
michael@0 58 {
michael@0 59 return aSurface &&
michael@0 60 aSurface->GetType() == gfxSurfaceType::Image &&
michael@0 61 aSurface->GetData(&SHAREDDIB_KEY);
michael@0 62 }
michael@0 63
michael@0 64 } // namespace gfx
michael@0 65 } // namespace mozilla

mercurial