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 867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 } | 878 } |
879 | 879 |
880 SkIRect srcRect, r; | 880 SkIRect srcRect, r; |
881 srcRect.set(0, 0, this->width(), this->height()); | 881 srcRect.set(0, 0, this->width(), this->height()); |
882 if (!r.intersect(srcRect, subset)) { | 882 if (!r.intersect(srcRect, subset)) { |
883 return false; // r is empty (i.e. no intersection) | 883 return false; // r is empty (i.e. no intersection) |
884 } | 884 } |
885 | 885 |
886 if (fPixelRef->getTexture() != NULL) { | 886 if (fPixelRef->getTexture() != NULL) { |
887 // Do a deep copy | 887 // Do a deep copy |
888 SkPixelRef* pixelRef = fPixelRef->deepCopy(this->config(), &subset); | 888 SkPixelRef* pixelRef = fPixelRef->deepCopy(&subset); |
889 if (pixelRef != NULL) { | 889 if (pixelRef != NULL) { |
890 SkBitmap dst; | 890 SkBitmap dst; |
891 dst.setConfig(this->config(), subset.width(), subset.height(), 0, | 891 dst.setConfig(this->config(), subset.width(), subset.height(), 0, |
892 this->alphaType()); | 892 this->alphaType()); |
893 dst.setIsVolatile(this->isVolatile()); | 893 dst.setIsVolatile(this->isVolatile()); |
894 dst.setPixelRef(pixelRef)->unref(); | 894 dst.setPixelRef(pixelRef)->unref(); |
895 SkDEBUGCODE(dst.validate()); | 895 SkDEBUGCODE(dst.validate()); |
896 result->swap(dst); | 896 result->swap(dst); |
897 return true; | 897 return true; |
898 } | 898 } |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1078 | 1078 |
1079 paint.setDither(true); | 1079 paint.setDither(true); |
1080 canvas.drawBitmap(*src, 0, 0, &paint); | 1080 canvas.drawBitmap(*src, 0, 0, &paint); |
1081 } | 1081 } |
1082 | 1082 |
1083 dst->swap(tmpDst); | 1083 dst->swap(tmpDst); |
1084 return true; | 1084 return true; |
1085 } | 1085 } |
1086 | 1086 |
1087 bool SkBitmap::deepCopyTo(SkBitmap* dst) const { | 1087 bool SkBitmap::deepCopyTo(SkBitmap* dst) const { |
1088 const SkBitmap::Config dstConfig = this->config(); | 1088 const SkColorType dstCT = this->colorType(); |
1089 const SkColorType dstCT = SkBitmapConfigToColorType(dstConfig); | |
1090 | 1089 |
1091 if (!this->canCopyTo(dstCT)) { | 1090 if (!this->canCopyTo(dstCT)) { |
1092 return false; | 1091 return false; |
1093 } | 1092 } |
1094 | 1093 |
1095 // If we have a PixelRef, and it supports deep copy, use it. | 1094 // If we have a PixelRef, and it supports deep copy, use it. |
1096 // Currently supported only by texture-backed bitmaps. | 1095 // Currently supported only by texture-backed bitmaps. |
1097 if (fPixelRef) { | 1096 if (fPixelRef) { |
1098 SkPixelRef* pixelRef = fPixelRef->deepCopy(dstConfig); | 1097 SkPixelRef* pixelRef = fPixelRef->deepCopy(); |
1099 if (pixelRef) { | 1098 if (pixelRef) { |
1100 uint32_t rowBytes; | 1099 // Since there is no subset to pass to deepCopy, and deepCopy |
1101 if (this->colorType() == dstCT) { | 1100 // succeeded, the new pixel ref must be identical. |
1102 // Since there is no subset to pass to deepCopy, and deepCopy | 1101 SkASSERT(fPixelRef->info() == pixelRef->info()); |
1103 // succeeded, the new pixel ref must be identical. | 1102 pixelRef->cloneGenID(*fPixelRef); |
1104 SkASSERT(fPixelRef->info() == pixelRef->info()); | |
1105 pixelRef->cloneGenID(*fPixelRef); | |
1106 // Use the same rowBytes as the original. | |
1107 rowBytes = fRowBytes; | |
1108 } else { | |
1109 // With the new config, an appropriate fRowBytes will be compute
d by setConfig. | |
1110 rowBytes = 0; | |
1111 } | |
1112 | 1103 |
1113 SkImageInfo info = fInfo; | 1104 SkImageInfo info = fInfo; |
1114 info.fColorType = dstCT; | 1105 if (!dst->setConfig(info, fRowBytes)) { |
1115 if (!dst->setConfig(info, rowBytes)) { | |
1116 return false; | 1106 return false; |
1117 } | 1107 } |
1118 dst->setPixelRef(pixelRef, fPixelRefOrigin)->unref(); | 1108 dst->setPixelRef(pixelRef, fPixelRefOrigin)->unref(); |
1119 return true; | 1109 return true; |
1120 } | 1110 } |
1121 } | 1111 } |
1122 | 1112 |
1123 if (this->getTexture()) { | 1113 if (this->getTexture()) { |
1124 return false; | 1114 return false; |
1125 } else { | 1115 } else { |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1423 /////////////////////////////////////////////////////////////////////////////// | 1413 /////////////////////////////////////////////////////////////////////////////// |
1424 | 1414 |
1425 #ifdef SK_DEBUG | 1415 #ifdef SK_DEBUG |
1426 void SkImageInfo::validate() const { | 1416 void SkImageInfo::validate() const { |
1427 SkASSERT(fWidth >= 0); | 1417 SkASSERT(fWidth >= 0); |
1428 SkASSERT(fHeight >= 0); | 1418 SkASSERT(fHeight >= 0); |
1429 SkASSERT(SkColorTypeIsValid(fColorType)); | 1419 SkASSERT(SkColorTypeIsValid(fColorType)); |
1430 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); | 1420 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); |
1431 } | 1421 } |
1432 #endif | 1422 #endif |
OLD | NEW |