| 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" |
| 11 #include "core/layout/compositing/CompositedLayerMapping.h" |
| 11 #include "core/paint/BlockPainter.h" | 12 #include "core/paint/BlockPainter.h" |
| 12 #include "core/paint/BoxPainter.h" | 13 #include "core/paint/BoxPainter.h" |
| 13 #include "core/paint/LayoutObjectDrawingRecorder.h" | 14 #include "core/paint/LayoutObjectDrawingRecorder.h" |
| 14 #include "core/paint/PaintInfo.h" | 15 #include "core/paint/PaintInfo.h" |
| 15 #include "core/paint/PaintLayer.h" | 16 #include "core/paint/PaintLayer.h" |
| 17 #include "core/paint/ScrollRecorder.h" |
| 16 #include "platform/RuntimeEnabledFeatures.h" | 18 #include "platform/RuntimeEnabledFeatures.h" |
| 17 | 19 |
| 18 namespace blink { | 20 namespace blink { |
| 19 | 21 |
| 20 void ViewPainter::paint(const PaintInfo& paintInfo, | 22 void ViewPainter::paint(const PaintInfo& paintInfo, |
| 21 const LayoutPoint& paintOffset) { | 23 const LayoutPoint& paintOffset) { |
| 22 // If we ever require layout but receive a paint anyway, something has gone | 24 // If we ever require layout but receive a paint anyway, something has gone |
| 23 // horribly wrong. | 25 // horribly wrong. |
| 24 DCHECK(!m_layoutView.needsLayout()); | 26 DCHECK(!m_layoutView.needsLayout()); |
| 25 // LayoutViews should never be called to paint with an offset not on device | 27 // LayoutViews should never be called to paint with an offset not on device |
| (...skipping 21 matching lines...) Expand all Loading... |
| 47 // element. | 49 // element. |
| 48 // 2. CSS background-clip is ignored, the background layers always expand to | 50 // 2. CSS background-clip is ignored, the background layers always expand to |
| 49 // cover the whole canvas. None of the stacking context effects (except | 51 // cover the whole canvas. None of the stacking context effects (except |
| 50 // transformation) on the root element affects the background. | 52 // transformation) on the root element affects the background. |
| 51 // 3. The main frame is also responsible for painting the user-agent-defined | 53 // 3. The main frame is also responsible for painting the user-agent-defined |
| 52 // base background color. Conceptually it should be painted by the embedder | 54 // base background color. Conceptually it should be painted by the embedder |
| 53 // but painting it here allows culling and pre-blending optimization when | 55 // but painting it here allows culling and pre-blending optimization when |
| 54 // possible. | 56 // possible. |
| 55 | 57 |
| 56 GraphicsContext& context = paintInfo.context; | 58 GraphicsContext& context = paintInfo.context; |
| 57 if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible( | |
| 58 context, m_layoutView, DisplayItem::kDocumentBackground)) | |
| 59 return; | |
| 60 | 59 |
| 61 // The background rect always includes at least the visible content size. | 60 // The background rect always includes at least the visible content size. |
| 62 IntRect backgroundRect(IntRect(m_layoutView.viewRect())); | 61 IntRect backgroundRect(IntRect(m_layoutView.viewRect())); |
| 63 | 62 |
| 64 if (!RuntimeEnabledFeatures::rootLayerScrollingEnabled() || | 63 if (!RuntimeEnabledFeatures::rootLayerScrollingEnabled()) |
| 65 BoxPainter:: | 64 backgroundRect.unite(m_layoutView.documentRect()); |
| 65 |
| 66 const DisplayItemClient* displayItemClient = &m_layoutView; |
| 67 |
| 68 Optional<ScrollRecorder> scrollRecorder; |
| 69 if (BoxPainter:: |
| 66 isPaintingBackgroundOfPaintContainerIntoScrollingContentsLayer( | 70 isPaintingBackgroundOfPaintContainerIntoScrollingContentsLayer( |
| 67 &m_layoutView, paintInfo)) { | 71 &m_layoutView, paintInfo)) { |
| 68 // Layout overflow, combined with the visible content size. | 72 // Layout overflow, combined with the visible content size. |
| 69 backgroundRect.unite(m_layoutView.documentRect()); | 73 backgroundRect.unite(m_layoutView.documentRect()); |
| 74 displayItemClient = |
| 75 static_cast<const DisplayItemClient*>(m_layoutView.layer() |
| 76 ->compositedLayerMapping() |
| 77 ->scrollingContentsLayer()); |
| 78 |
| 79 scrollRecorder.emplace(paintInfo.context, m_layoutView, paintInfo.phase, |
| 80 m_layoutView.scrolledContentOffset()); |
| 70 } | 81 } |
| 71 | 82 |
| 83 if (DrawingRecorder::useCachedDrawingIfPossible( |
| 84 context, *displayItemClient, DisplayItem::kDocumentBackground)) |
| 85 return; |
| 86 |
| 72 const Document& document = m_layoutView.document(); | 87 const Document& document = m_layoutView.document(); |
| 73 const FrameView& frameView = *m_layoutView.frameView(); | 88 const FrameView& frameView = *m_layoutView.frameView(); |
| 74 bool isMainFrame = document.isInMainFrame(); | 89 bool isMainFrame = document.isInMainFrame(); |
| 75 bool paintsBaseBackground = isMainFrame && !frameView.isTransparent(); | 90 bool paintsBaseBackground = isMainFrame && !frameView.isTransparent(); |
| 76 bool shouldClearCanvas = | 91 bool shouldClearCanvas = |
| 77 paintsBaseBackground && | 92 paintsBaseBackground && |
| 78 (document.settings() && | 93 (document.settings() && |
| 79 document.settings()->getShouldClearDocumentBackground()); | 94 document.settings()->getShouldClearDocumentBackground()); |
| 80 Color baseBackgroundColor = | 95 Color baseBackgroundColor = |
| 81 paintsBaseBackground ? frameView.baseBackgroundColor() : Color(); | 96 paintsBaseBackground ? frameView.baseBackgroundColor() : Color(); |
| 82 Color rootBackgroundColor = | 97 Color rootBackgroundColor = |
| 83 m_layoutView.style()->visitedDependentColor(CSSPropertyBackgroundColor); | 98 m_layoutView.style()->visitedDependentColor(CSSPropertyBackgroundColor); |
| 84 const LayoutObject* rootObject = | 99 const LayoutObject* rootObject = |
| 85 document.documentElement() ? document.documentElement()->layoutObject() | 100 document.documentElement() ? document.documentElement()->layoutObject() |
| 86 : nullptr; | 101 : nullptr; |
| 87 | 102 |
| 88 LayoutObjectDrawingRecorder recorder( | 103 DrawingRecorder recorder(context, *displayItemClient, |
| 89 context, m_layoutView, DisplayItem::kDocumentBackground, backgroundRect); | 104 DisplayItem::kDocumentBackground, backgroundRect); |
| 90 | 105 |
| 91 // Special handling for print economy mode. | 106 // Special handling for print economy mode. |
| 92 bool forceBackgroundToWhite = | 107 bool forceBackgroundToWhite = |
| 93 BoxPainter::shouldForceWhiteBackgroundForPrintEconomy( | 108 BoxPainter::shouldForceWhiteBackgroundForPrintEconomy( |
| 94 m_layoutView.styleRef(), document); | 109 m_layoutView.styleRef(), document); |
| 95 if (forceBackgroundToWhite) { | 110 if (forceBackgroundToWhite) { |
| 96 // If for any reason the view background is not transparent, paint white | 111 // If for any reason the view background is not transparent, paint white |
| 97 // instead, otherwise keep transparent as is. | 112 // instead, otherwise keep transparent as is. |
| 98 if (paintsBaseBackground || rootBackgroundColor.alpha() || | 113 if (paintsBaseBackground || rootBackgroundColor.alpha() || |
| 99 m_layoutView.style()->backgroundLayers().image()) | 114 m_layoutView.style()->backgroundLayers().image()) |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 LayoutRect(paintRect), BackgroundBleedNone); | 224 LayoutRect(paintRect), BackgroundBleedNone); |
| 210 context.restore(); | 225 context.restore(); |
| 211 } | 226 } |
| 212 } | 227 } |
| 213 | 228 |
| 214 if (shouldDrawBackgroundInSeparateBuffer) | 229 if (shouldDrawBackgroundInSeparateBuffer) |
| 215 context.endLayer(); | 230 context.endLayer(); |
| 216 } | 231 } |
| 217 | 232 |
| 218 } // namespace blink | 233 } // namespace blink |
| OLD | NEW |