Line data Source 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/. */
5 :
6 : #include "SharedDIB.h"
7 :
8 : namespace mozilla {
9 : namespace gfx {
10 :
11 0 : SharedDIB::SharedDIB() :
12 0 : mShMem(nullptr)
13 : {
14 0 : }
15 :
16 0 : SharedDIB::~SharedDIB()
17 : {
18 0 : Close();
19 0 : }
20 :
21 : nsresult
22 0 : SharedDIB::Create(uint32_t aSize)
23 : {
24 0 : Close();
25 :
26 0 : mShMem = new base::SharedMemory();
27 0 : if (!mShMem || !mShMem->Create("", false, false, aSize))
28 0 : return NS_ERROR_OUT_OF_MEMORY;
29 :
30 0 : return NS_OK;
31 : }
32 :
33 : bool
34 0 : SharedDIB::IsValid()
35 : {
36 0 : if (!mShMem)
37 0 : return false;
38 :
39 0 : return mShMem->IsHandleValid(mShMem->handle());
40 : }
41 :
42 : nsresult
43 0 : SharedDIB::Close()
44 : {
45 0 : delete mShMem;
46 :
47 0 : mShMem = nullptr;
48 :
49 0 : return NS_OK;
50 : }
51 :
52 : nsresult
53 0 : SharedDIB::Attach(Handle aHandle, uint32_t aSize)
54 : {
55 0 : Close();
56 :
57 0 : mShMem = new base::SharedMemory(aHandle, false);
58 0 : if(!mShMem)
59 0 : return NS_ERROR_OUT_OF_MEMORY;
60 :
61 0 : return NS_OK;
62 : }
63 :
64 : nsresult
65 0 : SharedDIB::ShareToProcess(base::ProcessId aTargetPid, Handle *aNewHandle)
66 : {
67 0 : if (!mShMem)
68 0 : return NS_ERROR_UNEXPECTED;
69 :
70 0 : if (!mShMem->ShareToProcess(aTargetPid, aNewHandle))
71 0 : return NS_ERROR_UNEXPECTED;
72 :
73 0 : return NS_OK;
74 : }
75 :
76 : } // namespace gfx
77 : } // namespace mozilla
|