gfx/layers/ipc/ShadowLayerUtilsGralloc.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     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/. */
     8 #ifndef mozilla_layers_ShadowLayerUtilsGralloc_h
     9 #define mozilla_layers_ShadowLayerUtilsGralloc_h
    11 #include <unistd.h>
    12 #include <ui/GraphicBuffer.h>
    14 #include "ipc/IPCMessageUtils.h"
    15 #include "mozilla/layers/PGrallocBufferChild.h"
    16 #include "mozilla/layers/PGrallocBufferParent.h"
    18 #define MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
    19 #define MOZ_HAVE_PLATFORM_SPECIFIC_LAYER_BUFFERS
    21 namespace mozilla {
    22 namespace layers {
    24 class MaybeMagicGrallocBufferHandle;
    25 class TextureHost;
    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;
    38   MagicGrallocBufferHandle()
    39   { }
    41   MagicGrallocBufferHandle(const android::sp<GraphicBuffer>& aGraphicBuffer);
    43   // Default copy ctor and operator= are OK
    45   bool operator==(const MagicGrallocBufferHandle& aOther) const {
    46     return mGraphicBuffer == aOther.mGraphicBuffer;
    47   }
    49   android::sp<GraphicBuffer> mGraphicBuffer;
    50 };
    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;
    65 public:
    66   virtual ~GrallocBufferActor();
    68   static PGrallocBufferParent*
    69   Create(const gfx::IntSize& aSize,
    70          const uint32_t& aFormat,
    71          const uint32_t& aUsage,
    72          MaybeMagicGrallocBufferHandle* aOutHandle);
    74   static PGrallocBufferChild*
    75   Create();
    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;
    81   void AddTextureHost(TextureHost* aTextureHost);
    82   void RemoveTextureHost();
    84   android::GraphicBuffer* GetGraphicBuffer();
    86   void InitFromHandle(const MagicGrallocBufferHandle& aHandle);
    88 private:
    89   GrallocBufferActor();
    91   android::sp<GraphicBuffer> mGraphicBuffer;
    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;
    97   // Used only for hacky fix for bug 966446.
    98   TextureHost* mTextureHost;
   100   friend class ISurfaceAllocator;
   101 };
   103 } // namespace layers
   104 } // namespace mozilla
   106 namespace IPC {
   108 template <>
   109 struct ParamTraits<mozilla::layers::MagicGrallocBufferHandle> {
   110   typedef mozilla::layers::MagicGrallocBufferHandle paramType;
   112   static void Write(Message* aMsg, const paramType& aParam);
   113   static bool Read(const Message* aMsg, void** aIter, paramType* aResult);
   114 };
   116 } // namespace IPC
   118 #endif  // mozilla_layers_ShadowLayerUtilsGralloc_h

mercurial