Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/ipc/SharedDIB.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "SharedDIB.h"
8
9
namespace mozilla {
10
namespace gfx {
11
12
SharedDIB::SharedDIB() :
13
  mShMem(nullptr)
14
0
{
15
0
}
16
17
SharedDIB::~SharedDIB()
18
0
{
19
0
  Close();
20
0
}
21
22
nsresult
23
SharedDIB::Create(uint32_t aSize)
24
0
{
25
0
  Close();
26
0
27
0
  mShMem = new base::SharedMemory();
28
0
  if (!mShMem || !mShMem->Create(aSize))
29
0
    return NS_ERROR_OUT_OF_MEMORY;
30
0
31
0
  return NS_OK;
32
0
}
33
34
bool
35
SharedDIB::IsValid()
36
0
{
37
0
  if (!mShMem)
38
0
    return false;
39
0
40
0
  return base::SharedMemory::IsHandleValid(mShMem->handle());
41
0
}
42
43
nsresult
44
SharedDIB::Close()
45
0
{
46
0
  delete mShMem;
47
0
48
0
  mShMem = nullptr;
49
0
50
0
  return NS_OK;
51
0
}
52
53
nsresult
54
SharedDIB::Attach(Handle aHandle, uint32_t aSize)
55
0
{
56
0
  Close();
57
0
58
0
  mShMem = new base::SharedMemory(aHandle, false);
59
0
  if(!mShMem)
60
0
    return NS_ERROR_OUT_OF_MEMORY;
61
0
62
0
  return NS_OK;
63
0
}
64
65
nsresult
66
SharedDIB::ShareToProcess(base::ProcessId aTargetPid, Handle *aNewHandle)
67
0
{
68
0
  if (!mShMem)
69
0
    return NS_ERROR_UNEXPECTED;
70
0
71
0
  if (!mShMem->ShareToProcess(aTargetPid, aNewHandle))
72
0
    return NS_ERROR_UNEXPECTED;
73
0
74
0
  return NS_OK;
75
0
}
76
77
} // namespace gfx
78
} // namespace mozilla