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

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

Issue 2823003002: SkBitmap and SkPixelRef no longer need lock/unlock (Closed)
Patch Set: win fix after rebase Created 3 years, 8 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"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 } 76 }
77 77
78 static bool BitmapsEqual(sk_sp<const PaintRecord> record1, 78 static bool BitmapsEqual(sk_sp<const PaintRecord> record1,
79 sk_sp<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();
87 bitmap2.lockPixels();
88 int mismatch_count = 0; 86 int mismatch_count = 0;
89 const int kMaxMismatches = 10; 87 const int kMaxMismatches = 10;
90 for (int y = 0; y < rect.height() && mismatch_count < kMaxMismatches; ++y) { 88 for (int y = 0; y < rect.height() && mismatch_count < kMaxMismatches; ++y) {
91 for (int x = 0; x < rect.width() && mismatch_count < kMaxMismatches; ++x) { 89 for (int x = 0; x < rect.width() && mismatch_count < kMaxMismatches; ++x) {
92 SkColor pixel1 = bitmap1.getColor(x, y); 90 SkColor pixel1 = bitmap1.getColor(x, y);
93 SkColor pixel2 = bitmap2.getColor(x, y); 91 SkColor pixel2 = bitmap2.getColor(x, y);
94 if (pixel1 != pixel2) { 92 if (pixel1 != pixel2) {
95 LOG(ERROR) << "x=" << x << " y=" << y << " " << std::hex << pixel1 93 LOG(ERROR) << "x=" << x << " y=" << y << " " << std::hex << pixel1
96 << " vs " << std::hex << pixel2; 94 << " vs " << std::hex << pixel2;
97 ++mismatch_count; 95 ++mismatch_count;
98 } 96 }
99 } 97 }
100 } 98 }
101 bitmap1.unlockPixels();
102 bitmap2.unlockPixels();
103 return !mismatch_count; 99 return !mismatch_count;
104 } 100 }
105 101
106 bool DrawingDisplayItem::Equals(const DisplayItem& other) const { 102 bool DrawingDisplayItem::Equals(const DisplayItem& other) const {
107 if (!DisplayItem::Equals(other)) 103 if (!DisplayItem::Equals(other))
108 return false; 104 return false;
109 105
110 const sk_sp<const PaintRecord>& record = this->GetPaintRecord(); 106 const sk_sp<const PaintRecord>& record = this->GetPaintRecord();
111 const sk_sp<const PaintRecord>& other_record = 107 const sk_sp<const PaintRecord>& other_record =
112 static_cast<const DrawingDisplayItem&>(other).GetPaintRecord(); 108 static_cast<const DrawingDisplayItem&>(other).GetPaintRecord();
113 109
114 if (!record && !other_record) 110 if (!record && !other_record)
115 return true; 111 return true;
116 if (!record || !other_record) 112 if (!record || !other_record)
117 return false; 113 return false;
118 114
119 if (RecordsEqual(record, other_record)) 115 if (RecordsEqual(record, other_record))
120 return true; 116 return true;
121 117
122 // Sometimes the client may produce different records for the same visual 118 // Sometimes the client may produce different records for the same visual
123 // result, which should be treated as equal. 119 // result, which should be treated as equal.
124 return BitmapsEqual(std::move(record), std::move(other_record)); 120 return BitmapsEqual(std::move(record), std::move(other_record));
125 } 121 }
126 122
127 } // namespace blink 123 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698