Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(389)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/paint/CompositingRecorder.cpp

Issue 2186643002: Fold compositing display items into contained drawings if the drawing is a singleton. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: none Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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();
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 }
34 } 72 }
35 73
36 } // namespace blink 74 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698