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

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

Issue 2743363006: Clean up cc/paint interfaces (Closed)
Patch Set: Rebase Created 3 years, 9 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/DrawingDisplayItem.h" 5 #include "platform/graphics/paint/DrawingDisplayItem.h"
6 6
7 #include "platform/graphics/GraphicsContext.h" 7 #include "platform/graphics/GraphicsContext.h"
8 #include "platform/graphics/paint/PaintCanvas.h" 8 #include "platform/graphics/paint/PaintCanvas.h"
9 #include "public/platform/WebDisplayItemList.h" 9 #include "public/platform/WebDisplayItemList.h"
10 #include "third_party/skia/include/core/SkBitmap.h" 10 #include "third_party/skia/include/core/SkBitmap.h"
11 #include "third_party/skia/include/core/SkCanvas.h" 11 #include "third_party/skia/include/core/SkCanvas.h"
12 #include "third_party/skia/include/core/SkData.h" 12 #include "third_party/skia/include/core/SkData.h"
13 #include "third_party/skia/include/core/SkPictureAnalyzer.h" 13 #include "third_party/skia/include/core/SkPictureAnalyzer.h"
14 14
15 namespace blink { 15 namespace blink {
16 16
17 void DrawingDisplayItem::replay(GraphicsContext& context) const { 17 void DrawingDisplayItem::replay(GraphicsContext& context) const {
18 if (m_record) 18 if (m_record)
19 context.drawRecord(m_record.get()); 19 context.drawRecord(m_record);
20 } 20 }
21 21
22 void DrawingDisplayItem::appendToWebDisplayItemList( 22 void DrawingDisplayItem::appendToWebDisplayItemList(
23 const IntRect& visualRect, 23 const IntRect& visualRect,
24 WebDisplayItemList* list) const { 24 WebDisplayItemList* list) const {
25 if (m_record) 25 if (m_record)
26 list->appendDrawingItem(visualRect, m_record); 26 list->appendDrawingItem(visualRect, m_record);
27 } 27 }
28 28
29 bool DrawingDisplayItem::drawsContent() const { 29 bool DrawingDisplayItem::drawsContent() const {
(...skipping 16 matching lines...) Expand all
46 DisplayItem::dumpPropertiesAsDebugString(stringBuilder); 46 DisplayItem::dumpPropertiesAsDebugString(stringBuilder);
47 if (m_record) { 47 if (m_record) {
48 stringBuilder.append( 48 stringBuilder.append(
49 String::format(", rect: [%f,%f %fx%f]", m_record->cullRect().x(), 49 String::format(", rect: [%f,%f %fx%f]", m_record->cullRect().x(),
50 m_record->cullRect().y(), m_record->cullRect().width(), 50 m_record->cullRect().y(), m_record->cullRect().width(),
51 m_record->cullRect().height())); 51 m_record->cullRect().height()));
52 } 52 }
53 } 53 }
54 #endif 54 #endif
55 55
56 static bool recordsEqual(const PaintRecord* record1, 56 static bool recordsEqual(sk_sp<const PaintRecord> record1,
danakj 2017/03/16 20:06:16 This seems like it should be T* still? ToSkPicture
enne (OOO) 2017/03/16 20:57:26 Agreed here.
57 const PaintRecord* record2) { 57 sk_sp<const PaintRecord> record2) {
58 if (record1->approximateOpCount() != record2->approximateOpCount()) 58 if (record1->approximateOpCount() != record2->approximateOpCount())
59 return false; 59 return false;
60 60
61 // TODO(enne): PaintRecord should have an operator== 61 // TODO(enne): PaintRecord should have an operator==
62 sk_sp<SkData> data1 = ToSkPicture(record1)->serialize(); 62 sk_sp<SkData> data1 = ToSkPicture(record1)->serialize();
danakj 2017/03/16 20:06:17 move()
63 sk_sp<SkData> data2 = ToSkPicture(record2)->serialize(); 63 sk_sp<SkData> data2 = ToSkPicture(record2)->serialize();
danakj 2017/03/16 20:06:16 move()
64 return data1->equals(data2.get()); 64 return data1->equals(data2.get());
65 } 65 }
66 66
67 static SkBitmap recordToBitmap(const PaintRecord* record) { 67 static SkBitmap recordToBitmap(sk_sp<const PaintRecord> record) {
68 SkBitmap bitmap; 68 SkBitmap bitmap;
69 SkRect rect = record->cullRect(); 69 SkRect rect = record->cullRect();
70 bitmap.allocPixels(SkImageInfo::MakeN32Premul(rect.width(), rect.height())); 70 bitmap.allocPixels(SkImageInfo::MakeN32Premul(rect.width(), rect.height()));
71 SkiaPaintCanvas canvas(bitmap); 71 SkiaPaintCanvas canvas(bitmap);
72 canvas.clear(SK_ColorTRANSPARENT); 72 canvas.clear(SK_ColorTRANSPARENT);
73 canvas.translate(-rect.x(), -rect.y()); 73 canvas.translate(-rect.x(), -rect.y());
74 canvas.drawPicture(record); 74 canvas.drawPicture(record);
danakj 2017/03/16 20:06:16 mvoe()
75 return bitmap; 75 return bitmap;
76 } 76 }
77 77
78 static bool bitmapsEqual(const PaintRecord* record1, 78 static bool bitmapsEqual(sk_sp<const PaintRecord> record1,
danakj 2017/03/16 20:06:17 This seems like it should be T* also, it's not pas
enne (OOO) 2017/03/16 20:57:26 Not agreed here. This is rasterizing via drawPict
danakj 2017/03/16 21:02:01 Oh ok I missed what recordToBitmap does.
79 const PaintRecord* record2) { 79 sk_sp<const PaintRecord> record2) {
80 SkRect rect = record1->cullRect(); 80 SkRect rect = record1->cullRect();
81 if (rect != record2->cullRect()) 81 if (rect != record2->cullRect())
82 return false; 82 return false;
83 83
84 SkBitmap bitmap1 = recordToBitmap(record1); 84 SkBitmap bitmap1 = recordToBitmap(record1);
danakj 2017/03/16 20:06:16 move()
85 SkBitmap bitmap2 = recordToBitmap(record2); 85 SkBitmap bitmap2 = recordToBitmap(record2);
danakj 2017/03/16 20:06:16 move()
86 bitmap1.lockPixels(); 86 bitmap1.lockPixels();
87 bitmap2.lockPixels(); 87 bitmap2.lockPixels();
88 int mismatchCount = 0; 88 int mismatchCount = 0;
89 const int maxMismatches = 10; 89 const int maxMismatches = 10;
90 for (int y = 0; y < rect.height() && mismatchCount < maxMismatches; ++y) { 90 for (int y = 0; y < rect.height() && mismatchCount < maxMismatches; ++y) {
91 for (int x = 0; x < rect.width() && mismatchCount < maxMismatches; ++x) { 91 for (int x = 0; x < rect.width() && mismatchCount < maxMismatches; ++x) {
92 SkColor pixel1 = bitmap1.getColor(x, y); 92 SkColor pixel1 = bitmap1.getColor(x, y);
93 SkColor pixel2 = bitmap2.getColor(x, y); 93 SkColor pixel2 = bitmap2.getColor(x, y);
94 if (pixel1 != pixel2) { 94 if (pixel1 != pixel2) {
95 LOG(ERROR) << "x=" << x << " y=" << y << " " << std::hex << pixel1 95 LOG(ERROR) << "x=" << x << " y=" << y << " " << std::hex << pixel1
96 << " vs " << std::hex << pixel2; 96 << " vs " << std::hex << pixel2;
97 ++mismatchCount; 97 ++mismatchCount;
98 } 98 }
99 } 99 }
100 } 100 }
101 bitmap1.unlockPixels(); 101 bitmap1.unlockPixels();
102 bitmap2.unlockPixels(); 102 bitmap2.unlockPixels();
103 return !mismatchCount; 103 return !mismatchCount;
104 } 104 }
105 105
106 bool DrawingDisplayItem::equals(const DisplayItem& other) const { 106 bool DrawingDisplayItem::equals(const DisplayItem& other) const {
107 if (!DisplayItem::equals(other)) 107 if (!DisplayItem::equals(other))
108 return false; 108 return false;
109 109
110 const PaintRecord* record = this->GetPaintRecord(); 110 sk_sp<const PaintRecord> record = this->GetPaintRecord();
danakj 2017/03/16 20:06:16 const& probably?
111 const PaintRecord* otherRecord = 111 sk_sp<const PaintRecord> otherRecord =
112 static_cast<const DrawingDisplayItem&>(other).GetPaintRecord(); 112 static_cast<const DrawingDisplayItem&>(other).GetPaintRecord();
113 113
114 if (!record && !otherRecord) 114 if (!record && !otherRecord)
115 return true; 115 return true;
116 if (!record || !otherRecord) 116 if (!record || !otherRecord)
117 return false; 117 return false;
118 118
119 if (recordsEqual(record, otherRecord)) 119 if (recordsEqual(record, otherRecord))
120 return true; 120 return true;
121 121
122 // Sometimes the client may produce different records for the same visual 122 // Sometimes the client may produce different records for the same visual
123 // result, which should be treated as equal. 123 // result, which should be treated as equal.
124 return bitmapsEqual(record, otherRecord); 124 return bitmapsEqual(record, otherRecord);
danakj 2017/03/16 21:02:01 Then these would be move()s
enne (OOO) 2017/03/16 21:06:32 Quite right.
125 } 125 }
126 126
127 } // namespace blink 127 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698