OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/paint/ViewPainter.h" | 5 #include "core/paint/ViewPainter.h" |
6 | 6 |
7 #include "core/frame/FrameView.h" | 7 #include "core/frame/FrameView.h" |
8 #include "core/frame/Settings.h" | 8 #include "core/frame/Settings.h" |
9 #include "core/layout/LayoutBox.h" | 9 #include "core/layout/LayoutBox.h" |
10 #include "core/layout/LayoutView.h" | 10 #include "core/layout/LayoutView.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 // canvas. None of the stacking context effects (except transformation) o
n the root element | 48 // canvas. None of the stacking context effects (except transformation) o
n the root element |
49 // affects the background. | 49 // affects the background. |
50 // 3. The main frame is also responsible for painting the user-agent-defined
base background | 50 // 3. The main frame is also responsible for painting the user-agent-defined
base background |
51 // color. Conceptually it should be painted by the embedder but painting
it here allows | 51 // color. Conceptually it should be painted by the embedder but painting
it here allows |
52 // culling and pre-blending optimization when possible. | 52 // culling and pre-blending optimization when possible. |
53 | 53 |
54 GraphicsContext& context = paintInfo.context; | 54 GraphicsContext& context = paintInfo.context; |
55 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, m_layou
tView, DisplayItem::BoxDecorationBackground, LayoutPoint())) | 55 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible(context, m_layou
tView, DisplayItem::BoxDecorationBackground, LayoutPoint())) |
56 return; | 56 return; |
57 | 57 |
58 IntRect documentRect = m_layoutView.documentRect(); | 58 // The background fill rect is the size of the LayoutView's main GraphicsLay
er. |
| 59 IntRect backgroundRect = pixelSnappedIntRect(m_layoutView.layer()->boundingB
oxForCompositing()); |
59 const Document& document = m_layoutView.document(); | 60 const Document& document = m_layoutView.document(); |
60 const FrameView& frameView = *m_layoutView.frameView(); | 61 const FrameView& frameView = *m_layoutView.frameView(); |
61 bool isMainFrame = !document.ownerElement(); | 62 bool isMainFrame = !document.ownerElement(); |
62 bool paintsBaseBackground = isMainFrame && !frameView.isTransparent(); | 63 bool paintsBaseBackground = isMainFrame && !frameView.isTransparent(); |
63 bool shouldClearCanvas = paintsBaseBackground && (document.settings() && doc
ument.settings()->shouldClearDocumentBackground()); | 64 bool shouldClearCanvas = paintsBaseBackground && (document.settings() && doc
ument.settings()->shouldClearDocumentBackground()); |
64 Color baseBackgroundColor = paintsBaseBackground ? frameView.baseBackgroundC
olor() : Color(); | 65 Color baseBackgroundColor = paintsBaseBackground ? frameView.baseBackgroundC
olor() : Color(); |
65 Color rootBackgroundColor = m_layoutView.style()->visitedDependentColor(CSSP
ropertyBackgroundColor); | 66 Color rootBackgroundColor = m_layoutView.style()->visitedDependentColor(CSSP
ropertyBackgroundColor); |
66 const LayoutObject* rootObject = document.documentElement() ? document.docum
entElement()->layoutObject() : nullptr; | 67 const LayoutObject* rootObject = document.documentElement() ? document.docum
entElement()->layoutObject() : nullptr; |
67 | 68 |
68 LayoutObjectDrawingRecorder recorder(context, m_layoutView, DisplayItem::Box
DecorationBackground, documentRect, LayoutPoint()); | 69 LayoutObjectDrawingRecorder recorder(context, m_layoutView, DisplayItem::Box
DecorationBackground, backgroundRect, LayoutPoint()); |
69 | 70 |
70 // Special handling for print economy mode. | 71 // Special handling for print economy mode. |
71 bool forceBackgroundToWhite = BoxPainter::shouldForceWhiteBackgroundForPrint
Economy(m_layoutView.styleRef(), document); | 72 bool forceBackgroundToWhite = BoxPainter::shouldForceWhiteBackgroundForPrint
Economy(m_layoutView.styleRef(), document); |
72 if (forceBackgroundToWhite) { | 73 if (forceBackgroundToWhite) { |
73 // If for any reason the view background is not transparent, paint white
instead, otherwise keep transparent as is. | 74 // If for any reason the view background is not transparent, paint white
instead, otherwise keep transparent as is. |
74 if (paintsBaseBackground || rootBackgroundColor.alpha() || m_layoutView.
style()->backgroundLayers().image()) | 75 if (paintsBaseBackground || rootBackgroundColor.alpha() || m_layoutView.
style()->backgroundLayers().image()) |
75 context.fillRect(documentRect, Color::white, SkXfermode::kSrc_Mode); | 76 context.fillRect(backgroundRect, Color::white, SkXfermode::kSrc_Mode
); |
76 return; | 77 return; |
77 } | 78 } |
78 | 79 |
79 // Compute the enclosing rect of the view, in root element space. | 80 // Compute the enclosing rect of the view, in root element space. |
80 // | 81 // |
81 // For background colors we can simply paint the document rect in the defaul
t space. | 82 // For background colors we can simply paint the document rect in the defaul
t space. |
82 // However for background image, the root element transform applies. The str
ategy is to apply | 83 // However for background image, the root element transform applies. The str
ategy is to apply |
83 // root element transform on the context and issue draw commands in the loca
l space, therefore | 84 // root element transform on the context and issue draw commands in the loca
l space, therefore |
84 // we need to apply inverse transform on the document rect to get to the roo
t element space. | 85 // we need to apply inverse transform on the document rect to get to the roo
t element space. |
85 bool backgroundRenderable = true; | 86 bool backgroundRenderable = true; |
86 TransformationMatrix transform; | 87 TransformationMatrix transform; |
87 IntRect paintRect = documentRect; | 88 IntRect paintRect = backgroundRect; |
88 if (!rootObject || !rootObject->isBox()) { | 89 if (!rootObject || !rootObject->isBox()) { |
89 backgroundRenderable = false; | 90 backgroundRenderable = false; |
90 } else if (rootObject->hasLayer()) { | 91 } else if (rootObject->hasLayer()) { |
91 const PaintLayer& rootLayer = *toLayoutBoxModelObject(rootObject)->layer
(); | 92 const PaintLayer& rootLayer = *toLayoutBoxModelObject(rootObject)->layer
(); |
92 LayoutPoint offset; | 93 LayoutPoint offset; |
93 rootLayer.convertToLayerCoords(nullptr, offset); | 94 rootLayer.convertToLayerCoords(nullptr, offset); |
94 transform.translate(offset.x(), offset.y()); | 95 transform.translate(offset.x(), offset.y()); |
95 transform.multiply(rootLayer.renderableTransform(paintInfo.globalPaintFl
ags())); | 96 transform.multiply(rootLayer.renderableTransform(paintInfo.globalPaintFl
ags())); |
96 | 97 |
97 if (!transform.isInvertible()) { | 98 if (!transform.isInvertible()) { |
98 backgroundRenderable = false; | 99 backgroundRenderable = false; |
99 } else { | 100 } else { |
100 bool isClamped; | 101 bool isClamped; |
101 paintRect = transform.inverse().projectQuad(FloatQuad(documentRect),
&isClamped).enclosingBoundingBox(); | 102 paintRect = transform.inverse().projectQuad(FloatQuad(backgroundRect
), &isClamped).enclosingBoundingBox(); |
102 backgroundRenderable = !isClamped; | 103 backgroundRenderable = !isClamped; |
103 } | 104 } |
104 } | 105 } |
105 | 106 |
106 if (!backgroundRenderable) { | 107 if (!backgroundRenderable) { |
107 if (baseBackgroundColor.alpha()) | 108 if (baseBackgroundColor.alpha()) |
108 context.fillRect(documentRect, baseBackgroundColor, shouldClearCanva
s ? SkXfermode::kSrc_Mode : SkXfermode::kSrcOver_Mode); | 109 context.fillRect(backgroundRect, baseBackgroundColor, shouldClearCan
vas ? SkXfermode::kSrc_Mode : SkXfermode::kSrcOver_Mode); |
109 else if (shouldClearCanvas) | 110 else if (shouldClearCanvas) |
110 context.fillRect(documentRect, Color(), SkXfermode::kClear_Mode); | 111 context.fillRect(backgroundRect, Color(), SkXfermode::kClear_Mode); |
111 return; | 112 return; |
112 } | 113 } |
113 | 114 |
114 BoxPainter::FillLayerOcclusionOutputList reversedPaintList; | 115 BoxPainter::FillLayerOcclusionOutputList reversedPaintList; |
115 bool shouldDrawBackgroundInSeparateBuffer = BoxPainter(m_layoutView).calcula
teFillLayerOcclusionCulling(reversedPaintList, m_layoutView.style()->backgroundL
ayers()); | 116 bool shouldDrawBackgroundInSeparateBuffer = BoxPainter(m_layoutView).calcula
teFillLayerOcclusionCulling(reversedPaintList, m_layoutView.style()->backgroundL
ayers()); |
116 ASSERT(reversedPaintList.size()); | 117 ASSERT(reversedPaintList.size()); |
117 | 118 |
118 // If the root background color is opaque, isolation group can be skipped be
cause the canvas | 119 // If the root background color is opaque, isolation group can be skipped be
cause the canvas |
119 // will be cleared by root background color. | 120 // will be cleared by root background color. |
120 if (!rootBackgroundColor.hasAlpha()) | 121 if (!rootBackgroundColor.hasAlpha()) |
121 shouldDrawBackgroundInSeparateBuffer = false; | 122 shouldDrawBackgroundInSeparateBuffer = false; |
122 | 123 |
123 // We are going to clear the canvas with transparent pixels, isolation group
can be skipped. | 124 // We are going to clear the canvas with transparent pixels, isolation group
can be skipped. |
124 if (!baseBackgroundColor.alpha() && shouldClearCanvas) | 125 if (!baseBackgroundColor.alpha() && shouldClearCanvas) |
125 shouldDrawBackgroundInSeparateBuffer = false; | 126 shouldDrawBackgroundInSeparateBuffer = false; |
126 | 127 |
127 if (shouldDrawBackgroundInSeparateBuffer) { | 128 if (shouldDrawBackgroundInSeparateBuffer) { |
128 if (baseBackgroundColor.alpha()) | 129 if (baseBackgroundColor.alpha()) |
129 context.fillRect(documentRect, baseBackgroundColor, shouldClearCanva
s ? SkXfermode::kSrc_Mode : SkXfermode::kSrcOver_Mode); | 130 context.fillRect(backgroundRect, baseBackgroundColor, shouldClearCan
vas ? SkXfermode::kSrc_Mode : SkXfermode::kSrcOver_Mode); |
130 context.beginLayer(); | 131 context.beginLayer(); |
131 } | 132 } |
132 | 133 |
133 Color combinedBackgroundColor = shouldDrawBackgroundInSeparateBuffer ? rootB
ackgroundColor : baseBackgroundColor.blend(rootBackgroundColor); | 134 Color combinedBackgroundColor = shouldDrawBackgroundInSeparateBuffer ? rootB
ackgroundColor : baseBackgroundColor.blend(rootBackgroundColor); |
134 if (combinedBackgroundColor.alpha()) | 135 if (combinedBackgroundColor.alpha()) |
135 context.fillRect(documentRect, combinedBackgroundColor, (shouldDrawBackg
roundInSeparateBuffer || shouldClearCanvas) ? SkXfermode::kSrc_Mode : SkXfermode
::kSrcOver_Mode); | 136 context.fillRect(backgroundRect, combinedBackgroundColor, (shouldDrawBac
kgroundInSeparateBuffer || shouldClearCanvas) ? SkXfermode::kSrc_Mode : SkXfermo
de::kSrcOver_Mode); |
136 else if (shouldClearCanvas && !shouldDrawBackgroundInSeparateBuffer) | 137 else if (shouldClearCanvas && !shouldDrawBackgroundInSeparateBuffer) |
137 context.fillRect(documentRect, Color(), SkXfermode::kClear_Mode); | 138 context.fillRect(backgroundRect, Color(), SkXfermode::kClear_Mode); |
138 | 139 |
139 for (auto it = reversedPaintList.rbegin(); it != reversedPaintList.rend(); +
+it) { | 140 for (auto it = reversedPaintList.rbegin(); it != reversedPaintList.rend(); +
+it) { |
140 ASSERT((*it)->clip() == BorderFillBox); | 141 ASSERT((*it)->clip() == BorderFillBox); |
141 | 142 |
142 bool shouldPaintInViewportSpace = (*it)->attachment() == FixedBackground
Attachment; | 143 bool shouldPaintInViewportSpace = (*it)->attachment() == FixedBackground
Attachment; |
143 if (shouldPaintInViewportSpace) { | 144 if (shouldPaintInViewportSpace) { |
144 BoxPainter::paintFillLayerExtended(m_layoutView, paintInfo, Color(),
**it, LayoutRect(LayoutRect::infiniteIntRect()), BackgroundBleedNone); | 145 BoxPainter::paintFillLayerExtended(m_layoutView, paintInfo, Color(),
**it, LayoutRect(LayoutRect::infiniteIntRect()), BackgroundBleedNone); |
145 } else { | 146 } else { |
146 context.save(); | 147 context.save(); |
147 // TODO(trchen): We should be able to handle 3D-transformed root | 148 // TODO(trchen): We should be able to handle 3D-transformed root |
148 // background with slimming paint by using transform display items. | 149 // background with slimming paint by using transform display items. |
149 context.concatCTM(transform.toAffineTransform()); | 150 context.concatCTM(transform.toAffineTransform()); |
150 BoxPainter::paintFillLayerExtended(m_layoutView, paintInfo, Color(),
**it, LayoutRect(paintRect), BackgroundBleedNone); | 151 BoxPainter::paintFillLayerExtended(m_layoutView, paintInfo, Color(),
**it, LayoutRect(paintRect), BackgroundBleedNone); |
151 context.restore(); | 152 context.restore(); |
152 } | 153 } |
153 } | 154 } |
154 | 155 |
155 if (shouldDrawBackgroundInSeparateBuffer) | 156 if (shouldDrawBackgroundInSeparateBuffer) |
156 context.endLayer(); | 157 context.endLayer(); |
157 } | 158 } |
158 | 159 |
159 } // namespace blink | 160 } // namespace blink |
OLD | NEW |