Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2008 The Android Open Source Project | 2 * Copyright 2008 The Android Open Source Project |
| 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 #include "SkAtomics.h" | 8 #include "SkAtomics.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 sk_bzero(this, sizeof(*this)); | 32 sk_bzero(this, sizeof(*this)); |
| 33 } | 33 } |
| 34 | 34 |
| 35 SkBitmap::SkBitmap(const SkBitmap& src) { | 35 SkBitmap::SkBitmap(const SkBitmap& src) { |
| 36 SkDEBUGCODE(src.validate();) | 36 SkDEBUGCODE(src.validate();) |
| 37 sk_bzero(this, sizeof(*this)); | 37 sk_bzero(this, sizeof(*this)); |
| 38 *this = src; | 38 *this = src; |
| 39 SkDEBUGCODE(this->validate();) | 39 SkDEBUGCODE(this->validate();) |
| 40 } | 40 } |
| 41 | 41 |
| 42 SkBitmap::SkBitmap(SkBitmap&& other) { | |
| 43 if (this != &other) { | |
| 44 memcpy(this, &other, sizeof(other)); | |
|
mtklein
2015/12/10 23:09:58
Can't this just be this->swap(other)?
hal.canary
2015/12/14 17:30:37
Done. need to initialize all variables first.
| |
| 45 sk_bzero(&other, sizeof(other)); | |
| 46 } | |
| 47 } | |
| 48 | |
| 42 SkBitmap::~SkBitmap() { | 49 SkBitmap::~SkBitmap() { |
| 43 SkDEBUGCODE(this->validate();) | 50 SkDEBUGCODE(this->validate();) |
| 44 this->freePixels(); | 51 this->freePixels(); |
| 45 } | 52 } |
| 46 | 53 |
| 47 SkBitmap& SkBitmap::operator=(const SkBitmap& src) { | 54 SkBitmap& SkBitmap::operator=(const SkBitmap& src) { |
| 48 if (this != &src) { | 55 if (this != &src) { |
| 49 this->freePixels(); | 56 this->freePixels(); |
| 50 memcpy(this, &src, sizeof(src)); | 57 memcpy(this, &src, sizeof(src)); |
| 51 | 58 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 65 // setPixels. | 72 // setPixels. |
| 66 // Just leave the memcpy'ed one but they'll get out of sync | 73 // Just leave the memcpy'ed one but they'll get out of sync |
| 67 // as soon either is modified. | 74 // as soon either is modified. |
| 68 } | 75 } |
| 69 } | 76 } |
| 70 | 77 |
| 71 SkDEBUGCODE(this->validate();) | 78 SkDEBUGCODE(this->validate();) |
| 72 return *this; | 79 return *this; |
| 73 } | 80 } |
| 74 | 81 |
| 82 SkBitmap& SkBitmap::operator=(SkBitmap&& other) { | |
| 83 if (this != &other) { | |
| 84 this->swap(other); | |
| 85 other.reset(); | |
| 86 } | |
| 87 return *this; | |
| 88 } | |
| 89 | |
| 75 void SkBitmap::swap(SkBitmap& other) { | 90 void SkBitmap::swap(SkBitmap& other) { |
| 76 SkTSwap(fColorTable, other.fColorTable); | 91 SkTSwap(fColorTable, other.fColorTable); |
| 77 SkTSwap(fPixelRef, other.fPixelRef); | 92 SkTSwap(fPixelRef, other.fPixelRef); |
| 78 SkTSwap(fPixelRefOrigin, other.fPixelRefOrigin); | 93 SkTSwap(fPixelRefOrigin, other.fPixelRefOrigin); |
| 79 SkTSwap(fPixelLockCount, other.fPixelLockCount); | 94 SkTSwap(fPixelLockCount, other.fPixelLockCount); |
| 80 SkTSwap(fPixels, other.fPixels); | 95 SkTSwap(fPixels, other.fPixels); |
| 81 SkTSwap(fInfo, other.fInfo); | 96 SkTSwap(fInfo, other.fInfo); |
| 82 SkTSwap(fRowBytes, other.fRowBytes); | 97 SkTSwap(fRowBytes, other.fRowBytes); |
| 83 SkTSwap(fFlags, other.fFlags); | 98 SkTSwap(fFlags, other.fFlags); |
| 84 | 99 |
| (...skipping 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1328 /////////////////////////////////////////////////////////////////////////////// | 1343 /////////////////////////////////////////////////////////////////////////////// |
| 1329 | 1344 |
| 1330 #ifdef SK_DEBUG | 1345 #ifdef SK_DEBUG |
| 1331 void SkImageInfo::validate() const { | 1346 void SkImageInfo::validate() const { |
| 1332 SkASSERT(fWidth >= 0); | 1347 SkASSERT(fWidth >= 0); |
| 1333 SkASSERT(fHeight >= 0); | 1348 SkASSERT(fHeight >= 0); |
| 1334 SkASSERT(SkColorTypeIsValid(fColorType)); | 1349 SkASSERT(SkColorTypeIsValid(fColorType)); |
| 1335 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); | 1350 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); |
| 1336 } | 1351 } |
| 1337 #endif | 1352 #endif |
| OLD | NEW |