Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / paint / ViewDisplayList.h
1 // Copyright 2014 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 ViewDisplayList_h
6 #define ViewDisplayList_h
7
8 #include "core/rendering/PaintPhase.h"
9 #include "wtf/HashSet.h"
10 #include "wtf/PassOwnPtr.h"
11 #include "wtf/Vector.h"
12
13 namespace blink {
14
15 class GraphicsContext;
16 class RenderObject;
17 class RenderLayer;
18
19 class DisplayItem {
20 public:
21     enum Type {
22         // DisplayItem types must be kept in sync with PaintPhase.
23         DrawingPaintPhaseBlockBackground = 0,
24         DrawingPaintPhaseChildBlockBackground = 1,
25         DrawingPaintPhaseChildBlockBackgrounds = 2,
26         DrawingPaintPhaseFloat = 3,
27         DrawingPaintPhaseForeground = 4,
28         DrawingPaintPhaseOutline = 5,
29         DrawingPaintPhaseChildOutlines = 6,
30         DrawingPaintPhaseSelfOutline = 7,
31         DrawingPaintPhaseSelection = 8,
32         DrawingPaintPhaseCollapsedTableBorders = 9,
33         DrawingPaintPhaseTextClip = 10,
34         DrawingPaintPhaseMask = 11,
35         DrawingPaintPhaseClippingMask = 12,
36         ClipLayerOverflowControls = 13,
37         ClipLayerBackground = 14,
38         ClipLayerParent = 15,
39         ClipLayerFilter = 16,
40         ClipLayerForeground = 17,
41         ClipLayerFragmentFloat = 18,
42         ClipLayerFragmentForeground = 19,
43         ClipLayerFragmentChildOutline = 20,
44         ClipLayerFragmentOutline = 21,
45         ClipLayerFragmentMask = 22,
46         ClipLayerFragmentClippingMask = 23,
47         ClipLayerFragmentParent = 24,
48         ClipLayerFragmentSelection = 25,
49         ClipLayerFragmentChildBlockBackgrounds = 26,
50         EndClip = 27,
51     };
52
53     virtual ~DisplayItem() { }
54
55     virtual void replay(GraphicsContext*) = 0;
56
57     const RenderObject* renderer() const { return m_id.renderer; }
58     Type type() const { return m_id.type; }
59     bool idsEqual(const DisplayItem& other) const { return m_id.renderer == other.m_id.renderer && m_id.type == other.m_id.type; }
60
61 #ifndef NDEBUG
62     static WTF::String typeAsDebugString(DisplayItem::Type);
63     static WTF::String rendererDebugString(const RenderObject*);
64     virtual WTF::String asDebugString() const;
65 #endif
66
67 protected:
68     DisplayItem(const RenderObject* renderer, Type type)
69         : m_id(renderer, type)
70     { }
71
72 private:
73     struct Id {
74         Id(const RenderObject* r, Type t)
75             : renderer(r)
76             , type(t)
77         { }
78
79         const RenderObject* renderer;
80         const Type type;
81     } m_id;
82 };
83
84 typedef Vector<OwnPtr<DisplayItem> > PaintList;
85
86 class ViewDisplayList {
87 public:
88     ViewDisplayList() { };
89
90     const PaintList& paintList();
91     void add(WTF::PassOwnPtr<DisplayItem>);
92     void invalidate(const RenderObject*);
93
94 #ifndef NDEBUG
95     void showDebugData() const;
96 #endif
97
98 private:
99     PaintList::iterator findDisplayItem(PaintList::iterator, const DisplayItem&);
100     bool wasInvalidated(const DisplayItem&) const;
101     void updatePaintList();
102
103     PaintList m_paintList;
104     HashSet<const RenderObject*> m_paintListRenderers;
105     HashSet<const RenderObject*> m_invalidated;
106     PaintList m_newPaints;
107 };
108
109 } // namespace blink
110
111 #endif // ViewDisplayList_h