gfx/ipc/SharedDIB.cpp

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

     1 /* -*- Mode: C++; tab-width: 2; 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 "SharedDIB.h"
     8 namespace mozilla {
     9 namespace gfx {
    11 SharedDIB::SharedDIB() :
    12   mShMem(nullptr)
    13 {
    14 }
    16 SharedDIB::~SharedDIB()
    17 {
    18   Close();
    19 }
    21 nsresult
    22 SharedDIB::Create(uint32_t aSize)
    23 {
    24   Close();
    26   mShMem = new base::SharedMemory();
    27   if (!mShMem || !mShMem->Create("", false, false, aSize))
    28     return NS_ERROR_OUT_OF_MEMORY;
    30   return NS_OK;
    31 }
    33 bool
    34 SharedDIB::IsValid()
    35 {
    36   if (!mShMem)
    37     return false;
    39   return mShMem->IsHandleValid(mShMem->handle());
    40 }
    42 nsresult
    43 SharedDIB::Close()
    44 {
    45   delete mShMem;
    47   mShMem = nullptr;
    49   return NS_OK;
    50 }
    52 nsresult
    53 SharedDIB::Attach(Handle aHandle, uint32_t aSize)
    54 {
    55   Close();
    57   mShMem = new base::SharedMemory(aHandle, false);
    58   if(!mShMem)
    59     return NS_ERROR_OUT_OF_MEMORY;
    61   return NS_OK;
    62 }
    64 nsresult
    65 SharedDIB::ShareToProcess(base::ProcessHandle aChildProcess, Handle *aChildHandle)
    66 {
    67   if (!mShMem)
    68     return NS_ERROR_UNEXPECTED;
    70   if (!mShMem->ShareToProcess(aChildProcess, aChildHandle))
    71     return NS_ERROR_UNEXPECTED;
    73   return NS_OK;
    74 }
    76 } // gfx
    77 } // mozilla

mercurial