|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 * vim: sw=2 ts=8 et : |
|
3 */ |
|
4 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
5 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
7 |
|
8 #ifndef mozilla_layers_ShadowLayerUtilsGralloc_h |
|
9 #define mozilla_layers_ShadowLayerUtilsGralloc_h |
|
10 |
|
11 #include <unistd.h> |
|
12 #include <ui/GraphicBuffer.h> |
|
13 |
|
14 #include "ipc/IPCMessageUtils.h" |
|
15 #include "mozilla/layers/PGrallocBufferChild.h" |
|
16 #include "mozilla/layers/PGrallocBufferParent.h" |
|
17 |
|
18 #define MOZ_HAVE_SURFACEDESCRIPTORGRALLOC |
|
19 #define MOZ_HAVE_PLATFORM_SPECIFIC_LAYER_BUFFERS |
|
20 |
|
21 namespace mozilla { |
|
22 namespace layers { |
|
23 |
|
24 class MaybeMagicGrallocBufferHandle; |
|
25 class TextureHost; |
|
26 |
|
27 /** |
|
28 * This class exists to share the underlying GraphicBuffer resources |
|
29 * from one thread context to another. This requires going through |
|
30 * slow paths in the kernel so can be somewhat expensive. |
|
31 * |
|
32 * This is not just platform-specific, but also |
|
33 * gralloc-implementation-specific. |
|
34 */ |
|
35 struct MagicGrallocBufferHandle { |
|
36 typedef android::GraphicBuffer GraphicBuffer; |
|
37 |
|
38 MagicGrallocBufferHandle() |
|
39 { } |
|
40 |
|
41 MagicGrallocBufferHandle(const android::sp<GraphicBuffer>& aGraphicBuffer); |
|
42 |
|
43 // Default copy ctor and operator= are OK |
|
44 |
|
45 bool operator==(const MagicGrallocBufferHandle& aOther) const { |
|
46 return mGraphicBuffer == aOther.mGraphicBuffer; |
|
47 } |
|
48 |
|
49 android::sp<GraphicBuffer> mGraphicBuffer; |
|
50 }; |
|
51 |
|
52 /** |
|
53 * GrallocBufferActor is an "IPC wrapper" for an underlying |
|
54 * GraphicBuffer (pmem region). It allows us to cheaply and |
|
55 * conveniently share gralloc handles between processes. |
|
56 */ |
|
57 class GrallocBufferActor : public PGrallocBufferChild |
|
58 , public PGrallocBufferParent |
|
59 { |
|
60 friend class ShadowLayerForwarder; |
|
61 friend class LayerManagerComposite; |
|
62 friend class ImageBridgeChild; |
|
63 typedef android::GraphicBuffer GraphicBuffer; |
|
64 |
|
65 public: |
|
66 virtual ~GrallocBufferActor(); |
|
67 |
|
68 static PGrallocBufferParent* |
|
69 Create(const gfx::IntSize& aSize, |
|
70 const uint32_t& aFormat, |
|
71 const uint32_t& aUsage, |
|
72 MaybeMagicGrallocBufferHandle* aOutHandle); |
|
73 |
|
74 static PGrallocBufferChild* |
|
75 Create(); |
|
76 |
|
77 // used only for hacky fix in gecko 23 for bug 862324 |
|
78 // see bug 865908 about fixing this. |
|
79 void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE; |
|
80 |
|
81 void AddTextureHost(TextureHost* aTextureHost); |
|
82 void RemoveTextureHost(); |
|
83 |
|
84 android::GraphicBuffer* GetGraphicBuffer(); |
|
85 |
|
86 void InitFromHandle(const MagicGrallocBufferHandle& aHandle); |
|
87 |
|
88 private: |
|
89 GrallocBufferActor(); |
|
90 |
|
91 android::sp<GraphicBuffer> mGraphicBuffer; |
|
92 |
|
93 // This value stores the number of bytes allocated in this |
|
94 // BufferActor. This will be used for the memory reporter. |
|
95 size_t mAllocBytes; |
|
96 |
|
97 // Used only for hacky fix for bug 966446. |
|
98 TextureHost* mTextureHost; |
|
99 |
|
100 friend class ISurfaceAllocator; |
|
101 }; |
|
102 |
|
103 } // namespace layers |
|
104 } // namespace mozilla |
|
105 |
|
106 namespace IPC { |
|
107 |
|
108 template <> |
|
109 struct ParamTraits<mozilla::layers::MagicGrallocBufferHandle> { |
|
110 typedef mozilla::layers::MagicGrallocBufferHandle paramType; |
|
111 |
|
112 static void Write(Message* aMsg, const paramType& aParam); |
|
113 static bool Read(const Message* aMsg, void** aIter, paramType* aResult); |
|
114 }; |
|
115 |
|
116 } // namespace IPC |
|
117 |
|
118 #endif // mozilla_layers_ShadowLayerUtilsGralloc_h |