| 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 "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 "platform/graphics/paint/DrawingDisplayItem.h" | 13 #include "platform/graphics/paint/DrawingDisplayItem.h" |
| 14 #include "third_party/skia/include/core/SkPicture.h" | 14 #include "third_party/skia/include/core/SkPicture.h" |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 | 17 |
| 18 DrawingRecorder::DrawingRecorder(GraphicsContext& context, const DisplayItemClie
ntWrapper& displayItemClient, DisplayItem::Type displayItemType, const FloatRect
& cullRect) | 18 DrawingRecorder::DrawingRecorder(GraphicsContext& context, const DisplayItemClie
ntWrapper& displayItemClient, DisplayItem::Type displayItemType) |
| 19 : m_context(context) | 19 : m_context(context) |
| 20 , m_displayItemClient(displayItemClient) | 20 , m_displayItemClient(displayItemClient) |
| 21 , m_displayItemType(displayItemType) | 21 , m_displayItemType(displayItemType) |
| 22 , m_canUseCachedDrawing(false) | 22 , m_canUseCachedDrawing(false) |
| 23 , m_engaged(false) |
| 23 #if ENABLE(ASSERT) | 24 #if ENABLE(ASSERT) |
| 24 , m_checkedCachedDrawing(false) | 25 , m_checkedCachedDrawing(false) |
| 25 , m_displayItemPosition(RuntimeEnabledFeatures::slimmingPaintEnabled() ? m_c
ontext.displayItemList()->newDisplayItemsSize() : 0) | 26 , m_displayItemPosition(RuntimeEnabledFeatures::slimmingPaintEnabled() ? m_c
ontext.displayItemList()->newDisplayItemsSize() : 0) |
| 26 , m_skipUnderInvalidationChecking(false) | 27 , m_skipUnderInvalidationChecking(false) |
| 27 #endif | 28 #endif |
| 28 { | 29 { |
| 29 if (!RuntimeEnabledFeatures::slimmingPaintEnabled()) | 30 } |
| 30 return; | |
| 31 | 31 |
| 32 ASSERT(context.displayItemList()); | 32 DrawingRecorder::DrawingRecorder(GraphicsContext& context, const DisplayItemClie
ntWrapper& displayItemClient, DisplayItem::Type displayItemType, const FloatRect
& cullRect) |
| 33 if (context.displayItemList()->displayItemConstructionIsDisabled()) | 33 : DrawingRecorder(context, displayItemClient, displayItemType) |
| 34 return; | 34 { |
| 35 | 35 begin(cullRect); |
| 36 ASSERT(DisplayItem::isDrawingType(displayItemType)); | |
| 37 m_canUseCachedDrawing = context.displayItemList()->clientCacheIsValid(displa
yItemClient.displayItemClient()); | |
| 38 | |
| 39 #if ENABLE(ASSERT) | |
| 40 context.setInDrawingRecorder(true); | |
| 41 m_canUseCachedDrawing &= !RuntimeEnabledFeatures::slimmingPaintUnderInvalida
tionCheckingEnabled(); | |
| 42 #endif | |
| 43 | |
| 44 #ifndef NDEBUG | |
| 45 // Enable recording to check if any painter is still doing unnecessary paint
ing when we can use cache. | |
| 46 context.beginRecording(cullRect); | |
| 47 #else | |
| 48 if (!m_canUseCachedDrawing) | |
| 49 context.beginRecording(cullRect); | |
| 50 #endif | |
| 51 | |
| 52 #if ENABLE(ASSERT) | |
| 53 if (RuntimeEnabledFeatures::slimmingPaintStrictCullRectClippingEnabled() &&
!m_canUseCachedDrawing) { | |
| 54 // Skia depends on the cull rect containing all of the display item comm
ands. When strict | |
| 55 // cull rect clipping is enabled, make this explicit. This allows us to
identify potential | |
| 56 // incorrect cull rects that might otherwise be masked due to Skia inter
nal optimizations. | |
| 57 context.save(); | |
| 58 context.clipRect(enclosingIntRect(cullRect), NotAntiAliased, SkRegion::k
Intersect_Op); | |
| 59 } | |
| 60 #endif | |
| 61 } | 36 } |
| 62 | 37 |
| 63 DrawingRecorder::~DrawingRecorder() | 38 DrawingRecorder::~DrawingRecorder() |
| 64 { | 39 { |
| 40 if (!m_engaged) |
| 41 return; |
| 65 if (!RuntimeEnabledFeatures::slimmingPaintEnabled()) | 42 if (!RuntimeEnabledFeatures::slimmingPaintEnabled()) |
| 66 return; | 43 return; |
| 67 | 44 |
| 68 ASSERT(m_context.displayItemList()); | 45 ASSERT(m_context.displayItemList()); |
| 69 if (m_context.displayItemList()->displayItemConstructionIsDisabled()) | 46 if (m_context.displayItemList()->displayItemConstructionIsDisabled()) |
| 70 return; | 47 return; |
| 71 | 48 |
| 72 #if ENABLE(ASSERT) | 49 #if ENABLE(ASSERT) |
| 73 if (RuntimeEnabledFeatures::slimmingPaintStrictCullRectClippingEnabled() &&
!m_canUseCachedDrawing) { | 50 if (RuntimeEnabledFeatures::slimmingPaintStrictCullRectClippingEnabled() &&
!m_canUseCachedDrawing) { |
| 74 m_context.restore(); | 51 m_context.restore(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 90 } else { | 67 } else { |
| 91 OwnPtr<DrawingDisplayItem> drawingDisplayItem = DrawingDisplayItem::crea
te(m_displayItemClient, m_displayItemType, m_context.endRecording()); | 68 OwnPtr<DrawingDisplayItem> drawingDisplayItem = DrawingDisplayItem::crea
te(m_displayItemClient, m_displayItemType, m_context.endRecording()); |
| 92 #if ENABLE(ASSERT) | 69 #if ENABLE(ASSERT) |
| 93 if (m_skipUnderInvalidationChecking) | 70 if (m_skipUnderInvalidationChecking) |
| 94 drawingDisplayItem->setSkipUnderInvalidationChecking(); | 71 drawingDisplayItem->setSkipUnderInvalidationChecking(); |
| 95 #endif | 72 #endif |
| 96 m_context.displayItemList()->add(drawingDisplayItem.release()); | 73 m_context.displayItemList()->add(drawingDisplayItem.release()); |
| 97 } | 74 } |
| 98 } | 75 } |
| 99 | 76 |
| 77 void DrawingRecorder::begin(const FloatRect& cullRect) |
| 78 { |
| 79 ASSERT(!m_engaged); |
| 80 m_engaged = true; |
| 81 |
| 82 if (!RuntimeEnabledFeatures::slimmingPaintEnabled()) |
| 83 return; |
| 84 |
| 85 ASSERT(m_context.displayItemList()); |
| 86 if (m_context.displayItemList()->displayItemConstructionIsDisabled()) |
| 87 return; |
| 88 |
| 89 ASSERT(DisplayItem::isDrawingType(m_displayItemType)); |
| 90 m_canUseCachedDrawing = m_context.displayItemList()->clientCacheIsValid(m_di
splayItemClient.displayItemClient()); |
| 91 |
| 92 #if ENABLE(ASSERT) |
| 93 m_context.setInDrawingRecorder(true); |
| 94 m_canUseCachedDrawing &= !RuntimeEnabledFeatures::slimmingPaintUnderInvalida
tionCheckingEnabled(); |
| 95 #endif |
| 96 |
| 97 #ifndef NDEBUG |
| 98 // Enable recording to check if any painter is still doing unnecessary paint
ing when we can use cache. |
| 99 m_context.beginRecording(cullRect); |
| 100 #else |
| 101 if (!m_canUseCachedDrawing) |
| 102 m_context.beginRecording(cullRect); |
| 103 #endif |
| 104 |
| 105 #if ENABLE(ASSERT) |
| 106 if (RuntimeEnabledFeatures::slimmingPaintStrictCullRectClippingEnabled() &&
!m_canUseCachedDrawing) { |
| 107 // Skia depends on the cull rect containing all of the display item comm
ands. When strict |
| 108 // cull rect clipping is enabled, make this explicit. This allows us to
identify potential |
| 109 // incorrect cull rects that might otherwise be masked due to Skia inter
nal optimizations. |
| 110 m_context.save(); |
| 111 m_context.clipRect(enclosingIntRect(cullRect), NotAntiAliased, SkRegion:
:kIntersect_Op); |
| 112 } |
| 113 #endif |
| 114 } |
| 115 |
| 100 } // namespace blink | 116 } // namespace blink |
| OLD | NEW |