1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set sw=2 ts=8 et tw=80 : */
/* 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/. */
#ifndef SharedBufferManagerCHILD_H_
#define SharedBufferManagerCHILD_H_
#include "mozilla/layers/PSharedBufferManagerChild.h"
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
#include "mozilla/Mutex.h"
#endif
namespace base {
class Thread;
}
namespace mozilla {
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
class Mutex;
#endif
namespace layers {
class SharedBufferManagerParent;
struct GrallocParam {
gfx::IntSize size;
uint32_t format;
uint32_t usage;
mozilla::layers::MaybeMagicGrallocBufferHandle* buffer;
GrallocParam(const gfx::IntSize& aSize,
const uint32_t& aFormat,
const uint32_t& aUsage,
mozilla::layers::MaybeMagicGrallocBufferHandle* aBuffer)
: size(aSize)
, format(aFormat)
, usage(aUsage)
, buffer(aBuffer)
{}
};
class SharedBufferManagerChild : public PSharedBufferManagerChild {
public:
SharedBufferManagerChild();
/**
* Creates the gralloc buffer manager with a dedicated thread for SharedBufferManagerChild.
*
* We may want to use a specific thread in the future. In this case, use
* CreateWithThread instead.
*/
static void StartUp();
static PSharedBufferManagerChild*
StartUpInChildProcess(Transport* aTransport, ProcessId aOtherProcess);
/**
* Creates the SharedBufferManagerChild manager protocol.
*/
static bool StartUpOnThread(base::Thread* aThread);
/**
* Destroys The SharedBufferManager protocol.
*
* The actual destruction happens synchronously on the SharedBufferManagerChild thread
* which means that if this function is called from another thread, the current
* thread will be paused until the destruction is done.
*/
static void DestroyManager();
/**
* Destroys the grallob buffer manager calling DestroyManager, and destroys the
* SharedBufferManager's thread.
*
* If you don't want to destroy the thread, call DestroyManager directly
* instead.
*/
static void ShutDown();
/**
* returns the singleton instance.
*
* can be called from any thread.
*/
static SharedBufferManagerChild* GetSingleton();
/**
* Dispatches a task to the SharedBufferManagerChild thread to do the connection
*/
void ConnectAsync(SharedBufferManagerParent* aParent);
/**
* Allocate GrallocBuffer remotely.
*/
bool
AllocGrallocBuffer(const gfx::IntSize&, const uint32_t&, const uint32_t&, mozilla::layers::MaybeMagicGrallocBufferHandle*);
/**
* Deallocate a remotely allocated gralloc buffer.
* As gralloc buffer life cycle controlled by sp, this just break the sharing status of the underlying buffer
* and decrease the reference count on both side.
*/
void
DeallocGrallocBuffer(const mozilla::layers::MaybeMagicGrallocBufferHandle& aBuffer);
void
DropGrallocBuffer(const mozilla::layers::MaybeMagicGrallocBufferHandle& aHandle);
virtual bool RecvDropGrallocBuffer(const mozilla::layers::MaybeMagicGrallocBufferHandle& aHandle);
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
android::sp<android::GraphicBuffer> GetGraphicBuffer(int64_t key);
#endif
bool IsValidKey(int64_t key);
base::Thread* GetThread() const;
MessageLoop* GetMessageLoop() const;
static bool IsCreated();
static base::Thread* sSharedBufferManagerChildThread;
static SharedBufferManagerChild* sSharedBufferManagerChildSingleton;
static SharedBufferManagerParent* sSharedBufferManagerParentSingleton; // Only available in Chrome process
protected:
/**
* Part of the allocation of gralloc SurfaceDescriptor that is
* executed on the SharedBufferManagerChild thread after invoking
* AllocSurfaceDescriptorGralloc.
*
* Must be called from the SharedBufferManagerChild thread.
*/
bool
AllocGrallocBufferNow(const gfx::IntSize& aSize,
const uint32_t& aFormat,
const uint32_t& aUsage,
mozilla::layers::MaybeMagicGrallocBufferHandle* aBuffer);
// Dispatched function
static void
AllocGrallocBufferSync(const GrallocParam& aParam,
Monitor* aBarrier,
bool* aDone);
/**
* Part of the deallocation of gralloc SurfaceDescriptor that is
* executed on the SharedBufferManagerChild thread after invoking
* DeallocSurfaceDescriptorGralloc.
*
* Must be called from the SharedBufferManagerChild thread.
*/
void
DeallocGrallocBufferNow(const mozilla::layers::MaybeMagicGrallocBufferHandle& handle);
// dispatched function
static void
DeallocGrallocBufferSync(const mozilla::layers::MaybeMagicGrallocBufferHandle& handle);
#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
std::map<int64_t, android::sp<android::GraphicBuffer> > mBuffers;
Mutex mBufferMutex;
#endif
};
} /* namespace layers */
} /* namespace mozilla */
#endif /* SharedBufferManagerCHILD_H_*/
|