michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * vim: sw=2 ts=8 et : michael@0: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_layers_ShadowLayerUtilsGralloc_h michael@0: #define mozilla_layers_ShadowLayerUtilsGralloc_h michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #include "ipc/IPCMessageUtils.h" michael@0: #include "mozilla/layers/PGrallocBufferChild.h" michael@0: #include "mozilla/layers/PGrallocBufferParent.h" michael@0: michael@0: #define MOZ_HAVE_SURFACEDESCRIPTORGRALLOC michael@0: #define MOZ_HAVE_PLATFORM_SPECIFIC_LAYER_BUFFERS michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: michael@0: class MaybeMagicGrallocBufferHandle; michael@0: class TextureHost; michael@0: michael@0: /** michael@0: * This class exists to share the underlying GraphicBuffer resources michael@0: * from one thread context to another. This requires going through michael@0: * slow paths in the kernel so can be somewhat expensive. michael@0: * michael@0: * This is not just platform-specific, but also michael@0: * gralloc-implementation-specific. michael@0: */ michael@0: struct MagicGrallocBufferHandle { michael@0: typedef android::GraphicBuffer GraphicBuffer; michael@0: michael@0: MagicGrallocBufferHandle() michael@0: { } michael@0: michael@0: MagicGrallocBufferHandle(const android::sp& aGraphicBuffer); michael@0: michael@0: // Default copy ctor and operator= are OK michael@0: michael@0: bool operator==(const MagicGrallocBufferHandle& aOther) const { michael@0: return mGraphicBuffer == aOther.mGraphicBuffer; michael@0: } michael@0: michael@0: android::sp mGraphicBuffer; michael@0: }; michael@0: michael@0: /** michael@0: * GrallocBufferActor is an "IPC wrapper" for an underlying michael@0: * GraphicBuffer (pmem region). It allows us to cheaply and michael@0: * conveniently share gralloc handles between processes. michael@0: */ michael@0: class GrallocBufferActor : public PGrallocBufferChild michael@0: , public PGrallocBufferParent michael@0: { michael@0: friend class ShadowLayerForwarder; michael@0: friend class LayerManagerComposite; michael@0: friend class ImageBridgeChild; michael@0: typedef android::GraphicBuffer GraphicBuffer; michael@0: michael@0: public: michael@0: virtual ~GrallocBufferActor(); michael@0: michael@0: static PGrallocBufferParent* michael@0: Create(const gfx::IntSize& aSize, michael@0: const uint32_t& aFormat, michael@0: const uint32_t& aUsage, michael@0: MaybeMagicGrallocBufferHandle* aOutHandle); michael@0: michael@0: static PGrallocBufferChild* michael@0: Create(); michael@0: michael@0: // used only for hacky fix in gecko 23 for bug 862324 michael@0: // see bug 865908 about fixing this. michael@0: void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE; michael@0: michael@0: void AddTextureHost(TextureHost* aTextureHost); michael@0: void RemoveTextureHost(); michael@0: michael@0: android::GraphicBuffer* GetGraphicBuffer(); michael@0: michael@0: void InitFromHandle(const MagicGrallocBufferHandle& aHandle); michael@0: michael@0: private: michael@0: GrallocBufferActor(); michael@0: michael@0: android::sp mGraphicBuffer; michael@0: michael@0: // This value stores the number of bytes allocated in this michael@0: // BufferActor. This will be used for the memory reporter. michael@0: size_t mAllocBytes; michael@0: michael@0: // Used only for hacky fix for bug 966446. michael@0: TextureHost* mTextureHost; michael@0: michael@0: friend class ISurfaceAllocator; michael@0: }; michael@0: michael@0: } // namespace layers michael@0: } // namespace mozilla michael@0: michael@0: namespace IPC { michael@0: michael@0: template <> michael@0: struct ParamTraits { michael@0: typedef mozilla::layers::MagicGrallocBufferHandle paramType; michael@0: michael@0: static void Write(Message* aMsg, const paramType& aParam); michael@0: static bool Read(const Message* aMsg, void** aIter, paramType* aResult); michael@0: }; michael@0: michael@0: } // namespace IPC michael@0: michael@0: #endif // mozilla_layers_ShadowLayerUtilsGralloc_h