| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2008 The Android Open Source Project | 3 * Copyright 2008 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| (...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 } | 758 } |
| 759 | 759 |
| 760 SkIRect srcRect, r; | 760 SkIRect srcRect, r; |
| 761 srcRect.set(0, 0, this->width(), this->height()); | 761 srcRect.set(0, 0, this->width(), this->height()); |
| 762 if (!r.intersect(srcRect, subset)) { | 762 if (!r.intersect(srcRect, subset)) { |
| 763 return false; // r is empty (i.e. no intersection) | 763 return false; // r is empty (i.e. no intersection) |
| 764 } | 764 } |
| 765 | 765 |
| 766 if (fPixelRef->getTexture() != NULL) { | 766 if (fPixelRef->getTexture() != NULL) { |
| 767 // Do a deep copy | 767 // Do a deep copy |
| 768 SkPixelRef* pixelRef = fPixelRef->deepCopy(this->colorType(), &subset); | 768 SkPixelRef* pixelRef = fPixelRef->deepCopy(this->colorType(), this->prof
ileType(), &subset); |
| 769 if (pixelRef != NULL) { | 769 if (pixelRef != NULL) { |
| 770 SkBitmap dst; | 770 SkBitmap dst; |
| 771 dst.setInfo(SkImageInfo::Make(subset.width(), subset.height(), | 771 dst.setInfo(SkImageInfo::Make(subset.width(), subset.height(), |
| 772 this->colorType(), this->alphaType()))
; | 772 this->colorType(), this->alphaType()))
; |
| 773 dst.setIsVolatile(this->isVolatile()); | 773 dst.setIsVolatile(this->isVolatile()); |
| 774 dst.setPixelRef(pixelRef)->unref(); | 774 dst.setPixelRef(pixelRef)->unref(); |
| 775 SkDEBUGCODE(dst.validate()); | 775 SkDEBUGCODE(dst.validate()); |
| 776 result->swap(dst); | 776 result->swap(dst); |
| 777 return true; | 777 return true; |
| 778 } | 778 } |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 969 dstPixelRef->cloneGenID(*fPixelRef); | 969 dstPixelRef->cloneGenID(*fPixelRef); |
| 970 } | 970 } |
| 971 } | 971 } |
| 972 | 972 |
| 973 dst->swap(tmpDst); | 973 dst->swap(tmpDst); |
| 974 return true; | 974 return true; |
| 975 } | 975 } |
| 976 | 976 |
| 977 bool SkBitmap::deepCopyTo(SkBitmap* dst) const { | 977 bool SkBitmap::deepCopyTo(SkBitmap* dst) const { |
| 978 const SkColorType dstCT = this->colorType(); | 978 const SkColorType dstCT = this->colorType(); |
| 979 const SkColorProfileType dstPT = this->profileType(); |
| 979 | 980 |
| 980 if (!this->canCopyTo(dstCT)) { | 981 if (!this->canCopyTo(dstCT)) { |
| 981 return false; | 982 return false; |
| 982 } | 983 } |
| 983 | 984 |
| 984 // If we have a PixelRef, and it supports deep copy, use it. | 985 // If we have a PixelRef, and it supports deep copy, use it. |
| 985 // Currently supported only by texture-backed bitmaps. | 986 // Currently supported only by texture-backed bitmaps. |
| 986 if (fPixelRef) { | 987 if (fPixelRef) { |
| 987 SkPixelRef* pixelRef = fPixelRef->deepCopy(dstCT, NULL); | 988 SkPixelRef* pixelRef = fPixelRef->deepCopy(dstCT, dstPT, NULL); |
| 988 if (pixelRef) { | 989 if (pixelRef) { |
| 989 uint32_t rowBytes; | 990 uint32_t rowBytes; |
| 990 if (this->colorType() == dstCT) { | 991 if (this->colorType() == dstCT && this->profileType() == dstPT) { |
| 991 // Since there is no subset to pass to deepCopy, and deepCopy | 992 // Since there is no subset to pass to deepCopy, and deepCopy |
| 992 // succeeded, the new pixel ref must be identical. | 993 // succeeded, the new pixel ref must be identical. |
| 993 SkASSERT(fPixelRef->info() == pixelRef->info()); | 994 SkASSERT(fPixelRef->info() == pixelRef->info()); |
| 994 pixelRef->cloneGenID(*fPixelRef); | 995 pixelRef->cloneGenID(*fPixelRef); |
| 995 // Use the same rowBytes as the original. | 996 // Use the same rowBytes as the original. |
| 996 rowBytes = fRowBytes; | 997 rowBytes = fRowBytes; |
| 997 } else { | 998 } else { |
| 998 // With the new config, an appropriate fRowBytes will be compute
d by setInfo. | 999 // With the new config, an appropriate fRowBytes will be compute
d by setInfo. |
| 999 rowBytes = 0; | 1000 rowBytes = 0; |
| 1000 } | 1001 } |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1377 /////////////////////////////////////////////////////////////////////////////// | 1378 /////////////////////////////////////////////////////////////////////////////// |
| 1378 | 1379 |
| 1379 #ifdef SK_DEBUG | 1380 #ifdef SK_DEBUG |
| 1380 void SkImageInfo::validate() const { | 1381 void SkImageInfo::validate() const { |
| 1381 SkASSERT(fWidth >= 0); | 1382 SkASSERT(fWidth >= 0); |
| 1382 SkASSERT(fHeight >= 0); | 1383 SkASSERT(fHeight >= 0); |
| 1383 SkASSERT(SkColorTypeIsValid(fColorType)); | 1384 SkASSERT(SkColorTypeIsValid(fColorType)); |
| 1384 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); | 1385 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); |
| 1385 } | 1386 } |
| 1386 #endif | 1387 #endif |
| OLD | NEW |