gfx/layers/ipc/CompositorChild.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.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set sw=2 ts=8 et tw=80 : */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef mozilla_layers_CompositorChild_h
michael@0 8 #define mozilla_layers_CompositorChild_h
michael@0 9
michael@0 10 #include "base/basictypes.h" // for DISALLOW_EVIL_CONSTRUCTORS
michael@0 11 #include "mozilla/Assertions.h" // for MOZ_ASSERT_HELPER2
michael@0 12 #include "mozilla/Attributes.h" // for MOZ_OVERRIDE
michael@0 13 #include "mozilla/ipc/ProtocolUtils.h"
michael@0 14 #include "mozilla/layers/PCompositorChild.h"
michael@0 15 #include "nsAutoPtr.h" // for nsRefPtr
michael@0 16 #include "nsClassHashtable.h" // for nsClassHashtable
michael@0 17 #include "nsCOMPtr.h" // for nsCOMPtr
michael@0 18 #include "nsHashKeys.h" // for nsUint64HashKey
michael@0 19 #include "nsISupportsImpl.h" // for NS_INLINE_DECL_REFCOUNTING
michael@0 20
michael@0 21 class nsIObserver;
michael@0 22
michael@0 23 namespace mozilla {
michael@0 24 namespace layers {
michael@0 25
michael@0 26 class ClientLayerManager;
michael@0 27 class CompositorParent;
michael@0 28 class FrameMetrics;
michael@0 29
michael@0 30 class CompositorChild MOZ_FINAL : public PCompositorChild
michael@0 31 {
michael@0 32 NS_INLINE_DECL_REFCOUNTING(CompositorChild)
michael@0 33 public:
michael@0 34 CompositorChild(ClientLayerManager *aLayerManager);
michael@0 35
michael@0 36 void Destroy();
michael@0 37
michael@0 38 /**
michael@0 39 * Lookup the FrameMetrics shared by the compositor process with the
michael@0 40 * associated FrameMetrics::ViewID. The returned FrameMetrics is used
michael@0 41 * in progressive paint calculations.
michael@0 42 */
michael@0 43 bool LookupCompositorFrameMetrics(const FrameMetrics::ViewID aId, FrameMetrics&);
michael@0 44
michael@0 45 /**
michael@0 46 * We're asked to create a new Compositor in response to an Opens()
michael@0 47 * or Bridge() request from our parent process. The Transport is to
michael@0 48 * the compositor's context.
michael@0 49 */
michael@0 50 static PCompositorChild*
michael@0 51 Create(Transport* aTransport, ProcessId aOtherProcess);
michael@0 52
michael@0 53 static CompositorChild* Get();
michael@0 54
michael@0 55 static bool ChildProcessHasCompositor() { return sCompositor != nullptr; }
michael@0 56
michael@0 57 virtual bool RecvInvalidateAll() MOZ_OVERRIDE;
michael@0 58
michael@0 59 virtual bool RecvDidComposite(const uint64_t& aId) MOZ_OVERRIDE;
michael@0 60
michael@0 61 private:
michael@0 62 // Private destructor, to discourage deletion outside of Release():
michael@0 63 virtual ~CompositorChild();
michael@0 64
michael@0 65 virtual PLayerTransactionChild*
michael@0 66 AllocPLayerTransactionChild(const nsTArray<LayersBackend>& aBackendHints,
michael@0 67 const uint64_t& aId,
michael@0 68 TextureFactoryIdentifier* aTextureFactoryIdentifier,
michael@0 69 bool* aSuccess) MOZ_OVERRIDE;
michael@0 70
michael@0 71 virtual bool DeallocPLayerTransactionChild(PLayerTransactionChild *aChild) MOZ_OVERRIDE;
michael@0 72
michael@0 73 virtual void ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE;
michael@0 74
michael@0 75 virtual bool RecvSharedCompositorFrameMetrics(const mozilla::ipc::SharedMemoryBasic::Handle& metrics,
michael@0 76 const CrossProcessMutexHandle& handle,
michael@0 77 const uint32_t& aAPZCId) MOZ_OVERRIDE;
michael@0 78
michael@0 79 virtual bool RecvReleaseSharedCompositorFrameMetrics(const ViewID& aId,
michael@0 80 const uint32_t& aAPZCId) MOZ_OVERRIDE;
michael@0 81
michael@0 82 // Class used to store the shared FrameMetrics, mutex, and APZCId in a hash table
michael@0 83 class SharedFrameMetricsData {
michael@0 84 public:
michael@0 85 SharedFrameMetricsData(
michael@0 86 const mozilla::ipc::SharedMemoryBasic::Handle& metrics,
michael@0 87 const CrossProcessMutexHandle& handle,
michael@0 88 const uint32_t& aAPZCId);
michael@0 89
michael@0 90 ~SharedFrameMetricsData();
michael@0 91
michael@0 92 void CopyFrameMetrics(FrameMetrics* aFrame);
michael@0 93 FrameMetrics::ViewID GetViewID();
michael@0 94 uint32_t GetAPZCId();
michael@0 95
michael@0 96 private:
michael@0 97 // Pointer to the class that allows access to the shared memory that contains
michael@0 98 // the shared FrameMetrics
michael@0 99 mozilla::ipc::SharedMemoryBasic* mBuffer;
michael@0 100 CrossProcessMutex* mMutex;
michael@0 101 // Unique ID of the APZC that is sharing the FrameMetrics
michael@0 102 uint32_t mAPZCId;
michael@0 103 };
michael@0 104
michael@0 105 nsRefPtr<ClientLayerManager> mLayerManager;
michael@0 106
michael@0 107 // The ViewID of the FrameMetrics is used as the key for this hash table.
michael@0 108 // While this should be safe to use since the ViewID is unique
michael@0 109 nsClassHashtable<nsUint64HashKey, SharedFrameMetricsData> mFrameMetricsTable;
michael@0 110
michael@0 111 // When we're in a child process, this is the process-global
michael@0 112 // compositor that we use to forward transactions directly to the
michael@0 113 // compositor context in another process.
michael@0 114 static CompositorChild* sCompositor;
michael@0 115
michael@0 116 DISALLOW_EVIL_CONSTRUCTORS(CompositorChild);
michael@0 117 };
michael@0 118
michael@0 119 } // layers
michael@0 120 } // mozilla
michael@0 121
michael@0 122 #endif // mozilla_layers_CompositorChild_h

mercurial