Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(419)

Side by Side Diff: third_party/WebKit/Source/core/paint/ViewPainter.cpp

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

Powered by Google App Engine
This is Rietveld 408576698