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 11 matching lines...) Expand all Loading... | |
| 22 #include "SkWriteBuffer.h" | 22 #include "SkWriteBuffer.h" | 
| 23 | 23 | 
| 24 #include <string.h> | 24 #include <string.h> | 
| 25 | 25 | 
| 26 static bool reset_return_false(SkBitmap* bm) { | 26 static bool reset_return_false(SkBitmap* bm) { | 
| 27 bm->reset(); | 27 bm->reset(); | 
| 28 return false; | 28 return false; | 
| 29 } | 29 } | 
| 30 | 30 | 
| 31 SkBitmap::SkBitmap() { | 31 SkBitmap::SkBitmap() { | 
| 32 this->fInfo = SkImageInfo::MakeUnknown(); | |
| 
 
msarett
2016/05/26 13:43:05
I could also add a reset() function to SkImageInfo
 
 | |
| 32 sk_bzero(this, sizeof(*this)); | 33 sk_bzero(this, sizeof(*this)); | 
| 33 } | 34 } | 
| 34 | 35 | 
| 35 SkBitmap::SkBitmap(const SkBitmap& src) { | 36 SkBitmap::SkBitmap(const SkBitmap& src) { | 
| 36 SkDEBUGCODE(src.validate();) | 37 SkDEBUGCODE(src.validate();) | 
| 38 this->fInfo = SkImageInfo::MakeUnknown(); | |
| 37 sk_bzero(this, sizeof(*this)); | 39 sk_bzero(this, sizeof(*this)); | 
| 38 *this = src; | 40 *this = src; | 
| 39 SkDEBUGCODE(this->validate();) | 41 SkDEBUGCODE(this->validate();) | 
| 40 } | 42 } | 
| 41 | 43 | 
| 42 SkBitmap::SkBitmap(SkBitmap&& other) : SkBitmap() { this->swap(other); } | 44 SkBitmap::SkBitmap(SkBitmap&& other) : SkBitmap() { this->swap(other); } | 
| 43 | 45 | 
| 44 SkBitmap::~SkBitmap() { | 46 SkBitmap::~SkBitmap() { | 
| 45 SkDEBUGCODE(this->validate();) | 47 SkDEBUGCODE(this->validate();) | 
| 46 this->freePixels(); | 48 this->freePixels(); | 
| 47 } | 49 } | 
| 48 | 50 | 
| 49 SkBitmap& SkBitmap::operator=(const SkBitmap& src) { | 51 SkBitmap& SkBitmap::operator=(const SkBitmap& src) { | 
| 50 if (this != &src) { | 52 if (this != &src) { | 
| 51 this->freePixels(); | 53 this->freePixels(); | 
| 54 this->fInfo = src.fInfo; | |
| 52 memcpy(this, &src, sizeof(src)); | 55 memcpy(this, &src, sizeof(src)); | 
| 53 | 56 | 
| 54 // inc src reference counts | 57 // inc src reference counts | 
| 55 SkSafeRef(src.fPixelRef); | 58 SkSafeRef(src.fPixelRef); | 
| 56 | 59 | 
| 57 // we reset our locks if we get blown away | 60 // we reset our locks if we get blown away | 
| 58 fPixelLockCount = 0; | 61 fPixelLockCount = 0; | 
| 59 | 62 | 
| 60 if (fPixelRef) { | 63 if (fPixelRef) { | 
| 61 // ignore the values from the memcpy | 64 // ignore the values from the memcpy | 
| (...skipping 28 matching lines...) Expand all Loading... | |
| 90 SkTSwap(fPixels, other.fPixels); | 93 SkTSwap(fPixels, other.fPixels); | 
| 91 SkTSwap(fInfo, other.fInfo); | 94 SkTSwap(fInfo, other.fInfo); | 
| 92 SkTSwap(fRowBytes, other.fRowBytes); | 95 SkTSwap(fRowBytes, other.fRowBytes); | 
| 93 SkTSwap(fFlags, other.fFlags); | 96 SkTSwap(fFlags, other.fFlags); | 
| 94 | 97 | 
| 95 SkDEBUGCODE(this->validate();) | 98 SkDEBUGCODE(this->validate();) | 
| 96 } | 99 } | 
| 97 | 100 | 
| 98 void SkBitmap::reset() { | 101 void SkBitmap::reset() { | 
| 99 this->freePixels(); | 102 this->freePixels(); | 
| 103 this->fInfo = SkImageInfo::MakeUnknown(); | |
| 100 sk_bzero(this, sizeof(*this)); | 104 sk_bzero(this, sizeof(*this)); | 
| 101 } | 105 } | 
| 102 | 106 | 
| 103 void SkBitmap::getBounds(SkRect* bounds) const { | 107 void SkBitmap::getBounds(SkRect* bounds) const { | 
| 104 SkASSERT(bounds); | 108 SkASSERT(bounds); | 
| 105 bounds->set(0, 0, | 109 bounds->set(0, 0, | 
| 106 SkIntToScalar(fInfo.width()), SkIntToScalar(fInfo.height())); | 110 SkIntToScalar(fInfo.width()), SkIntToScalar(fInfo.height())); | 
| 107 } | 111 } | 
| 108 | 112 | 
| 109 void SkBitmap::getBounds(SkIRect* bounds) const { | 113 void SkBitmap::getBounds(SkIRect* bounds) const { | 
| (...skipping 1239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1349 /////////////////////////////////////////////////////////////////////////////// | 1353 /////////////////////////////////////////////////////////////////////////////// | 
| 1350 | 1354 | 
| 1351 #ifdef SK_DEBUG | 1355 #ifdef SK_DEBUG | 
| 1352 void SkImageInfo::validate() const { | 1356 void SkImageInfo::validate() const { | 
| 1353 SkASSERT(fWidth >= 0); | 1357 SkASSERT(fWidth >= 0); | 
| 1354 SkASSERT(fHeight >= 0); | 1358 SkASSERT(fHeight >= 0); | 
| 1355 SkASSERT(SkColorTypeIsValid(fColorType)); | 1359 SkASSERT(SkColorTypeIsValid(fColorType)); | 
| 1356 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); | 1360 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); | 
| 1357 } | 1361 } | 
| 1358 #endif | 1362 #endif | 
| OLD | NEW |