| 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" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 } | 69 } |
| 70 | 70 |
| 71 static bool BitmapsEqual(sk_sp<const PaintRecord> record1, | 71 static bool BitmapsEqual(sk_sp<const PaintRecord> record1, |
| 72 sk_sp<const PaintRecord> record2) { | 72 sk_sp<const PaintRecord> record2) { |
| 73 SkRect rect = record1->cullRect(); | 73 SkRect rect = record1->cullRect(); |
| 74 if (rect != record2->cullRect()) | 74 if (rect != record2->cullRect()) |
| 75 return false; | 75 return false; |
| 76 | 76 |
| 77 SkBitmap bitmap1 = RecordToBitmap(record1); | 77 SkBitmap bitmap1 = RecordToBitmap(record1); |
| 78 SkBitmap bitmap2 = RecordToBitmap(record2); | 78 SkBitmap bitmap2 = RecordToBitmap(record2); |
| 79 bitmap1.lockPixels(); | |
| 80 bitmap2.lockPixels(); | |
| 81 int mismatch_count = 0; | 79 int mismatch_count = 0; |
| 82 const int kMaxMismatches = 10; | 80 const int kMaxMismatches = 10; |
| 83 for (int y = 0; y < rect.height() && mismatch_count < kMaxMismatches; ++y) { | 81 for (int y = 0; y < rect.height() && mismatch_count < kMaxMismatches; ++y) { |
| 84 for (int x = 0; x < rect.width() && mismatch_count < kMaxMismatches; ++x) { | 82 for (int x = 0; x < rect.width() && mismatch_count < kMaxMismatches; ++x) { |
| 85 SkColor pixel1 = bitmap1.getColor(x, y); | 83 SkColor pixel1 = bitmap1.getColor(x, y); |
| 86 SkColor pixel2 = bitmap2.getColor(x, y); | 84 SkColor pixel2 = bitmap2.getColor(x, y); |
| 87 if (pixel1 != pixel2) { | 85 if (pixel1 != pixel2) { |
| 88 LOG(ERROR) << "x=" << x << " y=" << y << " " << std::hex << pixel1 | 86 LOG(ERROR) << "x=" << x << " y=" << y << " " << std::hex << pixel1 |
| 89 << " vs " << std::hex << pixel2; | 87 << " vs " << std::hex << pixel2; |
| 90 ++mismatch_count; | 88 ++mismatch_count; |
| 91 } | 89 } |
| 92 } | 90 } |
| 93 } | 91 } |
| 94 bitmap1.unlockPixels(); | |
| 95 bitmap2.unlockPixels(); | |
| 96 return !mismatch_count; | 92 return !mismatch_count; |
| 97 } | 93 } |
| 98 | 94 |
| 99 bool DrawingDisplayItem::Equals(const DisplayItem& other) const { | 95 bool DrawingDisplayItem::Equals(const DisplayItem& other) const { |
| 100 if (!DisplayItem::Equals(other)) | 96 if (!DisplayItem::Equals(other)) |
| 101 return false; | 97 return false; |
| 102 | 98 |
| 103 const sk_sp<const PaintRecord>& record = this->GetPaintRecord(); | 99 const sk_sp<const PaintRecord>& record = this->GetPaintRecord(); |
| 104 const sk_sp<const PaintRecord>& other_record = | 100 const sk_sp<const PaintRecord>& other_record = |
| 105 static_cast<const DrawingDisplayItem&>(other).GetPaintRecord(); | 101 static_cast<const DrawingDisplayItem&>(other).GetPaintRecord(); |
| 106 | 102 |
| 107 if (!record && !other_record) | 103 if (!record && !other_record) |
| 108 return true; | 104 return true; |
| 109 if (!record || !other_record) | 105 if (!record || !other_record) |
| 110 return false; | 106 return false; |
| 111 | 107 |
| 112 if (RecordsEqual(record, other_record)) | 108 if (RecordsEqual(record, other_record)) |
| 113 return true; | 109 return true; |
| 114 | 110 |
| 115 // Sometimes the client may produce different records for the same visual | 111 // Sometimes the client may produce different records for the same visual |
| 116 // result, which should be treated as equal. | 112 // result, which should be treated as equal. |
| 117 return BitmapsEqual(std::move(record), std::move(other_record)); | 113 return BitmapsEqual(std::move(record), std::move(other_record)); |
| 118 } | 114 } |
| 119 | 115 |
| 120 } // namespace blink | 116 } // namespace blink |
| OLD | NEW |