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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 } | 308 } |
309 | 309 |
310 SkPixelRef* SkBitmap::setPixelRef(SkPixelRef* pr, int dx, int dy) { | 310 SkPixelRef* SkBitmap::setPixelRef(SkPixelRef* pr, int dx, int dy) { |
311 #ifdef SK_DEBUG | 311 #ifdef SK_DEBUG |
312 if (pr) { | 312 if (pr) { |
313 SkImageInfo info; | 313 SkImageInfo info; |
314 if (this->asImageInfo(&info)) { | 314 if (this->asImageInfo(&info)) { |
315 const SkImageInfo& prInfo = pr->info(); | 315 const SkImageInfo& prInfo = pr->info(); |
316 SkASSERT(info.fWidth <= prInfo.fWidth); | 316 SkASSERT(info.fWidth <= prInfo.fWidth); |
317 SkASSERT(info.fHeight <= prInfo.fHeight); | 317 SkASSERT(info.fHeight <= prInfo.fHeight); |
318 SkASSERT(info.fColorType == prInfo.fColorType); | 318 // We can't always assert that the two colortypes are the same, sinc
e ganesh is free |
| 319 // to change the 32bit swizzles as needed (e.g. RGBA <--> BGRA), so
we have a softer |
| 320 // check. |
| 321 // |
| 322 // TODO: perhaps setPixelRef should just overwrite the values in the
the bitmap anyway. |
| 323 if (info.fColorType != prInfo.fColorType) { |
| 324 SkASSERT(4 == info.bytesPerPixel() && 4 == prInfo.bytesPerPixel(
)); |
| 325 } |
319 switch (prInfo.fAlphaType) { | 326 switch (prInfo.fAlphaType) { |
320 case kIgnore_SkAlphaType: | 327 case kIgnore_SkAlphaType: |
321 SkASSERT(fInfo.fAlphaType == kIgnore_SkAlphaType); | 328 SkASSERT(fInfo.fAlphaType == kIgnore_SkAlphaType); |
322 break; | 329 break; |
323 case kOpaque_SkAlphaType: | 330 case kOpaque_SkAlphaType: |
324 case kPremul_SkAlphaType: | 331 case kPremul_SkAlphaType: |
325 SkASSERT(info.fAlphaType == kOpaque_SkAlphaType || | 332 SkASSERT(info.fAlphaType == kOpaque_SkAlphaType || |
326 info.fAlphaType == kPremul_SkAlphaType); | 333 info.fAlphaType == kPremul_SkAlphaType); |
327 break; | 334 break; |
328 case kUnpremul_SkAlphaType: | 335 case kUnpremul_SkAlphaType: |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 } | 885 } |
879 | 886 |
880 SkIRect srcRect, r; | 887 SkIRect srcRect, r; |
881 srcRect.set(0, 0, this->width(), this->height()); | 888 srcRect.set(0, 0, this->width(), this->height()); |
882 if (!r.intersect(srcRect, subset)) { | 889 if (!r.intersect(srcRect, subset)) { |
883 return false; // r is empty (i.e. no intersection) | 890 return false; // r is empty (i.e. no intersection) |
884 } | 891 } |
885 | 892 |
886 if (fPixelRef->getTexture() != NULL) { | 893 if (fPixelRef->getTexture() != NULL) { |
887 // Do a deep copy | 894 // Do a deep copy |
888 SkPixelRef* pixelRef = fPixelRef->deepCopy(this->config(), &subset); | 895 SkPixelRef* pixelRef = fPixelRef->deepCopy(&subset); |
889 if (pixelRef != NULL) { | 896 if (pixelRef != NULL) { |
890 SkBitmap dst; | 897 SkBitmap dst; |
891 dst.setConfig(this->config(), subset.width(), subset.height(), 0, | 898 dst.setConfig(this->config(), subset.width(), subset.height(), 0, |
892 this->alphaType()); | 899 this->alphaType()); |
893 dst.setIsVolatile(this->isVolatile()); | 900 dst.setIsVolatile(this->isVolatile()); |
894 dst.setPixelRef(pixelRef)->unref(); | 901 dst.setPixelRef(pixelRef)->unref(); |
895 SkDEBUGCODE(dst.validate()); | 902 SkDEBUGCODE(dst.validate()); |
896 result->swap(dst); | 903 result->swap(dst); |
897 return true; | 904 return true; |
898 } | 905 } |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1078 | 1085 |
1079 paint.setDither(true); | 1086 paint.setDither(true); |
1080 canvas.drawBitmap(*src, 0, 0, &paint); | 1087 canvas.drawBitmap(*src, 0, 0, &paint); |
1081 } | 1088 } |
1082 | 1089 |
1083 dst->swap(tmpDst); | 1090 dst->swap(tmpDst); |
1084 return true; | 1091 return true; |
1085 } | 1092 } |
1086 | 1093 |
1087 bool SkBitmap::deepCopyTo(SkBitmap* dst) const { | 1094 bool SkBitmap::deepCopyTo(SkBitmap* dst) const { |
1088 const SkBitmap::Config dstConfig = this->config(); | 1095 const SkColorType dstCT = this->colorType(); |
1089 const SkColorType dstCT = SkBitmapConfigToColorType(dstConfig); | |
1090 | 1096 |
1091 if (!this->canCopyTo(dstCT)) { | 1097 if (!this->canCopyTo(dstCT)) { |
1092 return false; | 1098 return false; |
1093 } | 1099 } |
1094 | 1100 |
1095 // If we have a PixelRef, and it supports deep copy, use it. | 1101 // If we have a PixelRef, and it supports deep copy, use it. |
1096 // Currently supported only by texture-backed bitmaps. | 1102 // Currently supported only by texture-backed bitmaps. |
1097 if (fPixelRef) { | 1103 if (fPixelRef) { |
1098 SkPixelRef* pixelRef = fPixelRef->deepCopy(dstConfig); | 1104 SkAutoTUnref<SkPixelRef> pixelRef(fPixelRef->deepCopy()); |
1099 if (pixelRef) { | 1105 if (pixelRef.get()) { |
1100 uint32_t rowBytes; | 1106 pixelRef->cloneGenID(*fPixelRef); |
1101 if (this->colorType() == dstCT) { | 1107 if (!dst->setConfig(pixelRef->info(), fRowBytes)) { |
1102 // Since there is no subset to pass to deepCopy, and deepCopy | |
1103 // succeeded, the new pixel ref must be identical. | |
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 | |
1113 SkImageInfo info = fInfo; | |
1114 info.fColorType = dstCT; | |
1115 if (!dst->setConfig(info, rowBytes)) { | |
1116 return false; | 1108 return false; |
1117 } | 1109 } |
1118 dst->setPixelRef(pixelRef, fPixelRefOrigin)->unref(); | 1110 dst->setPixelRef(pixelRef, fPixelRefOrigin); |
1119 return true; | 1111 return true; |
1120 } | 1112 } |
1121 } | 1113 } |
1122 | 1114 |
1123 if (this->getTexture()) { | 1115 if (this->getTexture()) { |
1124 return false; | 1116 return false; |
1125 } else { | 1117 } else { |
1126 return this->copyTo(dst, dstCT, NULL); | 1118 return this->copyTo(dst, dstCT, NULL); |
1127 } | 1119 } |
1128 } | 1120 } |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1423 /////////////////////////////////////////////////////////////////////////////// | 1415 /////////////////////////////////////////////////////////////////////////////// |
1424 | 1416 |
1425 #ifdef SK_DEBUG | 1417 #ifdef SK_DEBUG |
1426 void SkImageInfo::validate() const { | 1418 void SkImageInfo::validate() const { |
1427 SkASSERT(fWidth >= 0); | 1419 SkASSERT(fWidth >= 0); |
1428 SkASSERT(fHeight >= 0); | 1420 SkASSERT(fHeight >= 0); |
1429 SkASSERT(SkColorTypeIsValid(fColorType)); | 1421 SkASSERT(SkColorTypeIsValid(fColorType)); |
1430 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); | 1422 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); |
1431 } | 1423 } |
1432 #endif | 1424 #endif |
OLD | NEW |