1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/ipc/SharedDIB.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,77 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "SharedDIB.h" 1.10 + 1.11 +namespace mozilla { 1.12 +namespace gfx { 1.13 + 1.14 +SharedDIB::SharedDIB() : 1.15 + mShMem(nullptr) 1.16 +{ 1.17 +} 1.18 + 1.19 +SharedDIB::~SharedDIB() 1.20 +{ 1.21 + Close(); 1.22 +} 1.23 + 1.24 +nsresult 1.25 +SharedDIB::Create(uint32_t aSize) 1.26 +{ 1.27 + Close(); 1.28 + 1.29 + mShMem = new base::SharedMemory(); 1.30 + if (!mShMem || !mShMem->Create("", false, false, aSize)) 1.31 + return NS_ERROR_OUT_OF_MEMORY; 1.32 + 1.33 + return NS_OK; 1.34 +} 1.35 + 1.36 +bool 1.37 +SharedDIB::IsValid() 1.38 +{ 1.39 + if (!mShMem) 1.40 + return false; 1.41 + 1.42 + return mShMem->IsHandleValid(mShMem->handle()); 1.43 +} 1.44 + 1.45 +nsresult 1.46 +SharedDIB::Close() 1.47 +{ 1.48 + delete mShMem; 1.49 + 1.50 + mShMem = nullptr; 1.51 + 1.52 + return NS_OK; 1.53 +} 1.54 + 1.55 +nsresult 1.56 +SharedDIB::Attach(Handle aHandle, uint32_t aSize) 1.57 +{ 1.58 + Close(); 1.59 + 1.60 + mShMem = new base::SharedMemory(aHandle, false); 1.61 + if(!mShMem) 1.62 + return NS_ERROR_OUT_OF_MEMORY; 1.63 + 1.64 + return NS_OK; 1.65 +} 1.66 + 1.67 +nsresult 1.68 +SharedDIB::ShareToProcess(base::ProcessHandle aChildProcess, Handle *aChildHandle) 1.69 +{ 1.70 + if (!mShMem) 1.71 + return NS_ERROR_UNEXPECTED; 1.72 + 1.73 + if (!mShMem->ShareToProcess(aChildProcess, aChildHandle)) 1.74 + return NS_ERROR_UNEXPECTED; 1.75 + 1.76 + return NS_OK; 1.77 +} 1.78 + 1.79 +} // gfx 1.80 +} // mozilla