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
diff --git a/gm/bitmapcopy.cpp b/gm/bitmapcopy.cpp
index f210b4a..5bd2bf8 100644
--- a/gm/bitmapcopy.cpp
+++ b/gm/bitmapcopy.cpp
@@ -72,9 +72,7 @@
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);
diff --git a/gm/simpleaaclip.cpp b/gm/simpleaaclip.cpp
index a517b50..41fb9fba6 100644
--- a/gm/simpleaaclip.cpp
+++ b/gm/simpleaaclip.cpp
@@ -26,7 +26,7 @@
// 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,
diff --git a/include/core/SkBitmap.h b/include/core/SkBitmap.h
index 92d7473..80ccd0a 100644
--- a/include/core/SkBitmap.h
+++ b/include/core/SkBitmap.h
@@ -23,6 +23,8 @@
class SkRegion;
class SkString;
+#define SK_SUPPORT_DEEPCOPYTO_CONFIG
+
class GrTexture;
/** \class SkBitmap
@@ -637,7 +639,19 @@
* 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().
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp
index 6c9e81f..520ccd3 100644
--- a/src/core/SkBitmap.cpp
+++ b/src/core/SkBitmap.cpp
@@ -1173,6 +1173,10 @@
}
}
+bool SkBitmap::deepCopyTo(SkBitmap* dst) const {
+ return this->deepCopyTo(dst, this->config());
+}
+
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/SkBitmapHeap.cpp b/src/core/SkBitmapHeap.cpp
index da62893..efaa23f 100644
--- a/src/core/SkBitmapHeap.cpp
+++ b/src/core/SkBitmapHeap.cpp
@@ -265,7 +265,7 @@
// 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();
diff --git a/src/image/SkSurface_Raster.cpp b/src/image/SkSurface_Raster.cpp
index 1b218eb..e24c0e8 100644
--- a/src/image/SkSurface_Raster.cpp
+++ b/src/image/SkSurface_Raster.cpp
@@ -125,7 +125,7 @@
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
diff --git a/src/pdf/SkPDFImage.cpp b/src/pdf/SkPDFImage.cpp
index 81adcc2..f39dc59 100644
--- a/src/pdf/SkPDFImage.cpp
+++ b/src/pdf/SkPDFImage.cpp
@@ -507,7 +507,7 @@
if (bitmap.isImmutable()) {
fBitmap = bitmap;
} else {
- bitmap.deepCopyTo(&fBitmap, bitmap.config());
+ bitmap.deepCopyTo(&fBitmap);
fBitmap.setImmutable();
}
diff --git a/tests/GpuBitmapCopyTest.cpp b/tests/GpuBitmapCopyTest.cpp
index 08ceff2..d5485bb 100644
--- a/tests/GpuBitmapCopyTest.cpp
+++ b/tests/GpuBitmapCopyTest.cpp
@@ -161,6 +161,7 @@
// 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 @@
true);
}
} // for (size_t j = ...
+#endif
} // for (size_t i = ...
} // GrContextFactory::GLContextType
}