1 | /* |
2 | * Copyright (C) 2016 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #include "config.h" |
27 | #include "DisplayList.h" |
28 | |
29 | #include "DisplayListItems.h" |
30 | #include "Logging.h" |
31 | #include <wtf/StdLibExtras.h> |
32 | #include <wtf/text/TextStream.h> |
33 | |
34 | namespace WebCore { |
35 | namespace DisplayList { |
36 | |
37 | #if !defined(NDEBUG) || !LOG_DISABLED |
38 | WTF::CString DisplayList::description() const |
39 | { |
40 | TextStream ts; |
41 | ts << this; |
42 | return ts.release().utf8(); |
43 | } |
44 | |
45 | void DisplayList::dump() const |
46 | { |
47 | fprintf(stderr, "%s" , description().data()); |
48 | } |
49 | #endif |
50 | |
51 | void DisplayList::clear() |
52 | { |
53 | m_list.clear(); |
54 | } |
55 | |
56 | void DisplayList::removeItemsFromIndex(size_t index) |
57 | { |
58 | m_list.resize(index); |
59 | } |
60 | |
61 | bool DisplayList::shouldDumpForFlags(AsTextFlags flags, const Item& item) |
62 | { |
63 | switch (item.type()) { |
64 | case ItemType::SetState: |
65 | if (!(flags & AsTextFlag::IncludesPlatformOperations)) { |
66 | const auto& stateItem = downcast<SetState>(item); |
67 | // FIXME: for now, only drop the item if the only state-change flags are platform-specific. |
68 | if (stateItem.state().m_changeFlags == GraphicsContextState::ShouldSubpixelQuantizeFontsChange) |
69 | return false; |
70 | |
71 | if (stateItem.state().m_changeFlags == GraphicsContextState::ShouldSubpixelQuantizeFontsChange) |
72 | return false; |
73 | } |
74 | break; |
75 | #if USE(CG) |
76 | case ItemType::ApplyFillPattern: |
77 | case ItemType::ApplyStrokePattern: |
78 | if (!(flags & AsTextFlag::IncludesPlatformOperations)) |
79 | return false; |
80 | break; |
81 | #endif |
82 | default: |
83 | break; |
84 | } |
85 | return true; |
86 | } |
87 | |
88 | String DisplayList::asText(AsTextFlags flags) const |
89 | { |
90 | TextStream stream(TextStream::LineMode::MultipleLine, TextStream::Formatting::SVGStyleRect); |
91 | for (auto& item : m_list) { |
92 | if (!shouldDumpForFlags(flags, item)) |
93 | continue; |
94 | stream << item; |
95 | } |
96 | return stream.release(); |
97 | } |
98 | |
99 | void DisplayList::dump(TextStream& ts) const |
100 | { |
101 | TextStream::GroupScope group(ts); |
102 | ts << "display list" ; |
103 | |
104 | size_t numItems = m_list.size(); |
105 | for (size_t i = 0; i < numItems; ++i) { |
106 | TextStream::GroupScope scope(ts); |
107 | ts << i << " " << m_list[i].get(); |
108 | } |
109 | ts.startGroup(); |
110 | ts << "size in bytes: " << sizeInBytes(); |
111 | ts.endGroup(); |
112 | } |
113 | |
114 | size_t DisplayList::sizeInBytes() const |
115 | { |
116 | size_t result = 0; |
117 | for (auto& ref : m_list) |
118 | result += Item::sizeInBytes(ref); |
119 | |
120 | return result; |
121 | } |
122 | |
123 | } // namespace DisplayList |
124 | |
125 | TextStream& operator<<(TextStream& ts, const DisplayList::DisplayList& displayList) |
126 | { |
127 | displayList.dump(ts); |
128 | return ts; |
129 | } |
130 | |
131 | } // namespace WebCore |
132 | |