1 // Copyright 2019 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_SCROLLBAR_DISPLAY_ITEM_H_
6 #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_PAINT_SCROLLBAR_DISPLAY_ITEM_H_
7 
8 #include "cc/input/scrollbar.h"
9 #include "third_party/blink/renderer/platform/graphics/compositor_element_id.h"
10 #include "third_party/blink/renderer/platform/graphics/paint/display_item.h"
11 #include "third_party/blink/renderer/platform/graphics/paint/paint_record.h"
12 #include "third_party/skia/include/core/SkRefCnt.h"
13 
14 namespace cc {
15 class ScrollbarLayerBase;
16 }
17 
18 namespace blink {
19 
20 class GraphicsContext;
21 class TransformPaintPropertyNode;
22 
23 // Represents a non-custom scrollbar in CompositeAfterPaint. During paint, we
24 // create a ScrollbarDisplayItem for a non-custom scrollbar. During
25 // PaintArtifactCompositor::Update(), we decide whether to composite the
26 // scrollbar and, if not composited, call Paint() to actually paint the
27 // scrollbar into a paint record, otherwise call CreateLayer() to create a
28 // cc scrollbar layer.
29 class PLATFORM_EXPORT ScrollbarDisplayItem final : public DisplayItem {
30  public:
31   ScrollbarDisplayItem(const DisplayItemClient&,
32                        Type,
33                        scoped_refptr<cc::Scrollbar>,
34                        const IntRect& visual_rect,
35                        const TransformPaintPropertyNode* scroll_translation,
36                        CompositorElementId element_id);
37 
ScrollTranslation()38   const TransformPaintPropertyNode* ScrollTranslation() const {
39     return scroll_translation_;
40   }
ElementId()41   CompositorElementId ElementId() const { return element_id_; }
42 
43   // Paints the scrollbar into the internal paint record, for non-composited
44   // scrollbar.
45   sk_sp<const PaintRecord> Paint() const;
46 
47   // Create or reuse the cc scrollbar layer, for composited scrollbar.
48   scoped_refptr<cc::ScrollbarLayerBase> CreateOrReuseLayer(
49       cc::ScrollbarLayerBase* existing_layer) const;
50 
51   // DisplayItem
52   bool Equals(const DisplayItem&) const override;
53 #if DCHECK_IS_ON()
54   void PropertiesAsJSON(JSONObject&) const override;
55 #endif
56 
57   // Records a scrollbar into a GraphicsContext. Must check
58   // PaintController::UseCachedItem() before calling this function.
59   // |rect| is the bounding box of the scrollbar in the current transform space.
60   static void Record(GraphicsContext&,
61                      const DisplayItemClient&,
62                      DisplayItem::Type,
63                      scoped_refptr<cc::Scrollbar>,
64                      const IntRect& visual_rect,
65                      const TransformPaintPropertyNode* scroll_translation,
66                      CompositorElementId element_id);
67 
68  private:
69   scoped_refptr<cc::Scrollbar> scrollbar_;
70   const TransformPaintPropertyNode* scroll_translation_;
71   CompositorElementId element_id_;
72   // This is lazily created for non-composited scrollbar.
73   mutable sk_sp<const PaintRecord> record_;
74 };
75 
76 }  // namespace blink
77 
78 #endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_GRAPHICS_PAINT_SCROLLBAR_DISPLAY_ITEM_H_
79