gfx/ipc/SharedDIB.cpp
author Sebastian Kaspari <s.kaspari@gmail.com>
Tue, 27 Oct 2015 10:47:03 +0100
changeset 307700 ee8a828b497498c8a4325e3007197c75af931c3b
parent 278243 91d6e262b662a0b4e47358665e222d3927337af9
child 489668 cbb8fdf1daf98a15f7d57f6b08d273bdf96aa1a0
child 648192 c236dfe7dc98c387219d7cb45d0693560db708fd
child 687971 dc30e631d685e07adfb984cb8aa61eb4bb65e5f7
permissions -rw-r--r--
Bug 1182918 - Tab Queue: Add telemetry for double tap action. r=mfinkle, a=sylvestre

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "SharedDIB.h"

namespace mozilla {
namespace gfx {

SharedDIB::SharedDIB() :
  mShMem(nullptr)
{
}

SharedDIB::~SharedDIB()
{
  Close();
}

nsresult
SharedDIB::Create(uint32_t aSize)
{
  Close();

  mShMem = new base::SharedMemory();
  if (!mShMem || !mShMem->Create("", false, false, aSize))
    return NS_ERROR_OUT_OF_MEMORY;

  return NS_OK;
}

bool
SharedDIB::IsValid()
{
  if (!mShMem)
    return false;

  return mShMem->IsHandleValid(mShMem->handle());
}

nsresult
SharedDIB::Close()
{
  delete mShMem;

  mShMem = nullptr;

  return NS_OK;
}

nsresult
SharedDIB::Attach(Handle aHandle, uint32_t aSize)
{
  Close();

  mShMem = new base::SharedMemory(aHandle, false);
  if(!mShMem)
    return NS_ERROR_OUT_OF_MEMORY;

  return NS_OK;
}

nsresult
SharedDIB::ShareToProcess(base::ProcessId aTargetPid, Handle *aNewHandle)
{
  if (!mShMem)
    return NS_ERROR_UNEXPECTED;

  if (!mShMem->ShareToProcess(aTargetPid, aNewHandle))
    return NS_ERROR_UNEXPECTED;

  return NS_OK;
}

} // namespace gfx
} // namespace mozilla