| 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/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 27 matching lines...) Expand all Loading... |
| 57 const PaintRecord* record2) { | 57 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(); |
| 63 sk_sp<SkData> data2 = ToSkPicture(record2)->serialize(); | 63 sk_sp<SkData> data2 = ToSkPicture(record2)->serialize(); |
| 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(std::move(record)); |
| 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, |
| 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); |
| 85 SkBitmap bitmap2 = recordToBitmap(record2); | 85 SkBitmap bitmap2 = recordToBitmap(record2); |
| 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; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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 const sk_sp<const PaintRecord>& record = this->GetPaintRecord(); |
| 111 const PaintRecord* otherRecord = | 111 const 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.get(), otherRecord.get())) |
| 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(std::move(record), std::move(otherRecord)); |
| 125 } | 125 } |
| 126 | 126 |
| 127 } // namespace blink | 127 } // namespace blink |
| OLD | NEW |