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

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

Issue 112113005: Reland "Fix genID cloning bugs." (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Remove unnecessary include Created 6 years, 11 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 | « no previous file | tests/BitmapCopyTest.cpp » ('j') | tests/BitmapCopyTest.cpp » ('J')
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 975 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 if (fPixelRef) { 986 if (fPixelRef) {
987 SkIRect subset; 987 SkIRect subset;
988 subset.setXYWH(fPixelRefOrigin.fX, fPixelRefOrigin.fY, fWidth, fHeight); 988 subset.setXYWH(fPixelRefOrigin.fX, fPixelRefOrigin.fY, fWidth, fHeight);
989 if (fPixelRef->readPixels(&tmpSrc, &subset)) { 989 if (fPixelRef->readPixels(&tmpSrc, &subset)) {
990 SkASSERT(tmpSrc.width() == this->width()); 990 SkASSERT(tmpSrc.width() == this->width());
991 SkASSERT(tmpSrc.height() == this->height()); 991 SkASSERT(tmpSrc.height() == this->height());
992 992
993 // did we get lucky and we can just return tmpSrc? 993 // did we get lucky and we can just return tmpSrc?
994 if (tmpSrc.config() == dstConfig && NULL == alloc) { 994 if (tmpSrc.config() == dstConfig && NULL == alloc) {
995 dst->swap(tmpSrc); 995 dst->swap(tmpSrc);
996 if (dst->pixelRef() && this->config() == dstConfig) { 996 // If the result is an exact copy, clone the gen ID.
997 // TODO(scroggo): fix issue 1742 997 if (dst->pixelRef() && this->config() == dstConfig
reed1 2014/01/09 13:04:50 do we need to compare config && info, or just info
scroggo 2014/01/09 20:45:23 Just info. Fixed.
998 && dst->pixelRef()->info() == fPixelRef->info())
999 {
998 dst->pixelRef()->cloneGenID(*fPixelRef); 1000 dst->pixelRef()->cloneGenID(*fPixelRef);
999 } 1001 }
1000 return true; 1002 return true;
1001 } 1003 }
1002 1004
1003 // fall through to the raster case 1005 // fall through to the raster case
1004 src = &tmpSrc; 1006 src = &tmpSrc;
1005 } 1007 }
1006 } 1008 }
1007 1009
1008 // we lock this now, since we may need its colortable 1010 // we lock this now, since we may need its colortable
1009 SkAutoLockPixels srclock(*src); 1011 SkAutoLockPixels srclock(*src);
1010 if (!src->readyToDraw()) { 1012 if (!src->readyToDraw()) {
1011 return false; 1013 return false;
1012 } 1014 }
1013 1015
1016 // The only way to be readyToDraw is if fPixelRef is non NULL.
1017 SkASSERT(fPixelRef != NULL);
1018
1014 SkBitmap tmpDst; 1019 SkBitmap tmpDst;
1015 tmpDst.setConfig(dstConfig, src->width(), src->height(), 0, 1020 tmpDst.setConfig(dstConfig, src->width(), src->height(), 0,
1016 src->alphaType()); 1021 src->alphaType());
1017 1022
1018 // allocate colortable if srcConfig == kIndex8_Config 1023 // allocate colortable if srcConfig == kIndex8_Config
1019 SkColorTable* ctable = (dstConfig == kIndex8_Config) ? 1024 SkColorTable* ctable = (dstConfig == kIndex8_Config) ?
1020 new SkColorTable(*src->getColorTable()) : NULL; 1025 new SkColorTable(*src->getColorTable()) : NULL;
1021 SkAutoUnref au(ctable); 1026 SkAutoUnref au(ctable);
1022 if (!tmpDst.allocPixels(alloc, ctable)) { 1027 if (!tmpDst.allocPixels(alloc, ctable)) {
1023 return false; 1028 return false;
1024 } 1029 }
1025 1030
1026 if (!tmpDst.readyToDraw()) { 1031 if (!tmpDst.readyToDraw()) {
1027 // allocator/lock failed 1032 // allocator/lock failed
1028 return false; 1033 return false;
1029 } 1034 }
1030 1035
1031 /* do memcpy for the same configs cases, else use drawing 1036 /* do memcpy for the same configs cases, else use drawing
1032 */ 1037 */
1033 if (src->config() == dstConfig) { 1038 if (src->config() == dstConfig) {
1034 if (tmpDst.getSize() == src->getSize()) { 1039 if (tmpDst.getSize() == src->getSize()) {
1035 memcpy(tmpDst.getPixels(), src->getPixels(), src->getSafeSize()); 1040 memcpy(tmpDst.getPixels(), src->getPixels(), src->getSafeSize());
1036 SkPixelRef* pixelRef = tmpDst.pixelRef(); 1041 SkPixelRef* pixelRef = tmpDst.pixelRef();
1037 if (NULL != pixelRef && NULL != fPixelRef) { 1042
1038 // TODO(scroggo): fix issue 1742 1043 // pixelRef must be non NULL or tmpDst.readyToDraw() would have
1044 // returned false.
1045 SkASSERT(pixelRef != NULL);
mtklein 2014/01/09 15:58:07 I might even move this to right after the if(!tmpD
scroggo 2014/01/09 20:45:23 Done.
1046
1047 // If the resulting pixel ref is an exact copy, clone the genID.
1048 if (pixelRef->info() == fPixelRef->info()) {
mtklein 2014/01/09 15:58:07 Is it possible for this test to fail? They've got
scroggo 2014/01/09 20:45:23 It is possible for this test to fail, but it's a l
mtklein 2014/01/09 21:29:18 Thanks, that's tricky. The new comments help a lo
1039 pixelRef->cloneGenID(*fPixelRef); 1049 pixelRef->cloneGenID(*fPixelRef);
1040 } 1050 }
1041 } else { 1051 } else {
1042 const char* srcP = reinterpret_cast<const char*>(src->getPixels()); 1052 const char* srcP = reinterpret_cast<const char*>(src->getPixels());
1043 char* dstP = reinterpret_cast<char*>(tmpDst.getPixels()); 1053 char* dstP = reinterpret_cast<char*>(tmpDst.getPixels());
1044 // to be sure we don't read too much, only copy our logical pixels 1054 // to be sure we don't read too much, only copy our logical pixels
1045 size_t bytesToCopy = tmpDst.width() * tmpDst.bytesPerPixel(); 1055 size_t bytesToCopy = tmpDst.width() * tmpDst.bytesPerPixel();
1046 for (int y = 0; y < tmpDst.height(); y++) { 1056 for (int y = 0; y < tmpDst.height(); y++) {
1047 memcpy(dstP, srcP, bytesToCopy); 1057 memcpy(dstP, srcP, bytesToCopy);
1048 srcP += src->rowBytes(); 1058 srcP += src->rowBytes();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 return false; 1093 return false;
1084 } 1094 }
1085 1095
1086 // If we have a PixelRef, and it supports deep copy, use it. 1096 // If we have a PixelRef, and it supports deep copy, use it.
1087 // Currently supported only by texture-backed bitmaps. 1097 // Currently supported only by texture-backed bitmaps.
1088 if (fPixelRef) { 1098 if (fPixelRef) {
1089 SkPixelRef* pixelRef = fPixelRef->deepCopy(dstConfig); 1099 SkPixelRef* pixelRef = fPixelRef->deepCopy(dstConfig);
1090 if (pixelRef) { 1100 if (pixelRef) {
1091 uint32_t rowBytes; 1101 uint32_t rowBytes;
1092 if (dstConfig == fConfig) { 1102 if (dstConfig == fConfig) {
1093 // TODO(scroggo): fix issue 1742 1103 // Since there is no subset to pass to deepCopy, and deepCopy
1104 // succeeded, the new pixel ref must be identical.
scroggo 2014/01/08 23:34:59 Currently, calling deepCopyTo copies the entire Sk
1105 SkASSERT(fPixelRef->info() == pixelRef->info());
1094 pixelRef->cloneGenID(*fPixelRef); 1106 pixelRef->cloneGenID(*fPixelRef);
1095 // Use the same rowBytes as the original. 1107 // Use the same rowBytes as the original.
1096 rowBytes = fRowBytes; 1108 rowBytes = fRowBytes;
1097 } else { 1109 } else {
1098 // With the new config, an appropriate fRowBytes will be compute d by setConfig. 1110 // With the new config, an appropriate fRowBytes will be compute d by setConfig.
1099 rowBytes = 0; 1111 rowBytes = 0;
1100 } 1112 }
1101 dst->setConfig(dstConfig, fWidth, fHeight, rowBytes); 1113 dst->setConfig(dstConfig, fWidth, fHeight, rowBytes);
1102 dst->setPixelRef(pixelRef, fPixelRefOrigin)->unref(); 1114 dst->setPixelRef(pixelRef, fPixelRefOrigin)->unref();
1103 return true; 1115 return true;
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
1636 if (NULL != uri) { 1648 if (NULL != uri) {
1637 str->appendf(" uri:\"%s\"", uri); 1649 str->appendf(" uri:\"%s\"", uri);
1638 } else { 1650 } else {
1639 str->appendf(" pixelref:%p", pr); 1651 str->appendf(" pixelref:%p", pr);
1640 } 1652 }
1641 } 1653 }
1642 1654
1643 str->append(")"); 1655 str->append(")");
1644 } 1656 }
1645 #endif 1657 #endif
OLDNEW
« no previous file with comments | « no previous file | tests/BitmapCopyTest.cpp » ('j') | tests/BitmapCopyTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698