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

Unified Diff: src/core/SkRecords.h

Issue 799603002: Enforce thread-safety of bitmaps in pictures via the type. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkRecordDraw.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkRecords.h
diff --git a/src/core/SkRecords.h b/src/core/SkRecords.h
index d6fc723b39c866598a339d9c1e709af4c7099b66..d8dfb2b93729a60babe2dabfcbce3f3ed9cf19ad 100644
--- a/src/core/SkRecords.h
+++ b/src/core/SkRecords.h
@@ -183,15 +183,24 @@ private:
// Like SkBitmap, but deep copies pixels if they're not immutable.
// Using this, we guarantee the immutability of all bitmaps we record.
-struct ImmutableBitmap : public SkBitmap {
+class ImmutableBitmap : SkNoncopyable {
+public:
explicit ImmutableBitmap(const SkBitmap& bitmap) {
if (bitmap.isImmutable()) {
- *(SkBitmap*)this = bitmap;
+ fBitmap = bitmap;
} else {
- bitmap.copyTo(this);
+ bitmap.copyTo(&fBitmap);
}
- this->setImmutable();
+ fBitmap.setImmutable();
}
+
+ int width() const { return fBitmap.width(); }
+ int height() const { return fBitmap.height(); }
+
+ // While the pixels are immutable, SkBitmap itself is not thread-safe, so return a copy.
+ SkBitmap shallowCopy() const { return fBitmap; }
+private:
+ SkBitmap fBitmap;
};
// SkPath::getBounds() isn't thread safe unless we precache the bounds in a singlethreaded context.
« no previous file with comments | « src/core/SkRecordDraw.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698