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

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

Issue 323283002: switch to colortype for deepcopy (Closed) Base URL: https://skia.googlesource.com/skia.git@master
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
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 812 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 } 823 }
824 824
825 SkIRect srcRect, r; 825 SkIRect srcRect, r;
826 srcRect.set(0, 0, this->width(), this->height()); 826 srcRect.set(0, 0, this->width(), this->height());
827 if (!r.intersect(srcRect, subset)) { 827 if (!r.intersect(srcRect, subset)) {
828 return false; // r is empty (i.e. no intersection) 828 return false; // r is empty (i.e. no intersection)
829 } 829 }
830 830
831 if (fPixelRef->getTexture() != NULL) { 831 if (fPixelRef->getTexture() != NULL) {
832 // Do a deep copy 832 // Do a deep copy
833 SkPixelRef* pixelRef = fPixelRef->deepCopy(this->config(), &subset); 833 SkPixelRef* pixelRef = fPixelRef->deepCopy(this->colorType(), &subset);
834 if (pixelRef != NULL) { 834 if (pixelRef != NULL) {
835 SkBitmap dst; 835 SkBitmap dst;
836 dst.setInfo(SkImageInfo::Make(subset.width(), subset.height(), 836 dst.setInfo(SkImageInfo::Make(subset.width(), subset.height(),
837 this->colorType(), this->alphaType())) ; 837 this->colorType(), this->alphaType())) ;
838 dst.setIsVolatile(this->isVolatile()); 838 dst.setIsVolatile(this->isVolatile());
839 dst.setPixelRef(pixelRef)->unref(); 839 dst.setPixelRef(pixelRef)->unref();
840 SkDEBUGCODE(dst.validate()); 840 SkDEBUGCODE(dst.validate());
841 result->swap(dst); 841 result->swap(dst);
842 return true; 842 return true;
843 } 843 }
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 1024
1025 paint.setDither(true); 1025 paint.setDither(true);
1026 canvas.drawBitmap(*src, 0, 0, &paint); 1026 canvas.drawBitmap(*src, 0, 0, &paint);
1027 } 1027 }
1028 1028
1029 dst->swap(tmpDst); 1029 dst->swap(tmpDst);
1030 return true; 1030 return true;
1031 } 1031 }
1032 1032
1033 bool SkBitmap::deepCopyTo(SkBitmap* dst) const { 1033 bool SkBitmap::deepCopyTo(SkBitmap* dst) const {
1034 const SkBitmap::Config dstConfig = this->config(); 1034 const SkColorType dstCT = this->colorType();
1035 const SkColorType dstCT = SkBitmapConfigToColorType(dstConfig);
1036 1035
1037 if (!this->canCopyTo(dstCT)) { 1036 if (!this->canCopyTo(dstCT)) {
1038 return false; 1037 return false;
1039 } 1038 }
1040 1039
1041 // If we have a PixelRef, and it supports deep copy, use it. 1040 // If we have a PixelRef, and it supports deep copy, use it.
1042 // Currently supported only by texture-backed bitmaps. 1041 // Currently supported only by texture-backed bitmaps.
1043 if (fPixelRef) { 1042 if (fPixelRef) {
1044 SkPixelRef* pixelRef = fPixelRef->deepCopy(dstConfig); 1043 SkPixelRef* pixelRef = fPixelRef->deepCopy(dstCT, NULL);
1045 if (pixelRef) { 1044 if (pixelRef) {
1046 uint32_t rowBytes; 1045 uint32_t rowBytes;
1047 if (this->colorType() == dstCT) { 1046 if (this->colorType() == dstCT) {
1048 // Since there is no subset to pass to deepCopy, and deepCopy 1047 // Since there is no subset to pass to deepCopy, and deepCopy
1049 // succeeded, the new pixel ref must be identical. 1048 // succeeded, the new pixel ref must be identical.
1050 SkASSERT(fPixelRef->info() == pixelRef->info()); 1049 SkASSERT(fPixelRef->info() == pixelRef->info());
1051 pixelRef->cloneGenID(*fPixelRef); 1050 pixelRef->cloneGenID(*fPixelRef);
1052 // Use the same rowBytes as the original. 1051 // Use the same rowBytes as the original.
1053 rowBytes = fRowBytes; 1052 rowBytes = fRowBytes;
1054 } else { 1053 } else {
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
1427 /////////////////////////////////////////////////////////////////////////////// 1426 ///////////////////////////////////////////////////////////////////////////////
1428 1427
1429 #ifdef SK_DEBUG 1428 #ifdef SK_DEBUG
1430 void SkImageInfo::validate() const { 1429 void SkImageInfo::validate() const {
1431 SkASSERT(fWidth >= 0); 1430 SkASSERT(fWidth >= 0);
1432 SkASSERT(fHeight >= 0); 1431 SkASSERT(fHeight >= 0);
1433 SkASSERT(SkColorTypeIsValid(fColorType)); 1432 SkASSERT(SkColorTypeIsValid(fColorType));
1434 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); 1433 SkASSERT(SkAlphaTypeIsValid(fAlphaType));
1435 } 1434 }
1436 #endif 1435 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698