| 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" | |
| 11 #include "platform/graphics/paint/PaintController.h" | 10 #include "platform/graphics/paint/PaintController.h" |
| 12 #include "platform/graphics/paint/SkPictureBuilder.h" | |
| 13 | 11 |
| 14 namespace blink { | 12 namespace blink { |
| 15 | 13 |
| 16 CompositingRecorder::CompositingRecorder(GraphicsContext& graphicsContext, const
DisplayItemClient& client, const SkXfermode::Mode xferMode, const float opacity
, const FloatRect* bounds, ColorFilter colorFilter) | 14 CompositingRecorder::CompositingRecorder(GraphicsContext& graphicsContext, const
DisplayItemClient& client, const SkXfermode::Mode xferMode, const float opacity
, const FloatRect* bounds, ColorFilter colorFilter) |
| 17 : m_client(client) | 15 : m_client(client) |
| 18 , m_graphicsContext(graphicsContext) | 16 , m_graphicsContext(graphicsContext) |
| 19 { | 17 { |
| 20 beginCompositing(graphicsContext, m_client, xferMode, opacity, bounds, color
Filter); | 18 beginCompositing(graphicsContext, m_client, xferMode, opacity, bounds, color
Filter); |
| 21 } | 19 } |
| 22 | 20 |
| 23 CompositingRecorder::~CompositingRecorder() | 21 CompositingRecorder::~CompositingRecorder() |
| 24 { | 22 { |
| 25 endCompositing(m_graphicsContext, m_client); | 23 endCompositing(m_graphicsContext, m_client); |
| 26 } | 24 } |
| 27 | 25 |
| 28 void CompositingRecorder::beginCompositing(GraphicsContext& graphicsContext, con
st DisplayItemClient& client, const SkXfermode::Mode xferMode, const float opaci
ty, const FloatRect* bounds, ColorFilter colorFilter) | 26 void CompositingRecorder::beginCompositing(GraphicsContext& graphicsContext, con
st DisplayItemClient& client, const SkXfermode::Mode xferMode, const float opaci
ty, const FloatRect* bounds, ColorFilter colorFilter) |
| 29 { | 27 { |
| 30 graphicsContext.getPaintController().createAndAppend<BeginCompositingDisplay
Item>(client, xferMode, opacity, bounds, colorFilter); | 28 graphicsContext.getPaintController().createAndAppend<BeginCompositingDisplay
Item>(client, xferMode, opacity, bounds, colorFilter); |
| 31 } | 29 } |
| 32 | 30 |
| 33 void CompositingRecorder::endCompositing(GraphicsContext& graphicsContext, const
DisplayItemClient& client) | 31 void CompositingRecorder::endCompositing(GraphicsContext& graphicsContext, const
DisplayItemClient& client) |
| 34 { | 32 { |
| 35 // If the end of the current display list is of the form [BeginCompositingDi
splayItem] [DrawingDisplayItem], | 33 graphicsContext.getPaintController().endItem<EndCompositingDisplayItem>(clie
nt); |
| 36 // then fold the BeginCompositingDisplayItem into a new DrawingDisplayItem t
hat replaces them both. This allows | |
| 37 // Skia to optimize for the case when the BeginCompositingDisplayItem repres
ents a simple opacity/color that can be merged into | |
| 38 // the opacity/color of the drawing. See crbug.com/628831 for more details. | |
| 39 PaintController& paintController = graphicsContext.getPaintController(); | |
| 40 const DisplayItem* lastDisplayItem = paintController.lastDisplayItem(0); | |
| 41 const DisplayItem* secondToLastDisplayItem = paintController.lastDisplayItem
(1); | |
| 42 if (lastDisplayItem && secondToLastDisplayItem && lastDisplayItem->drawsCont
ent() && secondToLastDisplayItem->getType() == DisplayItem::BeginCompositing) { | |
| 43 FloatRect cullRect(((DrawingDisplayItem*)lastDisplayItem)->picture()->cu
llRect()); | |
| 44 const DisplayItemClient& displayItemClient = lastDisplayItem->client(); | |
| 45 DisplayItem::Type displayItemType = lastDisplayItem->getType(); | |
| 46 | |
| 47 // Re-record the last two DisplayItems into a new SkPicture. | |
| 48 SkPictureBuilder pictureBuilder(cullRect, nullptr, &graphicsContext); | |
| 49 { | |
| 50 DrawingRecorder newRecorder(pictureBuilder.context(), displayItemCli
ent, displayItemType, cullRect); | |
| 51 DCHECK(!DrawingRecorder::useCachedDrawingIfPossible(pictureBuilder.c
ontext(), displayItemClient, displayItemType)); | |
| 52 | |
| 53 secondToLastDisplayItem->replay(pictureBuilder.context()); | |
| 54 lastDisplayItem->replay(pictureBuilder.context()); | |
| 55 EndCompositingDisplayItem(client).replay(pictureBuilder.context()); | |
| 56 } | |
| 57 | |
| 58 paintController.removeLastDisplayItem(); // Remove the DrawingDisplayIte
m. | |
| 59 paintController.removeLastDisplayItem(); // Remove the BeginCompositingD
isplayItem. | |
| 60 | |
| 61 // The new item cannot be cached, because it is a mutation of the Displa
yItem the client thought it was painting. | |
| 62 paintController.beginSkippingCache(); | |
| 63 { | |
| 64 // Replay the new SKPicture into a new DrawingDisplayItem in the ori
ginal DisplayItemList. | |
| 65 DrawingRecorder newRecorder(graphicsContext, displayItemClient, disp
layItemType, cullRect); | |
| 66 pictureBuilder.endRecording()->playback(graphicsContext.canvas()); | |
| 67 } | |
| 68 paintController.endSkippingCache(); | |
| 69 } else { | |
| 70 graphicsContext.getPaintController().endItem<EndCompositingDisplayItem>(
client); | |
| 71 } | |
| 72 } | 34 } |
| 73 | 35 |
| 74 } // namespace blink | 36 } // namespace blink |
| OLD | NEW |