Offer single-param version of deepCopyTo -- much easier to migrate to colortypes

BUG=skia:
R=reed@google.com

Author: reed@chromium.org

Review URL: https://codereview.chromium.org/167683006

git-svn-id: http://skia.googlecode.com/svn/trunk@13516 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
commit-bot@chromium.org 2014-02-20 19:08:07 +00:00
parent 3613abe3de
commit 6285f4f766
8 changed files with 25 additions and 7 deletions

View File

@ -72,9 +72,7 @@ protected:
draw_checks(&canvasTmp, 40, 40);
for (unsigned i = 0; i < NUM_CONFIGS; ++i) {
if (!src.deepCopyTo(&fDst[i], gConfigs[i])) {
src.copyTo(&fDst[i], gConfigs[i]);
}
src.copyTo(&fDst[i], gConfigs[i]);
}
canvas->clear(0xFFDDDDDD);

View File

@ -26,7 +26,7 @@ static void paint_rgn(SkCanvas* canvas, const SkAAClip& clip,
// need to copy for deferred drawing test to work
SkBitmap bm2;
bm.deepCopyTo(&bm2, SkBitmap::kA8_Config);
bm.deepCopyTo(&bm2);
canvas->drawBitmap(bm2,
SK_Scalar1 * mask.fBounds.fLeft,

View File

@ -23,6 +23,8 @@ class SkPixelRefFactory;
class SkRegion;
class SkString;
#define SK_SUPPORT_DEEPCOPYTO_CONFIG
class GrTexture;
/** \class SkBitmap
@ -637,7 +639,19 @@ public:
* gpu (typically as a texture), the it will do the same for the dst.
* If the request cannot be fulfilled, returns false and dst is unmodified.
*/
#ifndef SK_SUPPORT_DEEPCOPYTO_CONFIG
private:
#endif
bool deepCopyTo(SkBitmap* dst, Config c) const;
public:
/** Makes a deep copy of this bitmap, keeping the copied pixels
* in the same domain as the source: If the src pixels are allocated for
* the cpu, then so will the dst. If the src pixels are allocated on the
* gpu (typically as a texture), the it will do the same for the dst.
* If the request cannot be fulfilled, returns false and dst is unmodified.
*/
bool deepCopyTo(SkBitmap* dst) const;
/** Returns true if this bitmap can be deep copied into the requested config
by calling copyTo().

View File

@ -1173,6 +1173,10 @@ bool SkBitmap::deepCopyTo(SkBitmap* dst, Config dstConfig) const {
}
}
bool SkBitmap::deepCopyTo(SkBitmap* dst) const {
return this->deepCopyTo(dst, this->config());
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

View File

@ -265,7 +265,7 @@ bool SkBitmapHeap::copyBitmap(const SkBitmap& originalBitmap, SkBitmap& copiedBi
// copiedBitmap.setPixelRef(sharedPixelRef, originalBitmap.pixelRefOffset());
} else if (originalBitmap.empty()) {
copiedBitmap.reset();
} else if (!originalBitmap.deepCopyTo(&copiedBitmap, originalBitmap.config())) {
} else if (!originalBitmap.deepCopyTo(&copiedBitmap)) {
return false;
}
copiedBitmap.setImmutable();

View File

@ -125,7 +125,7 @@ void SkSurface_Raster::onCopyOnWrite(ContentChangeMode mode) {
fBitmap.allocPixels();
} else {
SkBitmap prev(fBitmap);
prev.deepCopyTo(&fBitmap, prev.config());
prev.deepCopyTo(&fBitmap);
}
// Now fBitmap is a deep copy of itself (and therefore different from
// what is being used by the image. Next we update the canvas to use

View File

@ -507,7 +507,7 @@ SkPDFImage::SkPDFImage(SkStream* stream,
if (bitmap.isImmutable()) {
fBitmap = bitmap;
} else {
bitmap.deepCopyTo(&fBitmap, bitmap.config());
bitmap.deepCopyTo(&fBitmap);
fBitmap.setImmutable();
}

View File

@ -161,6 +161,7 @@ DEF_GPUTEST(GpuBitmapCopy, reporter, factory) {
// Extract a subset. If this succeeds we will test copying the subset.
SkBitmap subset;
#ifdef SK_SUPPORT_DEEPCOPYTO_CONFIG
const bool extracted = src.extractSubset(&subset, subsetRect);
for (size_t j = 0; j < SK_ARRAY_COUNT(gPairs); j++) {
@ -228,6 +229,7 @@ DEF_GPUTEST(GpuBitmapCopy, reporter, factory) {
true);
}
} // for (size_t j = ...
#endif
} // for (size_t i = ...
} // GrContextFactory::GLContextType
}