gfx/layers/ipc/ShadowLayerParent.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/layers/ipc/ShadowLayerParent.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,131 @@
     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 +#include "ShadowLayerParent.h"
    1.12 +#include "Layers.h"                     // for Layer, ContainerLayer
    1.13 +#include "nsDebug.h"                    // for NS_RUNTIMEABORT
    1.14 +#include "nsISupportsImpl.h"            // for Layer::AddRef, etc
    1.15 +
    1.16 +#include "mozilla/layers/ThebesLayerComposite.h"
    1.17 +#include "mozilla/layers/CanvasLayerComposite.h"
    1.18 +#include "mozilla/layers/ColorLayerComposite.h"
    1.19 +#include "mozilla/layers/ImageLayerComposite.h"
    1.20 +#include "mozilla/layers/ContainerLayerComposite.h"
    1.21 +
    1.22 +namespace mozilla {
    1.23 +namespace layers {
    1.24 +
    1.25 +ShadowLayerParent::ShadowLayerParent() : mLayer(nullptr)
    1.26 +{
    1.27 +}
    1.28 +
    1.29 +ShadowLayerParent::~ShadowLayerParent()
    1.30 +{
    1.31 +}
    1.32 +
    1.33 +void
    1.34 +ShadowLayerParent::Bind(Layer* layer)
    1.35 +{
    1.36 +  mLayer = layer;
    1.37 +}
    1.38 +
    1.39 +void
    1.40 +ShadowLayerParent::Destroy()
    1.41 +{
    1.42 +  // It's possible for Destroy() to come in just after this has been
    1.43 +  // created, but just before the transaction in which Bind() would
    1.44 +  // have been called.  In that case, we'll ignore shadow-layers
    1.45 +  // transactions from there on and never get a layer here.
    1.46 +  if (mLayer) {
    1.47 +    mLayer->Disconnect();
    1.48 +  }
    1.49 +}
    1.50 +
    1.51 +ContainerLayerComposite*
    1.52 +ShadowLayerParent::AsContainerLayerComposite() const
    1.53 +{
    1.54 +  return mLayer && mLayer->GetType() == Layer::TYPE_CONTAINER
    1.55 +         ? static_cast<ContainerLayerComposite*>(mLayer.get())
    1.56 +         : nullptr;
    1.57 +}
    1.58 +
    1.59 +CanvasLayerComposite*
    1.60 +ShadowLayerParent::AsCanvasLayerComposite() const
    1.61 +{
    1.62 +  return mLayer && mLayer->GetType() == Layer::TYPE_CANVAS
    1.63 +         ? static_cast<CanvasLayerComposite*>(mLayer.get())
    1.64 +         : nullptr;
    1.65 +}
    1.66 +
    1.67 +ColorLayerComposite*
    1.68 +ShadowLayerParent::AsColorLayerComposite() const
    1.69 +{
    1.70 +  return mLayer && mLayer->GetType() == Layer::TYPE_COLOR
    1.71 +         ? static_cast<ColorLayerComposite*>(mLayer.get())
    1.72 +         : nullptr;
    1.73 +}
    1.74 +
    1.75 +ImageLayerComposite*
    1.76 +ShadowLayerParent::AsImageLayerComposite() const
    1.77 +{
    1.78 +  return mLayer && mLayer->GetType() == Layer::TYPE_IMAGE
    1.79 +         ? static_cast<ImageLayerComposite*>(mLayer.get())
    1.80 +         : nullptr;
    1.81 +}
    1.82 +
    1.83 +RefLayerComposite*
    1.84 +ShadowLayerParent::AsRefLayerComposite() const
    1.85 +{
    1.86 +  return mLayer && mLayer->GetType() == Layer::TYPE_REF
    1.87 +         ? static_cast<RefLayerComposite*>(mLayer.get())
    1.88 +         : nullptr;
    1.89 +}
    1.90 +
    1.91 +ThebesLayerComposite*
    1.92 +ShadowLayerParent::AsThebesLayerComposite() const
    1.93 +{
    1.94 +  return mLayer && mLayer->GetType() == Layer::TYPE_THEBES
    1.95 +         ? static_cast<ThebesLayerComposite*>(mLayer.get())
    1.96 +         : nullptr;
    1.97 +}
    1.98 +
    1.99 +void
   1.100 +ShadowLayerParent::ActorDestroy(ActorDestroyReason why)
   1.101 +{
   1.102 +  switch (why) {
   1.103 +  case AncestorDeletion:
   1.104 +    NS_RUNTIMEABORT("shadow layer deleted out of order!");
   1.105 +    return;                     // unreached
   1.106 +
   1.107 +  case Deletion:
   1.108 +    // See comment near Destroy() above.
   1.109 +    if (mLayer) {
   1.110 +      mLayer->Disconnect();
   1.111 +    }
   1.112 +    break;
   1.113 +
   1.114 +  case AbnormalShutdown:
   1.115 +    if (mLayer) {
   1.116 +      mLayer->Disconnect();
   1.117 +    }
   1.118 +    break;
   1.119 +
   1.120 +  case NormalShutdown:
   1.121 +    // let IPDL-generated code automatically clean up Shmems and so
   1.122 +    // forth; our channel is disconnected anyway
   1.123 +    break;
   1.124 +
   1.125 +  case FailedConstructor:
   1.126 +    NS_RUNTIMEABORT("FailedConstructor isn't possible in PLayerTransaction");
   1.127 +    return;                     // unreached
   1.128 +  }
   1.129 +
   1.130 +  mLayer = nullptr;
   1.131 +}
   1.132 +
   1.133 +} // namespace layers
   1.134 +} // namespace mozilla

mercurial