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 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 } | 735 } |
736 | 736 |
737 SkIRect srcRect, r; | 737 SkIRect srcRect, r; |
738 srcRect.set(0, 0, this->width(), this->height()); | 738 srcRect.set(0, 0, this->width(), this->height()); |
739 if (!r.intersect(srcRect, subset)) { | 739 if (!r.intersect(srcRect, subset)) { |
740 return false; // r is empty (i.e. no intersection) | 740 return false; // r is empty (i.e. no intersection) |
741 } | 741 } |
742 | 742 |
743 if (fPixelRef->getTexture() != nullptr) { | 743 if (fPixelRef->getTexture() != nullptr) { |
744 // Do a deep copy | 744 // Do a deep copy |
745 SkPixelRef* pixelRef = fPixelRef->deepCopy(this->colorType(), this->colo
rSpace(), &subset); | 745 SkPixelRef* pixelRef = fPixelRef->deepCopy(this->colorType(), this->prof
ileType(), &subset); |
746 if (pixelRef != nullptr) { | 746 if (pixelRef != nullptr) { |
747 SkBitmap dst; | 747 SkBitmap dst; |
748 dst.setInfo(this->info().makeWH(subset.width(), subset.height())); | 748 dst.setInfo(this->info().makeWH(subset.width(), subset.height())); |
749 dst.setIsVolatile(this->isVolatile()); | 749 dst.setIsVolatile(this->isVolatile()); |
750 dst.setPixelRef(pixelRef)->unref(); | 750 dst.setPixelRef(pixelRef)->unref(); |
751 SkDEBUGCODE(dst.validate()); | 751 SkDEBUGCODE(dst.validate()); |
752 result->swap(dst); | 752 result->swap(dst); |
753 return true; | 753 return true; |
754 } | 754 } |
755 } | 755 } |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 dstPixelRef->cloneGenID(*fPixelRef); | 904 dstPixelRef->cloneGenID(*fPixelRef); |
905 } | 905 } |
906 } | 906 } |
907 | 907 |
908 dst->swap(tmpDst); | 908 dst->swap(tmpDst); |
909 return true; | 909 return true; |
910 } | 910 } |
911 | 911 |
912 bool SkBitmap::deepCopyTo(SkBitmap* dst) const { | 912 bool SkBitmap::deepCopyTo(SkBitmap* dst) const { |
913 const SkColorType dstCT = this->colorType(); | 913 const SkColorType dstCT = this->colorType(); |
914 SkColorSpace* dstCS = this->colorSpace(); | 914 const SkColorProfileType dstPT = this->profileType(); |
915 | 915 |
916 if (!this->canCopyTo(dstCT)) { | 916 if (!this->canCopyTo(dstCT)) { |
917 return false; | 917 return false; |
918 } | 918 } |
919 | 919 |
920 // If we have a PixelRef, and it supports deep copy, use it. | 920 // If we have a PixelRef, and it supports deep copy, use it. |
921 // Currently supported only by texture-backed bitmaps. | 921 // Currently supported only by texture-backed bitmaps. |
922 if (fPixelRef) { | 922 if (fPixelRef) { |
923 SkPixelRef* pixelRef = fPixelRef->deepCopy(dstCT, dstCS, nullptr); | 923 SkPixelRef* pixelRef = fPixelRef->deepCopy(dstCT, dstPT, nullptr); |
924 if (pixelRef) { | 924 if (pixelRef) { |
925 uint32_t rowBytes; | 925 uint32_t rowBytes; |
926 if (this->colorType() == dstCT && this->colorSpace() == dstCS) { | 926 if (this->colorType() == dstCT && this->profileType() == dstPT) { |
927 // Since there is no subset to pass to deepCopy, and deepCopy | 927 // Since there is no subset to pass to deepCopy, and deepCopy |
928 // succeeded, the new pixel ref must be identical. | 928 // succeeded, the new pixel ref must be identical. |
929 SkASSERT(fPixelRef->info() == pixelRef->info()); | 929 SkASSERT(fPixelRef->info() == pixelRef->info()); |
930 pixelRef->cloneGenID(*fPixelRef); | 930 pixelRef->cloneGenID(*fPixelRef); |
931 // Use the same rowBytes as the original. | 931 // Use the same rowBytes as the original. |
932 rowBytes = fRowBytes; | 932 rowBytes = fRowBytes; |
933 } else { | 933 } else { |
934 // With the new config, an appropriate fRowBytes will be compute
d by setInfo. | 934 // With the new config, an appropriate fRowBytes will be compute
d by setInfo. |
935 rowBytes = 0; | 935 rowBytes = 0; |
936 } | 936 } |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1347 /////////////////////////////////////////////////////////////////////////////// | 1347 /////////////////////////////////////////////////////////////////////////////// |
1348 | 1348 |
1349 #ifdef SK_DEBUG | 1349 #ifdef SK_DEBUG |
1350 void SkImageInfo::validate() const { | 1350 void SkImageInfo::validate() const { |
1351 SkASSERT(fWidth >= 0); | 1351 SkASSERT(fWidth >= 0); |
1352 SkASSERT(fHeight >= 0); | 1352 SkASSERT(fHeight >= 0); |
1353 SkASSERT(SkColorTypeIsValid(fColorType)); | 1353 SkASSERT(SkColorTypeIsValid(fColorType)); |
1354 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); | 1354 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); |
1355 } | 1355 } |
1356 #endif | 1356 #endif |
OLD | NEW |