gfx/layers/ipc/LayerTransactionChild.cpp

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 #include "LayerTransactionChild.h"
     9 #include "mozilla/layers/CompositableClient.h"  // for CompositableChild
    10 #include "mozilla/layers/LayersSurfaces.h"  // for PGrallocBufferChild
    11 #include "mozilla/layers/PCompositableChild.h"  // for PCompositableChild
    12 #include "mozilla/layers/PLayerChild.h"  // for PLayerChild
    13 #include "mozilla/mozalloc.h"           // for operator delete, etc
    14 #include "nsDebug.h"                    // for NS_RUNTIMEABORT, etc
    15 #include "nsTArray.h"                   // for nsTArray
    16 #include "mozilla/layers/TextureClient.h"
    18 namespace mozilla {
    19 namespace layers {
    21 class PGrallocBufferChild;
    23 void
    24 LayerTransactionChild::Destroy()
    25 {
    26   NS_ABORT_IF_FALSE(0 == ManagedPLayerChild().Length(),
    27                     "layers should have been cleaned up by now");
    28   PLayerTransactionChild::Send__delete__(this);
    29   // WARNING: |this| has gone to the great heap in the sky
    30 }
    32 PGrallocBufferChild*
    33 LayerTransactionChild::AllocPGrallocBufferChild(const IntSize&,
    34                                                 const uint32_t&,
    35                                                 const uint32_t&,
    36                                                 MaybeMagicGrallocBufferHandle*)
    37 {
    38 #ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
    39   return GrallocBufferActor::Create();
    40 #else
    41   NS_RUNTIMEABORT("No gralloc buffers for you");
    42   return nullptr;
    43 #endif
    44 }
    46 bool
    47 LayerTransactionChild::DeallocPGrallocBufferChild(PGrallocBufferChild* actor)
    48 {
    49 #ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
    50   delete actor;
    51   return true;
    52 #else
    53   NS_RUNTIMEABORT("Um, how did we get here?");
    54   return false;
    55 #endif
    56 }
    58 PLayerChild*
    59 LayerTransactionChild::AllocPLayerChild()
    60 {
    61   // we always use the "power-user" ctor
    62   NS_RUNTIMEABORT("not reached");
    63   return nullptr;
    64 }
    66 bool
    67 LayerTransactionChild::DeallocPLayerChild(PLayerChild* actor)
    68 {
    69   delete actor;
    70   return true;
    71 }
    73 PCompositableChild*
    74 LayerTransactionChild::AllocPCompositableChild(const TextureInfo& aInfo)
    75 {
    76   return CompositableClient::CreateIPDLActor();
    77 }
    79 bool
    80 LayerTransactionChild::DeallocPCompositableChild(PCompositableChild* actor)
    81 {
    82   return CompositableClient::DestroyIPDLActor(actor);
    83 }
    85 void
    86 LayerTransactionChild::ActorDestroy(ActorDestroyReason why)
    87 {
    88 #ifdef MOZ_B2G
    89   // Due to poor lifetime management of gralloc (and possibly shmems) we will
    90   // crash at some point in the future when we get destroyed due to abnormal
    91   // shutdown. Its better just to crash here. On desktop though, we have a chance
    92   // of recovering.
    93   if (why == AbnormalShutdown) {
    94     NS_RUNTIMEABORT("ActorDestroy by IPC channel failure at LayerTransactionChild");
    95   }
    96 #endif
    97 }
    99 PTextureChild*
   100 LayerTransactionChild::AllocPTextureChild(const SurfaceDescriptor&,
   101                                           const TextureFlags&)
   102 {
   103   return TextureClient::CreateIPDLActor();
   104 }
   106 bool
   107 LayerTransactionChild::DeallocPTextureChild(PTextureChild* actor)
   108 {
   109   return TextureClient::DestroyIPDLActor(actor);
   110 }
   112 }  // namespace layers
   113 }  // namespace mozilla

mercurial