void RenderLayerClipper::getOrCalculateClipRects(const ClipRectsContext& context, ClipRects& clipRects) const { if (context.usesCache()) clipRects = *getClipRects(context); else calculateClipRects(context, clipRects); }
void RenderLayerClipper::updateClipRects(const ClipRectsContext& clipRectsContext) { ClipRectsType clipRectsType = clipRectsContext.clipRectsType; ASSERT(clipRectsType < NumCachedClipRectsTypes); if (m_clipRectsCache && clipRectsContext.rootLayer == m_clipRectsCache->clipRectsRoot(clipRectsType) && m_clipRectsCache->getClipRects(clipRectsType, clipRectsContext.respectOverflowClip)) { // FIXME: We used to ASSERT that we always got a consistent root layer. // We should add a test that has an inconsistent root. See // http://crbug.com/366118 for an example. ASSERT(m_clipRectsCache->m_scrollbarRelevancy[clipRectsType] == clipRectsContext.overlayScrollbarSizeRelevancy); #ifdef CHECK_CACHED_CLIP_RECTS // This code is useful to check cached clip rects, but is too expensive to leave enabled in debug builds by default. ClipRectsContext tempContext(clipRectsContext); tempContext.clipRectsType = TemporaryClipRects; ClipRects clipRects; calculateClipRects(tempContext, clipRects); ASSERT(clipRects == *m_clipRectsCache->getClipRects(clipRectsType, clipRectsContext.respectOverflowClip).get()); #endif return; // We have the correct cached value. } // For transformed layers, the root layer was shifted to be us, so there is no need to // examine the parent. We want to cache clip rects with us as the root. RenderLayer* parentLayer = !isClippingRootForContext(clipRectsContext) ? m_renderer.layer()->parent() : 0; if (parentLayer) parentLayer->clipper().updateClipRects(clipRectsContext); ClipRects clipRects; calculateClipRects(clipRectsContext, clipRects); if (!m_clipRectsCache) m_clipRectsCache = adoptPtr(new ClipRectsCache); if (parentLayer && parentLayer->clipper().clipRects(clipRectsContext) && clipRects == *parentLayer->clipper().clipRects(clipRectsContext)) m_clipRectsCache->setClipRects(clipRectsType, clipRectsContext.respectOverflowClip, parentLayer->clipper().clipRects(clipRectsContext), clipRectsContext.rootLayer); else m_clipRectsCache->setClipRects(clipRectsType, clipRectsContext.respectOverflowClip, ClipRects::create(clipRects), clipRectsContext.rootLayer); #ifndef NDEBUG m_clipRectsCache->m_scrollbarRelevancy[clipRectsType] = clipRectsContext.overlayScrollbarSizeRelevancy; #endif }
void RenderLayerClipper::updateClipRects(const ClipRectsContext& clipRectsContext) { ClipRectsType clipRectsType = clipRectsContext.clipRectsType; ASSERT(clipRectsType < NumCachedClipRectsTypes); if (m_clipRectsCache && m_clipRectsCache->getClipRects(clipRectsType, clipRectsContext.respectOverflowClip)) { // FIXME: these asserts trigger for squashing. Need to update this code to support squashing as appropriate. ASSERT(clipRectsContext.rootLayer == m_clipRectsCache->m_clipRectsRoot[clipRectsType]); ASSERT(m_clipRectsCache->m_scrollbarRelevancy[clipRectsType] == clipRectsContext.overlayScrollbarSizeRelevancy); #ifdef CHECK_CACHED_CLIP_RECTS // This code is useful to check cached clip rects, but is too expensive to leave enabled in debug builds by default. ClipRectsContext tempContext(clipRectsContext); tempContext.clipRectsType = TemporaryClipRects; ClipRects clipRects; calculateClipRects(tempContext, clipRects); ASSERT(clipRects == *m_clipRectsCache->getClipRects(clipRectsType, clipRectsContext.respectOverflowClip).get()); #endif return; // We have the correct cached value. } // For transformed layers, the root layer was shifted to be us, so there is no need to // examine the parent. We want to cache clip rects with us as the root. RenderLayer* parentLayer = clipRectsContext.rootLayer != m_renderer->layer() ? m_renderer->layer()->parent() : 0; if (parentLayer) parentLayer->clipper().updateClipRects(clipRectsContext); ClipRects clipRects; calculateClipRects(clipRectsContext, clipRects); if (!m_clipRectsCache) m_clipRectsCache = adoptPtr(new ClipRectsCache); if (parentLayer && parentLayer->clipper().clipRects(clipRectsContext) && clipRects == *parentLayer->clipper().clipRects(clipRectsContext)) m_clipRectsCache->setClipRects(clipRectsType, clipRectsContext.respectOverflowClip, parentLayer->clipper().clipRects(clipRectsContext)); else m_clipRectsCache->setClipRects(clipRectsType, clipRectsContext.respectOverflowClip, ClipRects::create(clipRects)); #ifndef NDEBUG m_clipRectsCache->m_clipRectsRoot[clipRectsType] = clipRectsContext.rootLayer; m_clipRectsCache->m_scrollbarRelevancy[clipRectsType] = clipRectsContext.overlayScrollbarSizeRelevancy; #endif }
ClipRects* PaintLayerClipper::getClipRects(const ClipRectsContext& context) const { if (ClipRects* result = clipRectsIfCached(context)) return result; // Note that it's important that we call getClipRects on our parent // before we call calculateClipRects so that calculateClipRects will hit // the cache. ClipRects* parentClipRects = 0; if (context.rootLayer != m_layoutObject.layer() && m_layoutObject.layer()->parent()) parentClipRects = m_layoutObject.layer()->parent()->clipper().getClipRects(context); RefPtr<ClipRects> clipRects = ClipRects::create(); calculateClipRects(context, *clipRects); return storeClipRectsInCache(context, parentClipRects, *clipRects); }
ClipRects* RenderLayerClipper::getClipRects(const ClipRectsContext& context) const { if (ClipRects* result = clipRectsIfCached(context)) return result; // Note that it's important that we call getClipRects on our parent // before we call calculateClipRects so that calculateClipRects will hit // the cache. ClipRects* parentClipRects = 0; if (context.rootLayer != m_renderer.layer() && m_renderer.layer()->parent()) parentClipRects = m_renderer.layer()->parent()->clipper().getClipRects(context); ClipRects clipRects; calculateClipRects(context, clipRects); return storeClipRectsInCache(context, parentClipRects, clipRects); }
ClipRects* PaintLayerClipper::clipRectsIfCached(const ClipRectsContext& context) const { ASSERT(context.usesCache()); if (!m_cache) return 0; ClipRectsCache::Entry& entry = m_cache->get(context.cacheSlot()); // FIXME: We used to ASSERT that we always got a consistent root layer. // We should add a test that has an inconsistent root. See // http://crbug.com/366118 for an example. if (context.rootLayer != entry.root) return 0; ASSERT(entry.scrollbarRelevancy == context.scrollbarRelevancy); #ifdef CHECK_CACHED_CLIP_RECTS // This code is useful to check cached clip rects, but is too expensive to leave enabled in debug builds by default. ClipRectsContext tempContext(context); tempContext.cacheSlot = UncachedClipRects; RefPtr<ClipRects> clipRects = ClipRects::create(); calculateClipRects(tempContext, *clipRects); ASSERT(clipRects == *entry.clipRects); #endif return entry.clipRects.get(); }