| 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 "platform/graphics/paint/CompositingRecorder.h" | 5 #include "platform/graphics/paint/CompositingRecorder.h" |
| 6 | 6 |
| 7 #include "platform/graphics/GraphicsContext.h" | 7 #include "platform/graphics/GraphicsContext.h" |
| 8 #include "platform/graphics/GraphicsLayer.h" | 8 #include "platform/graphics/GraphicsLayer.h" |
| 9 #include "platform/graphics/paint/CompositingDisplayItem.h" | 9 #include "platform/graphics/paint/CompositingDisplayItem.h" |
| 10 #include "platform/graphics/paint/DrawingRecorder.h" | 10 #include "platform/graphics/paint/DrawingRecorder.h" |
| 11 #include "platform/graphics/paint/PaintController.h" | 11 #include "platform/graphics/paint/PaintController.h" |
| 12 #include "platform/graphics/paint/SkPictureBuilder.h" | |
| 13 | 12 |
| 14 namespace blink { | 13 namespace blink { |
| 15 | 14 |
| 16 CompositingRecorder::CompositingRecorder(GraphicsContext& graphicsContext, | 15 CompositingRecorder::CompositingRecorder(GraphicsContext& graphicsContext, |
| 17 const DisplayItemClient& client, | 16 const DisplayItemClient& client, |
| 18 const SkBlendMode xferMode, | 17 const SkBlendMode xferMode, |
| 19 const float opacity, | 18 const float opacity, |
| 20 const FloatRect* bounds, | 19 const FloatRect* bounds, |
| 21 ColorFilter colorFilter) | 20 ColorFilter colorFilter) |
| 22 : m_client(client), m_graphicsContext(graphicsContext) { | 21 : m_client(client), m_graphicsContext(graphicsContext) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 53 const DisplayItem* secondToLastDisplayItem = | 52 const DisplayItem* secondToLastDisplayItem = |
| 54 paintController.lastDisplayItem(1); | 53 paintController.lastDisplayItem(1); |
| 55 if (!RuntimeEnabledFeatures::slimmingPaintV2Enabled() && lastDisplayItem && | 54 if (!RuntimeEnabledFeatures::slimmingPaintV2Enabled() && lastDisplayItem && |
| 56 secondToLastDisplayItem && lastDisplayItem->drawsContent() && | 55 secondToLastDisplayItem && lastDisplayItem->drawsContent() && |
| 57 secondToLastDisplayItem->getType() == DisplayItem::kBeginCompositing) { | 56 secondToLastDisplayItem->getType() == DisplayItem::kBeginCompositing) { |
| 58 FloatRect cullRect( | 57 FloatRect cullRect( |
| 59 ((DrawingDisplayItem*)lastDisplayItem)->picture()->cullRect()); | 58 ((DrawingDisplayItem*)lastDisplayItem)->picture()->cullRect()); |
| 60 const DisplayItemClient& displayItemClient = lastDisplayItem->client(); | 59 const DisplayItemClient& displayItemClient = lastDisplayItem->client(); |
| 61 DisplayItem::Type displayItemType = lastDisplayItem->getType(); | 60 DisplayItem::Type displayItemType = lastDisplayItem->getType(); |
| 62 | 61 |
| 63 // Re-record the last two DisplayItems into a new PaintRecord. | 62 // Re-record the last two DisplayItems into a new drawing. The new item |
| 64 SkPictureBuilder pictureBuilder(cullRect, nullptr, &graphicsContext); | 63 // cannot be cached, because it is a mutation of the DisplayItem the client |
| 64 // thought it was painting. |
| 65 paintController.beginSkippingCache(); |
| 65 { | 66 { |
| 66 #if DCHECK_IS_ON() | 67 #if DCHECK_IS_ON() |
| 67 // The picture builder creates an internal paint controller that has been | 68 // In the recorder's scope we remove the last two display items which |
| 68 // initialized with null paint properties. Painting into this controller | 69 // are combined into a new drawing. |
| 69 // without properties will not cause problems because the display item | 70 DisableListModificationCheck disabler; |
| 70 // from this internal paint controller is immediately reunited with the | |
| 71 // correct properties. | |
| 72 DisableNullPaintPropertyChecks disabler; | |
| 73 #endif | 71 #endif |
| 74 DrawingRecorder newRecorder(pictureBuilder.context(), displayItemClient, | 72 DrawingRecorder newRecorder(graphicsContext, displayItemClient, |
| 75 displayItemType, cullRect); | 73 displayItemType, cullRect); |
| 76 DCHECK(!DrawingRecorder::useCachedDrawingIfPossible( | 74 DCHECK(!DrawingRecorder::useCachedDrawingIfPossible( |
| 77 pictureBuilder.context(), displayItemClient, displayItemType)); | 75 graphicsContext, displayItemClient, displayItemType)); |
| 78 | 76 |
| 79 secondToLastDisplayItem->replay(pictureBuilder.context()); | 77 secondToLastDisplayItem->replay(graphicsContext); |
| 80 lastDisplayItem->replay(pictureBuilder.context()); | 78 lastDisplayItem->replay(graphicsContext); |
| 81 EndCompositingDisplayItem(client).replay(pictureBuilder.context()); | 79 EndCompositingDisplayItem(client).replay(graphicsContext); |
| 82 } | |
| 83 | 80 |
| 84 paintController.removeLastDisplayItem(); // Remove the DrawingDisplayItem. | 81 // Remove the DrawingDisplayItem. |
| 85 paintController | 82 paintController.removeLastDisplayItem(); |
| 86 .removeLastDisplayItem(); // Remove the BeginCompositingDisplayItem. | 83 // Remove the BeginCompositingDisplayItem. |
| 87 | 84 paintController.removeLastDisplayItem(); |
| 88 // The new item cannot be cached, because it is a mutation of the | |
| 89 // DisplayItem the client thought it was painting. | |
| 90 paintController.beginSkippingCache(); | |
| 91 { | |
| 92 // Replay the new SKPicture into a new DrawingDisplayItem in the original | |
| 93 // DisplayItemList. | |
| 94 DrawingRecorder newRecorder(graphicsContext, displayItemClient, | |
| 95 displayItemType, cullRect); | |
| 96 pictureBuilder.endRecording()->playback(graphicsContext.canvas()); | |
| 97 } | 85 } |
| 98 paintController.endSkippingCache(); | 86 paintController.endSkippingCache(); |
| 99 } else { | 87 } else { |
| 100 graphicsContext.getPaintController().endItem<EndCompositingDisplayItem>( | 88 graphicsContext.getPaintController().endItem<EndCompositingDisplayItem>( |
| 101 client); | 89 client); |
| 102 } | 90 } |
| 103 } | 91 } |
| 104 | 92 |
| 105 } // namespace blink | 93 } // namespace blink |
| OLD | NEW |