gfx/layers/ipc/ShadowLayerUtilsGralloc.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/layers/ipc/ShadowLayerUtilsGralloc.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,118 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * vim: sw=2 ts=8 et :
     1.6 + */
     1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
    1.10 +
    1.11 +#ifndef mozilla_layers_ShadowLayerUtilsGralloc_h
    1.12 +#define mozilla_layers_ShadowLayerUtilsGralloc_h
    1.13 +
    1.14 +#include <unistd.h>
    1.15 +#include <ui/GraphicBuffer.h>
    1.16 +
    1.17 +#include "ipc/IPCMessageUtils.h"
    1.18 +#include "mozilla/layers/PGrallocBufferChild.h"
    1.19 +#include "mozilla/layers/PGrallocBufferParent.h"
    1.20 +
    1.21 +#define MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
    1.22 +#define MOZ_HAVE_PLATFORM_SPECIFIC_LAYER_BUFFERS
    1.23 +
    1.24 +namespace mozilla {
    1.25 +namespace layers {
    1.26 +
    1.27 +class MaybeMagicGrallocBufferHandle;
    1.28 +class TextureHost;
    1.29 +
    1.30 +/**
    1.31 + * This class exists to share the underlying GraphicBuffer resources
    1.32 + * from one thread context to another.  This requires going through
    1.33 + * slow paths in the kernel so can be somewhat expensive.
    1.34 + *
    1.35 + * This is not just platform-specific, but also
    1.36 + * gralloc-implementation-specific.
    1.37 + */
    1.38 +struct MagicGrallocBufferHandle {
    1.39 +  typedef android::GraphicBuffer GraphicBuffer;
    1.40 +
    1.41 +  MagicGrallocBufferHandle()
    1.42 +  { }
    1.43 +
    1.44 +  MagicGrallocBufferHandle(const android::sp<GraphicBuffer>& aGraphicBuffer);
    1.45 +
    1.46 +  // Default copy ctor and operator= are OK
    1.47 +
    1.48 +  bool operator==(const MagicGrallocBufferHandle& aOther) const {
    1.49 +    return mGraphicBuffer == aOther.mGraphicBuffer;
    1.50 +  }
    1.51 +
    1.52 +  android::sp<GraphicBuffer> mGraphicBuffer;
    1.53 +};
    1.54 +
    1.55 +/**
    1.56 + * GrallocBufferActor is an "IPC wrapper" for an underlying
    1.57 + * GraphicBuffer (pmem region).  It allows us to cheaply and
    1.58 + * conveniently share gralloc handles between processes.
    1.59 + */
    1.60 +class GrallocBufferActor : public PGrallocBufferChild
    1.61 +                         , public PGrallocBufferParent
    1.62 +{
    1.63 +  friend class ShadowLayerForwarder;
    1.64 +  friend class LayerManagerComposite;
    1.65 +  friend class ImageBridgeChild;
    1.66 +  typedef android::GraphicBuffer GraphicBuffer;
    1.67 +
    1.68 +public:
    1.69 +  virtual ~GrallocBufferActor();
    1.70 +
    1.71 +  static PGrallocBufferParent*
    1.72 +  Create(const gfx::IntSize& aSize,
    1.73 +         const uint32_t& aFormat,
    1.74 +         const uint32_t& aUsage,
    1.75 +         MaybeMagicGrallocBufferHandle* aOutHandle);
    1.76 +
    1.77 +  static PGrallocBufferChild*
    1.78 +  Create();
    1.79 +
    1.80 +  // used only for hacky fix in gecko 23 for bug 862324
    1.81 +  // see bug 865908 about fixing this.
    1.82 +  void ActorDestroy(ActorDestroyReason why) MOZ_OVERRIDE;
    1.83 +
    1.84 +  void AddTextureHost(TextureHost* aTextureHost);
    1.85 +  void RemoveTextureHost();
    1.86 +
    1.87 +  android::GraphicBuffer* GetGraphicBuffer();
    1.88 +
    1.89 +  void InitFromHandle(const MagicGrallocBufferHandle& aHandle);
    1.90 +
    1.91 +private:
    1.92 +  GrallocBufferActor();
    1.93 +
    1.94 +  android::sp<GraphicBuffer> mGraphicBuffer;
    1.95 +
    1.96 +  // This value stores the number of bytes allocated in this
    1.97 +  // BufferActor. This will be used for the memory reporter.
    1.98 +  size_t mAllocBytes;
    1.99 +
   1.100 +  // Used only for hacky fix for bug 966446.
   1.101 +  TextureHost* mTextureHost;
   1.102 +
   1.103 +  friend class ISurfaceAllocator;
   1.104 +};
   1.105 +
   1.106 +} // namespace layers
   1.107 +} // namespace mozilla
   1.108 +
   1.109 +namespace IPC {
   1.110 +
   1.111 +template <>
   1.112 +struct ParamTraits<mozilla::layers::MagicGrallocBufferHandle> {
   1.113 +  typedef mozilla::layers::MagicGrallocBufferHandle paramType;
   1.114 +
   1.115 +  static void Write(Message* aMsg, const paramType& aParam);
   1.116 +  static bool Read(const Message* aMsg, void** aIter, paramType* aResult);
   1.117 +};
   1.118 +
   1.119 +} // namespace IPC
   1.120 +
   1.121 +#endif  // mozilla_layers_ShadowLayerUtilsGralloc_h

mercurial