| 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" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 const float opacity, | 34 const float opacity, |
| 35 const FloatRect* bounds, | 35 const FloatRect* bounds, |
| 36 ColorFilter colorFilter) { | 36 ColorFilter colorFilter) { |
| 37 graphicsContext.getPaintController() | 37 graphicsContext.getPaintController() |
| 38 .createAndAppend<BeginCompositingDisplayItem>(client, xferMode, opacity, | 38 .createAndAppend<BeginCompositingDisplayItem>(client, xferMode, opacity, |
| 39 bounds, colorFilter); | 39 bounds, colorFilter); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void CompositingRecorder::endCompositing(GraphicsContext& graphicsContext, | 42 void CompositingRecorder::endCompositing(GraphicsContext& graphicsContext, |
| 43 const DisplayItemClient& client) { | 43 const DisplayItemClient& client) { |
| 44 // If the end of the current display list is of the form [BeginCompositingDisp
layItem] [DrawingDisplayItem], | 44 // If the end of the current display list is of the form |
| 45 // then fold the BeginCompositingDisplayItem into a new DrawingDisplayItem tha
t replaces them both. This allows | 45 // [BeginCompositingDisplayItem] [DrawingDisplayItem], then fold the |
| 46 // Skia to optimize for the case when the BeginCompositingDisplayItem represen
ts a simple opacity/color that can be merged into | 46 // BeginCompositingDisplayItem into a new DrawingDisplayItem that replaces |
| 47 // the opacity/color of the drawing. See crbug.com/628831 for more details. | 47 // them both. This allows Skia to optimize for the case when the |
| 48 // BeginCompositingDisplayItem represents a simple opacity/color that can be |
| 49 // merged into the opacity/color of the drawing. See crbug.com/628831 for more |
| 50 // details. |
| 48 PaintController& paintController = graphicsContext.getPaintController(); | 51 PaintController& paintController = graphicsContext.getPaintController(); |
| 49 const DisplayItem* lastDisplayItem = paintController.lastDisplayItem(0); | 52 const DisplayItem* lastDisplayItem = paintController.lastDisplayItem(0); |
| 50 const DisplayItem* secondToLastDisplayItem = | 53 const DisplayItem* secondToLastDisplayItem = |
| 51 paintController.lastDisplayItem(1); | 54 paintController.lastDisplayItem(1); |
| 52 if (lastDisplayItem && secondToLastDisplayItem && | 55 if (lastDisplayItem && secondToLastDisplayItem && |
| 53 lastDisplayItem->drawsContent() && | 56 lastDisplayItem->drawsContent() && |
| 54 secondToLastDisplayItem->getType() == DisplayItem::kBeginCompositing) { | 57 secondToLastDisplayItem->getType() == DisplayItem::kBeginCompositing) { |
| 55 FloatRect cullRect( | 58 FloatRect cullRect( |
| 56 ((DrawingDisplayItem*)lastDisplayItem)->picture()->cullRect()); | 59 ((DrawingDisplayItem*)lastDisplayItem)->picture()->cullRect()); |
| 57 const DisplayItemClient& displayItemClient = lastDisplayItem->client(); | 60 const DisplayItemClient& displayItemClient = lastDisplayItem->client(); |
| 58 DisplayItem::Type displayItemType = lastDisplayItem->getType(); | 61 DisplayItem::Type displayItemType = lastDisplayItem->getType(); |
| 59 | 62 |
| 60 // Re-record the last two DisplayItems into a new SkPicture. | 63 // Re-record the last two DisplayItems into a new SkPicture. |
| 61 SkPictureBuilder pictureBuilder(cullRect, nullptr, &graphicsContext); | 64 SkPictureBuilder pictureBuilder(cullRect, nullptr, &graphicsContext); |
| 62 { | 65 { |
| 63 DrawingRecorder newRecorder(pictureBuilder.context(), displayItemClient, | 66 DrawingRecorder newRecorder(pictureBuilder.context(), displayItemClient, |
| 64 displayItemType, cullRect); | 67 displayItemType, cullRect); |
| 65 DCHECK(!DrawingRecorder::useCachedDrawingIfPossible( | 68 DCHECK(!DrawingRecorder::useCachedDrawingIfPossible( |
| 66 pictureBuilder.context(), displayItemClient, displayItemType)); | 69 pictureBuilder.context(), displayItemClient, displayItemType)); |
| 67 | 70 |
| 68 secondToLastDisplayItem->replay(pictureBuilder.context()); | 71 secondToLastDisplayItem->replay(pictureBuilder.context()); |
| 69 lastDisplayItem->replay(pictureBuilder.context()); | 72 lastDisplayItem->replay(pictureBuilder.context()); |
| 70 EndCompositingDisplayItem(client).replay(pictureBuilder.context()); | 73 EndCompositingDisplayItem(client).replay(pictureBuilder.context()); |
| 71 } | 74 } |
| 72 | 75 |
| 73 paintController.removeLastDisplayItem(); // Remove the DrawingDisplayItem. | 76 paintController.removeLastDisplayItem(); // Remove the DrawingDisplayItem. |
| 74 paintController | 77 paintController |
| 75 .removeLastDisplayItem(); // Remove the BeginCompositingDisplayItem. | 78 .removeLastDisplayItem(); // Remove the BeginCompositingDisplayItem. |
| 76 | 79 |
| 77 // The new item cannot be cached, because it is a mutation of the DisplayIte
m the client thought it was painting. | 80 // The new item cannot be cached, because it is a mutation of the |
| 81 // DisplayItem the client thought it was painting. |
| 78 paintController.beginSkippingCache(); | 82 paintController.beginSkippingCache(); |
| 79 { | 83 { |
| 80 // Replay the new SKPicture into a new DrawingDisplayItem in the original
DisplayItemList. | 84 // Replay the new SKPicture into a new DrawingDisplayItem in the original |
| 85 // DisplayItemList. |
| 81 DrawingRecorder newRecorder(graphicsContext, displayItemClient, | 86 DrawingRecorder newRecorder(graphicsContext, displayItemClient, |
| 82 displayItemType, cullRect); | 87 displayItemType, cullRect); |
| 83 pictureBuilder.endRecording()->playback(graphicsContext.canvas()); | 88 pictureBuilder.endRecording()->playback(graphicsContext.canvas()); |
| 84 } | 89 } |
| 85 paintController.endSkippingCache(); | 90 paintController.endSkippingCache(); |
| 86 } else { | 91 } else { |
| 87 graphicsContext.getPaintController().endItem<EndCompositingDisplayItem>( | 92 graphicsContext.getPaintController().endItem<EndCompositingDisplayItem>( |
| 88 client); | 93 client); |
| 89 } | 94 } |
| 90 } | 95 } |
| 91 | 96 |
| 92 } // namespace blink | 97 } // namespace blink |
| OLD | NEW |