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