1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/layers/ipc/LayerTransactionParent.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,814 @@ 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 "LayerTransactionParent.h" 1.12 +#include <vector> // for vector 1.13 +#include "CompositableHost.h" // for CompositableParent, Get, etc 1.14 +#include "ImageLayers.h" // for ImageLayer 1.15 +#include "Layers.h" // for Layer, ContainerLayer, etc 1.16 +#include "ShadowLayerParent.h" // for ShadowLayerParent 1.17 +#include "gfx3DMatrix.h" // for gfx3DMatrix 1.18 +#include "gfxPoint3D.h" // for gfxPoint3D 1.19 +#include "CompositableTransactionParent.h" // for EditReplyVector 1.20 +#include "ShadowLayersManager.h" // for ShadowLayersManager 1.21 +#include "mozilla/gfx/BasePoint3D.h" // for BasePoint3D 1.22 +#include "mozilla/layers/CanvasLayerComposite.h" 1.23 +#include "mozilla/layers/ColorLayerComposite.h" 1.24 +#include "mozilla/layers/Compositor.h" // for Compositor 1.25 +#include "mozilla/layers/ContainerLayerComposite.h" 1.26 +#include "mozilla/layers/ImageLayerComposite.h" 1.27 +#include "mozilla/layers/LayerManagerComposite.h" 1.28 +#include "mozilla/layers/LayersMessages.h" // for EditReply, etc 1.29 +#include "mozilla/layers/LayersSurfaces.h" // for PGrallocBufferParent 1.30 +#include "mozilla/layers/LayersTypes.h" // for MOZ_LAYERS_LOG 1.31 +#include "mozilla/layers/PCompositableParent.h" 1.32 +#include "mozilla/layers/PLayerParent.h" // for PLayerParent 1.33 +#include "mozilla/layers/ThebesLayerComposite.h" 1.34 +#include "mozilla/mozalloc.h" // for operator delete, etc 1.35 +#include "nsCoord.h" // for NSAppUnitsToFloatPixels 1.36 +#include "nsDebug.h" // for NS_RUNTIMEABORT 1.37 +#include "nsDeviceContext.h" // for AppUnitsPerCSSPixel 1.38 +#include "nsISupportsImpl.h" // for Layer::Release, etc 1.39 +#include "nsLayoutUtils.h" // for nsLayoutUtils 1.40 +#include "nsMathUtils.h" // for NS_round 1.41 +#include "nsPoint.h" // for nsPoint 1.42 +#include "nsTArray.h" // for nsTArray, nsTArray_Impl, etc 1.43 +#include "GeckoProfiler.h" 1.44 +#include "mozilla/layers/TextureHost.h" 1.45 +#include "mozilla/layers/AsyncCompositionManager.h" 1.46 +#include "mozilla/layers/AsyncPanZoomController.h" 1.47 + 1.48 +typedef std::vector<mozilla::layers::EditReply> EditReplyVector; 1.49 + 1.50 +using mozilla::layout::RenderFrameParent; 1.51 + 1.52 +namespace mozilla { 1.53 +namespace layers { 1.54 + 1.55 +class PGrallocBufferParent; 1.56 + 1.57 +//-------------------------------------------------- 1.58 +// Convenience accessors 1.59 +static ShadowLayerParent* 1.60 +cast(const PLayerParent* in) 1.61 +{ 1.62 + return const_cast<ShadowLayerParent*>( 1.63 + static_cast<const ShadowLayerParent*>(in)); 1.64 +} 1.65 + 1.66 +template<class OpCreateT> 1.67 +static ShadowLayerParent* 1.68 +AsLayerComposite(const OpCreateT& op) 1.69 +{ 1.70 + return cast(op.layerParent()); 1.71 +} 1.72 + 1.73 +static ShadowLayerParent* 1.74 +AsLayerComposite(const OpSetRoot& op) 1.75 +{ 1.76 + return cast(op.rootParent()); 1.77 +} 1.78 + 1.79 +static ShadowLayerParent* 1.80 +ShadowContainer(const OpInsertAfter& op) 1.81 +{ 1.82 + return cast(op.containerParent()); 1.83 +} 1.84 +static ShadowLayerParent* 1.85 +ShadowChild(const OpInsertAfter& op) 1.86 +{ 1.87 + return cast(op.childLayerParent()); 1.88 +} 1.89 +static ShadowLayerParent* 1.90 +ShadowAfter(const OpInsertAfter& op) 1.91 +{ 1.92 + return cast(op.afterParent()); 1.93 +} 1.94 + 1.95 +static ShadowLayerParent* 1.96 +ShadowContainer(const OpPrependChild& op) 1.97 +{ 1.98 + return cast(op.containerParent()); 1.99 +} 1.100 +static ShadowLayerParent* 1.101 +ShadowChild(const OpPrependChild& op) 1.102 +{ 1.103 + return cast(op.childLayerParent()); 1.104 +} 1.105 + 1.106 +static ShadowLayerParent* 1.107 +ShadowContainer(const OpRemoveChild& op) 1.108 +{ 1.109 + return cast(op.containerParent()); 1.110 +} 1.111 +static ShadowLayerParent* 1.112 +ShadowChild(const OpRemoveChild& op) 1.113 +{ 1.114 + return cast(op.childLayerParent()); 1.115 +} 1.116 + 1.117 +static ShadowLayerParent* 1.118 +ShadowContainer(const OpRepositionChild& op) 1.119 +{ 1.120 + return cast(op.containerParent()); 1.121 +} 1.122 +static ShadowLayerParent* 1.123 +ShadowChild(const OpRepositionChild& op) 1.124 +{ 1.125 + return cast(op.childLayerParent()); 1.126 +} 1.127 +static ShadowLayerParent* 1.128 +ShadowAfter(const OpRepositionChild& op) 1.129 +{ 1.130 + return cast(op.afterParent()); 1.131 +} 1.132 + 1.133 +static ShadowLayerParent* 1.134 +ShadowContainer(const OpRaiseToTopChild& op) 1.135 +{ 1.136 + return cast(op.containerParent()); 1.137 +} 1.138 +static ShadowLayerParent* 1.139 +ShadowChild(const OpRaiseToTopChild& op) 1.140 +{ 1.141 + return cast(op.childLayerParent()); 1.142 +} 1.143 + 1.144 +//-------------------------------------------------- 1.145 +// LayerTransactionParent 1.146 +LayerTransactionParent::LayerTransactionParent(LayerManagerComposite* aManager, 1.147 + ShadowLayersManager* aLayersManager, 1.148 + uint64_t aId) 1.149 + : mLayerManager(aManager) 1.150 + , mShadowLayersManager(aLayersManager) 1.151 + , mId(aId) 1.152 + , mDestroyed(false) 1.153 + , mIPCOpen(false) 1.154 +{ 1.155 + MOZ_COUNT_CTOR(LayerTransactionParent); 1.156 +} 1.157 + 1.158 +LayerTransactionParent::~LayerTransactionParent() 1.159 +{ 1.160 + MOZ_COUNT_DTOR(LayerTransactionParent); 1.161 +} 1.162 + 1.163 +void 1.164 +LayerTransactionParent::Destroy() 1.165 +{ 1.166 + mDestroyed = true; 1.167 + for (size_t i = 0; i < ManagedPLayerParent().Length(); ++i) { 1.168 + ShadowLayerParent* slp = 1.169 + static_cast<ShadowLayerParent*>(ManagedPLayerParent()[i]); 1.170 + slp->Destroy(); 1.171 + } 1.172 +} 1.173 + 1.174 +LayersBackend 1.175 +LayerTransactionParent::GetCompositorBackendType() const 1.176 +{ 1.177 + return mLayerManager->GetBackendType(); 1.178 +} 1.179 + 1.180 +/* virtual */ 1.181 +bool 1.182 +LayerTransactionParent::RecvUpdateNoSwap(const InfallibleTArray<Edit>& cset, 1.183 + const TargetConfig& targetConfig, 1.184 + const bool& isFirstPaint, 1.185 + const bool& scheduleComposite) 1.186 +{ 1.187 + return RecvUpdate(cset, targetConfig, isFirstPaint, scheduleComposite, nullptr); 1.188 +} 1.189 + 1.190 +bool 1.191 +LayerTransactionParent::RecvUpdate(const InfallibleTArray<Edit>& cset, 1.192 + const TargetConfig& targetConfig, 1.193 + const bool& isFirstPaint, 1.194 + const bool& scheduleComposite, 1.195 + InfallibleTArray<EditReply>* reply) 1.196 +{ 1.197 + profiler_tracing("Paint", "Composite", TRACING_INTERVAL_START); 1.198 + PROFILER_LABEL("LayerTransactionParent", "RecvUpdate"); 1.199 +#ifdef COMPOSITOR_PERFORMANCE_WARNING 1.200 + TimeStamp updateStart = TimeStamp::Now(); 1.201 +#endif 1.202 + 1.203 + MOZ_LAYERS_LOG(("[ParentSide] received txn with %d edits", cset.Length())); 1.204 + 1.205 + if (mDestroyed || !layer_manager() || layer_manager()->IsDestroyed()) { 1.206 + return true; 1.207 + } 1.208 + 1.209 + if (mLayerManager && mLayerManager->GetCompositor() && 1.210 + !targetConfig.naturalBounds().IsEmpty()) { 1.211 + mLayerManager->GetCompositor()->SetScreenRotation(targetConfig.rotation()); 1.212 + } 1.213 + 1.214 + // Clear fence handles used in previsou transaction. 1.215 + ClearPrevFenceHandles(); 1.216 + 1.217 + EditReplyVector replyv; 1.218 + 1.219 + { 1.220 + AutoResolveRefLayers resolve(mShadowLayersManager->GetCompositionManager(this)); 1.221 + layer_manager()->BeginTransaction(); 1.222 + } 1.223 + 1.224 + for (EditArray::index_type i = 0; i < cset.Length(); ++i) { 1.225 + const Edit& edit = cset[i]; 1.226 + 1.227 + switch (edit.type()) { 1.228 + // Create* ops 1.229 + case Edit::TOpCreateThebesLayer: { 1.230 + MOZ_LAYERS_LOG(("[ParentSide] CreateThebesLayer")); 1.231 + 1.232 + nsRefPtr<ThebesLayerComposite> layer = 1.233 + layer_manager()->CreateThebesLayerComposite(); 1.234 + AsLayerComposite(edit.get_OpCreateThebesLayer())->Bind(layer); 1.235 + break; 1.236 + } 1.237 + case Edit::TOpCreateContainerLayer: { 1.238 + MOZ_LAYERS_LOG(("[ParentSide] CreateContainerLayer")); 1.239 + 1.240 + nsRefPtr<ContainerLayer> layer = layer_manager()->CreateContainerLayerComposite(); 1.241 + AsLayerComposite(edit.get_OpCreateContainerLayer())->Bind(layer); 1.242 + break; 1.243 + } 1.244 + case Edit::TOpCreateImageLayer: { 1.245 + MOZ_LAYERS_LOG(("[ParentSide] CreateImageLayer")); 1.246 + 1.247 + nsRefPtr<ImageLayerComposite> layer = 1.248 + layer_manager()->CreateImageLayerComposite(); 1.249 + AsLayerComposite(edit.get_OpCreateImageLayer())->Bind(layer); 1.250 + break; 1.251 + } 1.252 + case Edit::TOpCreateColorLayer: { 1.253 + MOZ_LAYERS_LOG(("[ParentSide] CreateColorLayer")); 1.254 + 1.255 + nsRefPtr<ColorLayerComposite> layer = layer_manager()->CreateColorLayerComposite(); 1.256 + AsLayerComposite(edit.get_OpCreateColorLayer())->Bind(layer); 1.257 + break; 1.258 + } 1.259 + case Edit::TOpCreateCanvasLayer: { 1.260 + MOZ_LAYERS_LOG(("[ParentSide] CreateCanvasLayer")); 1.261 + 1.262 + nsRefPtr<CanvasLayerComposite> layer = 1.263 + layer_manager()->CreateCanvasLayerComposite(); 1.264 + AsLayerComposite(edit.get_OpCreateCanvasLayer())->Bind(layer); 1.265 + break; 1.266 + } 1.267 + case Edit::TOpCreateRefLayer: { 1.268 + MOZ_LAYERS_LOG(("[ParentSide] CreateRefLayer")); 1.269 + 1.270 + nsRefPtr<RefLayerComposite> layer = 1.271 + layer_manager()->CreateRefLayerComposite(); 1.272 + AsLayerComposite(edit.get_OpCreateRefLayer())->Bind(layer); 1.273 + break; 1.274 + } 1.275 + 1.276 + // Attributes 1.277 + case Edit::TOpSetLayerAttributes: { 1.278 + MOZ_LAYERS_LOG(("[ParentSide] SetLayerAttributes")); 1.279 + 1.280 + const OpSetLayerAttributes& osla = edit.get_OpSetLayerAttributes(); 1.281 + ShadowLayerParent* layerParent = AsLayerComposite(osla); 1.282 + Layer* layer = layerParent->AsLayer(); 1.283 + if (!layer) { 1.284 + return false; 1.285 + } 1.286 + const LayerAttributes& attrs = osla.attrs(); 1.287 + 1.288 + const CommonLayerAttributes& common = attrs.common(); 1.289 + layer->SetVisibleRegion(common.visibleRegion()); 1.290 + layer->SetEventRegions(common.eventRegions()); 1.291 + layer->SetContentFlags(common.contentFlags()); 1.292 + layer->SetOpacity(common.opacity()); 1.293 + layer->SetClipRect(common.useClipRect() ? &common.clipRect() : nullptr); 1.294 + layer->SetBaseTransform(common.transform().value()); 1.295 + layer->SetPostScale(common.postXScale(), common.postYScale()); 1.296 + layer->SetIsFixedPosition(common.isFixedPosition()); 1.297 + layer->SetFixedPositionAnchor(common.fixedPositionAnchor()); 1.298 + layer->SetFixedPositionMargins(common.fixedPositionMargin()); 1.299 + if (common.isStickyPosition()) { 1.300 + layer->SetStickyPositionData(common.stickyScrollContainerId(), 1.301 + common.stickyScrollRangeOuter(), 1.302 + common.stickyScrollRangeInner()); 1.303 + } 1.304 + layer->SetScrollbarData(common.scrollbarTargetContainerId(), 1.305 + static_cast<Layer::ScrollDirection>(common.scrollbarDirection())); 1.306 + if (PLayerParent* maskLayer = common.maskLayerParent()) { 1.307 + layer->SetMaskLayer(cast(maskLayer)->AsLayer()); 1.308 + } else { 1.309 + layer->SetMaskLayer(nullptr); 1.310 + } 1.311 + layer->SetAnimations(common.animations()); 1.312 + layer->SetInvalidRegion(common.invalidRegion()); 1.313 + 1.314 + typedef SpecificLayerAttributes Specific; 1.315 + const SpecificLayerAttributes& specific = attrs.specific(); 1.316 + switch (specific.type()) { 1.317 + case Specific::Tnull_t: 1.318 + break; 1.319 + 1.320 + case Specific::TThebesLayerAttributes: { 1.321 + MOZ_LAYERS_LOG(("[ParentSide] thebes layer")); 1.322 + 1.323 + ThebesLayerComposite* thebesLayer = layerParent->AsThebesLayerComposite(); 1.324 + if (!thebesLayer) { 1.325 + return false; 1.326 + } 1.327 + const ThebesLayerAttributes& attrs = 1.328 + specific.get_ThebesLayerAttributes(); 1.329 + 1.330 + thebesLayer->SetValidRegion(attrs.validRegion()); 1.331 + 1.332 + break; 1.333 + } 1.334 + case Specific::TContainerLayerAttributes: { 1.335 + MOZ_LAYERS_LOG(("[ParentSide] container layer")); 1.336 + 1.337 + ContainerLayerComposite* containerLayer = layerParent->AsContainerLayerComposite(); 1.338 + if (!containerLayer) { 1.339 + return false; 1.340 + } 1.341 + const ContainerLayerAttributes& attrs = 1.342 + specific.get_ContainerLayerAttributes(); 1.343 + containerLayer->SetFrameMetrics(attrs.metrics()); 1.344 + containerLayer->SetScrollHandoffParentId(attrs.scrollParentId()); 1.345 + containerLayer->SetPreScale(attrs.preXScale(), attrs.preYScale()); 1.346 + containerLayer->SetInheritedScale(attrs.inheritedXScale(), attrs.inheritedYScale()); 1.347 + break; 1.348 + } 1.349 + case Specific::TColorLayerAttributes: { 1.350 + MOZ_LAYERS_LOG(("[ParentSide] color layer")); 1.351 + 1.352 + ColorLayerComposite* colorLayer = layerParent->AsColorLayerComposite(); 1.353 + if (!colorLayer) { 1.354 + return false; 1.355 + } 1.356 + colorLayer->SetColor(specific.get_ColorLayerAttributes().color().value()); 1.357 + colorLayer->SetBounds(specific.get_ColorLayerAttributes().bounds()); 1.358 + break; 1.359 + } 1.360 + case Specific::TCanvasLayerAttributes: { 1.361 + MOZ_LAYERS_LOG(("[ParentSide] canvas layer")); 1.362 + 1.363 + CanvasLayerComposite* canvasLayer = layerParent->AsCanvasLayerComposite(); 1.364 + if (!canvasLayer) { 1.365 + return false; 1.366 + } 1.367 + canvasLayer->SetFilter(specific.get_CanvasLayerAttributes().filter()); 1.368 + canvasLayer->SetBounds(specific.get_CanvasLayerAttributes().bounds()); 1.369 + break; 1.370 + } 1.371 + case Specific::TRefLayerAttributes: { 1.372 + MOZ_LAYERS_LOG(("[ParentSide] ref layer")); 1.373 + 1.374 + RefLayerComposite* refLayer = layerParent->AsRefLayerComposite(); 1.375 + if (!refLayer) { 1.376 + return false; 1.377 + } 1.378 + refLayer->SetReferentId(specific.get_RefLayerAttributes().id()); 1.379 + break; 1.380 + } 1.381 + case Specific::TImageLayerAttributes: { 1.382 + MOZ_LAYERS_LOG(("[ParentSide] image layer")); 1.383 + 1.384 + ImageLayerComposite* imageLayer = layerParent->AsImageLayerComposite(); 1.385 + if (!imageLayer) { 1.386 + return false; 1.387 + } 1.388 + const ImageLayerAttributes& attrs = specific.get_ImageLayerAttributes(); 1.389 + imageLayer->SetFilter(attrs.filter()); 1.390 + imageLayer->SetScaleToSize(attrs.scaleToSize(), attrs.scaleMode()); 1.391 + break; 1.392 + } 1.393 + default: 1.394 + NS_RUNTIMEABORT("not reached"); 1.395 + } 1.396 + break; 1.397 + } 1.398 + case Edit::TOpSetDiagnosticTypes: { 1.399 + mLayerManager->GetCompositor()->SetDiagnosticTypes( 1.400 + edit.get_OpSetDiagnosticTypes().diagnostics()); 1.401 + break; 1.402 + } 1.403 + // Tree ops 1.404 + case Edit::TOpSetRoot: { 1.405 + MOZ_LAYERS_LOG(("[ParentSide] SetRoot")); 1.406 + 1.407 + Layer* newRoot = AsLayerComposite(edit.get_OpSetRoot())->AsLayer(); 1.408 + if (!newRoot) { 1.409 + return false; 1.410 + } 1.411 + if (newRoot->GetParent()) { 1.412 + // newRoot is not a root! 1.413 + return false; 1.414 + } 1.415 + mRoot = newRoot; 1.416 + break; 1.417 + } 1.418 + case Edit::TOpInsertAfter: { 1.419 + MOZ_LAYERS_LOG(("[ParentSide] InsertAfter")); 1.420 + 1.421 + const OpInsertAfter& oia = edit.get_OpInsertAfter(); 1.422 + Layer* child = ShadowChild(oia)->AsLayer(); 1.423 + if (!child) { 1.424 + return false; 1.425 + } 1.426 + ContainerLayerComposite* container = ShadowContainer(oia)->AsContainerLayerComposite(); 1.427 + if (!container || 1.428 + !container->InsertAfter(child, ShadowAfter(oia)->AsLayer())) 1.429 + { 1.430 + return false; 1.431 + } 1.432 + break; 1.433 + } 1.434 + case Edit::TOpPrependChild: { 1.435 + MOZ_LAYERS_LOG(("[ParentSide] PrependChild")); 1.436 + 1.437 + const OpPrependChild& oac = edit.get_OpPrependChild(); 1.438 + Layer* child = ShadowChild(oac)->AsLayer(); 1.439 + if (!child) { 1.440 + return false; 1.441 + } 1.442 + ContainerLayerComposite* container = ShadowContainer(oac)->AsContainerLayerComposite(); 1.443 + if (!container || 1.444 + !container->InsertAfter(child, nullptr)) 1.445 + { 1.446 + return false; 1.447 + } 1.448 + break; 1.449 + } 1.450 + case Edit::TOpRemoveChild: { 1.451 + MOZ_LAYERS_LOG(("[ParentSide] RemoveChild")); 1.452 + 1.453 + const OpRemoveChild& orc = edit.get_OpRemoveChild(); 1.454 + Layer* childLayer = ShadowChild(orc)->AsLayer(); 1.455 + if (!childLayer) { 1.456 + return false; 1.457 + } 1.458 + ContainerLayerComposite* container = ShadowContainer(orc)->AsContainerLayerComposite(); 1.459 + if (!container || 1.460 + !container->RemoveChild(childLayer)) 1.461 + { 1.462 + return false; 1.463 + } 1.464 + break; 1.465 + } 1.466 + case Edit::TOpRepositionChild: { 1.467 + MOZ_LAYERS_LOG(("[ParentSide] RepositionChild")); 1.468 + 1.469 + const OpRepositionChild& orc = edit.get_OpRepositionChild(); 1.470 + Layer* child = ShadowChild(orc)->AsLayer(); 1.471 + if (!child) { 1.472 + return false; 1.473 + } 1.474 + ContainerLayerComposite* container = ShadowContainer(orc)->AsContainerLayerComposite(); 1.475 + if (!container || 1.476 + !container->RepositionChild(child, ShadowAfter(orc)->AsLayer())) 1.477 + { 1.478 + return false; 1.479 + } 1.480 + break; 1.481 + } 1.482 + case Edit::TOpRaiseToTopChild: { 1.483 + MOZ_LAYERS_LOG(("[ParentSide] RaiseToTopChild")); 1.484 + 1.485 + const OpRaiseToTopChild& rtc = edit.get_OpRaiseToTopChild(); 1.486 + Layer* child = ShadowChild(rtc)->AsLayer(); 1.487 + if (!child) { 1.488 + return false; 1.489 + } 1.490 + ContainerLayerComposite* container = ShadowContainer(rtc)->AsContainerLayerComposite(); 1.491 + if (!container || 1.492 + !container->RepositionChild(child, nullptr)) 1.493 + { 1.494 + return false; 1.495 + } 1.496 + break; 1.497 + } 1.498 + case Edit::TCompositableOperation: { 1.499 + if (!ReceiveCompositableUpdate(edit.get_CompositableOperation(), 1.500 + replyv)) { 1.501 + return false; 1.502 + } 1.503 + break; 1.504 + } 1.505 + case Edit::TOpAttachCompositable: { 1.506 + const OpAttachCompositable& op = edit.get_OpAttachCompositable(); 1.507 + CompositableHost* host = CompositableHost::FromIPDLActor(op.compositableParent()); 1.508 + if (!Attach(cast(op.layerParent()), host, false)) { 1.509 + return false; 1.510 + } 1.511 + host->SetCompositorID(mLayerManager->GetCompositor()->GetCompositorID()); 1.512 + break; 1.513 + } 1.514 + case Edit::TOpAttachAsyncCompositable: { 1.515 + const OpAttachAsyncCompositable& op = edit.get_OpAttachAsyncCompositable(); 1.516 + PCompositableParent* compositableParent = CompositableMap::Get(op.containerID()); 1.517 + if (!compositableParent) { 1.518 + NS_ERROR("CompositableParent not found in the map"); 1.519 + return false; 1.520 + } 1.521 + CompositableHost* host = CompositableHost::FromIPDLActor(compositableParent); 1.522 + if (!Attach(cast(op.layerParent()), host, true)) { 1.523 + return false; 1.524 + } 1.525 + 1.526 + host->SetCompositorID(mLayerManager->GetCompositor()->GetCompositorID()); 1.527 + break; 1.528 + } 1.529 + default: 1.530 + NS_RUNTIMEABORT("not reached"); 1.531 + } 1.532 + } 1.533 + 1.534 + { 1.535 + AutoResolveRefLayers resolve(mShadowLayersManager->GetCompositionManager(this)); 1.536 + layer_manager()->EndTransaction(nullptr, nullptr, LayerManager::END_NO_IMMEDIATE_REDRAW); 1.537 + } 1.538 + 1.539 + if (reply) { 1.540 + reply->SetCapacity(replyv.size()); 1.541 + if (replyv.size() > 0) { 1.542 + reply->AppendElements(&replyv.front(), replyv.size()); 1.543 + } 1.544 + } 1.545 + 1.546 + // Ensure that any pending operations involving back and front 1.547 + // buffers have completed, so that neither process stomps on the 1.548 + // other's buffer contents. 1.549 + LayerManagerComposite::PlatformSyncBeforeReplyUpdate(); 1.550 + 1.551 + mShadowLayersManager->ShadowLayersUpdated(this, targetConfig, isFirstPaint, scheduleComposite); 1.552 + 1.553 +#ifdef COMPOSITOR_PERFORMANCE_WARNING 1.554 + int compositeTime = (int)(mozilla::TimeStamp::Now() - updateStart).ToMilliseconds(); 1.555 + if (compositeTime > 15) { 1.556 + printf_stderr("Compositor: Layers update took %i ms (blocking gecko).\n", compositeTime); 1.557 + } 1.558 +#endif 1.559 + 1.560 + return true; 1.561 +} 1.562 + 1.563 +bool 1.564 +LayerTransactionParent::RecvSetTestSampleTime(const TimeStamp& aTime) 1.565 +{ 1.566 + return mShadowLayersManager->SetTestSampleTime(this, aTime); 1.567 +} 1.568 + 1.569 +bool 1.570 +LayerTransactionParent::RecvLeaveTestMode() 1.571 +{ 1.572 + mShadowLayersManager->LeaveTestMode(this); 1.573 + return true; 1.574 +} 1.575 + 1.576 +bool 1.577 +LayerTransactionParent::RecvGetOpacity(PLayerParent* aParent, 1.578 + float* aOpacity) 1.579 +{ 1.580 + if (mDestroyed || !layer_manager() || layer_manager()->IsDestroyed()) { 1.581 + return false; 1.582 + } 1.583 + 1.584 + Layer* layer = cast(aParent)->AsLayer(); 1.585 + if (!layer) { 1.586 + return false; 1.587 + } 1.588 + 1.589 + *aOpacity = layer->GetLocalOpacity(); 1.590 + return true; 1.591 +} 1.592 + 1.593 +bool 1.594 +LayerTransactionParent::RecvGetAnimationTransform(PLayerParent* aParent, 1.595 + MaybeTransform* aTransform) 1.596 +{ 1.597 + if (mDestroyed || !layer_manager() || layer_manager()->IsDestroyed()) { 1.598 + return false; 1.599 + } 1.600 + 1.601 + Layer* layer = cast(aParent)->AsLayer(); 1.602 + if (!layer) { 1.603 + return false; 1.604 + } 1.605 + 1.606 + // This method is specific to transforms applied by animation. 1.607 + // This is because this method uses the information stored with an animation 1.608 + // such as the origin of the reference frame corresponding to the layer, to 1.609 + // recover the untranslated transform from the shadow transform. For 1.610 + // transforms that are not set by animation we don't have this information 1.611 + // available. 1.612 + if (!layer->AsLayerComposite()->GetShadowTransformSetByAnimation()) { 1.613 + *aTransform = mozilla::void_t(); 1.614 + return true; 1.615 + } 1.616 + 1.617 + // The following code recovers the untranslated transform 1.618 + // from the shadow transform by undoing the translations in 1.619 + // AsyncCompositionManager::SampleValue. 1.620 + 1.621 + gfx3DMatrix transform; 1.622 + gfx::To3DMatrix(layer->AsLayerComposite()->GetShadowTransform(), transform); 1.623 + if (ContainerLayer* c = layer->AsContainerLayer()) { 1.624 + // Undo the scale transform applied by AsyncCompositionManager::SampleValue 1.625 + transform.ScalePost(1.0f/c->GetInheritedXScale(), 1.626 + 1.0f/c->GetInheritedYScale(), 1.627 + 1.0f); 1.628 + } 1.629 + float scale = 1; 1.630 + gfxPoint3D scaledOrigin; 1.631 + gfxPoint3D transformOrigin; 1.632 + for (uint32_t i=0; i < layer->GetAnimations().Length(); i++) { 1.633 + if (layer->GetAnimations()[i].data().type() == AnimationData::TTransformData) { 1.634 + const TransformData& data = layer->GetAnimations()[i].data().get_TransformData(); 1.635 + scale = data.appUnitsPerDevPixel(); 1.636 + scaledOrigin = 1.637 + gfxPoint3D(NS_round(NSAppUnitsToFloatPixels(data.origin().x, scale)), 1.638 + NS_round(NSAppUnitsToFloatPixels(data.origin().y, scale)), 1.639 + 0.0f); 1.640 + double cssPerDev = 1.641 + double(nsDeviceContext::AppUnitsPerCSSPixel()) / double(scale); 1.642 + transformOrigin = data.transformOrigin() * cssPerDev; 1.643 + break; 1.644 + } 1.645 + } 1.646 + 1.647 + // Undo the translation to the origin of the reference frame applied by 1.648 + // AsyncCompositionManager::SampleValue 1.649 + transform.Translate(-scaledOrigin); 1.650 + 1.651 + // Undo the rebasing applied by 1.652 + // nsDisplayTransform::GetResultingTransformMatrixInternal 1.653 + transform = nsLayoutUtils::ChangeMatrixBasis(-scaledOrigin - transformOrigin, 1.654 + transform); 1.655 + 1.656 + // Convert to CSS pixels (this undoes the operations performed by 1.657 + // nsStyleTransformMatrix::ProcessTranslatePart which is called from 1.658 + // nsDisplayTransform::GetResultingTransformMatrix) 1.659 + double devPerCss = 1.660 + double(scale) / double(nsDeviceContext::AppUnitsPerCSSPixel()); 1.661 + transform._41 *= devPerCss; 1.662 + transform._42 *= devPerCss; 1.663 + transform._43 *= devPerCss; 1.664 + 1.665 + *aTransform = transform; 1.666 + return true; 1.667 +} 1.668 + 1.669 +bool 1.670 +LayerTransactionParent::RecvSetAsyncScrollOffset(PLayerParent* aLayer, 1.671 + const int32_t& aX, const int32_t& aY) 1.672 +{ 1.673 + if (mDestroyed || !layer_manager() || layer_manager()->IsDestroyed()) { 1.674 + return false; 1.675 + } 1.676 + 1.677 + Layer* layer = cast(aLayer)->AsLayer(); 1.678 + if (!layer) { 1.679 + return false; 1.680 + } 1.681 + ContainerLayer* containerLayer = layer->AsContainerLayer(); 1.682 + if (!containerLayer) { 1.683 + return false; 1.684 + } 1.685 + AsyncPanZoomController* controller = containerLayer->GetAsyncPanZoomController(); 1.686 + if (!controller) { 1.687 + return false; 1.688 + } 1.689 + controller->SetTestAsyncScrollOffset(CSSPoint(aX, aY)); 1.690 + return true; 1.691 +} 1.692 + 1.693 +bool 1.694 +LayerTransactionParent::Attach(ShadowLayerParent* aLayerParent, 1.695 + CompositableHost* aCompositable, 1.696 + bool aIsAsync) 1.697 +{ 1.698 + if (!aCompositable) { 1.699 + return false; 1.700 + } 1.701 + 1.702 + Layer* baselayer = aLayerParent->AsLayer(); 1.703 + if (!baselayer) { 1.704 + return false; 1.705 + } 1.706 + LayerComposite* layer = baselayer->AsLayerComposite(); 1.707 + if (!layer) { 1.708 + return false; 1.709 + } 1.710 + 1.711 + Compositor* compositor 1.712 + = static_cast<LayerManagerComposite*>(aLayerParent->AsLayer()->Manager())->GetCompositor(); 1.713 + 1.714 + if (!layer->SetCompositableHost(aCompositable)) { 1.715 + // not all layer types accept a compositable, see bug 967824 1.716 + return false; 1.717 + } 1.718 + aCompositable->Attach(aLayerParent->AsLayer(), 1.719 + compositor, 1.720 + aIsAsync 1.721 + ? CompositableHost::ALLOW_REATTACH 1.722 + | CompositableHost::KEEP_ATTACHED 1.723 + : CompositableHost::NO_FLAGS); 1.724 + return true; 1.725 +} 1.726 + 1.727 +bool 1.728 +LayerTransactionParent::RecvClearCachedResources() 1.729 +{ 1.730 + if (mRoot) { 1.731 + // NB: |mRoot| here is the *child* context's root. In this parent 1.732 + // context, it's just a subtree root. We need to scope the clear 1.733 + // of resources to exactly that subtree, so we specify it here. 1.734 + mLayerManager->ClearCachedResources(mRoot); 1.735 + } 1.736 + return true; 1.737 +} 1.738 + 1.739 +bool 1.740 +LayerTransactionParent::RecvForceComposite() 1.741 +{ 1.742 + mShadowLayersManager->ForceComposite(this); 1.743 + return true; 1.744 +} 1.745 + 1.746 + 1.747 +PGrallocBufferParent* 1.748 +LayerTransactionParent::AllocPGrallocBufferParent(const IntSize& aSize, 1.749 + const uint32_t& aFormat, 1.750 + const uint32_t& aUsage, 1.751 + MaybeMagicGrallocBufferHandle* aOutHandle) 1.752 +{ 1.753 +#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC 1.754 + return GrallocBufferActor::Create(aSize, aFormat, aUsage, aOutHandle); 1.755 +#else 1.756 + NS_RUNTIMEABORT("No gralloc buffers for you"); 1.757 + return nullptr; 1.758 +#endif 1.759 +} 1.760 + 1.761 +bool 1.762 +LayerTransactionParent::DeallocPGrallocBufferParent(PGrallocBufferParent* actor) 1.763 +{ 1.764 +#ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC 1.765 + delete actor; 1.766 + return true; 1.767 +#else 1.768 + NS_RUNTIMEABORT("Um, how did we get here?"); 1.769 + return false; 1.770 +#endif 1.771 +} 1.772 + 1.773 +PLayerParent* 1.774 +LayerTransactionParent::AllocPLayerParent() 1.775 +{ 1.776 + return new ShadowLayerParent(); 1.777 +} 1.778 + 1.779 +bool 1.780 +LayerTransactionParent::DeallocPLayerParent(PLayerParent* actor) 1.781 +{ 1.782 + delete actor; 1.783 + return true; 1.784 +} 1.785 + 1.786 +PCompositableParent* 1.787 +LayerTransactionParent::AllocPCompositableParent(const TextureInfo& aInfo) 1.788 +{ 1.789 + return CompositableHost::CreateIPDLActor(this, aInfo, 0); 1.790 +} 1.791 + 1.792 +bool 1.793 +LayerTransactionParent::DeallocPCompositableParent(PCompositableParent* aActor) 1.794 +{ 1.795 + return CompositableHost::DestroyIPDLActor(aActor); 1.796 +} 1.797 + 1.798 +PTextureParent* 1.799 +LayerTransactionParent::AllocPTextureParent(const SurfaceDescriptor& aSharedData, 1.800 + const TextureFlags& aFlags) 1.801 +{ 1.802 + return TextureHost::CreateIPDLActor(this, aSharedData, aFlags); 1.803 +} 1.804 + 1.805 +bool 1.806 +LayerTransactionParent::DeallocPTextureParent(PTextureParent* actor) 1.807 +{ 1.808 + return TextureHost::DestroyIPDLActor(actor); 1.809 +} 1.810 + 1.811 +bool LayerTransactionParent::IsSameProcess() const 1.812 +{ 1.813 + return OtherProcess() == ipc::kInvalidProcessHandle; 1.814 +} 1.815 + 1.816 +} // namespace layers 1.817 +} // namespace mozilla