Layer* GetLayerFromOpPaint(const OpPaintT& op) { PTextureParent* textureParent = op.textureParent(); CompositableHost* compoHost = static_cast<CompositableParent*>(textureParent->Manager())->GetCompositableHost(); return compoHost ? compoHost->GetLayer() : nullptr; }
bool LayerTransactionParent::Attach(ShadowLayerParent* aLayerParent, CompositableParent* aCompositable, bool aIsAsyncVideo) { Layer* baselayer = aLayerParent->AsLayer(); if (!baselayer) { return false; } LayerComposite* layer = baselayer->AsLayerComposite(); if (!layer) { return false; } Compositor* compositor = static_cast<LayerManagerComposite*>(aLayerParent->AsLayer()->Manager())->GetCompositor(); CompositableHost* compositable = aCompositable->GetCompositableHost(); MOZ_ASSERT(compositable); if (!layer->SetCompositableHost(compositable)) { // not all layer types accept a compositable, see bug 967824 return false; } compositable->Attach(aLayerParent->AsLayer(), compositor, aIsAsyncVideo ? CompositableHost::ALLOW_REATTACH | CompositableHost::KEEP_ATTACHED : CompositableHost::NO_FLAGS); return true; }
bool ScheduleComposition(const T& op) { CompositableHost* comp = AsCompositable(op); uint64_t id = comp->GetCompositorID(); if (!comp || !id) { return false; } CompositorParent* cp = CompositorParent::GetCompositor(id); if (!cp) { return false; } cp->ScheduleComposition(); return true; }
void LayerTransactionParent::Attach(ShadowLayerParent* aLayerParent, CompositableParent* aCompositable) { LayerComposite* layer = aLayerParent->AsLayer()->AsLayerComposite(); MOZ_ASSERT(layer); Compositor* compositor = static_cast<LayerManagerComposite*>(aLayerParent->AsLayer()->Manager())->GetCompositor(); CompositableHost* compositable = aCompositable->GetCompositableHost(); MOZ_ASSERT(compositable); layer->SetCompositableHost(compositable); compositable->Attach(aLayerParent->AsLayer(), compositor); }
void LayerTransactionParent::Attach(ShadowLayerParent* aLayerParent, CompositableParent* aCompositable, bool aIsAsyncVideo) { LayerComposite* layer = aLayerParent->AsLayer()->AsLayerComposite(); MOZ_ASSERT(layer); Compositor* compositor = static_cast<LayerManagerComposite*>(aLayerParent->AsLayer()->Manager())->GetCompositor(); CompositableHost* compositable = aCompositable->GetCompositableHost(); MOZ_ASSERT(compositable); layer->SetCompositableHost(compositable); compositable->Attach(aLayerParent->AsLayer(), compositor, aIsAsyncVideo ? CompositableHost::ALLOW_REATTACH | CompositableHost::KEEP_ATTACHED : CompositableHost::NO_FLAGS); }
bool CompositableParentManager::ReceiveCompositableUpdate(const CompositableOperation& aEdit, EditReplyVector& replyv) { switch (aEdit.type()) { case CompositableOperation::TOpCreatedIncrementalTexture: { MOZ_LAYERS_LOG(("[ParentSide] Created texture")); const OpCreatedIncrementalTexture& op = aEdit.get_OpCreatedIncrementalTexture(); CompositableHost* compositable = AsCompositable(op); bool success = compositable->CreatedIncrementalTexture(this, op.textureInfo(), op.bufferRect()); if (!success) { return false; } break; } case CompositableOperation::TOpPaintTextureRegion: { MOZ_LAYERS_LOG(("[ParentSide] Paint ThebesLayer")); const OpPaintTextureRegion& op = aEdit.get_OpPaintTextureRegion(); CompositableHost* compositable = AsCompositable(op); Layer* layer = compositable->GetLayer(); if (!layer || layer->GetType() != Layer::TYPE_THEBES) { return false; } ThebesLayerComposite* thebes = static_cast<ThebesLayerComposite*>(layer); const ThebesBufferData& bufferData = op.bufferData(); RenderTraceInvalidateStart(thebes, "FF00FF", op.updatedRegion().GetBounds()); nsIntRegion frontUpdatedRegion; if (!compositable->UpdateThebes(bufferData, op.updatedRegion(), thebes->GetValidRegion(), &frontUpdatedRegion)) { return false; } replyv.push_back( OpContentBufferSwap(op.compositableParent(), nullptr, frontUpdatedRegion)); RenderTraceInvalidateEnd(thebes, "FF00FF"); break; } case CompositableOperation::TOpPaintTextureIncremental: { MOZ_LAYERS_LOG(("[ParentSide] Paint ThebesLayer")); const OpPaintTextureIncremental& op = aEdit.get_OpPaintTextureIncremental(); CompositableHost* compositable = AsCompositable(op); SurfaceDescriptor desc = op.image(); compositable->UpdateIncremental(op.textureId(), desc, op.updatedRegion(), op.bufferRect(), op.bufferRotation()); break; } case CompositableOperation::TOpUpdatePictureRect: { const OpUpdatePictureRect& op = aEdit.get_OpUpdatePictureRect(); CompositableHost* compositable = AsCompositable(op); MOZ_ASSERT(compositable); compositable->SetPictureRect(op.picture()); break; } case CompositableOperation::TOpUseTiledLayerBuffer: { MOZ_LAYERS_LOG(("[ParentSide] Paint TiledLayerBuffer")); const OpUseTiledLayerBuffer& op = aEdit.get_OpUseTiledLayerBuffer(); CompositableHost* compositable = AsCompositable(op); TiledLayerComposer* tileComposer = compositable->AsTiledLayerComposer(); NS_ASSERTION(tileComposer, "compositable is not a tile composer"); const SurfaceDescriptorTiles& tileDesc = op.tileLayerDescriptor(); tileComposer->UseTiledLayerBuffer(this, tileDesc); break; } case CompositableOperation::TOpRemoveTexture: { const OpRemoveTexture& op = aEdit.get_OpRemoveTexture(); CompositableHost* compositable = AsCompositable(op); RefPtr<TextureHost> tex = TextureHost::AsTextureHost(op.textureParent()); MOZ_ASSERT(tex.get()); compositable->RemoveTextureHost(tex); // send FenceHandle if present. TextureHost::SendFenceHandleIfPresent(op.textureParent()); break; } case CompositableOperation::TOpRemoveTextureAsync: { const OpRemoveTextureAsync& op = aEdit.get_OpRemoveTextureAsync(); CompositableHost* compositable = AsCompositable(op); RefPtr<TextureHost> tex = TextureHost::AsTextureHost(op.textureParent()); MOZ_ASSERT(tex.get()); compositable->RemoveTextureHost(tex); if (!IsAsync() && GetChildProcessId()) { // send FenceHandle if present via ImageBridge. ImageBridgeParent::SendFenceHandleToTrackerIfPresent( GetChildProcessId(), op.holderId(), op.transactionId(), op.textureParent()); // If the message is recievied via PLayerTransaction, // Send message back via PImageBridge. ImageBridgeParent::ReplyRemoveTexture( GetChildProcessId(), OpReplyRemoveTexture(true, // isMain op.holderId(), op.transactionId())); } else { // send FenceHandle if present. TextureHost::SendFenceHandleIfPresent(op.textureParent()); ReplyRemoveTexture(OpReplyRemoveTexture(false, // isMain op.holderId(), op.transactionId())); } break; } case CompositableOperation::TOpUseTexture: { const OpUseTexture& op = aEdit.get_OpUseTexture(); CompositableHost* compositable = AsCompositable(op); RefPtr<TextureHost> tex = TextureHost::AsTextureHost(op.textureParent()); MOZ_ASSERT(tex.get()); compositable->UseTextureHost(tex); if (IsAsync()) { ScheduleComposition(op); // Async layer updates don't trigger invalidation, manually tell the layer // that its content have changed. if (compositable->GetLayer()) { compositable->GetLayer()->SetInvalidRectToVisibleRegion(); } } break; } case CompositableOperation::TOpUseComponentAlphaTextures: { const OpUseComponentAlphaTextures& op = aEdit.get_OpUseComponentAlphaTextures(); CompositableHost* compositable = AsCompositable(op); RefPtr<TextureHost> texOnBlack = TextureHost::AsTextureHost(op.textureOnBlackParent()); RefPtr<TextureHost> texOnWhite = TextureHost::AsTextureHost(op.textureOnWhiteParent()); MOZ_ASSERT(texOnBlack && texOnWhite); compositable->UseComponentAlphaTextures(texOnBlack, texOnWhite); if (IsAsync()) { ScheduleComposition(op); } break; } #ifdef MOZ_WIDGET_GONK case CompositableOperation::TOpUseOverlaySource: { const OpUseOverlaySource& op = aEdit.get_OpUseOverlaySource(); CompositableHost* compositable = AsCompositable(op); MOZ_ASSERT(compositable->GetType() == CompositableType::IMAGE_OVERLAY, "Invalid operation!"); compositable->UseOverlaySource(op.overlay()); break; } #endif case CompositableOperation::TOpUpdateTexture: { const OpUpdateTexture& op = aEdit.get_OpUpdateTexture(); RefPtr<TextureHost> texture = TextureHost::AsTextureHost(op.textureParent()); MOZ_ASSERT(texture); texture->Updated(op.region().type() == MaybeRegion::TnsIntRegion ? &op.region().get_nsIntRegion() : nullptr); // no region means invalidate the entire surface break; } default: { MOZ_ASSERT(false, "bad type"); } } return true; }
bool LayerTransactionParent::RecvUpdate(const InfallibleTArray<Edit>& cset, const uint64_t& aTransactionId, const TargetConfig& targetConfig, const bool& isFirstPaint, const bool& scheduleComposite, const uint32_t& paintSequenceNumber, const bool& isRepeatTransaction, InfallibleTArray<EditReply>* reply) { profiler_tracing("Paint", "Composite", TRACING_INTERVAL_START); PROFILER_LABEL("LayerTransactionParent", "RecvUpdate", js::ProfileEntry::Category::GRAPHICS); #ifdef COMPOSITOR_PERFORMANCE_WARNING TimeStamp updateStart = TimeStamp::Now(); #endif MOZ_LAYERS_LOG(("[ParentSide] received txn with %d edits", cset.Length())); if (mDestroyed || !layer_manager() || layer_manager()->IsDestroyed()) { return true; } if (mLayerManager && mLayerManager->GetCompositor() && !targetConfig.naturalBounds().IsEmpty()) { mLayerManager->GetCompositor()->SetScreenRotation(targetConfig.rotation()); } EditReplyVector replyv; { AutoResolveRefLayers resolve(mShadowLayersManager->GetCompositionManager(this)); layer_manager()->BeginTransaction(); } for (EditArray::index_type i = 0; i < cset.Length(); ++i) { const Edit& edit = cset[i]; switch (edit.type()) { // Create* ops case Edit::TOpCreateThebesLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateThebesLayer")); nsRefPtr<ThebesLayerComposite> layer = layer_manager()->CreateThebesLayerComposite(); AsLayerComposite(edit.get_OpCreateThebesLayer())->Bind(layer); break; } case Edit::TOpCreateContainerLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateContainerLayer")); nsRefPtr<ContainerLayer> layer = layer_manager()->CreateContainerLayerComposite(); AsLayerComposite(edit.get_OpCreateContainerLayer())->Bind(layer); break; } case Edit::TOpCreateImageLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateImageLayer")); nsRefPtr<ImageLayerComposite> layer = layer_manager()->CreateImageLayerComposite(); AsLayerComposite(edit.get_OpCreateImageLayer())->Bind(layer); break; } case Edit::TOpCreateColorLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateColorLayer")); nsRefPtr<ColorLayerComposite> layer = layer_manager()->CreateColorLayerComposite(); AsLayerComposite(edit.get_OpCreateColorLayer())->Bind(layer); break; } case Edit::TOpCreateCanvasLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateCanvasLayer")); nsRefPtr<CanvasLayerComposite> layer = layer_manager()->CreateCanvasLayerComposite(); AsLayerComposite(edit.get_OpCreateCanvasLayer())->Bind(layer); break; } case Edit::TOpCreateRefLayer: { MOZ_LAYERS_LOG(("[ParentSide] CreateRefLayer")); nsRefPtr<RefLayerComposite> layer = layer_manager()->CreateRefLayerComposite(); AsLayerComposite(edit.get_OpCreateRefLayer())->Bind(layer); break; } // Attributes case Edit::TOpSetLayerAttributes: { MOZ_LAYERS_LOG(("[ParentSide] SetLayerAttributes")); const OpSetLayerAttributes& osla = edit.get_OpSetLayerAttributes(); ShadowLayerParent* layerParent = AsLayerComposite(osla); Layer* layer = layerParent->AsLayer(); if (!layer) { return false; } const LayerAttributes& attrs = osla.attrs(); const CommonLayerAttributes& common = attrs.common(); layer->SetVisibleRegion(common.visibleRegion()); layer->SetEventRegions(common.eventRegions()); layer->SetContentFlags(common.contentFlags()); layer->SetOpacity(common.opacity()); layer->SetClipRect(common.useClipRect() ? &common.clipRect() : nullptr); layer->SetBaseTransform(common.transform().value()); layer->SetPostScale(common.postXScale(), common.postYScale()); layer->SetIsFixedPosition(common.isFixedPosition()); layer->SetFixedPositionAnchor(common.fixedPositionAnchor()); layer->SetFixedPositionMargins(common.fixedPositionMargin()); if (common.isStickyPosition()) { layer->SetStickyPositionData(common.stickyScrollContainerId(), common.stickyScrollRangeOuter(), common.stickyScrollRangeInner()); } layer->SetScrollbarData(common.scrollbarTargetContainerId(), static_cast<Layer::ScrollDirection>(common.scrollbarDirection())); layer->SetMixBlendMode((gfx::CompositionOp)common.mixBlendMode()); layer->SetForceIsolatedGroup(common.forceIsolatedGroup()); if (PLayerParent* maskLayer = common.maskLayerParent()) { layer->SetMaskLayer(cast(maskLayer)->AsLayer()); } else { layer->SetMaskLayer(nullptr); } layer->SetAnimations(common.animations()); layer->SetInvalidRegion(common.invalidRegion()); typedef SpecificLayerAttributes Specific; const SpecificLayerAttributes& specific = attrs.specific(); switch (specific.type()) { case Specific::Tnull_t: break; case Specific::TThebesLayerAttributes: { MOZ_LAYERS_LOG(("[ParentSide] thebes layer")); ThebesLayerComposite* thebesLayer = layerParent->AsThebesLayerComposite(); if (!thebesLayer) { return false; } const ThebesLayerAttributes& attrs = specific.get_ThebesLayerAttributes(); thebesLayer->SetValidRegion(attrs.validRegion()); break; } case Specific::TContainerLayerAttributes: { MOZ_LAYERS_LOG(("[ParentSide] container layer")); ContainerLayerComposite* containerLayer = layerParent->AsContainerLayerComposite(); if (!containerLayer) { return false; } const ContainerLayerAttributes& attrs = specific.get_ContainerLayerAttributes(); containerLayer->SetFrameMetrics(attrs.metrics()); containerLayer->SetScrollHandoffParentId(attrs.scrollParentId()); containerLayer->SetPreScale(attrs.preXScale(), attrs.preYScale()); containerLayer->SetInheritedScale(attrs.inheritedXScale(), attrs.inheritedYScale()); containerLayer->SetBackgroundColor(attrs.backgroundColor().value()); containerLayer->SetContentDescription(attrs.contentDescription()); break; } case Specific::TColorLayerAttributes: { MOZ_LAYERS_LOG(("[ParentSide] color layer")); ColorLayerComposite* colorLayer = layerParent->AsColorLayerComposite(); if (!colorLayer) { return false; } colorLayer->SetColor(specific.get_ColorLayerAttributes().color().value()); colorLayer->SetBounds(specific.get_ColorLayerAttributes().bounds()); break; } case Specific::TCanvasLayerAttributes: { MOZ_LAYERS_LOG(("[ParentSide] canvas layer")); CanvasLayerComposite* canvasLayer = layerParent->AsCanvasLayerComposite(); if (!canvasLayer) { return false; } canvasLayer->SetFilter(specific.get_CanvasLayerAttributes().filter()); canvasLayer->SetBounds(specific.get_CanvasLayerAttributes().bounds()); break; } case Specific::TRefLayerAttributes: { MOZ_LAYERS_LOG(("[ParentSide] ref layer")); RefLayerComposite* refLayer = layerParent->AsRefLayerComposite(); if (!refLayer) { return false; } refLayer->SetReferentId(specific.get_RefLayerAttributes().id()); break; } case Specific::TImageLayerAttributes: { MOZ_LAYERS_LOG(("[ParentSide] image layer")); ImageLayerComposite* imageLayer = layerParent->AsImageLayerComposite(); if (!imageLayer) { return false; } const ImageLayerAttributes& attrs = specific.get_ImageLayerAttributes(); imageLayer->SetFilter(attrs.filter()); imageLayer->SetScaleToSize(attrs.scaleToSize(), attrs.scaleMode()); break; } default: NS_RUNTIMEABORT("not reached"); } break; } case Edit::TOpSetDiagnosticTypes: { mLayerManager->GetCompositor()->SetDiagnosticTypes( edit.get_OpSetDiagnosticTypes().diagnostics()); break; } // Tree ops case Edit::TOpSetRoot: { MOZ_LAYERS_LOG(("[ParentSide] SetRoot")); Layer* newRoot = AsLayerComposite(edit.get_OpSetRoot())->AsLayer(); if (!newRoot) { return false; } if (newRoot->GetParent()) { // newRoot is not a root! return false; } mRoot = newRoot; break; } case Edit::TOpInsertAfter: { MOZ_LAYERS_LOG(("[ParentSide] InsertAfter")); const OpInsertAfter& oia = edit.get_OpInsertAfter(); Layer* child = ShadowChild(oia)->AsLayer(); if (!child) { return false; } ContainerLayerComposite* container = ShadowContainer(oia)->AsContainerLayerComposite(); if (!container || !container->InsertAfter(child, ShadowAfter(oia)->AsLayer())) { return false; } break; } case Edit::TOpPrependChild: { MOZ_LAYERS_LOG(("[ParentSide] PrependChild")); const OpPrependChild& oac = edit.get_OpPrependChild(); Layer* child = ShadowChild(oac)->AsLayer(); if (!child) { return false; } ContainerLayerComposite* container = ShadowContainer(oac)->AsContainerLayerComposite(); if (!container || !container->InsertAfter(child, nullptr)) { return false; } break; } case Edit::TOpRemoveChild: { MOZ_LAYERS_LOG(("[ParentSide] RemoveChild")); const OpRemoveChild& orc = edit.get_OpRemoveChild(); Layer* childLayer = ShadowChild(orc)->AsLayer(); if (!childLayer) { return false; } ContainerLayerComposite* container = ShadowContainer(orc)->AsContainerLayerComposite(); if (!container || !container->RemoveChild(childLayer)) { return false; } break; } case Edit::TOpRepositionChild: { MOZ_LAYERS_LOG(("[ParentSide] RepositionChild")); const OpRepositionChild& orc = edit.get_OpRepositionChild(); Layer* child = ShadowChild(orc)->AsLayer(); if (!child) { return false; } ContainerLayerComposite* container = ShadowContainer(orc)->AsContainerLayerComposite(); if (!container || !container->RepositionChild(child, ShadowAfter(orc)->AsLayer())) { return false; } break; } case Edit::TOpRaiseToTopChild: { MOZ_LAYERS_LOG(("[ParentSide] RaiseToTopChild")); const OpRaiseToTopChild& rtc = edit.get_OpRaiseToTopChild(); Layer* child = ShadowChild(rtc)->AsLayer(); if (!child) { return false; } ContainerLayerComposite* container = ShadowContainer(rtc)->AsContainerLayerComposite(); if (!container || !container->RepositionChild(child, nullptr)) { return false; } break; } case Edit::TCompositableOperation: { if (!ReceiveCompositableUpdate(edit.get_CompositableOperation(), replyv)) { return false; } break; } case Edit::TOpAttachCompositable: { const OpAttachCompositable& op = edit.get_OpAttachCompositable(); CompositableHost* host = CompositableHost::FromIPDLActor(op.compositableParent()); if (!Attach(cast(op.layerParent()), host, false)) { return false; } host->SetCompositorID(mLayerManager->GetCompositor()->GetCompositorID()); break; } case Edit::TOpAttachAsyncCompositable: { const OpAttachAsyncCompositable& op = edit.get_OpAttachAsyncCompositable(); PCompositableParent* compositableParent = CompositableMap::Get(op.containerID()); if (!compositableParent) { NS_ERROR("CompositableParent not found in the map"); return false; } CompositableHost* host = CompositableHost::FromIPDLActor(compositableParent); if (!Attach(cast(op.layerParent()), host, true)) { return false; } host->SetCompositorID(mLayerManager->GetCompositor()->GetCompositorID()); break; } default: NS_RUNTIMEABORT("not reached"); } } mShadowLayersManager->ShadowLayersUpdated(this, aTransactionId, targetConfig, isFirstPaint, scheduleComposite, paintSequenceNumber, isRepeatTransaction); { AutoResolveRefLayers resolve(mShadowLayersManager->GetCompositionManager(this)); layer_manager()->EndTransaction(nullptr, nullptr, LayerManager::END_NO_IMMEDIATE_REDRAW); } if (reply) { reply->SetCapacity(replyv.size()); if (replyv.size() > 0) { reply->AppendElements(&replyv.front(), replyv.size()); } } if (!IsSameProcess()) { // Ensure that any pending operations involving back and front // buffers have completed, so that neither process stomps on the // other's buffer contents. LayerManagerComposite::PlatformSyncBeforeReplyUpdate(); } #ifdef COMPOSITOR_PERFORMANCE_WARNING int compositeTime = (int)(mozilla::TimeStamp::Now() - updateStart).ToMilliseconds(); if (compositeTime > 15) { printf_stderr("Compositor: Layers update took %i ms (blocking gecko).\n", compositeTime); } #endif return true; }
bool CompositableParentManager::ReceiveCompositableUpdate(const CompositableOperation& aEdit, EditReplyVector& replyv) { switch (aEdit.type()) { case CompositableOperation::TOpCreatedTexture: { MOZ_LAYERS_LOG(("[ParentSide] Created texture")); const OpCreatedTexture& op = aEdit.get_OpCreatedTexture(); CompositableParent* compositableParent = static_cast<CompositableParent*>(op.compositableParent()); CompositableHost* compositable = compositableParent->GetCompositableHost(); compositable->EnsureDeprecatedTextureHost(op.textureId(), op.descriptor(), compositableParent->GetCompositableManager(), op.textureInfo()); break; } case CompositableOperation::TOpCreatedIncrementalTexture: { MOZ_LAYERS_LOG(("[ParentSide] Created texture")); const OpCreatedIncrementalTexture& op = aEdit.get_OpCreatedIncrementalTexture(); CompositableParent* compositableParent = static_cast<CompositableParent*>(op.compositableParent()); CompositableHost* compositable = compositableParent->GetCompositableHost(); compositable->EnsureDeprecatedTextureHostIncremental(compositableParent->GetCompositableManager(), op.textureInfo(), op.bufferRect()); break; } case CompositableOperation::TOpDestroyThebesBuffer: { MOZ_LAYERS_LOG(("[ParentSide] Created double buffer")); const OpDestroyThebesBuffer& op = aEdit.get_OpDestroyThebesBuffer(); CompositableParent* compositableParent = static_cast<CompositableParent*>(op.compositableParent()); CompositableHost* compositableHost = compositableParent->GetCompositableHost(); if (compositableHost->GetType() != BUFFER_CONTENT && compositableHost->GetType() != BUFFER_CONTENT_DIRECT) { return false; } DeprecatedContentHostBase* content = static_cast<DeprecatedContentHostBase*>(compositableHost); content->DestroyTextures(); break; } case CompositableOperation::TOpPaintTexture: { MOZ_LAYERS_LOG(("[ParentSide] Paint Texture X")); const OpPaintTexture& op = aEdit.get_OpPaintTexture(); CompositableParent* compositableParent = static_cast<CompositableParent*>(op.compositableParent()); CompositableHost* compositable = compositableParent->GetCompositableHost(); Layer* layer = compositable ? compositable->GetLayer() : nullptr; LayerComposite* shadowLayer = layer ? layer->AsLayerComposite() : nullptr; if (shadowLayer) { Compositor* compositor = static_cast<LayerManagerComposite*>(layer->Manager())->GetCompositor(); compositable->SetCompositor(compositor); compositable->SetLayer(layer); } else { // if we reach this branch, it most likely means that async textures // are coming in before we had time to attach the compositable to a // layer. Don't panic, it is okay in this case. it should not be // happening continuously, though. } if (layer) { RenderTraceInvalidateStart(layer, "FF00FF", layer->GetVisibleRegion().GetBounds()); } if (compositable) { const SurfaceDescriptor& descriptor = op.image(); compositable->EnsureDeprecatedTextureHost(op.textureId(), descriptor, compositableParent->GetCompositableManager(), TextureInfo()); MOZ_ASSERT(compositable->GetDeprecatedTextureHost()); SurfaceDescriptor newBack; bool shouldRecomposite = compositable->Update(descriptor, &newBack); if (IsSurfaceDescriptorValid(newBack)) { replyv.push_back(OpTextureSwap(compositableParent, nullptr, op.textureId(), newBack)); } if (IsAsync() && shouldRecomposite) { ScheduleComposition(op); } } if (layer) { RenderTraceInvalidateEnd(layer, "FF00FF"); } // return texure data to client if necessary ReturnTextureDataIfNecessary(compositable, replyv, op.compositableParent()); break; } case CompositableOperation::TOpPaintTextureRegion: { MOZ_LAYERS_LOG(("[ParentSide] Paint ThebesLayer")); const OpPaintTextureRegion& op = aEdit.get_OpPaintTextureRegion(); CompositableParent* compositableParent = static_cast<CompositableParent*>(op.compositableParent()); CompositableHost* compositable = compositableParent->GetCompositableHost(); Layer* layer = compositable->GetLayer(); if (!layer || layer->GetType() != Layer::TYPE_THEBES) { return false; } ThebesLayerComposite* thebes = static_cast<ThebesLayerComposite*>(layer); const ThebesBufferData& bufferData = op.bufferData(); RenderTraceInvalidateStart(thebes, "FF00FF", op.updatedRegion().GetBounds()); nsIntRegion frontUpdatedRegion; if (!compositable->UpdateThebes(bufferData, op.updatedRegion(), thebes->GetValidRegion(), &frontUpdatedRegion)) { return false; } replyv.push_back( OpContentBufferSwap(compositableParent, nullptr, frontUpdatedRegion)); RenderTraceInvalidateEnd(thebes, "FF00FF"); // return texure data to client if necessary ReturnTextureDataIfNecessary(compositable, replyv, op.compositableParent()); break; } case CompositableOperation::TOpPaintTextureIncremental: { MOZ_LAYERS_LOG(("[ParentSide] Paint ThebesLayer")); const OpPaintTextureIncremental& op = aEdit.get_OpPaintTextureIncremental(); CompositableParent* compositableParent = static_cast<CompositableParent*>(op.compositableParent()); CompositableHost* compositable = compositableParent->GetCompositableHost(); SurfaceDescriptor desc = op.image(); compositable->UpdateIncremental(op.textureId(), desc, op.updatedRegion(), op.bufferRect(), op.bufferRotation()); break; } case CompositableOperation::TOpUpdatePictureRect: { const OpUpdatePictureRect& op = aEdit.get_OpUpdatePictureRect(); CompositableHost* compositable = static_cast<CompositableParent*>(op.compositableParent())->GetCompositableHost(); MOZ_ASSERT(compositable); compositable->SetPictureRect(op.picture()); break; } case CompositableOperation::TOpUseTiledLayerBuffer: { MOZ_LAYERS_LOG(("[ParentSide] Paint TiledLayerBuffer")); const OpUseTiledLayerBuffer& op = aEdit.get_OpUseTiledLayerBuffer(); CompositableParent* compositableParent = static_cast<CompositableParent*>(op.compositableParent()); CompositableHost* compositable = compositableParent->GetCompositableHost(); TiledLayerComposer* tileComposer = compositable->AsTiledLayerComposer(); NS_ASSERTION(tileComposer, "compositable is not a tile composer"); const SurfaceDescriptorTiles& tileDesc = op.tileLayerDescriptor(); tileComposer->UseTiledLayerBuffer(this, tileDesc); break; } case CompositableOperation::TOpRemoveTexture: { const OpRemoveTexture& op = aEdit.get_OpRemoveTexture(); CompositableHost* compositable = AsCompositable(op); RefPtr<TextureHost> tex = TextureHost::AsTextureHost(op.textureParent()); MOZ_ASSERT(tex.get()); compositable->RemoveTextureHost(tex); // return texure data to client if necessary ReturnTextureDataIfNecessary(compositable, replyv, op.compositableParent()); break; } case CompositableOperation::TOpUseTexture: { const OpUseTexture& op = aEdit.get_OpUseTexture(); CompositableHost* compositable = AsCompositable(op); RefPtr<TextureHost> tex = TextureHost::AsTextureHost(op.textureParent()); MOZ_ASSERT(tex.get()); compositable->UseTextureHost(tex); if (IsAsync()) { ScheduleComposition(op); // Async layer updates don't trigger invalidation, manually tell the layer // that its content have changed. if (compositable->GetLayer()) { compositable->GetLayer()->SetInvalidRectToVisibleRegion(); } } // return texure data to client if necessary ReturnTextureDataIfNecessary(compositable, replyv, op.compositableParent()); break; } case CompositableOperation::TOpUseComponentAlphaTextures: { const OpUseComponentAlphaTextures& op = aEdit.get_OpUseComponentAlphaTextures(); CompositableHost* compositable = AsCompositable(op); RefPtr<TextureHost> texOnBlack = TextureHost::AsTextureHost(op.textureOnBlackParent()); RefPtr<TextureHost> texOnWhite = TextureHost::AsTextureHost(op.textureOnWhiteParent()); MOZ_ASSERT(texOnBlack && texOnWhite); compositable->UseComponentAlphaTextures(texOnBlack, texOnWhite); if (IsAsync()) { ScheduleComposition(op); } // return texure data to client if necessary ReturnTextureDataIfNecessary(compositable, replyv, op.compositableParent()); break; } case CompositableOperation::TOpUpdateTexture: { const OpUpdateTexture& op = aEdit.get_OpUpdateTexture(); RefPtr<TextureHost> texture = TextureHost::AsTextureHost(op.textureParent()); MOZ_ASSERT(texture); texture->Updated(op.region().type() == MaybeRegion::TnsIntRegion ? &op.region().get_nsIntRegion() : nullptr); // no region means invalidate the entire surface break; } default: { MOZ_ASSERT(false, "bad type"); } } return true; }
bool CompositableParentManager::ReceiveCompositableUpdate(const CompositableOperation& aEdit, EditReplyVector& replyv) { switch (aEdit.type()) { case CompositableOperation::TOpPaintTextureRegion: { MOZ_LAYERS_LOG(("[ParentSide] Paint PaintedLayer")); const OpPaintTextureRegion& op = aEdit.get_OpPaintTextureRegion(); CompositableHost* compositable = AsCompositable(op); Layer* layer = compositable->GetLayer(); if (!layer || layer->GetType() != Layer::TYPE_PAINTED) { return false; } PaintedLayerComposite* thebes = static_cast<PaintedLayerComposite*>(layer); const ThebesBufferData& bufferData = op.bufferData(); RenderTraceInvalidateStart(thebes, "FF00FF", op.updatedRegion().GetBounds()); nsIntRegion frontUpdatedRegion; if (!compositable->UpdateThebes(bufferData, op.updatedRegion(), thebes->GetValidRegion(), &frontUpdatedRegion)) { return false; } replyv.push_back( OpContentBufferSwap(op.compositableParent(), nullptr, frontUpdatedRegion)); RenderTraceInvalidateEnd(thebes, "FF00FF"); break; } case CompositableOperation::TOpUseTiledLayerBuffer: { MOZ_LAYERS_LOG(("[ParentSide] Paint TiledLayerBuffer")); const OpUseTiledLayerBuffer& op = aEdit.get_OpUseTiledLayerBuffer(); TiledContentHost* compositable = AsCompositable(op)->AsTiledContentHost(); NS_ASSERTION(compositable, "The compositable is not tiled"); const SurfaceDescriptorTiles& tileDesc = op.tileLayerDescriptor(); bool success = compositable->UseTiledLayerBuffer(this, tileDesc); if (!success) { return false; } break; } case CompositableOperation::TOpRemoveTexture: { const OpRemoveTexture& op = aEdit.get_OpRemoveTexture(); CompositableHost* compositable = AsCompositable(op); RefPtr<TextureHost> tex = TextureHost::AsTextureHost(op.textureParent()); MOZ_ASSERT(tex.get()); compositable->RemoveTextureHost(tex); // send FenceHandle if present. SendFenceHandleIfPresent(op.textureParent(), compositable); break; } case CompositableOperation::TOpRemoveTextureAsync: { const OpRemoveTextureAsync& op = aEdit.get_OpRemoveTextureAsync(); CompositableHost* compositable = AsCompositable(op); RefPtr<TextureHost> tex = TextureHost::AsTextureHost(op.textureParent()); MOZ_ASSERT(tex.get()); compositable->RemoveTextureHost(tex); if (!IsAsync() && ImageBridgeParent::GetInstance(GetChildProcessId())) { // send FenceHandle if present via ImageBridge. ImageBridgeParent::AppendDeliverFenceMessage( GetChildProcessId(), op.holderId(), op.transactionId(), op.textureParent(), compositable); // If the message is recievied via PLayerTransaction, // Send message back via PImageBridge. ImageBridgeParent::ReplyRemoveTexture( GetChildProcessId(), OpReplyRemoveTexture(op.holderId(), op.transactionId())); } else { // send FenceHandle if present. SendFenceHandleIfPresent(op.textureParent(), compositable); ReplyRemoveTexture(OpReplyRemoveTexture(op.holderId(), op.transactionId())); } break; } case CompositableOperation::TOpUseTexture: { const OpUseTexture& op = aEdit.get_OpUseTexture(); CompositableHost* compositable = AsCompositable(op); nsAutoTArray<CompositableHost::TimedTexture,4> textures; for (auto& timedTexture : op.textures()) { CompositableHost::TimedTexture* t = textures.AppendElement(); t->mTexture = TextureHost::AsTextureHost(timedTexture.textureParent()); MOZ_ASSERT(t->mTexture); t->mTimeStamp = timedTexture.timeStamp(); t->mPictureRect = timedTexture.picture(); t->mFrameID = timedTexture.frameID(); t->mProducerID = timedTexture.producerID(); MOZ_ASSERT(ValidatePictureRect(t->mTexture->GetSize(), t->mPictureRect)); MaybeFence maybeFence = timedTexture.fence(); if (maybeFence.type() == MaybeFence::TFenceHandle) { FenceHandle fence = maybeFence.get_FenceHandle(); if (fence.IsValid()) { t->mTexture->SetAcquireFenceHandle(fence); } } } compositable->UseTextureHost(textures); if (IsAsync() && compositable->GetLayer()) { ScheduleComposition(op); } break; } case CompositableOperation::TOpUseComponentAlphaTextures: { const OpUseComponentAlphaTextures& op = aEdit.get_OpUseComponentAlphaTextures(); CompositableHost* compositable = AsCompositable(op); RefPtr<TextureHost> texOnBlack = TextureHost::AsTextureHost(op.textureOnBlackParent()); RefPtr<TextureHost> texOnWhite = TextureHost::AsTextureHost(op.textureOnWhiteParent()); MOZ_ASSERT(texOnBlack && texOnWhite); compositable->UseComponentAlphaTextures(texOnBlack, texOnWhite); if (IsAsync()) { ScheduleComposition(op); } break; } #ifdef MOZ_WIDGET_GONK case CompositableOperation::TOpUseOverlaySource: { const OpUseOverlaySource& op = aEdit.get_OpUseOverlaySource(); CompositableHost* compositable = AsCompositable(op); MOZ_ASSERT(compositable->GetType() == CompositableType::IMAGE_OVERLAY, "Invalid operation!"); if (!ValidatePictureRect(op.overlay().size(), op.picture())) { return false; } compositable->UseOverlaySource(op.overlay(), op.picture()); break; } #endif default: { MOZ_ASSERT(false, "bad type"); } } return true; }
bool CompositableParentManager::ReceiveCompositableUpdate(const CompositableOperation& aEdit, EditReplyVector& replyv) { switch (aEdit.type()) { case CompositableOperation::TOpCreatedIncrementalTexture: { MOZ_LAYERS_LOG(("[ParentSide] Created texture")); const OpCreatedIncrementalTexture& op = aEdit.get_OpCreatedIncrementalTexture(); CompositableHost* compositable = AsCompositable(op); bool success = compositable->CreatedIncrementalTexture(this, op.textureInfo(), op.bufferRect()); if (!success) { return false; } break; } case CompositableOperation::TOpPaintTextureRegion: { MOZ_LAYERS_LOG(("[ParentSide] Paint ThebesLayer")); const OpPaintTextureRegion& op = aEdit.get_OpPaintTextureRegion(); CompositableHost* compositable = AsCompositable(op); Layer* layer = compositable->GetLayer(); if (!layer || layer->GetType() != Layer::TYPE_THEBES) { return false; } ThebesLayerComposite* thebes = static_cast<ThebesLayerComposite*>(layer); const ThebesBufferData& bufferData = op.bufferData(); RenderTraceInvalidateStart(thebes, "FF00FF", op.updatedRegion().GetBounds()); nsIntRegion frontUpdatedRegion; if (!compositable->UpdateThebes(bufferData, op.updatedRegion(), thebes->GetValidRegion(), &frontUpdatedRegion)) { return false; } replyv.push_back( OpContentBufferSwap(op.compositableParent(), nullptr, frontUpdatedRegion)); RenderTraceInvalidateEnd(thebes, "FF00FF"); // return texure data to client if necessary ReturnTextureDataIfNecessary(compositable, replyv, op.compositableParent()); break; } case CompositableOperation::TOpPaintTextureIncremental: { MOZ_LAYERS_LOG(("[ParentSide] Paint ThebesLayer")); const OpPaintTextureIncremental& op = aEdit.get_OpPaintTextureIncremental(); CompositableHost* compositable = AsCompositable(op); SurfaceDescriptor desc = op.image(); compositable->UpdateIncremental(op.textureId(), desc, op.updatedRegion(), op.bufferRect(), op.bufferRotation()); break; } case CompositableOperation::TOpUpdatePictureRect: { const OpUpdatePictureRect& op = aEdit.get_OpUpdatePictureRect(); CompositableHost* compositable = AsCompositable(op); MOZ_ASSERT(compositable); compositable->SetPictureRect(op.picture()); break; } case CompositableOperation::TOpUseTiledLayerBuffer: { MOZ_LAYERS_LOG(("[ParentSide] Paint TiledLayerBuffer")); const OpUseTiledLayerBuffer& op = aEdit.get_OpUseTiledLayerBuffer(); CompositableHost* compositable = AsCompositable(op); TiledLayerComposer* tileComposer = compositable->AsTiledLayerComposer(); NS_ASSERTION(tileComposer, "compositable is not a tile composer"); const SurfaceDescriptorTiles& tileDesc = op.tileLayerDescriptor(); tileComposer->UseTiledLayerBuffer(this, tileDesc); break; } case CompositableOperation::TOpRemoveTexture: { const OpRemoveTexture& op = aEdit.get_OpRemoveTexture(); CompositableHost* compositable = AsCompositable(op); RefPtr<TextureHost> tex = TextureHost::AsTextureHost(op.textureParent()); MOZ_ASSERT(tex.get()); compositable->RemoveTextureHost(tex); // return texure data to client if necessary ReturnTextureDataIfNecessary(compositable, replyv, op.compositableParent()); break; } case CompositableOperation::TOpUseTexture: { const OpUseTexture& op = aEdit.get_OpUseTexture(); CompositableHost* compositable = AsCompositable(op); RefPtr<TextureHost> tex = TextureHost::AsTextureHost(op.textureParent()); MOZ_ASSERT(tex.get()); compositable->UseTextureHost(tex); if (IsAsync()) { ScheduleComposition(op); // Async layer updates don't trigger invalidation, manually tell the layer // that its content have changed. if (compositable->GetLayer()) { compositable->GetLayer()->SetInvalidRectToVisibleRegion(); } } // return texure data to client if necessary ReturnTextureDataIfNecessary(compositable, replyv, op.compositableParent()); break; } case CompositableOperation::TOpUseComponentAlphaTextures: { const OpUseComponentAlphaTextures& op = aEdit.get_OpUseComponentAlphaTextures(); CompositableHost* compositable = AsCompositable(op); RefPtr<TextureHost> texOnBlack = TextureHost::AsTextureHost(op.textureOnBlackParent()); RefPtr<TextureHost> texOnWhite = TextureHost::AsTextureHost(op.textureOnWhiteParent()); MOZ_ASSERT(texOnBlack && texOnWhite); compositable->UseComponentAlphaTextures(texOnBlack, texOnWhite); if (IsAsync()) { ScheduleComposition(op); } // return texure data to client if necessary ReturnTextureDataIfNecessary(compositable, replyv, op.compositableParent()); break; } case CompositableOperation::TOpUpdateTexture: { const OpUpdateTexture& op = aEdit.get_OpUpdateTexture(); RefPtr<TextureHost> texture = TextureHost::AsTextureHost(op.textureParent()); MOZ_ASSERT(texture); texture->Updated(op.region().type() == MaybeRegion::TnsIntRegion ? &op.region().get_nsIntRegion() : nullptr); // no region means invalidate the entire surface break; } default: { MOZ_ASSERT(false, "bad type"); } } return true; }
bool CompositableParentManager::ReceiveCompositableUpdate(const CompositableOperation& aEdit, EditReplyVector& replyv) { switch (aEdit.type()) { case CompositableOperation::TOpCreatedSingleBuffer: { MOZ_LAYERS_LOG(("[ParentSide] Created single buffer")); const OpCreatedSingleBuffer& op = aEdit.get_OpCreatedSingleBuffer(); CompositableParent* compositableParent = static_cast<CompositableParent*>(op.compositableParent()); TextureParent* textureParent = static_cast<TextureParent*>(op.bufferParent()); textureParent->EnsureTextureHost(op.descriptor().type()); textureParent->GetTextureHost()->SetBuffer(new SurfaceDescriptor(op.descriptor()), compositableParent->GetCompositableManager()); ContentHostBase* content = static_cast<ContentHostBase*>(compositableParent->GetCompositableHost()); content->SetTextureHosts(textureParent->GetTextureHost()); break; } case CompositableOperation::TOpCreatedDoubleBuffer: { MOZ_LAYERS_LOG(("[ParentSide] Created double buffer")); const OpCreatedDoubleBuffer& op = aEdit.get_OpCreatedDoubleBuffer(); CompositableParent* compositableParent = static_cast<CompositableParent*>(op.compositableParent()); TextureParent* frontParent = static_cast<TextureParent*>(op.frontParent()); TextureParent* backParent = static_cast<TextureParent*>(op.backParent()); frontParent->EnsureTextureHost(op.frontDescriptor().type()); backParent->EnsureTextureHost(op.backDescriptor().type()); frontParent->GetTextureHost()->SetBuffer(new SurfaceDescriptor(op.frontDescriptor()), compositableParent->GetCompositableManager()); backParent->GetTextureHost()->SetBuffer(new SurfaceDescriptor(op.backDescriptor()), compositableParent->GetCompositableManager()); ContentHostBase* content = static_cast<ContentHostBase*>(compositableParent->GetCompositableHost()); content->SetTextureHosts(frontParent->GetTextureHost(), backParent->GetTextureHost()); break; } case CompositableOperation::TOpDestroyThebesBuffer: { MOZ_LAYERS_LOG(("[ParentSide] Created double buffer")); const OpDestroyThebesBuffer& op = aEdit.get_OpDestroyThebesBuffer(); CompositableParent* compositableParent = static_cast<CompositableParent*>(op.compositableParent()); ContentHostBase* content = static_cast<ContentHostBase*>(compositableParent->GetCompositableHost()); content->DestroyTextures(); break; } case CompositableOperation::TOpPaintTexture: { MOZ_LAYERS_LOG(("[ParentSide] Paint Texture X")); const OpPaintTexture& op = aEdit.get_OpPaintTexture(); TextureParent* textureParent = static_cast<TextureParent*>(op.textureParent()); CompositableHost* compositable = textureParent->GetCompositableHost(); Layer* layer = GetLayerFromOpPaint(op); ShadowLayer* shadowLayer = layer ? layer->AsShadowLayer() : nullptr; if (shadowLayer) { Compositor* compositor = static_cast<LayerManagerComposite*>(layer->Manager())->GetCompositor(); compositable->SetCompositor(compositor); compositable->SetLayer(layer); } else { // if we reach this branch, it most likely means that async textures // are coming in before we had time to attach the conmpositable to a // layer. Don't panic, it is okay in this case. it should not be // happening continuously, though. } if (layer) { RenderTraceInvalidateStart(layer, "FF00FF", layer->GetVisibleRegion().GetBounds()); } const SurfaceDescriptor& descriptor = op.image(); textureParent->EnsureTextureHost(descriptor.type()); MOZ_ASSERT(textureParent->GetTextureHost()); SurfaceDescriptor newBack; bool shouldRecomposite = compositable->Update(op.image(), &newBack); if (IsSurfaceDescriptorValid(newBack)) { replyv.push_back(OpTextureSwap(op.textureParent(), nullptr, newBack)); } if (shouldRecomposite && textureParent->GetCompositorID()) { CompositorParent* cp = CompositorParent::GetCompositor(textureParent->GetCompositorID()); if (cp) { cp->ScheduleComposition(); } } if (layer) { RenderTraceInvalidateEnd(layer, "FF00FF"); } break; } case CompositableOperation::TOpPaintTextureRegion: { MOZ_LAYERS_LOG(("[ParentSide] Paint ThebesLayer")); const OpPaintTextureRegion& op = aEdit.get_OpPaintTextureRegion(); CompositableParent* compositableParent = static_cast<CompositableParent*>(op.compositableParent()); CompositableHost* compositable = compositableParent->GetCompositableHost(); ShadowThebesLayer* thebes = static_cast<ShadowThebesLayer*>(compositable->GetLayer()); const ThebesBufferData& bufferData = op.bufferData(); RenderTraceInvalidateStart(thebes, "FF00FF", op.updatedRegion().GetBounds()); nsIntRegion frontUpdatedRegion; compositable->UpdateThebes(bufferData, op.updatedRegion(), thebes->GetValidRegion(), &frontUpdatedRegion); replyv.push_back( OpContentBufferSwap(compositableParent, nullptr, frontUpdatedRegion)); RenderTraceInvalidateEnd(thebes, "FF00FF"); break; } case CompositableOperation::TOpUpdatePictureRect: { const OpUpdatePictureRect& op = aEdit.get_OpUpdatePictureRect(); CompositableHost* compositable = static_cast<CompositableParent*>(op.compositableParent())->GetCompositableHost(); MOZ_ASSERT(compositable); compositable->SetPictureRect(op.picture()); break; } default: { MOZ_ASSERT(false, "bad type"); } } return true; }