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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/gpu/SkGrPixelRef.h ('k') | src/gpu/SkGrPixelRef.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkBitmap.cpp
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index 9fb041ff8e7fc56947fc3a2f3a2c74bdb9d97464..84f363e564f2a7a46e6928c430d2744dca88bb46 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -315,14 +315,7 @@
const SkImageInfo& prInfo = pr->info();
SkASSERT(info.fWidth <= prInfo.fWidth);
SkASSERT(info.fHeight <= prInfo.fHeight);
- // We can't always assert that the two colortypes are the same, since ganesh is free
- // to change the 32bit swizzles as needed (e.g. RGBA <--> BGRA), so we have a softer
- // check.
- //
- // TODO: perhaps setPixelRef should just overwrite the values in the the bitmap anyway.
- if (info.fColorType != prInfo.fColorType) {
- SkASSERT(4 == info.bytesPerPixel() && 4 == prInfo.bytesPerPixel());
- }
+ SkASSERT(info.fColorType == prInfo.fColorType);
switch (prInfo.fAlphaType) {
case kIgnore_SkAlphaType:
SkASSERT(fInfo.fAlphaType == kIgnore_SkAlphaType);
@@ -892,7 +885,7 @@
if (fPixelRef->getTexture() != NULL) {
// Do a deep copy
- SkPixelRef* pixelRef = fPixelRef->deepCopy(&subset);
+ SkPixelRef* pixelRef = fPixelRef->deepCopy(this->config(), &subset);
if (pixelRef != NULL) {
SkBitmap dst;
dst.setConfig(this->config(), subset.width(), subset.height(), 0,
@@ -1092,7 +1085,8 @@
}
bool SkBitmap::deepCopyTo(SkBitmap* dst) const {
- const SkColorType dstCT = this->colorType();
+ const SkBitmap::Config dstConfig = this->config();
+ const SkColorType dstCT = SkBitmapConfigToColorType(dstConfig);
if (!this->canCopyTo(dstCT)) {
return false;
@@ -1101,13 +1095,27 @@
// If we have a PixelRef, and it supports deep copy, use it.
// Currently supported only by texture-backed bitmaps.
if (fPixelRef) {
- SkAutoTUnref<SkPixelRef> pixelRef(fPixelRef->deepCopy());
- if (pixelRef.get()) {
- pixelRef->cloneGenID(*fPixelRef);
- if (!dst->setConfig(pixelRef->info(), fRowBytes)) {
+ SkPixelRef* pixelRef = fPixelRef->deepCopy(dstConfig);
+ if (pixelRef) {
+ uint32_t rowBytes;
+ if (this->colorType() == dstCT) {
+ // Since there is no subset to pass to deepCopy, and deepCopy
+ // succeeded, the new pixel ref must be identical.
+ SkASSERT(fPixelRef->info() == pixelRef->info());
+ pixelRef->cloneGenID(*fPixelRef);
+ // Use the same rowBytes as the original.
+ rowBytes = fRowBytes;
+ } else {
+ // With the new config, an appropriate fRowBytes will be computed by setConfig.
+ rowBytes = 0;
+ }
+
+ SkImageInfo info = fInfo;
+ info.fColorType = dstCT;
+ if (!dst->setConfig(info, rowBytes)) {
return false;
}
- dst->setPixelRef(pixelRef, fPixelRefOrigin);
+ dst->setPixelRef(pixelRef, fPixelRefOrigin)->unref();
return true;
}
}
« 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