Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(421)

Side by Side Diff: src/core/SkBitmap.cpp

Issue 295093003: Revert of Revert ""Revert of eliminate config param -- it was always self's config (https://codereview.chromi… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « include/gpu/SkGrPixelRef.h ('k') | src/gpu/SkGrPixelRef.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // We can't always assert that the two colortypes are the same, sinc e ganesh is free 318 SkASSERT(info.fColorType == prInfo.fColorType);
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 }
326 switch (prInfo.fAlphaType) { 319 switch (prInfo.fAlphaType) {
327 case kIgnore_SkAlphaType: 320 case kIgnore_SkAlphaType:
328 SkASSERT(fInfo.fAlphaType == kIgnore_SkAlphaType); 321 SkASSERT(fInfo.fAlphaType == kIgnore_SkAlphaType);
329 break; 322 break;
330 case kOpaque_SkAlphaType: 323 case kOpaque_SkAlphaType:
331 case kPremul_SkAlphaType: 324 case kPremul_SkAlphaType:
332 SkASSERT(info.fAlphaType == kOpaque_SkAlphaType || 325 SkASSERT(info.fAlphaType == kOpaque_SkAlphaType ||
333 info.fAlphaType == kPremul_SkAlphaType); 326 info.fAlphaType == kPremul_SkAlphaType);
334 break; 327 break;
335 case kUnpremul_SkAlphaType: 328 case kUnpremul_SkAlphaType:
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 } 878 }
886 879
887 SkIRect srcRect, r; 880 SkIRect srcRect, r;
888 srcRect.set(0, 0, this->width(), this->height()); 881 srcRect.set(0, 0, this->width(), this->height());
889 if (!r.intersect(srcRect, subset)) { 882 if (!r.intersect(srcRect, subset)) {
890 return false; // r is empty (i.e. no intersection) 883 return false; // r is empty (i.e. no intersection)
891 } 884 }
892 885
893 if (fPixelRef->getTexture() != NULL) { 886 if (fPixelRef->getTexture() != NULL) {
894 // Do a deep copy 887 // Do a deep copy
895 SkPixelRef* pixelRef = fPixelRef->deepCopy(&subset); 888 SkPixelRef* pixelRef = fPixelRef->deepCopy(this->config(), &subset);
896 if (pixelRef != NULL) { 889 if (pixelRef != NULL) {
897 SkBitmap dst; 890 SkBitmap dst;
898 dst.setConfig(this->config(), subset.width(), subset.height(), 0, 891 dst.setConfig(this->config(), subset.width(), subset.height(), 0,
899 this->alphaType()); 892 this->alphaType());
900 dst.setIsVolatile(this->isVolatile()); 893 dst.setIsVolatile(this->isVolatile());
901 dst.setPixelRef(pixelRef)->unref(); 894 dst.setPixelRef(pixelRef)->unref();
902 SkDEBUGCODE(dst.validate()); 895 SkDEBUGCODE(dst.validate());
903 result->swap(dst); 896 result->swap(dst);
904 return true; 897 return true;
905 } 898 }
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 1078
1086 paint.setDither(true); 1079 paint.setDither(true);
1087 canvas.drawBitmap(*src, 0, 0, &paint); 1080 canvas.drawBitmap(*src, 0, 0, &paint);
1088 } 1081 }
1089 1082
1090 dst->swap(tmpDst); 1083 dst->swap(tmpDst);
1091 return true; 1084 return true;
1092 } 1085 }
1093 1086
1094 bool SkBitmap::deepCopyTo(SkBitmap* dst) const { 1087 bool SkBitmap::deepCopyTo(SkBitmap* dst) const {
1095 const SkColorType dstCT = this->colorType(); 1088 const SkBitmap::Config dstConfig = this->config();
1089 const SkColorType dstCT = SkBitmapConfigToColorType(dstConfig);
1096 1090
1097 if (!this->canCopyTo(dstCT)) { 1091 if (!this->canCopyTo(dstCT)) {
1098 return false; 1092 return false;
1099 } 1093 }
1100 1094
1101 // If we have a PixelRef, and it supports deep copy, use it. 1095 // If we have a PixelRef, and it supports deep copy, use it.
1102 // Currently supported only by texture-backed bitmaps. 1096 // Currently supported only by texture-backed bitmaps.
1103 if (fPixelRef) { 1097 if (fPixelRef) {
1104 SkAutoTUnref<SkPixelRef> pixelRef(fPixelRef->deepCopy()); 1098 SkPixelRef* pixelRef = fPixelRef->deepCopy(dstConfig);
1105 if (pixelRef.get()) { 1099 if (pixelRef) {
1106 pixelRef->cloneGenID(*fPixelRef); 1100 uint32_t rowBytes;
1107 if (!dst->setConfig(pixelRef->info(), fRowBytes)) { 1101 if (this->colorType() == dstCT) {
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)) {
1108 return false; 1116 return false;
1109 } 1117 }
1110 dst->setPixelRef(pixelRef, fPixelRefOrigin); 1118 dst->setPixelRef(pixelRef, fPixelRefOrigin)->unref();
1111 return true; 1119 return true;
1112 } 1120 }
1113 } 1121 }
1114 1122
1115 if (this->getTexture()) { 1123 if (this->getTexture()) {
1116 return false; 1124 return false;
1117 } else { 1125 } else {
1118 return this->copyTo(dst, dstCT, NULL); 1126 return this->copyTo(dst, dstCT, NULL);
1119 } 1127 }
1120 } 1128 }
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
1415 /////////////////////////////////////////////////////////////////////////////// 1423 ///////////////////////////////////////////////////////////////////////////////
1416 1424
1417 #ifdef SK_DEBUG 1425 #ifdef SK_DEBUG
1418 void SkImageInfo::validate() const { 1426 void SkImageInfo::validate() const {
1419 SkASSERT(fWidth >= 0); 1427 SkASSERT(fWidth >= 0);
1420 SkASSERT(fHeight >= 0); 1428 SkASSERT(fHeight >= 0);
1421 SkASSERT(SkColorTypeIsValid(fColorType)); 1429 SkASSERT(SkColorTypeIsValid(fColorType));
1422 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); 1430 SkASSERT(SkAlphaTypeIsValid(fAlphaType));
1423 } 1431 }
1424 #endif 1432 #endif
OLDNEW
« no previous file with comments | « include/gpu/SkGrPixelRef.h ('k') | src/gpu/SkGrPixelRef.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698