gfx/layers/ipc/LayerTransactionParent.cpp

branch
TOR_BUG_9701
changeset 8
97036ab72558
equal deleted inserted replaced
-1:000000000000 0:593394c0b8e5
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/. */
7
8 #include "LayerTransactionParent.h"
9 #include <vector> // for vector
10 #include "CompositableHost.h" // for CompositableParent, Get, etc
11 #include "ImageLayers.h" // for ImageLayer
12 #include "Layers.h" // for Layer, ContainerLayer, etc
13 #include "ShadowLayerParent.h" // for ShadowLayerParent
14 #include "gfx3DMatrix.h" // for gfx3DMatrix
15 #include "gfxPoint3D.h" // for gfxPoint3D
16 #include "CompositableTransactionParent.h" // for EditReplyVector
17 #include "ShadowLayersManager.h" // for ShadowLayersManager
18 #include "mozilla/gfx/BasePoint3D.h" // for BasePoint3D
19 #include "mozilla/layers/CanvasLayerComposite.h"
20 #include "mozilla/layers/ColorLayerComposite.h"
21 #include "mozilla/layers/Compositor.h" // for Compositor
22 #include "mozilla/layers/ContainerLayerComposite.h"
23 #include "mozilla/layers/ImageLayerComposite.h"
24 #include "mozilla/layers/LayerManagerComposite.h"
25 #include "mozilla/layers/LayersMessages.h" // for EditReply, etc
26 #include "mozilla/layers/LayersSurfaces.h" // for PGrallocBufferParent
27 #include "mozilla/layers/LayersTypes.h" // for MOZ_LAYERS_LOG
28 #include "mozilla/layers/PCompositableParent.h"
29 #include "mozilla/layers/PLayerParent.h" // for PLayerParent
30 #include "mozilla/layers/ThebesLayerComposite.h"
31 #include "mozilla/mozalloc.h" // for operator delete, etc
32 #include "nsCoord.h" // for NSAppUnitsToFloatPixels
33 #include "nsDebug.h" // for NS_RUNTIMEABORT
34 #include "nsDeviceContext.h" // for AppUnitsPerCSSPixel
35 #include "nsISupportsImpl.h" // for Layer::Release, etc
36 #include "nsLayoutUtils.h" // for nsLayoutUtils
37 #include "nsMathUtils.h" // for NS_round
38 #include "nsPoint.h" // for nsPoint
39 #include "nsTArray.h" // for nsTArray, nsTArray_Impl, etc
40 #include "GeckoProfiler.h"
41 #include "mozilla/layers/TextureHost.h"
42 #include "mozilla/layers/AsyncCompositionManager.h"
43 #include "mozilla/layers/AsyncPanZoomController.h"
44
45 typedef std::vector<mozilla::layers::EditReply> EditReplyVector;
46
47 using mozilla::layout::RenderFrameParent;
48
49 namespace mozilla {
50 namespace layers {
51
52 class PGrallocBufferParent;
53
54 //--------------------------------------------------
55 // Convenience accessors
56 static ShadowLayerParent*
57 cast(const PLayerParent* in)
58 {
59 return const_cast<ShadowLayerParent*>(
60 static_cast<const ShadowLayerParent*>(in));
61 }
62
63 template<class OpCreateT>
64 static ShadowLayerParent*
65 AsLayerComposite(const OpCreateT& op)
66 {
67 return cast(op.layerParent());
68 }
69
70 static ShadowLayerParent*
71 AsLayerComposite(const OpSetRoot& op)
72 {
73 return cast(op.rootParent());
74 }
75
76 static ShadowLayerParent*
77 ShadowContainer(const OpInsertAfter& op)
78 {
79 return cast(op.containerParent());
80 }
81 static ShadowLayerParent*
82 ShadowChild(const OpInsertAfter& op)
83 {
84 return cast(op.childLayerParent());
85 }
86 static ShadowLayerParent*
87 ShadowAfter(const OpInsertAfter& op)
88 {
89 return cast(op.afterParent());
90 }
91
92 static ShadowLayerParent*
93 ShadowContainer(const OpPrependChild& op)
94 {
95 return cast(op.containerParent());
96 }
97 static ShadowLayerParent*
98 ShadowChild(const OpPrependChild& op)
99 {
100 return cast(op.childLayerParent());
101 }
102
103 static ShadowLayerParent*
104 ShadowContainer(const OpRemoveChild& op)
105 {
106 return cast(op.containerParent());
107 }
108 static ShadowLayerParent*
109 ShadowChild(const OpRemoveChild& op)
110 {
111 return cast(op.childLayerParent());
112 }
113
114 static ShadowLayerParent*
115 ShadowContainer(const OpRepositionChild& op)
116 {
117 return cast(op.containerParent());
118 }
119 static ShadowLayerParent*
120 ShadowChild(const OpRepositionChild& op)
121 {
122 return cast(op.childLayerParent());
123 }
124 static ShadowLayerParent*
125 ShadowAfter(const OpRepositionChild& op)
126 {
127 return cast(op.afterParent());
128 }
129
130 static ShadowLayerParent*
131 ShadowContainer(const OpRaiseToTopChild& op)
132 {
133 return cast(op.containerParent());
134 }
135 static ShadowLayerParent*
136 ShadowChild(const OpRaiseToTopChild& op)
137 {
138 return cast(op.childLayerParent());
139 }
140
141 //--------------------------------------------------
142 // LayerTransactionParent
143 LayerTransactionParent::LayerTransactionParent(LayerManagerComposite* aManager,
144 ShadowLayersManager* aLayersManager,
145 uint64_t aId)
146 : mLayerManager(aManager)
147 , mShadowLayersManager(aLayersManager)
148 , mId(aId)
149 , mDestroyed(false)
150 , mIPCOpen(false)
151 {
152 MOZ_COUNT_CTOR(LayerTransactionParent);
153 }
154
155 LayerTransactionParent::~LayerTransactionParent()
156 {
157 MOZ_COUNT_DTOR(LayerTransactionParent);
158 }
159
160 void
161 LayerTransactionParent::Destroy()
162 {
163 mDestroyed = true;
164 for (size_t i = 0; i < ManagedPLayerParent().Length(); ++i) {
165 ShadowLayerParent* slp =
166 static_cast<ShadowLayerParent*>(ManagedPLayerParent()[i]);
167 slp->Destroy();
168 }
169 }
170
171 LayersBackend
172 LayerTransactionParent::GetCompositorBackendType() const
173 {
174 return mLayerManager->GetBackendType();
175 }
176
177 /* virtual */
178 bool
179 LayerTransactionParent::RecvUpdateNoSwap(const InfallibleTArray<Edit>& cset,
180 const TargetConfig& targetConfig,
181 const bool& isFirstPaint,
182 const bool& scheduleComposite)
183 {
184 return RecvUpdate(cset, targetConfig, isFirstPaint, scheduleComposite, nullptr);
185 }
186
187 bool
188 LayerTransactionParent::RecvUpdate(const InfallibleTArray<Edit>& cset,
189 const TargetConfig& targetConfig,
190 const bool& isFirstPaint,
191 const bool& scheduleComposite,
192 InfallibleTArray<EditReply>* reply)
193 {
194 profiler_tracing("Paint", "Composite", TRACING_INTERVAL_START);
195 PROFILER_LABEL("LayerTransactionParent", "RecvUpdate");
196 #ifdef COMPOSITOR_PERFORMANCE_WARNING
197 TimeStamp updateStart = TimeStamp::Now();
198 #endif
199
200 MOZ_LAYERS_LOG(("[ParentSide] received txn with %d edits", cset.Length()));
201
202 if (mDestroyed || !layer_manager() || layer_manager()->IsDestroyed()) {
203 return true;
204 }
205
206 if (mLayerManager && mLayerManager->GetCompositor() &&
207 !targetConfig.naturalBounds().IsEmpty()) {
208 mLayerManager->GetCompositor()->SetScreenRotation(targetConfig.rotation());
209 }
210
211 // Clear fence handles used in previsou transaction.
212 ClearPrevFenceHandles();
213
214 EditReplyVector replyv;
215
216 {
217 AutoResolveRefLayers resolve(mShadowLayersManager->GetCompositionManager(this));
218 layer_manager()->BeginTransaction();
219 }
220
221 for (EditArray::index_type i = 0; i < cset.Length(); ++i) {
222 const Edit& edit = cset[i];
223
224 switch (edit.type()) {
225 // Create* ops
226 case Edit::TOpCreateThebesLayer: {
227 MOZ_LAYERS_LOG(("[ParentSide] CreateThebesLayer"));
228
229 nsRefPtr<ThebesLayerComposite> layer =
230 layer_manager()->CreateThebesLayerComposite();
231 AsLayerComposite(edit.get_OpCreateThebesLayer())->Bind(layer);
232 break;
233 }
234 case Edit::TOpCreateContainerLayer: {
235 MOZ_LAYERS_LOG(("[ParentSide] CreateContainerLayer"));
236
237 nsRefPtr<ContainerLayer> layer = layer_manager()->CreateContainerLayerComposite();
238 AsLayerComposite(edit.get_OpCreateContainerLayer())->Bind(layer);
239 break;
240 }
241 case Edit::TOpCreateImageLayer: {
242 MOZ_LAYERS_LOG(("[ParentSide] CreateImageLayer"));
243
244 nsRefPtr<ImageLayerComposite> layer =
245 layer_manager()->CreateImageLayerComposite();
246 AsLayerComposite(edit.get_OpCreateImageLayer())->Bind(layer);
247 break;
248 }
249 case Edit::TOpCreateColorLayer: {
250 MOZ_LAYERS_LOG(("[ParentSide] CreateColorLayer"));
251
252 nsRefPtr<ColorLayerComposite> layer = layer_manager()->CreateColorLayerComposite();
253 AsLayerComposite(edit.get_OpCreateColorLayer())->Bind(layer);
254 break;
255 }
256 case Edit::TOpCreateCanvasLayer: {
257 MOZ_LAYERS_LOG(("[ParentSide] CreateCanvasLayer"));
258
259 nsRefPtr<CanvasLayerComposite> layer =
260 layer_manager()->CreateCanvasLayerComposite();
261 AsLayerComposite(edit.get_OpCreateCanvasLayer())->Bind(layer);
262 break;
263 }
264 case Edit::TOpCreateRefLayer: {
265 MOZ_LAYERS_LOG(("[ParentSide] CreateRefLayer"));
266
267 nsRefPtr<RefLayerComposite> layer =
268 layer_manager()->CreateRefLayerComposite();
269 AsLayerComposite(edit.get_OpCreateRefLayer())->Bind(layer);
270 break;
271 }
272
273 // Attributes
274 case Edit::TOpSetLayerAttributes: {
275 MOZ_LAYERS_LOG(("[ParentSide] SetLayerAttributes"));
276
277 const OpSetLayerAttributes& osla = edit.get_OpSetLayerAttributes();
278 ShadowLayerParent* layerParent = AsLayerComposite(osla);
279 Layer* layer = layerParent->AsLayer();
280 if (!layer) {
281 return false;
282 }
283 const LayerAttributes& attrs = osla.attrs();
284
285 const CommonLayerAttributes& common = attrs.common();
286 layer->SetVisibleRegion(common.visibleRegion());
287 layer->SetEventRegions(common.eventRegions());
288 layer->SetContentFlags(common.contentFlags());
289 layer->SetOpacity(common.opacity());
290 layer->SetClipRect(common.useClipRect() ? &common.clipRect() : nullptr);
291 layer->SetBaseTransform(common.transform().value());
292 layer->SetPostScale(common.postXScale(), common.postYScale());
293 layer->SetIsFixedPosition(common.isFixedPosition());
294 layer->SetFixedPositionAnchor(common.fixedPositionAnchor());
295 layer->SetFixedPositionMargins(common.fixedPositionMargin());
296 if (common.isStickyPosition()) {
297 layer->SetStickyPositionData(common.stickyScrollContainerId(),
298 common.stickyScrollRangeOuter(),
299 common.stickyScrollRangeInner());
300 }
301 layer->SetScrollbarData(common.scrollbarTargetContainerId(),
302 static_cast<Layer::ScrollDirection>(common.scrollbarDirection()));
303 if (PLayerParent* maskLayer = common.maskLayerParent()) {
304 layer->SetMaskLayer(cast(maskLayer)->AsLayer());
305 } else {
306 layer->SetMaskLayer(nullptr);
307 }
308 layer->SetAnimations(common.animations());
309 layer->SetInvalidRegion(common.invalidRegion());
310
311 typedef SpecificLayerAttributes Specific;
312 const SpecificLayerAttributes& specific = attrs.specific();
313 switch (specific.type()) {
314 case Specific::Tnull_t:
315 break;
316
317 case Specific::TThebesLayerAttributes: {
318 MOZ_LAYERS_LOG(("[ParentSide] thebes layer"));
319
320 ThebesLayerComposite* thebesLayer = layerParent->AsThebesLayerComposite();
321 if (!thebesLayer) {
322 return false;
323 }
324 const ThebesLayerAttributes& attrs =
325 specific.get_ThebesLayerAttributes();
326
327 thebesLayer->SetValidRegion(attrs.validRegion());
328
329 break;
330 }
331 case Specific::TContainerLayerAttributes: {
332 MOZ_LAYERS_LOG(("[ParentSide] container layer"));
333
334 ContainerLayerComposite* containerLayer = layerParent->AsContainerLayerComposite();
335 if (!containerLayer) {
336 return false;
337 }
338 const ContainerLayerAttributes& attrs =
339 specific.get_ContainerLayerAttributes();
340 containerLayer->SetFrameMetrics(attrs.metrics());
341 containerLayer->SetScrollHandoffParentId(attrs.scrollParentId());
342 containerLayer->SetPreScale(attrs.preXScale(), attrs.preYScale());
343 containerLayer->SetInheritedScale(attrs.inheritedXScale(), attrs.inheritedYScale());
344 break;
345 }
346 case Specific::TColorLayerAttributes: {
347 MOZ_LAYERS_LOG(("[ParentSide] color layer"));
348
349 ColorLayerComposite* colorLayer = layerParent->AsColorLayerComposite();
350 if (!colorLayer) {
351 return false;
352 }
353 colorLayer->SetColor(specific.get_ColorLayerAttributes().color().value());
354 colorLayer->SetBounds(specific.get_ColorLayerAttributes().bounds());
355 break;
356 }
357 case Specific::TCanvasLayerAttributes: {
358 MOZ_LAYERS_LOG(("[ParentSide] canvas layer"));
359
360 CanvasLayerComposite* canvasLayer = layerParent->AsCanvasLayerComposite();
361 if (!canvasLayer) {
362 return false;
363 }
364 canvasLayer->SetFilter(specific.get_CanvasLayerAttributes().filter());
365 canvasLayer->SetBounds(specific.get_CanvasLayerAttributes().bounds());
366 break;
367 }
368 case Specific::TRefLayerAttributes: {
369 MOZ_LAYERS_LOG(("[ParentSide] ref layer"));
370
371 RefLayerComposite* refLayer = layerParent->AsRefLayerComposite();
372 if (!refLayer) {
373 return false;
374 }
375 refLayer->SetReferentId(specific.get_RefLayerAttributes().id());
376 break;
377 }
378 case Specific::TImageLayerAttributes: {
379 MOZ_LAYERS_LOG(("[ParentSide] image layer"));
380
381 ImageLayerComposite* imageLayer = layerParent->AsImageLayerComposite();
382 if (!imageLayer) {
383 return false;
384 }
385 const ImageLayerAttributes& attrs = specific.get_ImageLayerAttributes();
386 imageLayer->SetFilter(attrs.filter());
387 imageLayer->SetScaleToSize(attrs.scaleToSize(), attrs.scaleMode());
388 break;
389 }
390 default:
391 NS_RUNTIMEABORT("not reached");
392 }
393 break;
394 }
395 case Edit::TOpSetDiagnosticTypes: {
396 mLayerManager->GetCompositor()->SetDiagnosticTypes(
397 edit.get_OpSetDiagnosticTypes().diagnostics());
398 break;
399 }
400 // Tree ops
401 case Edit::TOpSetRoot: {
402 MOZ_LAYERS_LOG(("[ParentSide] SetRoot"));
403
404 Layer* newRoot = AsLayerComposite(edit.get_OpSetRoot())->AsLayer();
405 if (!newRoot) {
406 return false;
407 }
408 if (newRoot->GetParent()) {
409 // newRoot is not a root!
410 return false;
411 }
412 mRoot = newRoot;
413 break;
414 }
415 case Edit::TOpInsertAfter: {
416 MOZ_LAYERS_LOG(("[ParentSide] InsertAfter"));
417
418 const OpInsertAfter& oia = edit.get_OpInsertAfter();
419 Layer* child = ShadowChild(oia)->AsLayer();
420 if (!child) {
421 return false;
422 }
423 ContainerLayerComposite* container = ShadowContainer(oia)->AsContainerLayerComposite();
424 if (!container ||
425 !container->InsertAfter(child, ShadowAfter(oia)->AsLayer()))
426 {
427 return false;
428 }
429 break;
430 }
431 case Edit::TOpPrependChild: {
432 MOZ_LAYERS_LOG(("[ParentSide] PrependChild"));
433
434 const OpPrependChild& oac = edit.get_OpPrependChild();
435 Layer* child = ShadowChild(oac)->AsLayer();
436 if (!child) {
437 return false;
438 }
439 ContainerLayerComposite* container = ShadowContainer(oac)->AsContainerLayerComposite();
440 if (!container ||
441 !container->InsertAfter(child, nullptr))
442 {
443 return false;
444 }
445 break;
446 }
447 case Edit::TOpRemoveChild: {
448 MOZ_LAYERS_LOG(("[ParentSide] RemoveChild"));
449
450 const OpRemoveChild& orc = edit.get_OpRemoveChild();
451 Layer* childLayer = ShadowChild(orc)->AsLayer();
452 if (!childLayer) {
453 return false;
454 }
455 ContainerLayerComposite* container = ShadowContainer(orc)->AsContainerLayerComposite();
456 if (!container ||
457 !container->RemoveChild(childLayer))
458 {
459 return false;
460 }
461 break;
462 }
463 case Edit::TOpRepositionChild: {
464 MOZ_LAYERS_LOG(("[ParentSide] RepositionChild"));
465
466 const OpRepositionChild& orc = edit.get_OpRepositionChild();
467 Layer* child = ShadowChild(orc)->AsLayer();
468 if (!child) {
469 return false;
470 }
471 ContainerLayerComposite* container = ShadowContainer(orc)->AsContainerLayerComposite();
472 if (!container ||
473 !container->RepositionChild(child, ShadowAfter(orc)->AsLayer()))
474 {
475 return false;
476 }
477 break;
478 }
479 case Edit::TOpRaiseToTopChild: {
480 MOZ_LAYERS_LOG(("[ParentSide] RaiseToTopChild"));
481
482 const OpRaiseToTopChild& rtc = edit.get_OpRaiseToTopChild();
483 Layer* child = ShadowChild(rtc)->AsLayer();
484 if (!child) {
485 return false;
486 }
487 ContainerLayerComposite* container = ShadowContainer(rtc)->AsContainerLayerComposite();
488 if (!container ||
489 !container->RepositionChild(child, nullptr))
490 {
491 return false;
492 }
493 break;
494 }
495 case Edit::TCompositableOperation: {
496 if (!ReceiveCompositableUpdate(edit.get_CompositableOperation(),
497 replyv)) {
498 return false;
499 }
500 break;
501 }
502 case Edit::TOpAttachCompositable: {
503 const OpAttachCompositable& op = edit.get_OpAttachCompositable();
504 CompositableHost* host = CompositableHost::FromIPDLActor(op.compositableParent());
505 if (!Attach(cast(op.layerParent()), host, false)) {
506 return false;
507 }
508 host->SetCompositorID(mLayerManager->GetCompositor()->GetCompositorID());
509 break;
510 }
511 case Edit::TOpAttachAsyncCompositable: {
512 const OpAttachAsyncCompositable& op = edit.get_OpAttachAsyncCompositable();
513 PCompositableParent* compositableParent = CompositableMap::Get(op.containerID());
514 if (!compositableParent) {
515 NS_ERROR("CompositableParent not found in the map");
516 return false;
517 }
518 CompositableHost* host = CompositableHost::FromIPDLActor(compositableParent);
519 if (!Attach(cast(op.layerParent()), host, true)) {
520 return false;
521 }
522
523 host->SetCompositorID(mLayerManager->GetCompositor()->GetCompositorID());
524 break;
525 }
526 default:
527 NS_RUNTIMEABORT("not reached");
528 }
529 }
530
531 {
532 AutoResolveRefLayers resolve(mShadowLayersManager->GetCompositionManager(this));
533 layer_manager()->EndTransaction(nullptr, nullptr, LayerManager::END_NO_IMMEDIATE_REDRAW);
534 }
535
536 if (reply) {
537 reply->SetCapacity(replyv.size());
538 if (replyv.size() > 0) {
539 reply->AppendElements(&replyv.front(), replyv.size());
540 }
541 }
542
543 // Ensure that any pending operations involving back and front
544 // buffers have completed, so that neither process stomps on the
545 // other's buffer contents.
546 LayerManagerComposite::PlatformSyncBeforeReplyUpdate();
547
548 mShadowLayersManager->ShadowLayersUpdated(this, targetConfig, isFirstPaint, scheduleComposite);
549
550 #ifdef COMPOSITOR_PERFORMANCE_WARNING
551 int compositeTime = (int)(mozilla::TimeStamp::Now() - updateStart).ToMilliseconds();
552 if (compositeTime > 15) {
553 printf_stderr("Compositor: Layers update took %i ms (blocking gecko).\n", compositeTime);
554 }
555 #endif
556
557 return true;
558 }
559
560 bool
561 LayerTransactionParent::RecvSetTestSampleTime(const TimeStamp& aTime)
562 {
563 return mShadowLayersManager->SetTestSampleTime(this, aTime);
564 }
565
566 bool
567 LayerTransactionParent::RecvLeaveTestMode()
568 {
569 mShadowLayersManager->LeaveTestMode(this);
570 return true;
571 }
572
573 bool
574 LayerTransactionParent::RecvGetOpacity(PLayerParent* aParent,
575 float* aOpacity)
576 {
577 if (mDestroyed || !layer_manager() || layer_manager()->IsDestroyed()) {
578 return false;
579 }
580
581 Layer* layer = cast(aParent)->AsLayer();
582 if (!layer) {
583 return false;
584 }
585
586 *aOpacity = layer->GetLocalOpacity();
587 return true;
588 }
589
590 bool
591 LayerTransactionParent::RecvGetAnimationTransform(PLayerParent* aParent,
592 MaybeTransform* aTransform)
593 {
594 if (mDestroyed || !layer_manager() || layer_manager()->IsDestroyed()) {
595 return false;
596 }
597
598 Layer* layer = cast(aParent)->AsLayer();
599 if (!layer) {
600 return false;
601 }
602
603 // This method is specific to transforms applied by animation.
604 // This is because this method uses the information stored with an animation
605 // such as the origin of the reference frame corresponding to the layer, to
606 // recover the untranslated transform from the shadow transform. For
607 // transforms that are not set by animation we don't have this information
608 // available.
609 if (!layer->AsLayerComposite()->GetShadowTransformSetByAnimation()) {
610 *aTransform = mozilla::void_t();
611 return true;
612 }
613
614 // The following code recovers the untranslated transform
615 // from the shadow transform by undoing the translations in
616 // AsyncCompositionManager::SampleValue.
617
618 gfx3DMatrix transform;
619 gfx::To3DMatrix(layer->AsLayerComposite()->GetShadowTransform(), transform);
620 if (ContainerLayer* c = layer->AsContainerLayer()) {
621 // Undo the scale transform applied by AsyncCompositionManager::SampleValue
622 transform.ScalePost(1.0f/c->GetInheritedXScale(),
623 1.0f/c->GetInheritedYScale(),
624 1.0f);
625 }
626 float scale = 1;
627 gfxPoint3D scaledOrigin;
628 gfxPoint3D transformOrigin;
629 for (uint32_t i=0; i < layer->GetAnimations().Length(); i++) {
630 if (layer->GetAnimations()[i].data().type() == AnimationData::TTransformData) {
631 const TransformData& data = layer->GetAnimations()[i].data().get_TransformData();
632 scale = data.appUnitsPerDevPixel();
633 scaledOrigin =
634 gfxPoint3D(NS_round(NSAppUnitsToFloatPixels(data.origin().x, scale)),
635 NS_round(NSAppUnitsToFloatPixels(data.origin().y, scale)),
636 0.0f);
637 double cssPerDev =
638 double(nsDeviceContext::AppUnitsPerCSSPixel()) / double(scale);
639 transformOrigin = data.transformOrigin() * cssPerDev;
640 break;
641 }
642 }
643
644 // Undo the translation to the origin of the reference frame applied by
645 // AsyncCompositionManager::SampleValue
646 transform.Translate(-scaledOrigin);
647
648 // Undo the rebasing applied by
649 // nsDisplayTransform::GetResultingTransformMatrixInternal
650 transform = nsLayoutUtils::ChangeMatrixBasis(-scaledOrigin - transformOrigin,
651 transform);
652
653 // Convert to CSS pixels (this undoes the operations performed by
654 // nsStyleTransformMatrix::ProcessTranslatePart which is called from
655 // nsDisplayTransform::GetResultingTransformMatrix)
656 double devPerCss =
657 double(scale) / double(nsDeviceContext::AppUnitsPerCSSPixel());
658 transform._41 *= devPerCss;
659 transform._42 *= devPerCss;
660 transform._43 *= devPerCss;
661
662 *aTransform = transform;
663 return true;
664 }
665
666 bool
667 LayerTransactionParent::RecvSetAsyncScrollOffset(PLayerParent* aLayer,
668 const int32_t& aX, const int32_t& aY)
669 {
670 if (mDestroyed || !layer_manager() || layer_manager()->IsDestroyed()) {
671 return false;
672 }
673
674 Layer* layer = cast(aLayer)->AsLayer();
675 if (!layer) {
676 return false;
677 }
678 ContainerLayer* containerLayer = layer->AsContainerLayer();
679 if (!containerLayer) {
680 return false;
681 }
682 AsyncPanZoomController* controller = containerLayer->GetAsyncPanZoomController();
683 if (!controller) {
684 return false;
685 }
686 controller->SetTestAsyncScrollOffset(CSSPoint(aX, aY));
687 return true;
688 }
689
690 bool
691 LayerTransactionParent::Attach(ShadowLayerParent* aLayerParent,
692 CompositableHost* aCompositable,
693 bool aIsAsync)
694 {
695 if (!aCompositable) {
696 return false;
697 }
698
699 Layer* baselayer = aLayerParent->AsLayer();
700 if (!baselayer) {
701 return false;
702 }
703 LayerComposite* layer = baselayer->AsLayerComposite();
704 if (!layer) {
705 return false;
706 }
707
708 Compositor* compositor
709 = static_cast<LayerManagerComposite*>(aLayerParent->AsLayer()->Manager())->GetCompositor();
710
711 if (!layer->SetCompositableHost(aCompositable)) {
712 // not all layer types accept a compositable, see bug 967824
713 return false;
714 }
715 aCompositable->Attach(aLayerParent->AsLayer(),
716 compositor,
717 aIsAsync
718 ? CompositableHost::ALLOW_REATTACH
719 | CompositableHost::KEEP_ATTACHED
720 : CompositableHost::NO_FLAGS);
721 return true;
722 }
723
724 bool
725 LayerTransactionParent::RecvClearCachedResources()
726 {
727 if (mRoot) {
728 // NB: |mRoot| here is the *child* context's root. In this parent
729 // context, it's just a subtree root. We need to scope the clear
730 // of resources to exactly that subtree, so we specify it here.
731 mLayerManager->ClearCachedResources(mRoot);
732 }
733 return true;
734 }
735
736 bool
737 LayerTransactionParent::RecvForceComposite()
738 {
739 mShadowLayersManager->ForceComposite(this);
740 return true;
741 }
742
743
744 PGrallocBufferParent*
745 LayerTransactionParent::AllocPGrallocBufferParent(const IntSize& aSize,
746 const uint32_t& aFormat,
747 const uint32_t& aUsage,
748 MaybeMagicGrallocBufferHandle* aOutHandle)
749 {
750 #ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
751 return GrallocBufferActor::Create(aSize, aFormat, aUsage, aOutHandle);
752 #else
753 NS_RUNTIMEABORT("No gralloc buffers for you");
754 return nullptr;
755 #endif
756 }
757
758 bool
759 LayerTransactionParent::DeallocPGrallocBufferParent(PGrallocBufferParent* actor)
760 {
761 #ifdef MOZ_HAVE_SURFACEDESCRIPTORGRALLOC
762 delete actor;
763 return true;
764 #else
765 NS_RUNTIMEABORT("Um, how did we get here?");
766 return false;
767 #endif
768 }
769
770 PLayerParent*
771 LayerTransactionParent::AllocPLayerParent()
772 {
773 return new ShadowLayerParent();
774 }
775
776 bool
777 LayerTransactionParent::DeallocPLayerParent(PLayerParent* actor)
778 {
779 delete actor;
780 return true;
781 }
782
783 PCompositableParent*
784 LayerTransactionParent::AllocPCompositableParent(const TextureInfo& aInfo)
785 {
786 return CompositableHost::CreateIPDLActor(this, aInfo, 0);
787 }
788
789 bool
790 LayerTransactionParent::DeallocPCompositableParent(PCompositableParent* aActor)
791 {
792 return CompositableHost::DestroyIPDLActor(aActor);
793 }
794
795 PTextureParent*
796 LayerTransactionParent::AllocPTextureParent(const SurfaceDescriptor& aSharedData,
797 const TextureFlags& aFlags)
798 {
799 return TextureHost::CreateIPDLActor(this, aSharedData, aFlags);
800 }
801
802 bool
803 LayerTransactionParent::DeallocPTextureParent(PTextureParent* actor)
804 {
805 return TextureHost::DestroyIPDLActor(actor);
806 }
807
808 bool LayerTransactionParent::IsSameProcess() const
809 {
810 return OtherProcess() == ipc::kInvalidProcessHandle;
811 }
812
813 } // namespace layers
814 } // namespace mozilla

mercurial