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

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

Issue 302053002: Revert of setConfig -> setInfo (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 6 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/core/SkBitmap.h ('k') | src/core/SkBitmapDevice.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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 break; 195 break;
196 default: 196 default:
197 return false; 197 return false;
198 } 198 }
199 if (canonical) { 199 if (canonical) {
200 *canonical = alphaType; 200 *canonical = alphaType;
201 } 201 }
202 return true; 202 return true;
203 } 203 }
204 204
205 bool SkBitmap::setInfo(const SkImageInfo& origInfo, size_t rowBytes) { 205 bool SkBitmap::setConfig(const SkImageInfo& origInfo, size_t rowBytes) {
206 SkImageInfo info = origInfo; 206 SkImageInfo info = origInfo;
207 207
208 if (!validate_alphaType(info.fColorType, info.fAlphaType, 208 if (!validate_alphaType(info.fColorType, info.fAlphaType,
209 &info.fAlphaType)) { 209 &info.fAlphaType)) {
210 return reset_return_false(this); 210 return reset_return_false(this);
211 } 211 }
212 212
213 // require that rowBytes fit in 31bits 213 // require that rowBytes fit in 31bits
214 int64_t mrb = info.minRowBytes64(); 214 int64_t mrb = info.minRowBytes64();
215 if ((int32_t)mrb != mrb) { 215 if ((int32_t)mrb != mrb) {
(...skipping 18 matching lines...) Expand all
234 this->freePixels(); 234 this->freePixels();
235 235
236 fInfo = info; 236 fInfo = info;
237 fRowBytes = SkToU32(rowBytes); 237 fRowBytes = SkToU32(rowBytes);
238 return true; 238 return true;
239 } 239 }
240 240
241 bool SkBitmap::setConfig(Config config, int width, int height, size_t rowBytes, 241 bool SkBitmap::setConfig(Config config, int width, int height, size_t rowBytes,
242 SkAlphaType alphaType) { 242 SkAlphaType alphaType) {
243 SkColorType ct = SkBitmapConfigToColorType(config); 243 SkColorType ct = SkBitmapConfigToColorType(config);
244 return this->setInfo(SkImageInfo::Make(width, height, ct, alphaType), rowByt es); 244 return this->setConfig(SkImageInfo::Make(width, height, ct, alphaType),
245 rowBytes);
245 } 246 }
246 247
247 bool SkBitmap::setAlphaType(SkAlphaType alphaType) { 248 bool SkBitmap::setAlphaType(SkAlphaType alphaType) {
248 if (!validate_alphaType(fInfo.fColorType, alphaType, &alphaType)) { 249 if (!validate_alphaType(fInfo.fColorType, alphaType, &alphaType)) {
249 return false; 250 return false;
250 } 251 }
251 if (fInfo.fAlphaType != alphaType) { 252 if (fInfo.fAlphaType != alphaType) {
252 fInfo.fAlphaType = alphaType; 253 fInfo.fAlphaType = alphaType;
253 if (fPixelRef) { 254 if (fPixelRef) {
254 fPixelRef->changeAlphaType(alphaType); 255 fPixelRef->changeAlphaType(alphaType);
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 return allocator->allocPixelRef(this, ctable); 412 return allocator->allocPixelRef(this, ctable);
412 } 413 }
413 414
414 /////////////////////////////////////////////////////////////////////////////// 415 ///////////////////////////////////////////////////////////////////////////////
415 416
416 bool SkBitmap::allocPixels(const SkImageInfo& info, SkPixelRefFactory* factory, 417 bool SkBitmap::allocPixels(const SkImageInfo& info, SkPixelRefFactory* factory,
417 SkColorTable* ctable) { 418 SkColorTable* ctable) {
418 if (kIndex_8_SkColorType == info.fColorType && NULL == ctable) { 419 if (kIndex_8_SkColorType == info.fColorType && NULL == ctable) {
419 return reset_return_false(this); 420 return reset_return_false(this);
420 } 421 }
421 if (!this->setInfo(info)) { 422 if (!this->setConfig(info)) {
422 return reset_return_false(this); 423 return reset_return_false(this);
423 } 424 }
424 425
425 SkMallocPixelRef::PRFactory defaultFactory; 426 SkMallocPixelRef::PRFactory defaultFactory;
426 if (NULL == factory) { 427 if (NULL == factory) {
427 factory = &defaultFactory; 428 factory = &defaultFactory;
428 } 429 }
429 430
430 SkPixelRef* pr = factory->create(info, ctable); 431 SkPixelRef* pr = factory->create(info, ctable);
431 if (NULL == pr) { 432 if (NULL == pr) {
432 return reset_return_false(this); 433 return reset_return_false(this);
433 } 434 }
434 this->setPixelRef(pr)->unref(); 435 this->setPixelRef(pr)->unref();
435 436
436 // TODO: lockPixels could/should return bool or void*/NULL 437 // TODO: lockPixels could/should return bool or void*/NULL
437 this->lockPixels(); 438 this->lockPixels();
438 if (NULL == this->getPixels()) { 439 if (NULL == this->getPixels()) {
439 return reset_return_false(this); 440 return reset_return_false(this);
440 } 441 }
441 return true; 442 return true;
442 } 443 }
443 444
444 bool SkBitmap::installPixels(const SkImageInfo& info, void* pixels, size_t rb, S kColorTable* ct, 445 bool SkBitmap::installPixels(const SkImageInfo& info, void* pixels, size_t rb, S kColorTable* ct,
445 void (*releaseProc)(void* addr, void* context), voi d* context) { 446 void (*releaseProc)(void* addr, void* context), voi d* context) {
446 if (!this->setInfo(info, rb)) { 447 if (!this->setConfig(info, rb)) {
447 this->reset(); 448 this->reset();
448 return false; 449 return false;
449 } 450 }
450 451
451 SkPixelRef* pr = SkMallocPixelRef::NewWithProc(info, rb, ct, pixels, release Proc, context); 452 SkPixelRef* pr = SkMallocPixelRef::NewWithProc(info, rb, ct, pixels, release Proc, context);
452 if (!pr) { 453 if (!pr) {
453 this->reset(); 454 this->reset();
454 return false; 455 return false;
455 } 456 }
456 457
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 srcRect.set(0, 0, this->width(), this->height()); 877 srcRect.set(0, 0, this->width(), this->height());
877 if (!r.intersect(srcRect, subset)) { 878 if (!r.intersect(srcRect, subset)) {
878 return false; // r is empty (i.e. no intersection) 879 return false; // r is empty (i.e. no intersection)
879 } 880 }
880 881
881 if (fPixelRef->getTexture() != NULL) { 882 if (fPixelRef->getTexture() != NULL) {
882 // Do a deep copy 883 // Do a deep copy
883 SkPixelRef* pixelRef = fPixelRef->deepCopy(this->config(), &subset); 884 SkPixelRef* pixelRef = fPixelRef->deepCopy(this->config(), &subset);
884 if (pixelRef != NULL) { 885 if (pixelRef != NULL) {
885 SkBitmap dst; 886 SkBitmap dst;
886 dst.setInfo(SkImageInfo::Make(subset.width(), subset.height(), 887 dst.setConfig(SkImageInfo::Make(subset.width(), subset.height(),
887 this->colorType(), this->alphaType())) ; 888 this->colorType(), this->alphaType() ));
888 dst.setIsVolatile(this->isVolatile()); 889 dst.setIsVolatile(this->isVolatile());
889 dst.setPixelRef(pixelRef)->unref(); 890 dst.setPixelRef(pixelRef)->unref();
890 SkDEBUGCODE(dst.validate()); 891 SkDEBUGCODE(dst.validate());
891 result->swap(dst); 892 result->swap(dst);
892 return true; 893 return true;
893 } 894 }
894 } 895 }
895 896
896 // If the upper left of the rectangle was outside the bounds of this SkBitma p, we should have 897 // If the upper left of the rectangle was outside the bounds of this SkBitma p, we should have
897 // exited above. 898 // exited above.
898 SkASSERT(static_cast<unsigned>(r.fLeft) < static_cast<unsigned>(this->width( ))); 899 SkASSERT(static_cast<unsigned>(r.fLeft) < static_cast<unsigned>(this->width( )));
899 SkASSERT(static_cast<unsigned>(r.fTop) < static_cast<unsigned>(this->height( ))); 900 SkASSERT(static_cast<unsigned>(r.fTop) < static_cast<unsigned>(this->height( )));
900 901
901 SkBitmap dst; 902 SkBitmap dst;
902 dst.setInfo(SkImageInfo::Make(r.width(), r.height(), this->colorType(), this ->alphaType()), 903 dst.setConfig(SkImageInfo::Make(r.width(), r.height(), this->colorType(), th is->alphaType()),
903 this->rowBytes()); 904 this->rowBytes());
904 dst.setIsVolatile(this->isVolatile()); 905 dst.setIsVolatile(this->isVolatile());
905 906
906 if (fPixelRef) { 907 if (fPixelRef) {
907 SkIPoint origin = fPixelRefOrigin; 908 SkIPoint origin = fPixelRefOrigin;
908 origin.fX += r.fLeft; 909 origin.fX += r.fLeft;
909 origin.fY += r.fTop; 910 origin.fY += r.fTop;
910 // share the pixelref with a custom offset 911 // share the pixelref with a custom offset
911 dst.setPixelRef(fPixelRef, origin); 912 dst.setPixelRef(fPixelRef, origin);
912 } 913 }
913 SkDEBUGCODE(dst.validate();) 914 SkDEBUGCODE(dst.validate();)
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 return false; 987 return false;
987 } 988 }
988 989
989 // The only way to be readyToDraw is if fPixelRef is non NULL. 990 // The only way to be readyToDraw is if fPixelRef is non NULL.
990 SkASSERT(fPixelRef != NULL); 991 SkASSERT(fPixelRef != NULL);
991 992
992 SkImageInfo dstInfo = src->info(); 993 SkImageInfo dstInfo = src->info();
993 dstInfo.fColorType = dstColorType; 994 dstInfo.fColorType = dstColorType;
994 995
995 SkBitmap tmpDst; 996 SkBitmap tmpDst;
996 if (!tmpDst.setInfo(dstInfo)) { 997 if (!tmpDst.setConfig(dstInfo)) {
997 return false; 998 return false;
998 } 999 }
999 1000
1000 // allocate colortable if srcConfig == kIndex8_Config 1001 // allocate colortable if srcConfig == kIndex8_Config
1001 SkAutoTUnref<SkColorTable> ctable; 1002 SkAutoTUnref<SkColorTable> ctable;
1002 if (dstColorType == kIndex_8_SkColorType) { 1003 if (dstColorType == kIndex_8_SkColorType) {
1003 // TODO: can we just ref() the src colortable? Is it reentrant-safe? 1004 // TODO: can we just ref() the src colortable? Is it reentrant-safe?
1004 ctable.reset(SkNEW_ARGS(SkColorTable, (*src->getColorTable()))); 1005 ctable.reset(SkNEW_ARGS(SkColorTable, (*src->getColorTable())));
1005 } 1006 }
1006 if (!tmpDst.allocPixels(alloc, ctable)) { 1007 if (!tmpDst.allocPixels(alloc, ctable)) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 if (pixelRef) { 1095 if (pixelRef) {
1095 uint32_t rowBytes; 1096 uint32_t rowBytes;
1096 if (this->colorType() == dstCT) { 1097 if (this->colorType() == dstCT) {
1097 // Since there is no subset to pass to deepCopy, and deepCopy 1098 // Since there is no subset to pass to deepCopy, and deepCopy
1098 // succeeded, the new pixel ref must be identical. 1099 // succeeded, the new pixel ref must be identical.
1099 SkASSERT(fPixelRef->info() == pixelRef->info()); 1100 SkASSERT(fPixelRef->info() == pixelRef->info());
1100 pixelRef->cloneGenID(*fPixelRef); 1101 pixelRef->cloneGenID(*fPixelRef);
1101 // Use the same rowBytes as the original. 1102 // Use the same rowBytes as the original.
1102 rowBytes = fRowBytes; 1103 rowBytes = fRowBytes;
1103 } else { 1104 } else {
1104 // With the new config, an appropriate fRowBytes will be compute d by setInfo. 1105 // With the new config, an appropriate fRowBytes will be compute d by setConfig.
1105 rowBytes = 0; 1106 rowBytes = 0;
1106 } 1107 }
1107 1108
1108 SkImageInfo info = fInfo; 1109 SkImageInfo info = fInfo;
1109 info.fColorType = dstCT; 1110 info.fColorType = dstCT;
1110 if (!dst->setInfo(info, rowBytes)) { 1111 if (!dst->setConfig(info, rowBytes)) {
1111 return false; 1112 return false;
1112 } 1113 }
1113 dst->setPixelRef(pixelRef, fPixelRefOrigin)->unref(); 1114 dst->setPixelRef(pixelRef, fPixelRefOrigin)->unref();
1114 return true; 1115 return true;
1115 } 1116 }
1116 } 1117 }
1117 1118
1118 if (this->getTexture()) { 1119 if (this->getTexture()) {
1119 return false; 1120 return false;
1120 } else { 1121 } else {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 // compute our (larger?) dst bounds if we have a filter 1211 // compute our (larger?) dst bounds if we have a filter
1211 if (NULL != filter) { 1212 if (NULL != filter) {
1212 identity.reset(); 1213 identity.reset();
1213 srcM.fImage = NULL; 1214 srcM.fImage = NULL;
1214 if (!filter->filterMask(&dstM, srcM, identity, NULL)) { 1215 if (!filter->filterMask(&dstM, srcM, identity, NULL)) {
1215 goto NO_FILTER_CASE; 1216 goto NO_FILTER_CASE;
1216 } 1217 }
1217 dstM.fRowBytes = SkAlign4(dstM.fBounds.width()); 1218 dstM.fRowBytes = SkAlign4(dstM.fBounds.width());
1218 } else { 1219 } else {
1219 NO_FILTER_CASE: 1220 NO_FILTER_CASE:
1220 tmpBitmap.setInfo(SkImageInfo::MakeA8(this->width(), this->height()), sr cM.fRowBytes); 1221 tmpBitmap.setConfig(SkImageInfo::MakeA8(this->width(), this->height()), srcM.fRowBytes);
1221 if (!tmpBitmap.allocPixels(allocator, NULL)) { 1222 if (!tmpBitmap.allocPixels(allocator, NULL)) {
1222 // Allocation of pixels for alpha bitmap failed. 1223 // Allocation of pixels for alpha bitmap failed.
1223 SkDebugf("extractAlpha failed to allocate (%d,%d) alpha bitmap\n", 1224 SkDebugf("extractAlpha failed to allocate (%d,%d) alpha bitmap\n",
1224 tmpBitmap.width(), tmpBitmap.height()); 1225 tmpBitmap.width(), tmpBitmap.height());
1225 return false; 1226 return false;
1226 } 1227 }
1227 GetBitmapAlpha(*this, tmpBitmap.getAddr8(0, 0), srcM.fRowBytes); 1228 GetBitmapAlpha(*this, tmpBitmap.getAddr8(0, 0), srcM.fRowBytes);
1228 if (offset) { 1229 if (offset) {
1229 offset->set(0, 0); 1230 offset->set(0, 0);
1230 } 1231 }
1231 tmpBitmap.swap(*dst); 1232 tmpBitmap.swap(*dst);
1232 return true; 1233 return true;
1233 } 1234 }
1234 srcM.fImage = SkMask::AllocImage(srcM.computeImageSize()); 1235 srcM.fImage = SkMask::AllocImage(srcM.computeImageSize());
1235 SkAutoMaskFreeImage srcCleanup(srcM.fImage); 1236 SkAutoMaskFreeImage srcCleanup(srcM.fImage);
1236 1237
1237 GetBitmapAlpha(*this, srcM.fImage, srcM.fRowBytes); 1238 GetBitmapAlpha(*this, srcM.fImage, srcM.fRowBytes);
1238 if (!filter->filterMask(&dstM, srcM, identity, NULL)) { 1239 if (!filter->filterMask(&dstM, srcM, identity, NULL)) {
1239 goto NO_FILTER_CASE; 1240 goto NO_FILTER_CASE;
1240 } 1241 }
1241 SkAutoMaskFreeImage dstCleanup(dstM.fImage); 1242 SkAutoMaskFreeImage dstCleanup(dstM.fImage);
1242 1243
1243 tmpBitmap.setInfo(SkImageInfo::MakeA8(dstM.fBounds.width(), dstM.fBounds.hei ght()), 1244 tmpBitmap.setConfig(SkImageInfo::MakeA8(dstM.fBounds.width(), dstM.fBounds.h eight()),
1244 dstM.fRowBytes); 1245 dstM.fRowBytes);
1245 if (!tmpBitmap.allocPixels(allocator, NULL)) { 1246 if (!tmpBitmap.allocPixels(allocator, NULL)) {
1246 // Allocation of pixels for alpha bitmap failed. 1247 // Allocation of pixels for alpha bitmap failed.
1247 SkDebugf("extractAlpha failed to allocate (%d,%d) alpha bitmap\n", 1248 SkDebugf("extractAlpha failed to allocate (%d,%d) alpha bitmap\n",
1248 tmpBitmap.width(), tmpBitmap.height()); 1249 tmpBitmap.width(), tmpBitmap.height());
1249 return false; 1250 return false;
1250 } 1251 }
1251 memcpy(tmpBitmap.getPixels(), dstM.fImage, dstM.computeImageSize()); 1252 memcpy(tmpBitmap.getPixels(), dstM.fImage, dstM.computeImageSize());
1252 if (offset) { 1253 if (offset) {
1253 offset->set(dstM.fBounds.fLeft, dstM.fBounds.fTop); 1254 offset->set(dstM.fBounds.fLeft, dstM.fBounds.fTop);
1254 } 1255 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1324 SkASSERT(srcRow == dstRow); // first row does not need to be moved 1325 SkASSERT(srcRow == dstRow); // first row does not need to be moved
1325 } 1326 }
1326 1327
1327 SkAutoTUnref<SkColorTable> ctable; 1328 SkAutoTUnref<SkColorTable> ctable;
1328 if (buffer->readBool()) { 1329 if (buffer->readBool()) {
1329 ctable.reset(SkNEW_ARGS(SkColorTable, (*buffer))); 1330 ctable.reset(SkNEW_ARGS(SkColorTable, (*buffer)));
1330 } 1331 }
1331 1332
1332 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewWithData(info, info.minRowB ytes(), 1333 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewWithData(info, info.minRowB ytes(),
1333 ctable.get(), data .get())); 1334 ctable.get(), data .get()));
1334 bitmap->setInfo(pr->info()); 1335 bitmap->setConfig(pr->info());
1335 bitmap->setPixelRef(pr, 0, 0); 1336 bitmap->setPixelRef(pr, 0, 0);
1336 return true; 1337 return true;
1337 } 1338 }
1338 1339
1339 enum { 1340 enum {
1340 SERIALIZE_PIXELTYPE_NONE, 1341 SERIALIZE_PIXELTYPE_NONE,
1341 SERIALIZE_PIXELTYPE_REF_DATA 1342 SERIALIZE_PIXELTYPE_REF_DATA
1342 }; 1343 };
1343 1344
1344 void SkBitmap::legacyUnflatten(SkReadBuffer& buffer) { 1345 void SkBitmap::legacyUnflatten(SkReadBuffer& buffer) {
1345 this->reset(); 1346 this->reset();
1346 1347
1347 SkImageInfo info; 1348 SkImageInfo info;
1348 info.unflatten(buffer); 1349 info.unflatten(buffer);
1349 size_t rowBytes = buffer.readInt(); 1350 size_t rowBytes = buffer.readInt();
1350 if (!buffer.validate((info.width() >= 0) && (info.height() >= 0) && 1351 if (!buffer.validate((info.width() >= 0) && (info.height() >= 0) &&
1351 SkColorTypeIsValid(info.fColorType) && 1352 SkColorTypeIsValid(info.fColorType) &&
1352 SkAlphaTypeIsValid(info.fAlphaType) && 1353 SkAlphaTypeIsValid(info.fAlphaType) &&
1353 validate_alphaType(info.fColorType, info.fAlphaType) && 1354 validate_alphaType(info.fColorType, info.fAlphaType) &&
1354 info.validRowBytes(rowBytes))) { 1355 info.validRowBytes(rowBytes))) {
1355 return; 1356 return;
1356 } 1357 }
1357 1358
1358 bool configIsValid = this->setInfo(info, rowBytes); 1359 bool configIsValid = this->setConfig(info, rowBytes);
1359 buffer.validate(configIsValid); 1360 buffer.validate(configIsValid);
1360 1361
1361 int reftype = buffer.readInt(); 1362 int reftype = buffer.readInt();
1362 if (buffer.validate((SERIALIZE_PIXELTYPE_REF_DATA == reftype) || 1363 if (buffer.validate((SERIALIZE_PIXELTYPE_REF_DATA == reftype) ||
1363 (SERIALIZE_PIXELTYPE_NONE == reftype))) { 1364 (SERIALIZE_PIXELTYPE_NONE == reftype))) {
1364 switch (reftype) { 1365 switch (reftype) {
1365 case SERIALIZE_PIXELTYPE_REF_DATA: { 1366 case SERIALIZE_PIXELTYPE_REF_DATA: {
1366 SkIPoint origin; 1367 SkIPoint origin;
1367 origin.fX = buffer.readInt(); 1368 origin.fX = buffer.readInt();
1368 origin.fY = buffer.readInt(); 1369 origin.fY = buffer.readInt();
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1474 /////////////////////////////////////////////////////////////////////////////// 1475 ///////////////////////////////////////////////////////////////////////////////
1475 1476
1476 #ifdef SK_DEBUG 1477 #ifdef SK_DEBUG
1477 void SkImageInfo::validate() const { 1478 void SkImageInfo::validate() const {
1478 SkASSERT(fWidth >= 0); 1479 SkASSERT(fWidth >= 0);
1479 SkASSERT(fHeight >= 0); 1480 SkASSERT(fHeight >= 0);
1480 SkASSERT(SkColorTypeIsValid(fColorType)); 1481 SkASSERT(SkColorTypeIsValid(fColorType));
1481 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); 1482 SkASSERT(SkAlphaTypeIsValid(fAlphaType));
1482 } 1483 }
1483 #endif 1484 #endif
OLDNEW
« no previous file with comments | « include/core/SkBitmap.h ('k') | src/core/SkBitmapDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698