OLD | NEW |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |