gfx/layers/ipc/ShadowLayers.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/layers/ipc/ShadowLayers.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,704 @@
     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 "ShadowLayers.h"
    1.12 +#include <set>                          // for _Rb_tree_const_iterator, etc
    1.13 +#include <vector>                       // for vector
    1.14 +#include "GeckoProfiler.h"              // for PROFILER_LABEL
    1.15 +#include "ISurfaceAllocator.h"          // for IsSurfaceDescriptorValid
    1.16 +#include "Layers.h"                     // for Layer
    1.17 +#include "RenderTrace.h"                // for RenderTraceScope
    1.18 +#include "ShadowLayerChild.h"           // for ShadowLayerChild
    1.19 +#include "gfx2DGlue.h"                  // for Moz2D transition helpers
    1.20 +#include "gfxPlatform.h"                // for gfxImageFormat, gfxPlatform
    1.21 +#include "gfxSharedImageSurface.h"      // for gfxSharedImageSurface
    1.22 +#include "ipc/IPCMessageUtils.h"        // for gfxContentType, null_t
    1.23 +#include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc
    1.24 +#include "mozilla/gfx/Point.h"          // for IntSize
    1.25 +#include "mozilla/layers/CompositableClient.h"  // for CompositableClient, etc
    1.26 +#include "mozilla/layers/LayersMessages.h"  // for Edit, etc
    1.27 +#include "mozilla/layers/LayersSurfaces.h"  // for SurfaceDescriptor, etc
    1.28 +#include "mozilla/layers/LayersTypes.h"  // for MOZ_LAYERS_LOG
    1.29 +#include "mozilla/layers/LayerTransactionChild.h"
    1.30 +#include "ShadowLayerUtils.h"
    1.31 +#include "mozilla/layers/TextureClient.h"  // for TextureClient
    1.32 +#include "mozilla/mozalloc.h"           // for operator new, etc
    1.33 +#include "nsAutoPtr.h"                  // for nsRefPtr, getter_AddRefs, etc
    1.34 +#include "nsDebug.h"                    // for NS_ABORT_IF_FALSE, etc
    1.35 +#include "nsRect.h"                     // for nsIntRect
    1.36 +#include "nsSize.h"                     // for nsIntSize
    1.37 +#include "nsTArray.h"                   // for nsAutoTArray, nsTArray, etc
    1.38 +#include "nsXULAppAPI.h"                // for XRE_GetProcessType, etc
    1.39 +
    1.40 +struct nsIntPoint;
    1.41 +
    1.42 +using namespace mozilla::ipc;
    1.43 +using namespace mozilla::gl;
    1.44 +using namespace mozilla::dom;
    1.45 +
    1.46 +namespace mozilla {
    1.47 +namespace ipc {
    1.48 +class Shmem;
    1.49 +}
    1.50 +
    1.51 +namespace layers {
    1.52 +
    1.53 +class ClientTiledLayerBuffer;
    1.54 +
    1.55 +typedef nsTArray<SurfaceDescriptor> BufferArray;
    1.56 +typedef std::vector<Edit> EditVector;
    1.57 +typedef std::set<ShadowableLayer*> ShadowableLayerSet;
    1.58 +
    1.59 +class Transaction
    1.60 +{
    1.61 +public:
    1.62 +  Transaction()
    1.63 +    : mTargetRotation(ROTATION_0)
    1.64 +    , mSwapRequired(false)
    1.65 +    , mOpen(false)
    1.66 +    , mRotationChanged(false)
    1.67 +  {}
    1.68 +
    1.69 +  void Begin(const nsIntRect& aTargetBounds, ScreenRotation aRotation,
    1.70 +             const nsIntRect& aClientBounds, ScreenOrientation aOrientation)
    1.71 +  {
    1.72 +    mOpen = true;
    1.73 +    mTargetBounds = aTargetBounds;
    1.74 +    if (aRotation != mTargetRotation) {
    1.75 +      // the first time this is called, mRotationChanged will be false if
    1.76 +      // aRotation is 0, but we should be OK because for the first transaction
    1.77 +      // we should only compose if it is non-empty. See the caller(s) of
    1.78 +      // RotationChanged.
    1.79 +      mRotationChanged = true;
    1.80 +    }
    1.81 +    mTargetRotation = aRotation;
    1.82 +    mClientBounds = aClientBounds;
    1.83 +    mTargetOrientation = aOrientation;
    1.84 +  }
    1.85 +  void MarkSyncTransaction()
    1.86 +  {
    1.87 +    mSwapRequired = true;
    1.88 +  }
    1.89 +  void AddEdit(const Edit& aEdit)
    1.90 +  {
    1.91 +    NS_ABORT_IF_FALSE(!Finished(), "forgot BeginTransaction?");
    1.92 +    mCset.push_back(aEdit);
    1.93 +  }
    1.94 +  void AddEdit(const CompositableOperation& aEdit)
    1.95 +  {
    1.96 +    AddEdit(Edit(aEdit));
    1.97 +  }
    1.98 +  void AddPaint(const Edit& aPaint)
    1.99 +  {
   1.100 +    AddNoSwapPaint(aPaint);
   1.101 +    mSwapRequired = true;
   1.102 +  }
   1.103 +  void AddPaint(const CompositableOperation& aPaint)
   1.104 +  {
   1.105 +    AddNoSwapPaint(Edit(aPaint));
   1.106 +    mSwapRequired = true;
   1.107 +  }
   1.108 +
   1.109 +  void AddNoSwapPaint(const Edit& aPaint)
   1.110 +  {
   1.111 +    NS_ABORT_IF_FALSE(!Finished(), "forgot BeginTransaction?");
   1.112 +    mPaints.push_back(aPaint);
   1.113 +  }
   1.114 +  void AddNoSwapPaint(const CompositableOperation& aPaint)
   1.115 +  {
   1.116 +    NS_ABORT_IF_FALSE(!Finished(), "forgot BeginTransaction?");
   1.117 +    mPaints.push_back(Edit(aPaint));
   1.118 +  }
   1.119 +  void AddMutant(ShadowableLayer* aLayer)
   1.120 +  {
   1.121 +    NS_ABORT_IF_FALSE(!Finished(), "forgot BeginTransaction?");
   1.122 +    mMutants.insert(aLayer);
   1.123 +  }
   1.124 +  void End()
   1.125 +  {
   1.126 +    mCset.clear();
   1.127 +    mPaints.clear();
   1.128 +    mMutants.clear();
   1.129 +    mOpen = false;
   1.130 +    mSwapRequired = false;
   1.131 +    mRotationChanged = false;
   1.132 +  }
   1.133 +
   1.134 +  bool Empty() const {
   1.135 +    return mCset.empty() && mPaints.empty() && mMutants.empty();
   1.136 +  }
   1.137 +  bool RotationChanged() const {
   1.138 +    return mRotationChanged;
   1.139 +  }
   1.140 +  bool Finished() const { return !mOpen && Empty(); }
   1.141 +
   1.142 +  EditVector mCset;
   1.143 +  EditVector mPaints;
   1.144 +  ShadowableLayerSet mMutants;
   1.145 +  nsIntRect mTargetBounds;
   1.146 +  ScreenRotation mTargetRotation;
   1.147 +  nsIntRect mClientBounds;
   1.148 +  ScreenOrientation mTargetOrientation;
   1.149 +  bool mSwapRequired;
   1.150 +
   1.151 +private:
   1.152 +  bool mOpen;
   1.153 +  bool mRotationChanged;
   1.154 +
   1.155 +  // disabled
   1.156 +  Transaction(const Transaction&);
   1.157 +  Transaction& operator=(const Transaction&);
   1.158 +};
   1.159 +struct AutoTxnEnd {
   1.160 +  AutoTxnEnd(Transaction* aTxn) : mTxn(aTxn) {}
   1.161 +  ~AutoTxnEnd() { mTxn->End(); }
   1.162 +  Transaction* mTxn;
   1.163 +};
   1.164 +
   1.165 +void
   1.166 +CompositableForwarder::IdentifyTextureHost(const TextureFactoryIdentifier& aIdentifier)
   1.167 +{
   1.168 +  mTextureFactoryIdentifier = aIdentifier;
   1.169 +}
   1.170 +
   1.171 +ShadowLayerForwarder::ShadowLayerForwarder()
   1.172 + : mDiagnosticTypes(DIAGNOSTIC_NONE)
   1.173 + , mIsFirstPaint(false)
   1.174 + , mWindowOverlayChanged(false)
   1.175 +{
   1.176 +  mTxn = new Transaction();
   1.177 +}
   1.178 +
   1.179 +ShadowLayerForwarder::~ShadowLayerForwarder()
   1.180 +{
   1.181 +  NS_ABORT_IF_FALSE(mTxn->Finished(), "unfinished transaction?");
   1.182 +  delete mTxn;
   1.183 +}
   1.184 +
   1.185 +void
   1.186 +ShadowLayerForwarder::BeginTransaction(const nsIntRect& aTargetBounds,
   1.187 +                                       ScreenRotation aRotation,
   1.188 +                                       const nsIntRect& aClientBounds,
   1.189 +                                       ScreenOrientation aOrientation)
   1.190 +{
   1.191 +  NS_ABORT_IF_FALSE(HasShadowManager(), "no manager to forward to");
   1.192 +  NS_ABORT_IF_FALSE(mTxn->Finished(), "uncommitted txn?");
   1.193 +  mTxn->Begin(aTargetBounds, aRotation, aClientBounds, aOrientation);
   1.194 +}
   1.195 +
   1.196 +static PLayerChild*
   1.197 +Shadow(ShadowableLayer* aLayer)
   1.198 +{
   1.199 +  return aLayer->GetShadow();
   1.200 +}
   1.201 +
   1.202 +template<typename OpCreateT>
   1.203 +static void
   1.204 +CreatedLayer(Transaction* aTxn, ShadowableLayer* aLayer)
   1.205 +{
   1.206 +  aTxn->AddEdit(OpCreateT(nullptr, Shadow(aLayer)));
   1.207 +}
   1.208 +
   1.209 +void
   1.210 +ShadowLayerForwarder::CreatedThebesLayer(ShadowableLayer* aThebes)
   1.211 +{
   1.212 +  CreatedLayer<OpCreateThebesLayer>(mTxn, aThebes);
   1.213 +}
   1.214 +void
   1.215 +ShadowLayerForwarder::CreatedContainerLayer(ShadowableLayer* aContainer)
   1.216 +{
   1.217 +  CreatedLayer<OpCreateContainerLayer>(mTxn, aContainer);
   1.218 +}
   1.219 +void
   1.220 +ShadowLayerForwarder::CreatedImageLayer(ShadowableLayer* aImage)
   1.221 +{
   1.222 +  CreatedLayer<OpCreateImageLayer>(mTxn, aImage);
   1.223 +}
   1.224 +void
   1.225 +ShadowLayerForwarder::CreatedColorLayer(ShadowableLayer* aColor)
   1.226 +{
   1.227 +  CreatedLayer<OpCreateColorLayer>(mTxn, aColor);
   1.228 +}
   1.229 +void
   1.230 +ShadowLayerForwarder::CreatedCanvasLayer(ShadowableLayer* aCanvas)
   1.231 +{
   1.232 +  CreatedLayer<OpCreateCanvasLayer>(mTxn, aCanvas);
   1.233 +}
   1.234 +void
   1.235 +ShadowLayerForwarder::CreatedRefLayer(ShadowableLayer* aRef)
   1.236 +{
   1.237 +  CreatedLayer<OpCreateRefLayer>(mTxn, aRef);
   1.238 +}
   1.239 +
   1.240 +void
   1.241 +ShadowLayerForwarder::Mutated(ShadowableLayer* aMutant)
   1.242 +{
   1.243 +mTxn->AddMutant(aMutant);
   1.244 +}
   1.245 +
   1.246 +void
   1.247 +ShadowLayerForwarder::SetRoot(ShadowableLayer* aRoot)
   1.248 +{
   1.249 +  mTxn->AddEdit(OpSetRoot(nullptr, Shadow(aRoot)));
   1.250 +}
   1.251 +void
   1.252 +ShadowLayerForwarder::InsertAfter(ShadowableLayer* aContainer,
   1.253 +                                  ShadowableLayer* aChild,
   1.254 +                                  ShadowableLayer* aAfter)
   1.255 +{
   1.256 +  if (aAfter)
   1.257 +    mTxn->AddEdit(OpInsertAfter(nullptr, Shadow(aContainer),
   1.258 +                                nullptr, Shadow(aChild),
   1.259 +                                nullptr, Shadow(aAfter)));
   1.260 +  else
   1.261 +    mTxn->AddEdit(OpPrependChild(nullptr, Shadow(aContainer),
   1.262 +                                 nullptr, Shadow(aChild)));
   1.263 +}
   1.264 +void
   1.265 +ShadowLayerForwarder::RemoveChild(ShadowableLayer* aContainer,
   1.266 +                                  ShadowableLayer* aChild)
   1.267 +{
   1.268 +  MOZ_LAYERS_LOG(("[LayersForwarder] OpRemoveChild container=%p child=%p\n",
   1.269 +                  aContainer->AsLayer(), aChild->AsLayer()));
   1.270 +
   1.271 +  mTxn->AddEdit(OpRemoveChild(nullptr, Shadow(aContainer),
   1.272 +                              nullptr, Shadow(aChild)));
   1.273 +}
   1.274 +void
   1.275 +ShadowLayerForwarder::RepositionChild(ShadowableLayer* aContainer,
   1.276 +                                      ShadowableLayer* aChild,
   1.277 +                                      ShadowableLayer* aAfter)
   1.278 +{
   1.279 +  if (aAfter) {
   1.280 +    MOZ_LAYERS_LOG(("[LayersForwarder] OpRepositionChild container=%p child=%p after=%p",
   1.281 +                   aContainer->AsLayer(), aChild->AsLayer(), aAfter->AsLayer()));
   1.282 +    mTxn->AddEdit(OpRepositionChild(nullptr, Shadow(aContainer),
   1.283 +                                    nullptr, Shadow(aChild),
   1.284 +                                    nullptr, Shadow(aAfter)));
   1.285 +  } else {
   1.286 +    MOZ_LAYERS_LOG(("[LayersForwarder] OpRaiseToTopChild container=%p child=%p",
   1.287 +                   aContainer->AsLayer(), aChild->AsLayer()));
   1.288 +    mTxn->AddEdit(OpRaiseToTopChild(nullptr, Shadow(aContainer),
   1.289 +                                    nullptr, Shadow(aChild)));
   1.290 +  }
   1.291 +}
   1.292 +
   1.293 +
   1.294 +#ifdef DEBUG
   1.295 +void
   1.296 +ShadowLayerForwarder::CheckSurfaceDescriptor(const SurfaceDescriptor* aDescriptor) const
   1.297 +{
   1.298 +  if (!aDescriptor) {
   1.299 +    return;
   1.300 +  }
   1.301 +
   1.302 +  if (aDescriptor->type() == SurfaceDescriptor::TSurfaceDescriptorShmem) {
   1.303 +    const SurfaceDescriptorShmem& shmem = aDescriptor->get_SurfaceDescriptorShmem();
   1.304 +    shmem.data().AssertInvariants();
   1.305 +    MOZ_ASSERT(mShadowManager &&
   1.306 +               mShadowManager->IsTrackingSharedMemory(shmem.data().mSegment));
   1.307 +  }
   1.308 +}
   1.309 +#endif
   1.310 +
   1.311 +void
   1.312 +ShadowLayerForwarder::UseTiledLayerBuffer(CompositableClient* aCompositable,
   1.313 +                                          const SurfaceDescriptorTiles& aTileLayerDescriptor)
   1.314 +{
   1.315 +  MOZ_ASSERT(aCompositable);
   1.316 +  MOZ_ASSERT(aCompositable->GetIPDLActor());
   1.317 +  mTxn->AddNoSwapPaint(OpUseTiledLayerBuffer(nullptr, aCompositable->GetIPDLActor(),
   1.318 +                                             aTileLayerDescriptor));
   1.319 +}
   1.320 +
   1.321 +void
   1.322 +ShadowLayerForwarder::UpdateTextureRegion(CompositableClient* aCompositable,
   1.323 +                                          const ThebesBufferData& aThebesBufferData,
   1.324 +                                          const nsIntRegion& aUpdatedRegion)
   1.325 +{
   1.326 +  MOZ_ASSERT(aCompositable);
   1.327 +  MOZ_ASSERT(aCompositable->GetIPDLActor());
   1.328 +  mTxn->AddPaint(OpPaintTextureRegion(nullptr, aCompositable->GetIPDLActor(),
   1.329 +                                      aThebesBufferData,
   1.330 +                                      aUpdatedRegion));
   1.331 +}
   1.332 +
   1.333 +void
   1.334 +ShadowLayerForwarder::UpdateTextureIncremental(CompositableClient* aCompositable,
   1.335 +                                               TextureIdentifier aTextureId,
   1.336 +                                               SurfaceDescriptor& aDescriptor,
   1.337 +                                               const nsIntRegion& aUpdatedRegion,
   1.338 +                                               const nsIntRect& aBufferRect,
   1.339 +                                               const nsIntPoint& aBufferRotation)
   1.340 +{
   1.341 +  CheckSurfaceDescriptor(&aDescriptor);
   1.342 +  MOZ_ASSERT(aCompositable);
   1.343 +  MOZ_ASSERT(aCompositable->GetIPDLActor());
   1.344 +  mTxn->AddNoSwapPaint(OpPaintTextureIncremental(nullptr, aCompositable->GetIPDLActor(),
   1.345 +                                                 aTextureId,
   1.346 +                                                 aDescriptor,
   1.347 +                                                 aUpdatedRegion,
   1.348 +                                                 aBufferRect,
   1.349 +                                                 aBufferRotation));
   1.350 +}
   1.351 +
   1.352 +
   1.353 +void
   1.354 +ShadowLayerForwarder::UpdatePictureRect(CompositableClient* aCompositable,
   1.355 +                                        const nsIntRect& aRect)
   1.356 +{
   1.357 +  MOZ_ASSERT(aCompositable);
   1.358 +  MOZ_ASSERT(aCompositable->GetIPDLActor());
   1.359 +  mTxn->AddNoSwapPaint(OpUpdatePictureRect(nullptr, aCompositable->GetIPDLActor(), aRect));
   1.360 +}
   1.361 +
   1.362 +void
   1.363 +ShadowLayerForwarder::UpdatedTexture(CompositableClient* aCompositable,
   1.364 +                                     TextureClient* aTexture,
   1.365 +                                     nsIntRegion* aRegion)
   1.366 +{
   1.367 +  MOZ_ASSERT(aCompositable);
   1.368 +  MOZ_ASSERT(aTexture);
   1.369 +  MOZ_ASSERT(aCompositable->GetIPDLActor());
   1.370 +  MOZ_ASSERT(aTexture->GetIPDLActor());
   1.371 +  MaybeRegion region = aRegion ? MaybeRegion(*aRegion)
   1.372 +                               : MaybeRegion(null_t());
   1.373 +  if (aTexture->GetFlags() & TEXTURE_IMMEDIATE_UPLOAD) {
   1.374 +    mTxn->AddPaint(OpUpdateTexture(nullptr, aCompositable->GetIPDLActor(),
   1.375 +                                   nullptr, aTexture->GetIPDLActor(),
   1.376 +                                   region));
   1.377 +  } else {
   1.378 +    mTxn->AddNoSwapPaint(OpUpdateTexture(nullptr, aCompositable->GetIPDLActor(),
   1.379 +                                         nullptr, aTexture->GetIPDLActor(),
   1.380 +                                         region));
   1.381 +  }
   1.382 +}
   1.383 +
   1.384 +void
   1.385 +ShadowLayerForwarder::UseTexture(CompositableClient* aCompositable,
   1.386 +                                 TextureClient* aTexture)
   1.387 +{
   1.388 +  MOZ_ASSERT(aCompositable);
   1.389 +  MOZ_ASSERT(aTexture);
   1.390 +  MOZ_ASSERT(aCompositable->GetIPDLActor());
   1.391 +  MOZ_ASSERT(aTexture->GetIPDLActor());
   1.392 +  mTxn->AddEdit(OpUseTexture(nullptr, aCompositable->GetIPDLActor(),
   1.393 +                             nullptr, aTexture->GetIPDLActor()));
   1.394 +}
   1.395 +
   1.396 +void
   1.397 +ShadowLayerForwarder::UseComponentAlphaTextures(CompositableClient* aCompositable,
   1.398 +                                                TextureClient* aTextureOnBlack,
   1.399 +                                                TextureClient* aTextureOnWhite)
   1.400 +{
   1.401 +  MOZ_ASSERT(aCompositable);
   1.402 +  MOZ_ASSERT(aTextureOnWhite);
   1.403 +  MOZ_ASSERT(aTextureOnBlack);
   1.404 +  MOZ_ASSERT(aCompositable->GetIPDLActor());
   1.405 +  MOZ_ASSERT(aTextureOnBlack->GetIPDLActor());
   1.406 +  MOZ_ASSERT(aTextureOnWhite->GetIPDLActor());
   1.407 +  MOZ_ASSERT(aTextureOnBlack->GetSize() == aTextureOnWhite->GetSize());
   1.408 +  mTxn->AddEdit(OpUseComponentAlphaTextures(nullptr, aCompositable->GetIPDLActor(),
   1.409 +                                            nullptr, aTextureOnBlack->GetIPDLActor(),
   1.410 +                                            nullptr, aTextureOnWhite->GetIPDLActor()));
   1.411 +}
   1.412 +
   1.413 +void
   1.414 +ShadowLayerForwarder::RemoveTextureFromCompositable(CompositableClient* aCompositable,
   1.415 +                                                    TextureClient* aTexture)
   1.416 +{
   1.417 +  MOZ_ASSERT(aCompositable);
   1.418 +  MOZ_ASSERT(aTexture);
   1.419 +  MOZ_ASSERT(aCompositable->GetIPDLActor());
   1.420 +  MOZ_ASSERT(aTexture->GetIPDLActor());
   1.421 +  mTxn->AddEdit(OpRemoveTexture(nullptr, aCompositable->GetIPDLActor(),
   1.422 +                                nullptr, aTexture->GetIPDLActor()));
   1.423 +  if (aTexture->GetFlags() & TEXTURE_DEALLOCATE_CLIENT) {
   1.424 +    mTxn->MarkSyncTransaction();
   1.425 +  }
   1.426 +  // Hold texture until transaction complete.
   1.427 +  HoldUntilTransaction(aTexture);
   1.428 +}
   1.429 +
   1.430 +void
   1.431 +ShadowLayerForwarder::RemoveTexture(TextureClient* aTexture)
   1.432 +{
   1.433 +  MOZ_ASSERT(aTexture);
   1.434 +  aTexture->ForceRemove();
   1.435 +}
   1.436 +
   1.437 +bool
   1.438 +ShadowLayerForwarder::EndTransaction(InfallibleTArray<EditReply>* aReplies,
   1.439 +                                     const nsIntRegion& aRegionToClear,
   1.440 +                                     bool aScheduleComposite,
   1.441 +                                     bool* aSent)
   1.442 +{
   1.443 +  *aSent = false;
   1.444 +
   1.445 +  PROFILER_LABEL("ShadowLayerForwarder", "EndTranscation");
   1.446 +  RenderTraceScope rendertrace("Foward Transaction", "000091");
   1.447 +  NS_ABORT_IF_FALSE(HasShadowManager(), "no manager to forward to");
   1.448 +  NS_ABORT_IF_FALSE(!mTxn->Finished(), "forgot BeginTransaction?");
   1.449 +
   1.450 +  DiagnosticTypes diagnostics = gfxPlatform::GetPlatform()->GetLayerDiagnosticTypes();
   1.451 +  if (mDiagnosticTypes != diagnostics) {
   1.452 +    mDiagnosticTypes = diagnostics;
   1.453 +    mTxn->AddEdit(OpSetDiagnosticTypes(diagnostics));
   1.454 +  }
   1.455 +
   1.456 +  AutoTxnEnd _(mTxn);
   1.457 +
   1.458 +  if (mTxn->Empty() && !mTxn->RotationChanged() && !mWindowOverlayChanged) {
   1.459 +    MOZ_LAYERS_LOG(("[LayersForwarder] 0-length cset (?) and no rotation event, skipping Update()"));
   1.460 +    return true;
   1.461 +  }
   1.462 +
   1.463 +  MOZ_LAYERS_LOG(("[LayersForwarder] destroying buffers..."));
   1.464 +
   1.465 +  MOZ_LAYERS_LOG(("[LayersForwarder] building transaction..."));
   1.466 +
   1.467 +  // We purposely add attribute-change ops to the final changeset
   1.468 +  // before we add paint ops.  This allows layers to record the
   1.469 +  // attribute changes before new pixels arrive, which can be useful
   1.470 +  // for setting up back/front buffers.
   1.471 +  RenderTraceScope rendertrace2("Foward Transaction", "000092");
   1.472 +  for (ShadowableLayerSet::const_iterator it = mTxn->mMutants.begin();
   1.473 +       it != mTxn->mMutants.end(); ++it) {
   1.474 +    ShadowableLayer* shadow = *it;
   1.475 +    Layer* mutant = shadow->AsLayer();
   1.476 +    NS_ABORT_IF_FALSE(!!mutant, "unshadowable layer?");
   1.477 +
   1.478 +    LayerAttributes attrs;
   1.479 +    CommonLayerAttributes& common = attrs.common();
   1.480 +    common.visibleRegion() = mutant->GetVisibleRegion();
   1.481 +    common.eventRegions() = mutant->GetEventRegions();
   1.482 +    common.postXScale() = mutant->GetPostXScale();
   1.483 +    common.postYScale() = mutant->GetPostYScale();
   1.484 +    common.transform() = mutant->GetBaseTransform();
   1.485 +    common.contentFlags() = mutant->GetContentFlags();
   1.486 +    common.opacity() = mutant->GetOpacity();
   1.487 +    common.useClipRect() = !!mutant->GetClipRect();
   1.488 +    common.clipRect() = (common.useClipRect() ?
   1.489 +                         *mutant->GetClipRect() : nsIntRect());
   1.490 +    common.isFixedPosition() = mutant->GetIsFixedPosition();
   1.491 +    common.fixedPositionAnchor() = mutant->GetFixedPositionAnchor();
   1.492 +    common.fixedPositionMargin() = mutant->GetFixedPositionMargins();
   1.493 +    common.isStickyPosition() = mutant->GetIsStickyPosition();
   1.494 +    if (mutant->GetIsStickyPosition()) {
   1.495 +      common.stickyScrollContainerId() = mutant->GetStickyScrollContainerId();
   1.496 +      common.stickyScrollRangeOuter() = mutant->GetStickyScrollRangeOuter();
   1.497 +      common.stickyScrollRangeInner() = mutant->GetStickyScrollRangeInner();
   1.498 +    }
   1.499 +    common.scrollbarTargetContainerId() = mutant->GetScrollbarTargetContainerId();
   1.500 +    common.scrollbarDirection() = mutant->GetScrollbarDirection();
   1.501 +    if (Layer* maskLayer = mutant->GetMaskLayer()) {
   1.502 +      common.maskLayerChild() = Shadow(maskLayer->AsShadowableLayer());
   1.503 +    } else {
   1.504 +      common.maskLayerChild() = nullptr;
   1.505 +    }
   1.506 +    common.maskLayerParent() = nullptr;
   1.507 +    common.animations() = mutant->GetAnimations();
   1.508 +    common.invalidRegion() = mutant->GetInvalidRegion();
   1.509 +    attrs.specific() = null_t();
   1.510 +    mutant->FillSpecificAttributes(attrs.specific());
   1.511 +
   1.512 +    MOZ_LAYERS_LOG(("[LayersForwarder] OpSetLayerAttributes(%p)\n", mutant));
   1.513 +
   1.514 +    mTxn->AddEdit(OpSetLayerAttributes(nullptr, Shadow(shadow), attrs));
   1.515 +  }
   1.516 +
   1.517 +  AutoInfallibleTArray<Edit, 10> cset;
   1.518 +  size_t nCsets = mTxn->mCset.size() + mTxn->mPaints.size();
   1.519 +  NS_ABORT_IF_FALSE(nCsets > 0 || mWindowOverlayChanged, "should have bailed by now");
   1.520 +
   1.521 +  cset.SetCapacity(nCsets);
   1.522 +  if (!mTxn->mCset.empty()) {
   1.523 +    cset.AppendElements(&mTxn->mCset.front(), mTxn->mCset.size());
   1.524 +  }
   1.525 +  // Paints after non-paint ops, including attribute changes.  See
   1.526 +  // above.
   1.527 +  if (!mTxn->mPaints.empty()) {
   1.528 +    cset.AppendElements(&mTxn->mPaints.front(), mTxn->mPaints.size());
   1.529 +  }
   1.530 +
   1.531 +  mWindowOverlayChanged = false;
   1.532 +
   1.533 +  TargetConfig targetConfig(mTxn->mTargetBounds,
   1.534 +                            mTxn->mTargetRotation,
   1.535 +                            mTxn->mClientBounds,
   1.536 +                            mTxn->mTargetOrientation,
   1.537 +                            aRegionToClear);
   1.538 +
   1.539 +  MOZ_LAYERS_LOG(("[LayersForwarder] syncing before send..."));
   1.540 +  PlatformSyncBeforeUpdate();
   1.541 +
   1.542 +  profiler_tracing("Paint", "Rasterize", TRACING_INTERVAL_END);
   1.543 +  if (mTxn->mSwapRequired) {
   1.544 +    MOZ_LAYERS_LOG(("[LayersForwarder] sending transaction..."));
   1.545 +    RenderTraceScope rendertrace3("Forward Transaction", "000093");
   1.546 +    if (!HasShadowManager() ||
   1.547 +        !mShadowManager->IPCOpen() ||
   1.548 +        !mShadowManager->SendUpdate(cset, targetConfig, mIsFirstPaint,
   1.549 +                                    aScheduleComposite, aReplies)) {
   1.550 +      MOZ_LAYERS_LOG(("[LayersForwarder] WARNING: sending transaction failed!"));
   1.551 +      return false;
   1.552 +    }
   1.553 +  } else {
   1.554 +    // If we don't require a swap we can call SendUpdateNoSwap which
   1.555 +    // assumes that aReplies is empty (DEBUG assertion)
   1.556 +    MOZ_LAYERS_LOG(("[LayersForwarder] sending no swap transaction..."));
   1.557 +    RenderTraceScope rendertrace3("Forward NoSwap Transaction", "000093");
   1.558 +    if (!HasShadowManager() ||
   1.559 +        !mShadowManager->IPCOpen() ||
   1.560 +        !mShadowManager->SendUpdateNoSwap(cset, targetConfig, mIsFirstPaint, aScheduleComposite)) {
   1.561 +      MOZ_LAYERS_LOG(("[LayersForwarder] WARNING: sending transaction failed!"));
   1.562 +      return false;
   1.563 +    }
   1.564 +  }
   1.565 +
   1.566 +  *aSent = true;
   1.567 +  mIsFirstPaint = false;
   1.568 +  MOZ_LAYERS_LOG(("[LayersForwarder] ... done"));
   1.569 +  return true;
   1.570 +}
   1.571 +
   1.572 +bool
   1.573 +ShadowLayerForwarder::AllocShmem(size_t aSize,
   1.574 +                                 ipc::SharedMemory::SharedMemoryType aType,
   1.575 +                                 ipc::Shmem* aShmem)
   1.576 +{
   1.577 +  NS_ABORT_IF_FALSE(HasShadowManager(), "no shadow manager");
   1.578 +  if (!mShadowManager->IPCOpen()) {
   1.579 +    return false;
   1.580 +  }
   1.581 +  return mShadowManager->AllocShmem(aSize, aType, aShmem);
   1.582 +}
   1.583 +bool
   1.584 +ShadowLayerForwarder::AllocUnsafeShmem(size_t aSize,
   1.585 +                                          ipc::SharedMemory::SharedMemoryType aType,
   1.586 +                                          ipc::Shmem* aShmem)
   1.587 +{
   1.588 +  NS_ABORT_IF_FALSE(HasShadowManager(), "no shadow manager");
   1.589 +  if (!mShadowManager->IPCOpen()) {
   1.590 +    return false;
   1.591 +  }
   1.592 +  return mShadowManager->AllocUnsafeShmem(aSize, aType, aShmem);
   1.593 +}
   1.594 +void
   1.595 +ShadowLayerForwarder::DeallocShmem(ipc::Shmem& aShmem)
   1.596 +{
   1.597 +  NS_ABORT_IF_FALSE(HasShadowManager(), "no shadow manager");
   1.598 +  if (!mShadowManager->IPCOpen()) {
   1.599 +    return;
   1.600 +  }
   1.601 +  mShadowManager->DeallocShmem(aShmem);
   1.602 +}
   1.603 +
   1.604 +bool
   1.605 +ShadowLayerForwarder::IPCOpen() const
   1.606 +{
   1.607 +  return mShadowManager->IPCOpen();
   1.608 +}
   1.609 +
   1.610 +bool
   1.611 +ShadowLayerForwarder::IsSameProcess() const
   1.612 +{
   1.613 +  if (!mShadowManager->IPCOpen()) {
   1.614 +    return false;
   1.615 +  }
   1.616 +  return mShadowManager->OtherProcess() == kInvalidProcessHandle;
   1.617 +}
   1.618 +
   1.619 +/**
   1.620 +  * We bail out when we have no shadow manager. That can happen when the
   1.621 +  * layer manager is created by the preallocated process.
   1.622 +  * See bug 914843 for details.
   1.623 +  */
   1.624 +PLayerChild*
   1.625 +ShadowLayerForwarder::ConstructShadowFor(ShadowableLayer* aLayer)
   1.626 +{
   1.627 +  NS_ABORT_IF_FALSE(HasShadowManager(), "no manager to forward to");
   1.628 +  if (!mShadowManager->IPCOpen()) {
   1.629 +    return nullptr;
   1.630 +  }
   1.631 +  return mShadowManager->SendPLayerConstructor(new ShadowLayerChild(aLayer));
   1.632 +}
   1.633 +
   1.634 +#if !defined(MOZ_HAVE_PLATFORM_SPECIFIC_LAYER_BUFFERS)
   1.635 +
   1.636 +/*static*/ void
   1.637 +ShadowLayerForwarder::PlatformSyncBeforeUpdate()
   1.638 +{
   1.639 +}
   1.640 +
   1.641 +#endif  // !defined(MOZ_HAVE_PLATFORM_SPECIFIC_LAYER_BUFFERS)
   1.642 +
   1.643 +void
   1.644 +ShadowLayerForwarder::Connect(CompositableClient* aCompositable)
   1.645 +{
   1.646 +#ifdef GFX_COMPOSITOR_LOGGING
   1.647 +  printf("ShadowLayerForwarder::Connect(Compositable)\n");
   1.648 +#endif
   1.649 +  MOZ_ASSERT(aCompositable);
   1.650 +  MOZ_ASSERT(mShadowManager);
   1.651 +  if (!mShadowManager->IPCOpen()) {
   1.652 +    return;
   1.653 +  }
   1.654 +  PCompositableChild* actor =
   1.655 +    mShadowManager->SendPCompositableConstructor(aCompositable->GetTextureInfo());
   1.656 +  MOZ_ASSERT(actor);
   1.657 +  aCompositable->InitIPDLActor(actor);
   1.658 +}
   1.659 +
   1.660 +void
   1.661 +ShadowLayerForwarder::CreatedIncrementalBuffer(CompositableClient* aCompositable,
   1.662 +                                               const TextureInfo& aTextureInfo,
   1.663 +                                               const nsIntRect& aBufferRect)
   1.664 +{
   1.665 +  MOZ_ASSERT(aCompositable);
   1.666 +  mTxn->AddNoSwapPaint(OpCreatedIncrementalTexture(nullptr, aCompositable->GetIPDLActor(),
   1.667 +                                                   aTextureInfo, aBufferRect));
   1.668 +}
   1.669 +
   1.670 +void ShadowLayerForwarder::Attach(CompositableClient* aCompositable,
   1.671 +                                  ShadowableLayer* aLayer)
   1.672 +{
   1.673 +  MOZ_ASSERT(aLayer);
   1.674 +  MOZ_ASSERT(aCompositable);
   1.675 +  MOZ_ASSERT(aCompositable->GetIPDLActor());
   1.676 +  mTxn->AddEdit(OpAttachCompositable(nullptr, Shadow(aLayer),
   1.677 +                                     nullptr, aCompositable->GetIPDLActor()));
   1.678 +}
   1.679 +
   1.680 +void ShadowLayerForwarder::AttachAsyncCompositable(uint64_t aCompositableID,
   1.681 +                                                   ShadowableLayer* aLayer)
   1.682 +{
   1.683 +  MOZ_ASSERT(aLayer);
   1.684 +  MOZ_ASSERT(aCompositableID != 0); // zero is always an invalid compositable id.
   1.685 +  mTxn->AddEdit(OpAttachAsyncCompositable(nullptr, Shadow(aLayer),
   1.686 +                                          aCompositableID));
   1.687 +}
   1.688 +
   1.689 +PTextureChild*
   1.690 +ShadowLayerForwarder::CreateTexture(const SurfaceDescriptor& aSharedData,
   1.691 +                                    TextureFlags aFlags)
   1.692 +{
   1.693 +  if (!mShadowManager->IPCOpen()) {
   1.694 +    return nullptr;
   1.695 +  }
   1.696 +  return mShadowManager->SendPTextureConstructor(aSharedData, aFlags);
   1.697 +}
   1.698 +
   1.699 +
   1.700 +void ShadowLayerForwarder::SetShadowManager(PLayerTransactionChild* aShadowManager)
   1.701 +{
   1.702 +  mShadowManager = static_cast<LayerTransactionChild*>(aShadowManager);
   1.703 +}
   1.704 +
   1.705 +
   1.706 +} // namespace layers
   1.707 +} // namespace mozilla

mercurial