diff options
author | 2014-05-21 15:58:00 +0000 | |
---|---|---|
committer | 2014-05-21 15:58:00 +0000 | |
commit | eeef0cc49bf71e8b5e044d6a73b79cfe2b2c87b3 (patch) | |
tree | 36a3011620b57c6a4bbf998de1b292676f5e7ede | |
parent | af159a580b29488c717c8ae7ee442dbe006a20ba (diff) |
Revert of Revert ""Revert of eliminate config param -- it was always self's config (https://codereview.chromi… (https://codereview.chromium.org/291163005/)
Reason for revert:
broke 6 webgl/canvas tests in blink (don't know why yet)
https://storage.googleapis.com/chromium-layout-test-archives/WebKit_Mac10_7/27348/layout-test-results/results.html
Original issue's description:
> Revert ""Revert of eliminate config param -- it was always self's config (https://codereview.chromium.org/246513002/)"""
>
> This reverts commit 3dbceb4f8283b2fb1728d0daf010d036099a2eae.
>
> BUG=skia:
>
> Committed: http://code.google.com/p/skia/source/detail?r=14806
R=bsalomon@google.com, robertphillips@google.com
TBR=bsalomon@google.com, robertphillips@google.com
NOTREECHECKS=true
NOTRY=true
BUG=skia:
Author: reed@google.com
Review URL: https://codereview.chromium.org/295093003
git-svn-id: http://skia.googlecode.com/svn/trunk@14826 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | include/core/SkPixelRef.h | 3 | ||||
-rw-r--r-- | include/gpu/SkGrPixelRef.h | 2 | ||||
-rw-r--r-- | src/core/SkBitmap.cpp | 38 | ||||
-rw-r--r-- | src/gpu/SkGrPixelRef.cpp | 9 |
4 files changed, 31 insertions, 21 deletions
diff --git a/include/core/SkPixelRef.h b/include/core/SkPixelRef.h index 579ca5b7e8..8319ec6da5 100644 --- a/include/core/SkPixelRef.h +++ b/include/core/SkPixelRef.h @@ -223,13 +223,14 @@ public: /** * Makes a deep copy of this PixelRef, respecting the requested config. + * @param config Desired config. * @param subset Subset of this PixelRef to copy. Must be fully contained within the bounds of * of this PixelRef. * @return A new SkPixelRef, or NULL if either there is an error (e.g. the destination could * not be created with the given config), or this PixelRef does not support deep * copies. */ - virtual SkPixelRef* deepCopy(const SkIRect* subset = NULL) { + virtual SkPixelRef* deepCopy(SkBitmap::Config config, const SkIRect* subset = NULL) { return NULL; } diff --git a/include/gpu/SkGrPixelRef.h b/include/gpu/SkGrPixelRef.h index 702a3bf871..1e495611fc 100644 --- a/include/gpu/SkGrPixelRef.h +++ b/include/gpu/SkGrPixelRef.h @@ -56,7 +56,7 @@ public: protected: // overrides from SkPixelRef virtual bool onReadPixels(SkBitmap* dst, const SkIRect* subset) SK_OVERRIDE; - virtual SkPixelRef* deepCopy(const SkIRect* subset) SK_OVERRIDE; + virtual SkPixelRef* deepCopy(SkBitmap::Config dstConfig, const SkIRect* subset) SK_OVERRIDE; private: GrSurface* fSurface; diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp index 9fb041ff8e..84f363e564 100644 --- a/src/core/SkBitmap.cpp +++ b/src/core/SkBitmap.cpp @@ -315,14 +315,7 @@ SkPixelRef* SkBitmap::setPixelRef(SkPixelRef* pr, int dx, int dy) { 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 @@ bool SkBitmap::extractSubset(SkBitmap* result, const SkIRect& subset) const { 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::copyTo(SkBitmap* dst, SkColorType dstColorType, } 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 @@ bool SkBitmap::deepCopyTo(SkBitmap* dst) const { // 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; } } diff --git a/src/gpu/SkGrPixelRef.cpp b/src/gpu/SkGrPixelRef.cpp index 85de285779..fd21f1073b 100644 --- a/src/gpu/SkGrPixelRef.cpp +++ b/src/gpu/SkGrPixelRef.cpp @@ -51,7 +51,8 @@ bool SkROLockPixelsPixelRef::onLockPixelsAreWritable() const { /////////////////////////////////////////////////////////////////////////////// -static SkGrPixelRef* copyToTexturePixelRef(GrTexture* texture, const SkIRect* subset) { +static SkGrPixelRef* copyToTexturePixelRef(GrTexture* texture, SkBitmap::Config dstConfig, + const SkIRect* subset) { if (NULL == texture) { return NULL; } @@ -76,7 +77,7 @@ static SkGrPixelRef* copyToTexturePixelRef(GrTexture* texture, const SkIRect* su topLeft = NULL; } desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; - desc.fConfig = texture->config(); + desc.fConfig = SkBitmapConfig2GrPixelConfig(dstConfig); SkImageInfo info; if (!GrPixelConfig2ColorType(desc.fConfig, &info.fColorType)) { @@ -151,7 +152,7 @@ GrTexture* SkGrPixelRef::getTexture() { return NULL; } -SkPixelRef* SkGrPixelRef::deepCopy(const SkIRect* subset) { +SkPixelRef* SkGrPixelRef::deepCopy(SkBitmap::Config dstConfig, const SkIRect* subset) { if (NULL == fSurface) { return NULL; } @@ -162,7 +163,7 @@ SkPixelRef* SkGrPixelRef::deepCopy(const SkIRect* subset) { // a GrTexture owned elsewhere (e.g., SkGpuDevice), and cannot live // independently of that texture. Texture-backed pixel refs, on the other // hand, own their GrTextures, and are thus self-contained. - return copyToTexturePixelRef(fSurface->asTexture(), subset); + return copyToTexturePixelRef(fSurface->asTexture(), dstConfig, subset); } bool SkGrPixelRef::onReadPixels(SkBitmap* dst, const SkIRect* subset) { |