gfx/layers/client/ClientLayerManager.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/layers/client/ClientLayerManager.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,575 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "ClientLayerManager.h"
    1.10 +#include "CompositorChild.h"            // for CompositorChild
    1.11 +#include "GeckoProfiler.h"              // for PROFILER_LABEL
    1.12 +#include "gfxPrefs.h"                   // for gfxPrefs::LayersTileWidth/Height
    1.13 +#include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc
    1.14 +#include "mozilla/Hal.h"
    1.15 +#include "mozilla/dom/ScreenOrientation.h"  // for ScreenOrientation
    1.16 +#include "mozilla/dom/TabChild.h"       // for TabChild
    1.17 +#include "mozilla/hal_sandbox/PHal.h"   // for ScreenConfiguration
    1.18 +#include "mozilla/layers/CompositableClient.h"
    1.19 +#include "mozilla/layers/ContentClient.h"
    1.20 +#include "mozilla/layers/ISurfaceAllocator.h"
    1.21 +#include "mozilla/layers/LayersMessages.h"  // for EditReply, etc
    1.22 +#include "mozilla/layers/LayersSurfaces.h"  // for SurfaceDescriptor
    1.23 +#include "mozilla/layers/PLayerChild.h"  // for PLayerChild
    1.24 +#include "mozilla/layers/LayerTransactionChild.h"
    1.25 +#include "mozilla/layers/TextureClientPool.h" // for TextureClientPool
    1.26 +#include "mozilla/layers/SimpleTextureClientPool.h" // for SimpleTextureClientPool
    1.27 +#include "nsAString.h"
    1.28 +#include "nsIWidget.h"                  // for nsIWidget
    1.29 +#include "nsIWidgetListener.h"
    1.30 +#include "nsTArray.h"                   // for AutoInfallibleTArray
    1.31 +#include "nsXULAppAPI.h"                // for XRE_GetProcessType, etc
    1.32 +#include "TiledLayerBuffer.h"
    1.33 +#ifdef MOZ_WIDGET_ANDROID
    1.34 +#include "AndroidBridge.h"
    1.35 +#endif
    1.36 +
    1.37 +using namespace mozilla::dom;
    1.38 +using namespace mozilla::gfx;
    1.39 +
    1.40 +namespace mozilla {
    1.41 +namespace layers {
    1.42 +
    1.43 +ClientLayerManager::ClientLayerManager(nsIWidget* aWidget)
    1.44 +  : mPhase(PHASE_NONE)
    1.45 +  , mWidget(aWidget) 
    1.46 +  , mTargetRotation(ROTATION_0)
    1.47 +  , mRepeatTransaction(false)
    1.48 +  , mIsRepeatTransaction(false)
    1.49 +  , mTransactionIncomplete(false)
    1.50 +  , mCompositorMightResample(false)
    1.51 +  , mNeedsComposite(false)
    1.52 +  , mForwarder(new ShadowLayerForwarder)
    1.53 +{
    1.54 +  MOZ_COUNT_CTOR(ClientLayerManager);
    1.55 +}
    1.56 +
    1.57 +ClientLayerManager::~ClientLayerManager()
    1.58 +{
    1.59 +  mRoot = nullptr;
    1.60 +
    1.61 +  MOZ_COUNT_DTOR(ClientLayerManager);
    1.62 +}
    1.63 +
    1.64 +int32_t
    1.65 +ClientLayerManager::GetMaxTextureSize() const
    1.66 +{
    1.67 +  return mForwarder->GetMaxTextureSize();
    1.68 +}
    1.69 +
    1.70 +void
    1.71 +ClientLayerManager::SetDefaultTargetConfiguration(BufferMode aDoubleBuffering,
    1.72 +                                                  ScreenRotation aRotation)
    1.73 +{
    1.74 +  mTargetRotation = aRotation;
    1.75 +  if (mWidget) {
    1.76 +    mTargetBounds = mWidget->GetNaturalBounds();
    1.77 +   }
    1.78 + }
    1.79 +
    1.80 +void
    1.81 +ClientLayerManager::SetRoot(Layer* aLayer)
    1.82 +{
    1.83 +  if (mRoot != aLayer) {
    1.84 +    // Have to hold the old root and its children in order to
    1.85 +    // maintain the same view of the layer tree in this process as
    1.86 +    // the parent sees.  Otherwise layers can be destroyed
    1.87 +    // mid-transaction and bad things can happen (v. bug 612573)
    1.88 +    if (mRoot) {
    1.89 +      Hold(mRoot);
    1.90 +    }
    1.91 +    mForwarder->SetRoot(Hold(aLayer));
    1.92 +    NS_ASSERTION(aLayer, "Root can't be null");
    1.93 +    NS_ASSERTION(aLayer->Manager() == this, "Wrong manager");
    1.94 +    NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
    1.95 +    mRoot = aLayer;
    1.96 +  }
    1.97 +}
    1.98 +
    1.99 +void
   1.100 +ClientLayerManager::Mutated(Layer* aLayer)
   1.101 +{
   1.102 +  LayerManager::Mutated(aLayer);
   1.103 +
   1.104 +  NS_ASSERTION(InConstruction() || InDrawing(), "wrong phase");
   1.105 +  mForwarder->Mutated(Hold(aLayer));
   1.106 +}
   1.107 +
   1.108 +void
   1.109 +ClientLayerManager::BeginTransactionWithTarget(gfxContext* aTarget)
   1.110 +{
   1.111 +  mInTransaction = true;
   1.112 +
   1.113 +#ifdef MOZ_LAYERS_HAVE_LOG
   1.114 +  MOZ_LAYERS_LOG(("[----- BeginTransaction"));
   1.115 +  Log();
   1.116 +#endif
   1.117 +
   1.118 +  NS_ASSERTION(!InTransaction(), "Nested transactions not allowed");
   1.119 +  mPhase = PHASE_CONSTRUCTION;
   1.120 +
   1.121 +  NS_ABORT_IF_FALSE(mKeepAlive.IsEmpty(), "uncommitted txn?");
   1.122 +  nsRefPtr<gfxContext> targetContext = aTarget;
   1.123 +
   1.124 +  // If the last transaction was incomplete (a failed DoEmptyTransaction),
   1.125 +  // don't signal a new transaction to ShadowLayerForwarder. Carry on adding
   1.126 +  // to the previous transaction.
   1.127 +  ScreenOrientation orientation;
   1.128 +  if (TabChild* window = mWidget->GetOwningTabChild()) {
   1.129 +    orientation = window->GetOrientation();
   1.130 +  } else {
   1.131 +    hal::ScreenConfiguration currentConfig;
   1.132 +    hal::GetCurrentScreenConfiguration(&currentConfig);
   1.133 +    orientation = currentConfig.orientation();
   1.134 +  }
   1.135 +  nsIntRect clientBounds;
   1.136 +  mWidget->GetClientBounds(clientBounds);
   1.137 +  clientBounds.x = clientBounds.y = 0;
   1.138 +  mForwarder->BeginTransaction(mTargetBounds, mTargetRotation, clientBounds, orientation);
   1.139 +
   1.140 +  // If we're drawing on behalf of a context with async pan/zoom
   1.141 +  // enabled, then the entire buffer of thebes layers might be
   1.142 +  // composited (including resampling) asynchronously before we get
   1.143 +  // a chance to repaint, so we have to ensure that it's all valid
   1.144 +  // and not rotated.
   1.145 +  if (mWidget) {
   1.146 +    if (TabChild* window = mWidget->GetOwningTabChild()) {
   1.147 +      mCompositorMightResample = window->IsAsyncPanZoomEnabled();
   1.148 +    }
   1.149 +  }
   1.150 +
   1.151 +  // If we have a non-default target, we need to let our shadow manager draw
   1.152 +  // to it. This will happen at the end of the transaction.
   1.153 +  if (aTarget && XRE_GetProcessType() == GeckoProcessType_Default) {
   1.154 +    mShadowTarget = aTarget;
   1.155 +  }
   1.156 +}
   1.157 +
   1.158 +void
   1.159 +ClientLayerManager::BeginTransaction()
   1.160 +{
   1.161 +  mInTransaction = true;
   1.162 +  BeginTransactionWithTarget(nullptr);
   1.163 +}
   1.164 +
   1.165 +bool
   1.166 +ClientLayerManager::EndTransactionInternal(DrawThebesLayerCallback aCallback,
   1.167 +                                           void* aCallbackData,
   1.168 +                                           EndTransactionFlags)
   1.169 +{
   1.170 +  PROFILER_LABEL("ClientLayerManager", "EndTransactionInternal");
   1.171 +#ifdef MOZ_LAYERS_HAVE_LOG
   1.172 +  MOZ_LAYERS_LOG(("  ----- (beginning paint)"));
   1.173 +  Log();
   1.174 +#endif
   1.175 +  profiler_tracing("Paint", "Rasterize", TRACING_INTERVAL_START);
   1.176 +
   1.177 +  NS_ASSERTION(InConstruction(), "Should be in construction phase");
   1.178 +  mPhase = PHASE_DRAWING;
   1.179 +
   1.180 +  ClientLayer* root = ClientLayer::ToClientLayer(GetRoot());
   1.181 +
   1.182 +  mTransactionIncomplete = false;
   1.183 +      
   1.184 +  // Apply pending tree updates before recomputing effective
   1.185 +  // properties.
   1.186 +  GetRoot()->ApplyPendingUpdatesToSubtree();
   1.187 +    
   1.188 +  mThebesLayerCallback = aCallback;
   1.189 +  mThebesLayerCallbackData = aCallbackData;
   1.190 +
   1.191 +  GetRoot()->ComputeEffectiveTransforms(Matrix4x4());
   1.192 +
   1.193 +  root->RenderLayer();
   1.194 +  if (!mRepeatTransaction && !GetRoot()->GetInvalidRegion().IsEmpty()) {
   1.195 +    GetRoot()->Mutated();
   1.196 +  }
   1.197 +  
   1.198 +  mThebesLayerCallback = nullptr;
   1.199 +  mThebesLayerCallbackData = nullptr;
   1.200 +
   1.201 +  // Go back to the construction phase if the transaction isn't complete.
   1.202 +  // Layout will update the layer tree and call EndTransaction().
   1.203 +  mPhase = mTransactionIncomplete ? PHASE_CONSTRUCTION : PHASE_NONE;
   1.204 +
   1.205 +  NS_ASSERTION(!aCallback || !mTransactionIncomplete,
   1.206 +               "If callback is not null, transaction must be complete");
   1.207 +
   1.208 +  return !mTransactionIncomplete;
   1.209 +}
   1.210 +
   1.211 +void
   1.212 +ClientLayerManager::EndTransaction(DrawThebesLayerCallback aCallback,
   1.213 +                                   void* aCallbackData,
   1.214 +                                   EndTransactionFlags aFlags)
   1.215 +{
   1.216 +  if (mWidget) {
   1.217 +    mWidget->PrepareWindowEffects();
   1.218 +  }
   1.219 +  EndTransactionInternal(aCallback, aCallbackData, aFlags);
   1.220 +  ForwardTransaction(!(aFlags & END_NO_REMOTE_COMPOSITE));
   1.221 +
   1.222 +  if (mRepeatTransaction) {
   1.223 +    mRepeatTransaction = false;
   1.224 +    mIsRepeatTransaction = true;
   1.225 +    BeginTransaction();
   1.226 +    ClientLayerManager::EndTransaction(aCallback, aCallbackData, aFlags);
   1.227 +    mIsRepeatTransaction = false;
   1.228 +  } else {
   1.229 +    MakeSnapshotIfRequired();
   1.230 +  }
   1.231 +
   1.232 +  for (size_t i = 0; i < mTexturePools.Length(); i++) {
   1.233 +    mTexturePools[i]->ReturnDeferredClients();
   1.234 +  }
   1.235 +}
   1.236 +
   1.237 +bool
   1.238 +ClientLayerManager::EndEmptyTransaction(EndTransactionFlags aFlags)
   1.239 +{
   1.240 +  mInTransaction = false;
   1.241 +
   1.242 +  if (!mRoot) {
   1.243 +    return false;
   1.244 +  }
   1.245 +  if (!EndTransactionInternal(nullptr, nullptr, aFlags)) {
   1.246 +    // Return without calling ForwardTransaction. This leaves the
   1.247 +    // ShadowLayerForwarder transaction open; the following
   1.248 +    // EndTransaction will complete it.
   1.249 +    return false;
   1.250 +  }
   1.251 +  if (mWidget) {
   1.252 +    mWidget->PrepareWindowEffects();
   1.253 +  }
   1.254 +  ForwardTransaction(!(aFlags & END_NO_REMOTE_COMPOSITE));
   1.255 +  MakeSnapshotIfRequired();
   1.256 +  return true;
   1.257 +}
   1.258 +
   1.259 +CompositorChild *
   1.260 +ClientLayerManager::GetRemoteRenderer()
   1.261 +{
   1.262 +  if (!mWidget) {
   1.263 +    return nullptr;
   1.264 +  }
   1.265 +
   1.266 +  return mWidget->GetRemoteRenderer();
   1.267 +}
   1.268 +
   1.269 +void
   1.270 +ClientLayerManager::Composite()
   1.271 +{
   1.272 +  if (LayerTransactionChild* manager = mForwarder->GetShadowManager()) {
   1.273 +    manager->SendForceComposite();
   1.274 +  }
   1.275 +}
   1.276 +
   1.277 +void
   1.278 +ClientLayerManager::DidComposite()
   1.279 +{
   1.280 +  MOZ_ASSERT(mWidget);
   1.281 +  nsIWidgetListener *listener = mWidget->GetWidgetListener();
   1.282 +  if (listener) {
   1.283 +    listener->DidCompositeWindow();
   1.284 +  }
   1.285 +  listener = mWidget->GetAttachedWidgetListener();
   1.286 +  if (listener) {
   1.287 +    listener->DidCompositeWindow();
   1.288 +  }
   1.289 +}
   1.290 +
   1.291 +void 
   1.292 +ClientLayerManager::MakeSnapshotIfRequired()
   1.293 +{
   1.294 +  if (!mShadowTarget) {
   1.295 +    return;
   1.296 +  }
   1.297 +  if (mWidget) {
   1.298 +    if (CompositorChild* remoteRenderer = GetRemoteRenderer()) {
   1.299 +      nsIntRect bounds;
   1.300 +      mWidget->GetBounds(bounds);
   1.301 +      IntSize widgetSize = bounds.Size().ToIntSize();
   1.302 +      SurfaceDescriptor inSnapshot, snapshot;
   1.303 +      if (mForwarder->AllocSurfaceDescriptor(widgetSize,
   1.304 +                                             gfxContentType::COLOR_ALPHA,
   1.305 +                                             &inSnapshot) &&
   1.306 +          // The compositor will usually reuse |snapshot| and return
   1.307 +          // it through |outSnapshot|, but if it doesn't, it's
   1.308 +          // responsible for freeing |snapshot|.
   1.309 +          remoteRenderer->SendMakeSnapshot(inSnapshot, &snapshot)) {
   1.310 +        RefPtr<DataSourceSurface> surf = GetSurfaceForDescriptor(snapshot);
   1.311 +        DrawTarget* dt = mShadowTarget->GetDrawTarget();
   1.312 +        Rect widgetRect(Point(0, 0), Size(widgetSize.width, widgetSize.height));
   1.313 +        dt->DrawSurface(surf, widgetRect, widgetRect,
   1.314 +                        DrawSurfaceOptions(),
   1.315 +                        DrawOptions(1.0f, CompositionOp::OP_OVER));
   1.316 +      }
   1.317 +      if (IsSurfaceDescriptorValid(snapshot)) {
   1.318 +        mForwarder->DestroySharedSurface(&snapshot);
   1.319 +      }
   1.320 +    }
   1.321 +  }
   1.322 +  mShadowTarget = nullptr;
   1.323 +}
   1.324 +
   1.325 +void
   1.326 +ClientLayerManager::FlushRendering()
   1.327 +{
   1.328 +  if (mWidget) {
   1.329 +    if (CompositorChild* remoteRenderer = mWidget->GetRemoteRenderer()) {
   1.330 +      remoteRenderer->SendFlushRendering();
   1.331 +    }
   1.332 +  }
   1.333 +}
   1.334 +
   1.335 +void
   1.336 +ClientLayerManager::SendInvalidRegion(const nsIntRegion& aRegion)
   1.337 +{
   1.338 +  if (mWidget) {
   1.339 +    if (CompositorChild* remoteRenderer = mWidget->GetRemoteRenderer()) {
   1.340 +      remoteRenderer->SendNotifyRegionInvalidated(aRegion);
   1.341 +    }
   1.342 +  }
   1.343 +}
   1.344 +
   1.345 +uint32_t
   1.346 +ClientLayerManager::StartFrameTimeRecording(int32_t aBufferSize)
   1.347 +{
   1.348 +  CompositorChild* renderer = GetRemoteRenderer();
   1.349 +  if (renderer) {
   1.350 +    uint32_t startIndex;
   1.351 +    renderer->SendStartFrameTimeRecording(aBufferSize, &startIndex);
   1.352 +    return startIndex;
   1.353 +  }
   1.354 +  return -1;
   1.355 +}
   1.356 +
   1.357 +void
   1.358 +ClientLayerManager::StopFrameTimeRecording(uint32_t         aStartIndex,
   1.359 +                                           nsTArray<float>& aFrameIntervals)
   1.360 +{
   1.361 +  CompositorChild* renderer = GetRemoteRenderer();
   1.362 +  if (renderer) {
   1.363 +    renderer->SendStopFrameTimeRecording(aStartIndex, &aFrameIntervals);
   1.364 +  }
   1.365 +}
   1.366 +
   1.367 +void
   1.368 +ClientLayerManager::ForwardTransaction(bool aScheduleComposite)
   1.369 +{
   1.370 +  mPhase = PHASE_FORWARD;
   1.371 +
   1.372 +  // forward this transaction's changeset to our LayerManagerComposite
   1.373 +  bool sent;
   1.374 +  AutoInfallibleTArray<EditReply, 10> replies;
   1.375 +  if (HasShadowManager() && mForwarder->EndTransaction(&replies, mRegionToClear, aScheduleComposite, &sent)) {
   1.376 +    for (nsTArray<EditReply>::size_type i = 0; i < replies.Length(); ++i) {
   1.377 +      const EditReply& reply = replies[i];
   1.378 +
   1.379 +      switch (reply.type()) {
   1.380 +      case EditReply::TOpContentBufferSwap: {
   1.381 +        MOZ_LAYERS_LOG(("[LayersForwarder] DoubleBufferSwap"));
   1.382 +
   1.383 +        const OpContentBufferSwap& obs = reply.get_OpContentBufferSwap();
   1.384 +
   1.385 +        CompositableClient* compositable =
   1.386 +          CompositableClient::FromIPDLActor(obs.compositableChild());
   1.387 +        ContentClientRemote* contentClient =
   1.388 +          static_cast<ContentClientRemote*>(compositable);
   1.389 +        MOZ_ASSERT(contentClient);
   1.390 +
   1.391 +        contentClient->SwapBuffers(obs.frontUpdatedRegion());
   1.392 +
   1.393 +        break;
   1.394 +      }
   1.395 +      case EditReply::TOpTextureSwap: {
   1.396 +        MOZ_LAYERS_LOG(("[LayersForwarder] TextureSwap"));
   1.397 +
   1.398 +        const OpTextureSwap& ots = reply.get_OpTextureSwap();
   1.399 +
   1.400 +        CompositableClient* compositable =
   1.401 +          CompositableClient::FromIPDLActor(ots.compositableChild());
   1.402 +        MOZ_ASSERT(compositable);
   1.403 +        compositable->SetDescriptorFromReply(ots.textureId(), ots.image());
   1.404 +        break;
   1.405 +      }
   1.406 +      case EditReply::TReturnReleaseFence: {
   1.407 +        const ReturnReleaseFence& rep = reply.get_ReturnReleaseFence();
   1.408 +        FenceHandle fence = rep.fence();
   1.409 +        PTextureChild* child = rep.textureChild();
   1.410 +
   1.411 +        if (!fence.IsValid() || !child) {
   1.412 +          break;
   1.413 +        }
   1.414 +        RefPtr<TextureClient> texture = TextureClient::AsTextureClient(child);
   1.415 +        if (texture) {
   1.416 +          texture->SetReleaseFenceHandle(fence);
   1.417 +        }
   1.418 +        break;
   1.419 +      }
   1.420 +
   1.421 +      default:
   1.422 +        NS_RUNTIMEABORT("not reached");
   1.423 +      }
   1.424 +    }
   1.425 +
   1.426 +    if (sent) {
   1.427 +      mNeedsComposite = false;
   1.428 +    }
   1.429 +  } else if (HasShadowManager()) {
   1.430 +    NS_WARNING("failed to forward Layers transaction");
   1.431 +  }
   1.432 +
   1.433 +  mForwarder->RemoveTexturesIfNecessary();
   1.434 +  mPhase = PHASE_NONE;
   1.435 +
   1.436 +  // this may result in Layers being deleted, which results in
   1.437 +  // PLayer::Send__delete__() and DeallocShmem()
   1.438 +  mKeepAlive.Clear();
   1.439 +}
   1.440 +
   1.441 +ShadowableLayer*
   1.442 +ClientLayerManager::Hold(Layer* aLayer)
   1.443 +{
   1.444 +  NS_ABORT_IF_FALSE(HasShadowManager(),
   1.445 +                    "top-level tree, no shadow tree to remote to");
   1.446 +
   1.447 +  ShadowableLayer* shadowable = ClientLayer::ToClientLayer(aLayer);
   1.448 +  NS_ABORT_IF_FALSE(shadowable, "trying to remote an unshadowable layer");
   1.449 +
   1.450 +  mKeepAlive.AppendElement(aLayer);
   1.451 +  return shadowable;
   1.452 +}
   1.453 +
   1.454 +bool
   1.455 +ClientLayerManager::IsCompositingCheap()
   1.456 +{
   1.457 +  // Whether compositing is cheap depends on the parent backend.
   1.458 +  return mForwarder->mShadowManager &&
   1.459 +         LayerManager::IsCompositingCheap(mForwarder->GetCompositorBackendType());
   1.460 +}
   1.461 +
   1.462 +void
   1.463 +ClientLayerManager::SetIsFirstPaint()
   1.464 +{
   1.465 +  mForwarder->SetIsFirstPaint();
   1.466 +}
   1.467 +
   1.468 +TextureClientPool*
   1.469 +ClientLayerManager::GetTexturePool(SurfaceFormat aFormat)
   1.470 +{
   1.471 +  for (size_t i = 0; i < mTexturePools.Length(); i++) {
   1.472 +    if (mTexturePools[i]->GetFormat() == aFormat) {
   1.473 +      return mTexturePools[i];
   1.474 +    }
   1.475 +  }
   1.476 +
   1.477 +  mTexturePools.AppendElement(
   1.478 +      new TextureClientPool(aFormat, IntSize(gfxPrefs::LayersTileWidth(),
   1.479 +                                             gfxPrefs::LayersTileHeight()),
   1.480 +                            mForwarder));
   1.481 +
   1.482 +  return mTexturePools.LastElement();
   1.483 +}
   1.484 +
   1.485 +SimpleTextureClientPool*
   1.486 +ClientLayerManager::GetSimpleTileTexturePool(SurfaceFormat aFormat)
   1.487 +{
   1.488 +  int index = (int) aFormat;
   1.489 +  mSimpleTilePools.EnsureLengthAtLeast(index+1);
   1.490 +
   1.491 +  if (mSimpleTilePools[index].get() == nullptr) {
   1.492 +    mSimpleTilePools[index] = new SimpleTextureClientPool(aFormat, IntSize(gfxPrefs::LayersTileWidth(),
   1.493 +                                                                           gfxPrefs::LayersTileHeight()),
   1.494 +                                                          mForwarder);
   1.495 +  }
   1.496 +
   1.497 +  return mSimpleTilePools[index];
   1.498 +}
   1.499 +
   1.500 +void
   1.501 +ClientLayerManager::ClearCachedResources(Layer* aSubtree)
   1.502 +{
   1.503 +  MOZ_ASSERT(!HasShadowManager() || !aSubtree);
   1.504 +  if (LayerTransactionChild* manager = mForwarder->GetShadowManager()) {
   1.505 +    manager->SendClearCachedResources();
   1.506 +  }
   1.507 +  if (aSubtree) {
   1.508 +    ClearLayer(aSubtree);
   1.509 +  } else if (mRoot) {
   1.510 +    ClearLayer(mRoot);
   1.511 +  }
   1.512 +  for (size_t i = 0; i < mTexturePools.Length(); i++) {
   1.513 +    mTexturePools[i]->Clear();
   1.514 +  }
   1.515 +}
   1.516 +
   1.517 +void
   1.518 +ClientLayerManager::ClearLayer(Layer* aLayer)
   1.519 +{
   1.520 +  ClientLayer::ToClientLayer(aLayer)->ClearCachedResources();
   1.521 +  for (Layer* child = aLayer->GetFirstChild(); child;
   1.522 +       child = child->GetNextSibling()) {
   1.523 +    ClearLayer(child);
   1.524 +  }
   1.525 +}
   1.526 +
   1.527 +void
   1.528 +ClientLayerManager::GetBackendName(nsAString& aName)
   1.529 +{
   1.530 +  switch (mForwarder->GetCompositorBackendType()) {
   1.531 +    case LayersBackend::LAYERS_BASIC: aName.AssignLiteral("Basic"); return;
   1.532 +    case LayersBackend::LAYERS_OPENGL: aName.AssignLiteral("OpenGL"); return;
   1.533 +    case LayersBackend::LAYERS_D3D9: aName.AssignLiteral("Direct3D 9"); return;
   1.534 +    case LayersBackend::LAYERS_D3D10: aName.AssignLiteral("Direct3D 10"); return;
   1.535 +    case LayersBackend::LAYERS_D3D11: aName.AssignLiteral("Direct3D 11"); return;
   1.536 +    default: NS_RUNTIMEABORT("Invalid backend");
   1.537 +  }
   1.538 +}
   1.539 +
   1.540 +bool
   1.541 +ClientLayerManager::ProgressiveUpdateCallback(bool aHasPendingNewThebesContent,
   1.542 +                                              ParentLayerRect& aCompositionBounds,
   1.543 +                                              CSSToParentLayerScale& aZoom,
   1.544 +                                              bool aDrawingCritical)
   1.545 +{
   1.546 +  aZoom.scale = 1.0;
   1.547 +#ifdef MOZ_WIDGET_ANDROID
   1.548 +  Layer* primaryScrollable = GetPrimaryScrollableLayer();
   1.549 +  if (primaryScrollable) {
   1.550 +    const FrameMetrics& metrics = primaryScrollable->AsContainerLayer()->GetFrameMetrics();
   1.551 +
   1.552 +    // This is derived from the code in
   1.553 +    // gfx/layers/ipc/CompositorParent.cpp::TransformShadowTree.
   1.554 +    CSSToLayerScale paintScale = metrics.LayersPixelsPerCSSPixel();
   1.555 +    const CSSRect& metricsDisplayPort =
   1.556 +      (aDrawingCritical && !metrics.mCriticalDisplayPort.IsEmpty()) ?
   1.557 +        metrics.mCriticalDisplayPort : metrics.mDisplayPort;
   1.558 +    LayerRect displayPort = (metricsDisplayPort + metrics.GetScrollOffset()) * paintScale;
   1.559 +
   1.560 +    return AndroidBridge::Bridge()->ProgressiveUpdateCallback(
   1.561 +      aHasPendingNewThebesContent, displayPort, paintScale.scale, aDrawingCritical,
   1.562 +      aCompositionBounds, aZoom);
   1.563 +  }
   1.564 +#endif
   1.565 +
   1.566 +  return false;
   1.567 +}
   1.568 +
   1.569 +ClientLayer::~ClientLayer()
   1.570 +{
   1.571 +  if (HasShadow()) {
   1.572 +    PLayerChild::Send__delete__(GetShadow());
   1.573 +  }
   1.574 +  MOZ_COUNT_DTOR(ClientLayer);
   1.575 +}
   1.576 +
   1.577 +}
   1.578 +}

mercurial