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

Side by Side Diff: Source/platform/graphics/paint/DrawingRecorder.cpp

Issue 1220583004: Refactor DrawingRecorders to check for cached drawings earlier (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix some !'s and &&'s. De Morgan would be proud. Created 5 years, 5 months 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 "platform/graphics/paint/DrawingRecorder.h" 6 #include "platform/graphics/paint/DrawingRecorder.h"
7 7
8 #include "platform/RuntimeEnabledFeatures.h" 8 #include "platform/RuntimeEnabledFeatures.h"
9 #include "platform/graphics/GraphicsContext.h" 9 #include "platform/graphics/GraphicsContext.h"
10 #include "platform/graphics/GraphicsLayer.h" 10 #include "platform/graphics/GraphicsLayer.h"
11 #include "platform/graphics/paint/CachedDisplayItem.h" 11 #include "platform/graphics/paint/CachedDisplayItem.h"
12 #include "platform/graphics/paint/DisplayItemList.h" 12 #include "platform/graphics/paint/DisplayItemList.h"
13 #include "third_party/skia/include/core/SkPicture.h" 13 #include "third_party/skia/include/core/SkPicture.h"
14 14
15 namespace blink { 15 namespace blink {
16 16
17 bool DrawingRecorder::useCachedDrawingIfPossible(GraphicsContext& context, const DisplayItemClientWrapper& client, DisplayItem::Type type)
18 {
19 if (!RuntimeEnabledFeatures::slimmingPaintEnabled())
20 return false;
21
22 ASSERT(context.displayItemList());
23 ASSERT(DisplayItem::isDrawingType(type));
24
25 if (context.displayItemList()->displayItemConstructionIsDisabled() || Runtim eEnabledFeatures::slimmingPaintUnderInvalidationCheckingEnabled())
26 return false;
27
28 if (!context.displayItemList()->clientCacheIsValid(client.displayItemClient( )))
29 return false;
30
31 context.displayItemList()->createAndAppend<CachedDisplayItem>(client, Displa yItem::drawingTypeToCachedType(type));
32 return true;
33 }
34
17 DrawingRecorder::DrawingRecorder(GraphicsContext& context, const DisplayItemClie ntWrapper& displayItemClient, DisplayItem::Type displayItemType, const FloatRect & cullRect) 35 DrawingRecorder::DrawingRecorder(GraphicsContext& context, const DisplayItemClie ntWrapper& displayItemClient, DisplayItem::Type displayItemType, const FloatRect & cullRect)
18 : m_context(context) 36 : m_context(context)
19 , m_displayItemClient(displayItemClient) 37 , m_displayItemClient(displayItemClient)
20 , m_displayItemType(displayItemType) 38 , m_displayItemType(displayItemType)
21 , m_canUseCachedDrawing(false)
22 #if ENABLE(ASSERT) 39 #if ENABLE(ASSERT)
23 , m_checkedCachedDrawing(false)
24 , m_displayItemPosition(RuntimeEnabledFeatures::slimmingPaintEnabled() ? m_c ontext.displayItemList()->newDisplayItemsSize() : 0) 40 , m_displayItemPosition(RuntimeEnabledFeatures::slimmingPaintEnabled() ? m_c ontext.displayItemList()->newDisplayItemsSize() : 0)
25 , m_underInvalidationCheckingMode(DrawingDisplayItem::CheckPicture) 41 , m_underInvalidationCheckingMode(DrawingDisplayItem::CheckPicture)
26 #endif 42 #endif
27 { 43 {
28 if (!RuntimeEnabledFeatures::slimmingPaintEnabled()) 44 if (!RuntimeEnabledFeatures::slimmingPaintEnabled())
29 return; 45 return;
30 46
31 ASSERT(context.displayItemList()); 47 ASSERT(context.displayItemList());
32 if (context.displayItemList()->displayItemConstructionIsDisabled()) 48 if (context.displayItemList()->displayItemConstructionIsDisabled())
33 return; 49 return;
34 50
51 // Must check DrawingRecorder::useCachedDrawingIfPossible before creating th e DrawingRecorder.
52 ASSERT(!useCachedDrawingIfPossible(m_context, m_displayItemClient, m_display ItemType));
53
35 ASSERT(DisplayItem::isDrawingType(displayItemType)); 54 ASSERT(DisplayItem::isDrawingType(displayItemType));
36 m_canUseCachedDrawing = context.displayItemList()->clientCacheIsValid(displa yItemClient.displayItemClient());
37 55
38 #if ENABLE(ASSERT) 56 #if ENABLE(ASSERT)
39 context.setInDrawingRecorder(true); 57 context.setInDrawingRecorder(true);
40 m_canUseCachedDrawing &= !RuntimeEnabledFeatures::slimmingPaintUnderInvalida tionCheckingEnabled();
41 #endif 58 #endif
42 59
43 #ifndef NDEBUG
44 // Enable recording to check if any painter is still doing unnecessary paint ing when we can use cache.
45 context.beginRecording(cullRect); 60 context.beginRecording(cullRect);
46 #else
47 if (!m_canUseCachedDrawing)
48 context.beginRecording(cullRect);
49 #endif
50 61
51 #if ENABLE(ASSERT) 62 #if ENABLE(ASSERT)
52 if (RuntimeEnabledFeatures::slimmingPaintStrictCullRectClippingEnabled() && !m_canUseCachedDrawing) { 63 if (RuntimeEnabledFeatures::slimmingPaintStrictCullRectClippingEnabled()) {
53 // Skia depends on the cull rect containing all of the display item comm ands. When strict 64 // Skia depends on the cull rect containing all of the display item comm ands. When strict
54 // cull rect clipping is enabled, make this explicit. This allows us to identify potential 65 // cull rect clipping is enabled, make this explicit. This allows us to identify potential
55 // incorrect cull rects that might otherwise be masked due to Skia inter nal optimizations. 66 // incorrect cull rects that might otherwise be masked due to Skia inter nal optimizations.
56 context.save(); 67 context.save();
57 IntRect verificationClip = enclosingIntRect(cullRect); 68 IntRect verificationClip = enclosingIntRect(cullRect);
58 // Expand the verification clip by one pixel to account for Skia's SkCan vas::getClipBounds() 69 // Expand the verification clip by one pixel to account for Skia's SkCan vas::getClipBounds()
59 // expansion, used in testing cull rects. 70 // expansion, used in testing cull rects.
60 // TODO(schenney) This is not the best place to do this. Ideally, we wou ld expand by one pixel 71 // TODO(schenney) This is not the best place to do this. Ideally, we wou ld expand by one pixel
61 // in device (pixel) space, but to do that we would need to add the veri fication mode to Skia. 72 // in device (pixel) space, but to do that we would need to add the veri fication mode to Skia.
62 verificationClip.inflate(1); 73 verificationClip.inflate(1);
63 context.clipRect(verificationClip, NotAntiAliased, SkRegion::kIntersect_ Op); 74 context.clipRect(verificationClip, NotAntiAliased, SkRegion::kIntersect_ Op);
64 } 75 }
65 #endif 76 #endif
66 } 77 }
67 78
68 DrawingRecorder::~DrawingRecorder() 79 DrawingRecorder::~DrawingRecorder()
69 { 80 {
70 if (!RuntimeEnabledFeatures::slimmingPaintEnabled()) 81 if (!RuntimeEnabledFeatures::slimmingPaintEnabled())
71 return; 82 return;
72 83
73 ASSERT(m_context.displayItemList()); 84 ASSERT(m_context.displayItemList());
74 if (m_context.displayItemList()->displayItemConstructionIsDisabled()) 85 if (m_context.displayItemList()->displayItemConstructionIsDisabled())
75 return; 86 return;
76 87
77 #if ENABLE(ASSERT) 88 #if ENABLE(ASSERT)
78 if (RuntimeEnabledFeatures::slimmingPaintStrictCullRectClippingEnabled() && !m_canUseCachedDrawing) { 89 if (RuntimeEnabledFeatures::slimmingPaintStrictCullRectClippingEnabled())
79 m_context.restore(); 90 m_context.restore();
80 } 91
81 ASSERT(m_checkedCachedDrawing);
82 m_context.setInDrawingRecorder(false); 92 m_context.setInDrawingRecorder(false);
83 ASSERT(m_displayItemPosition == m_context.displayItemList()->newDisplayItems Size()); 93 ASSERT(m_displayItemPosition == m_context.displayItemList()->newDisplayItems Size());
84 #endif 94 #endif
85 95
86 if (m_canUseCachedDrawing) { 96 m_context.displayItemList()->createAndAppend<DrawingDisplayItem>(m_displayIt emClient
87 #ifndef NDEBUG 97 , m_displayItemType
88 RefPtr<const SkPicture> picture = m_context.endRecording(); 98 , m_context.endRecording()
89 if (picture && picture->approximateOpCount()) { 99 #if ENABLE(ASSERT)
90 WTF_LOG_ERROR("Unnecessary painting for %s\n. Should check recorder. canUseCachedDrawing() before painting", 100 , m_underInvalidationCheckingMode
91 m_displayItemClient.debugName().utf8().data());
92 }
93 #endif 101 #endif
94 m_context.displayItemList()->createAndAppend<CachedDisplayItem>(m_displa yItemClient, DisplayItem::drawingTypeToCachedType(m_displayItemType)); 102 );
95 } else {
96 m_context.displayItemList()->createAndAppend<DrawingDisplayItem>(m_displ ayItemClient
97 , m_displayItemType
98 , m_context.endRecording()
99 #if ENABLE(ASSERT)
100 , m_underInvalidationCheckingMode
101 #endif
102 );
103 }
104 } 103 }
105 104
106 } // namespace blink 105 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698