Chromium Code Reviews| 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/PaintController.h" | 11 #include "platform/graphics/paint/PaintController.h" |
| 12 #include "platform/graphics/paint/SkPictureBuilder.h" | |
| 11 | 13 |
| 12 namespace blink { | 14 namespace blink { |
| 13 | 15 |
| 14 CompositingRecorder::CompositingRecorder(GraphicsContext& graphicsContext, const DisplayItemClient& client, const SkXfermode::Mode xferMode, const float opacity , const FloatRect* bounds, ColorFilter colorFilter) | 16 CompositingRecorder::CompositingRecorder(GraphicsContext& graphicsContext, const DisplayItemClient& client, const SkXfermode::Mode xferMode, const float opacity , const FloatRect* bounds, ColorFilter colorFilter) |
| 15 : m_client(client) | 17 : m_client(client) |
| 16 , m_graphicsContext(graphicsContext) | 18 , m_graphicsContext(graphicsContext) |
| 17 { | 19 { |
| 18 beginCompositing(graphicsContext, m_client, xferMode, opacity, bounds, color Filter); | 20 beginCompositing(graphicsContext, m_client, xferMode, opacity, bounds, color Filter); |
| 19 } | 21 } |
| 20 | 22 |
| 21 CompositingRecorder::~CompositingRecorder() | 23 CompositingRecorder::~CompositingRecorder() |
| 22 { | 24 { |
| 23 endCompositing(m_graphicsContext, m_client); | 25 endCompositing(m_graphicsContext, m_client); |
| 24 } | 26 } |
| 25 | 27 |
| 26 void CompositingRecorder::beginCompositing(GraphicsContext& graphicsContext, con st DisplayItemClient& client, const SkXfermode::Mode xferMode, const float opaci ty, const FloatRect* bounds, ColorFilter colorFilter) | 28 void CompositingRecorder::beginCompositing(GraphicsContext& graphicsContext, con st DisplayItemClient& client, const SkXfermode::Mode xferMode, const float opaci ty, const FloatRect* bounds, ColorFilter colorFilter) |
| 27 { | 29 { |
| 28 graphicsContext.getPaintController().createAndAppend<BeginCompositingDisplay Item>(client, xferMode, opacity, bounds, colorFilter); | 30 graphicsContext.getPaintController().createAndAppend<BeginCompositingDisplay Item>(client, xferMode, opacity, bounds, colorFilter); |
| 29 } | 31 } |
| 30 | 32 |
| 31 void CompositingRecorder::endCompositing(GraphicsContext& graphicsContext, const DisplayItemClient& client) | 33 void CompositingRecorder::endCompositing(GraphicsContext& graphicsContext, const DisplayItemClient& client) |
| 32 { | 34 { |
| 33 graphicsContext.getPaintController().endItem<EndCompositingDisplayItem>(clie nt); | 35 // If the end of the current display list is of the form [BeginCompositingDi splayItem] [DrawingDisplayItem], |
| 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(); | |
|
wkorman
2016/07/26 18:41:08
Need to turn off caching.
chrishtr
2016/07/26 18:49:45
Done.
| |
| 40 const DisplayItem* lastDisplayItem = paintController.lastDisplayItem(0); | |
| 41 const DisplayItem* secondToLastDisplayItem = paintController.lastDisplayItem (1); | |
|
wkorman
2016/07/26 18:41:08
fun: opportunity to use 'penultimate' vs 'secondTo
chrishtr
2016/07/26 18:49:45
Acknowledged.
| |
| 42 if (lastDisplayItem && secondToLastDisplayItem && lastDisplayItem->drawsCont ent() && secondToLastDisplayItem->isBeginCompositingDisplayItem()) { | |
| 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); | |
|
f(malita)
2016/07/26 19:03:15
Why is this inner DrawingRecording needed? Wouldn
chrishtr
2016/07/26 19:54:24
SkPictureBuilder doesn't start a recording of a sp
| |
| 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 { | |
| 62 // Replay the new SKPicture into a new DrawingDisplayItem in the ori ginal DisplayItemList. | |
| 63 DrawingRecorder newRecorder(graphicsContext, displayItemClient, disp layItemType, cullRect); | |
| 64 pictureBuilder.endRecording()->playback(graphicsContext.canvas()); | |
| 65 } | |
| 66 } else { | |
| 67 graphicsContext.getPaintController().endItem<EndCompositingDisplayItem>( client); | |
| 68 } | |
| 34 } | 69 } |
| 35 | 70 |
| 36 } // namespace blink | 71 } // namespace blink |
| OLD | NEW |