forked from mirrors/gecko-dev
		
	Bug 873378 - Add a limit on mobile of 20 layers per container layer. r=roc
This commit is contained in:
		
							parent
							
								
									94f57948a0
								
							
						
					
					
						commit
						1591216c2a
					
				
					 5 changed files with 39 additions and 0 deletions
				
			
		|  | @ -2041,6 +2041,9 @@ ContainerState::ProcessDisplayItems(const nsDisplayList& aList, | ||||||
|     topLeft = lastActiveScrolledRoot->GetOffsetToCrossDoc(mContainerReferenceFrame); |     topLeft = lastActiveScrolledRoot->GetOffsetToCrossDoc(mContainerReferenceFrame); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   int32_t maxLayers = nsDisplayItem::MaxActiveLayers(); | ||||||
|  |   int layerCount = 0; | ||||||
|  | 
 | ||||||
|   for (nsDisplayItem* item = aList.GetBottom(); item; item = item->GetAbove()) { |   for (nsDisplayItem* item = aList.GetBottom(); item; item = item->GetAbove()) { | ||||||
|     NS_ASSERTION(mAppUnitsPerDevPixel == AppUnitsPerDevPixel(item), |     NS_ASSERTION(mAppUnitsPerDevPixel == AppUnitsPerDevPixel(item), | ||||||
|       "items in a container layer should all have the same app units per dev pixel"); |       "items in a container layer should all have the same app units per dev pixel"); | ||||||
|  | @ -2083,6 +2086,10 @@ ContainerState::ProcessDisplayItems(const nsDisplayList& aList, | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     if (maxLayers != -1 && layerCount >= maxLayers) { | ||||||
|  |       forceInactive = true; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     // Assign the item to a layer
 |     // Assign the item to a layer
 | ||||||
|     if (layerState == LAYER_ACTIVE_FORCE || |     if (layerState == LAYER_ACTIVE_FORCE || | ||||||
|         (layerState == LAYER_INACTIVE && !mManager->IsWidgetLayerManager()) || |         (layerState == LAYER_INACTIVE && !mManager->IsWidgetLayerManager()) || | ||||||
|  | @ -2090,6 +2097,8 @@ ContainerState::ProcessDisplayItems(const nsDisplayList& aList, | ||||||
|          (layerState == LAYER_ACTIVE_EMPTY || |          (layerState == LAYER_ACTIVE_EMPTY || | ||||||
|           layerState == LAYER_ACTIVE))) { |           layerState == LAYER_ACTIVE))) { | ||||||
| 
 | 
 | ||||||
|  |       layerCount++; | ||||||
|  | 
 | ||||||
|       // LAYER_ACTIVE_EMPTY means the layer is created just for its metadata.
 |       // LAYER_ACTIVE_EMPTY means the layer is created just for its metadata.
 | ||||||
|       // We should never see an empty layer with any visible content!
 |       // We should never see an empty layer with any visible content!
 | ||||||
|       NS_ASSERTION(layerState != LAYER_ACTIVE_EMPTY || |       NS_ASSERTION(layerState != LAYER_ACTIVE_EMPTY || | ||||||
|  |  | ||||||
|  | @ -1497,6 +1497,20 @@ nsDisplayItem::ForceActiveLayers() | ||||||
|   return sForce; |   return sForce; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | /* static */ int32_t | ||||||
|  | nsDisplayItem::MaxActiveLayers() | ||||||
|  | { | ||||||
|  |   static int32_t sMaxLayers = false; | ||||||
|  |   static bool sMaxLayersCached = false; | ||||||
|  | 
 | ||||||
|  |   if (!sMaxLayersCached) { | ||||||
|  |     Preferences::AddIntVarCache(&sMaxLayers, "layers.max-active", -1); | ||||||
|  |     sMaxLayersCached = true; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   return sMaxLayersCached; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| bool | bool | ||||||
| nsDisplayItem::RecomputeVisibility(nsDisplayListBuilder* aBuilder, | nsDisplayItem::RecomputeVisibility(nsDisplayListBuilder* aBuilder, | ||||||
|                                    nsRegion* aVisibleRegion) { |                                    nsRegion* aVisibleRegion) { | ||||||
|  |  | ||||||
|  | @ -1003,6 +1003,12 @@ public: | ||||||
|    */ |    */ | ||||||
|   static bool ForceActiveLayers(); |   static bool ForceActiveLayers(); | ||||||
| 
 | 
 | ||||||
|  |   /**
 | ||||||
|  |    * Returns the maximum number of layers that should be created | ||||||
|  |    * or -1 for no limit. Requires setting the pref layers.max-acitve. | ||||||
|  |    */ | ||||||
|  |   static int32_t MaxActiveLayers(); | ||||||
|  | 
 | ||||||
|   /**
 |   /**
 | ||||||
|    * @return LAYER_NONE if BuildLayer will return null. In this case |    * @return LAYER_NONE if BuildLayer will return null. In this case | ||||||
|    * there is no layer for the item, and Paint should be called instead |    * there is no layer for the item, and Paint should be called instead | ||||||
|  |  | ||||||
|  | @ -546,6 +546,12 @@ pref("layers.async-video.enabled", true); | ||||||
| pref("layers.progressive-paint", true); | pref("layers.progressive-paint", true); | ||||||
| pref("layers.low-precision-buffer", true); | pref("layers.low-precision-buffer", true); | ||||||
| pref("layers.low-precision-resolution", 250); | pref("layers.low-precision-resolution", 250); | ||||||
|  | // We want to limit layers for two reasons:
 | ||||||
|  | // 1) We can't scroll smoothly if we have to many draw calls
 | ||||||
|  | // 2) Pages that have too many layers consume too much memory and crash.
 | ||||||
|  | // By limiting the number of layers on mobile we're making the main thread
 | ||||||
|  | // work harder keep scrolling smooth and memory low.
 | ||||||
|  | pref("layers.max-active", 20); | ||||||
| 
 | 
 | ||||||
| pref("notification.feature.enabled", true); | pref("notification.feature.enabled", true); | ||||||
| pref("dom.webnotifications.enabled", true); | pref("dom.webnotifications.enabled", true); | ||||||
|  |  | ||||||
|  | @ -4053,6 +4053,10 @@ pref("layers.acceleration.draw-fps", false); | ||||||
| pref("layers.draw-borders", false); | pref("layers.draw-borders", false); | ||||||
| pref("layers.frame-counter", false); | pref("layers.frame-counter", false); | ||||||
| 
 | 
 | ||||||
|  | // Max number of layers per container. See Overwrite in mobile prefs.
 | ||||||
|  | pref("layers.max-active", -1); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| #ifdef XP_MACOSX | #ifdef XP_MACOSX | ||||||
| pref("layers.offmainthreadcomposition.enabled", true); | pref("layers.offmainthreadcomposition.enabled", true); | ||||||
| #else | #else | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 Benoit Girard
						Benoit Girard