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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/core/SkRecordDraw.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkRecords_DEFINED 8 #ifndef SkRecords_DEFINED
9 #define SkRecords_DEFINED 9 #define SkRecords_DEFINED
10 10
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 176
177 ACT_AS_PTR(fPtr); 177 ACT_AS_PTR(fPtr);
178 private: 178 private:
179 T* fPtr; 179 T* fPtr;
180 }; 180 };
181 181
182 #undef ACT_AS_PTR 182 #undef ACT_AS_PTR
183 183
184 // Like SkBitmap, but deep copies pixels if they're not immutable. 184 // Like SkBitmap, but deep copies pixels if they're not immutable.
185 // Using this, we guarantee the immutability of all bitmaps we record. 185 // Using this, we guarantee the immutability of all bitmaps we record.
186 struct ImmutableBitmap : public SkBitmap { 186 class ImmutableBitmap : SkNoncopyable {
187 public:
187 explicit ImmutableBitmap(const SkBitmap& bitmap) { 188 explicit ImmutableBitmap(const SkBitmap& bitmap) {
188 if (bitmap.isImmutable()) { 189 if (bitmap.isImmutable()) {
189 *(SkBitmap*)this = bitmap; 190 fBitmap = bitmap;
190 } else { 191 } else {
191 bitmap.copyTo(this); 192 bitmap.copyTo(&fBitmap);
192 } 193 }
193 this->setImmutable(); 194 fBitmap.setImmutable();
194 } 195 }
196
197 int width() const { return fBitmap.width(); }
198 int height() const { return fBitmap.height(); }
199
200 // While the pixels are immutable, SkBitmap itself is not thread-safe, so re turn a copy.
201 SkBitmap shallowCopy() const { return fBitmap; }
202 private:
203 SkBitmap fBitmap;
195 }; 204 };
196 205
197 // SkPath::getBounds() isn't thread safe unless we precache the bounds in a sing lethreaded context. 206 // SkPath::getBounds() isn't thread safe unless we precache the bounds in a sing lethreaded context.
198 // Recording is a convenient time to do this, but we could delay it to between r ecord and playback. 207 // Recording is a convenient time to do this, but we could delay it to between r ecord and playback.
199 struct BoundedPath : public SkPath { 208 struct BoundedPath : public SkPath {
200 explicit BoundedPath(const SkPath& path) : SkPath(path) { 209 explicit BoundedPath(const SkPath& path) : SkPath(path) {
201 this->updateBoundsCache(); 210 this->updateBoundsCache();
202 } 211 }
203 }; 212 };
204 213
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 #undef RECORD0 355 #undef RECORD0
347 #undef RECORD1 356 #undef RECORD1
348 #undef RECORD2 357 #undef RECORD2
349 #undef RECORD3 358 #undef RECORD3
350 #undef RECORD4 359 #undef RECORD4
351 #undef RECORD5 360 #undef RECORD5
352 361
353 } // namespace SkRecords 362 } // namespace SkRecords
354 363
355 #endif//SkRecords_DEFINED 364 #endif//SkRecords_DEFINED
OLDNEW
« 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