1 // Copyright 2017 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_PAINT_GEOMETRY_MAPPER_CLIP_CACHE_H_ 6 #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_PAINT_GEOMETRY_MAPPER_CLIP_CACHE_H_ 7 8 #include "third_party/blink/renderer/platform/graphics/paint/float_clip_rect.h" 9 #include "third_party/blink/renderer/platform/graphics/scroll_types.h" 10 #include "third_party/blink/renderer/platform/platform_export.h" 11 #include "third_party/blink/renderer/platform/wtf/vector.h" 12 13 namespace blink { 14 15 class ClipPaintPropertyNode; 16 class FloatClipRect; 17 class TransformPaintPropertyNode; 18 19 // A GeometryMapperClipCache hangs off a ClipPaintPropertyNode. It stores 20 // cached "clip visual rects" (See GeometryMapper.h) from that node in 21 // ancestor spaces. 22 class PLATFORM_EXPORT GeometryMapperClipCache { 23 USING_FAST_MALLOC(GeometryMapperClipCache); 24 25 public: 26 GeometryMapperClipCache(); 27 28 struct ClipAndTransform { 29 const ClipPaintPropertyNode* ancestor_clip; 30 const TransformPaintPropertyNode* ancestor_transform; 31 OverlayScrollbarClipBehavior clip_behavior; 32 bool operator==(const ClipAndTransform& other) const { 33 return ancestor_clip == other.ancestor_clip && 34 ancestor_transform == other.ancestor_transform && 35 clip_behavior == other.clip_behavior; 36 } ClipAndTransformClipAndTransform37 ClipAndTransform(const ClipPaintPropertyNode* ancestor_clip_arg, 38 const TransformPaintPropertyNode* ancestor_transform_arg, 39 OverlayScrollbarClipBehavior clip_behavior_arg) 40 : ancestor_clip(ancestor_clip_arg), 41 ancestor_transform(ancestor_transform_arg), 42 clip_behavior(clip_behavior_arg) { 43 DCHECK(ancestor_clip); 44 DCHECK(ancestor_transform); 45 } 46 }; 47 48 struct ClipCacheEntry { 49 const ClipAndTransform clip_and_transform; 50 // The clip visual rect of the associated clip node in the space of 51 // |clip_and_transform|. 52 const FloatClipRect clip_rect; 53 // Whether there is any transform animation between the transform space 54 // of the associated clip node and |clip_and_transform|. 55 const bool has_transform_animation; 56 }; 57 58 // Returns the clip visual rect of the owning 59 // clip of |this| in the space of |ancestors|, if there is one cached. 60 // Otherwise returns null. 61 const ClipCacheEntry* GetCachedClip(const ClipAndTransform& ancestors); 62 63 // Stores cached the "clip visual rect" of |this| in the space of |ancestors|, 64 // into a local cache. 65 void SetCachedClip(const ClipCacheEntry&); 66 67 static void ClearCache(); 68 bool IsValid() const; 69 70 private: 71 void InvalidateCacheIfNeeded(); 72 73 Vector<ClipCacheEntry> clip_cache_; 74 unsigned cache_generation_; 75 76 DISALLOW_COPY_AND_ASSIGN(GeometryMapperClipCache); 77 }; 78 79 } // namespace blink 80 81 #endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_PAINT_GEOMETRY_MAPPER_CLIP_CACHE_H_ 82