aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkRecords.h
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2014-12-11 12:43:04 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-12-11 12:43:04 -0800
commitf55c314bfa6db980941f8d0ab485beb2e08589ab (patch)
tree741d0ab97bd554965db907a269b2727a32bd3959 /src/core/SkRecords.h
parent1a4900e8be6086a824488dc98d4822e440815657 (diff)
Enforce thread-safety of bitmaps in pictures via the type.
No runtime difference here, but it makes it impossible to forget to make a shallow copy; you can't get at the full bitmap without it. NOTREECHECKS=true BUG=skia: Review URL: https://codereview.chromium.org/799603002
Diffstat (limited to 'src/core/SkRecords.h')
-rw-r--r--src/core/SkRecords.h17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/core/SkRecords.h b/src/core/SkRecords.h
index d6fc723b39..d8dfb2b937 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.