michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * vim: sw=2 ts=8 et : michael@0: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "ShadowLayerParent.h" michael@0: #include "Layers.h" // for Layer, ContainerLayer michael@0: #include "nsDebug.h" // for NS_RUNTIMEABORT michael@0: #include "nsISupportsImpl.h" // for Layer::AddRef, etc michael@0: michael@0: #include "mozilla/layers/ThebesLayerComposite.h" michael@0: #include "mozilla/layers/CanvasLayerComposite.h" michael@0: #include "mozilla/layers/ColorLayerComposite.h" michael@0: #include "mozilla/layers/ImageLayerComposite.h" michael@0: #include "mozilla/layers/ContainerLayerComposite.h" michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: michael@0: ShadowLayerParent::ShadowLayerParent() : mLayer(nullptr) michael@0: { michael@0: } michael@0: michael@0: ShadowLayerParent::~ShadowLayerParent() michael@0: { michael@0: } michael@0: michael@0: void michael@0: ShadowLayerParent::Bind(Layer* layer) michael@0: { michael@0: mLayer = layer; michael@0: } michael@0: michael@0: void michael@0: ShadowLayerParent::Destroy() michael@0: { michael@0: // It's possible for Destroy() to come in just after this has been michael@0: // created, but just before the transaction in which Bind() would michael@0: // have been called. In that case, we'll ignore shadow-layers michael@0: // transactions from there on and never get a layer here. michael@0: if (mLayer) { michael@0: mLayer->Disconnect(); michael@0: } michael@0: } michael@0: michael@0: ContainerLayerComposite* michael@0: ShadowLayerParent::AsContainerLayerComposite() const michael@0: { michael@0: return mLayer && mLayer->GetType() == Layer::TYPE_CONTAINER michael@0: ? static_cast(mLayer.get()) michael@0: : nullptr; michael@0: } michael@0: michael@0: CanvasLayerComposite* michael@0: ShadowLayerParent::AsCanvasLayerComposite() const michael@0: { michael@0: return mLayer && mLayer->GetType() == Layer::TYPE_CANVAS michael@0: ? static_cast(mLayer.get()) michael@0: : nullptr; michael@0: } michael@0: michael@0: ColorLayerComposite* michael@0: ShadowLayerParent::AsColorLayerComposite() const michael@0: { michael@0: return mLayer && mLayer->GetType() == Layer::TYPE_COLOR michael@0: ? static_cast(mLayer.get()) michael@0: : nullptr; michael@0: } michael@0: michael@0: ImageLayerComposite* michael@0: ShadowLayerParent::AsImageLayerComposite() const michael@0: { michael@0: return mLayer && mLayer->GetType() == Layer::TYPE_IMAGE michael@0: ? static_cast(mLayer.get()) michael@0: : nullptr; michael@0: } michael@0: michael@0: RefLayerComposite* michael@0: ShadowLayerParent::AsRefLayerComposite() const michael@0: { michael@0: return mLayer && mLayer->GetType() == Layer::TYPE_REF michael@0: ? static_cast(mLayer.get()) michael@0: : nullptr; michael@0: } michael@0: michael@0: ThebesLayerComposite* michael@0: ShadowLayerParent::AsThebesLayerComposite() const michael@0: { michael@0: return mLayer && mLayer->GetType() == Layer::TYPE_THEBES michael@0: ? static_cast(mLayer.get()) michael@0: : nullptr; michael@0: } michael@0: michael@0: void michael@0: ShadowLayerParent::ActorDestroy(ActorDestroyReason why) michael@0: { michael@0: switch (why) { michael@0: case AncestorDeletion: michael@0: NS_RUNTIMEABORT("shadow layer deleted out of order!"); michael@0: return; // unreached michael@0: michael@0: case Deletion: michael@0: // See comment near Destroy() above. michael@0: if (mLayer) { michael@0: mLayer->Disconnect(); michael@0: } michael@0: break; michael@0: michael@0: case AbnormalShutdown: michael@0: if (mLayer) { michael@0: mLayer->Disconnect(); michael@0: } michael@0: break; michael@0: michael@0: case NormalShutdown: michael@0: // let IPDL-generated code automatically clean up Shmems and so michael@0: // forth; our channel is disconnected anyway michael@0: break; michael@0: michael@0: case FailedConstructor: michael@0: NS_RUNTIMEABORT("FailedConstructor isn't possible in PLayerTransaction"); michael@0: return; // unreached michael@0: } michael@0: michael@0: mLayer = nullptr; michael@0: } michael@0: michael@0: } // namespace layers michael@0: } // namespace mozilla