aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-05-27 14:14:22 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-05-27 14:14:22 +0000
commit2d970b5128f7270cd01a93e4ce68d0c3ea67ac71 (patch)
tree2592f202dfb36d05e42004ecdb237ddd4471ef9e
parent851155c28e18e3f5b702ef15ee7bfb12f3cbacda (diff)
hide discardable factory from public imagegenerator api
BUG=skia: R=halcanary@google.com, scroggo@google.com, djsollen@google.com Author: reed@google.com Review URL: https://codereview.chromium.org/295243006 git-svn-id: http://skia.googlecode.com/svn/trunk@14889 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--gm/factory.cpp2
-rw-r--r--include/core/SkImageGenerator.h9
-rw-r--r--samplecode/SampleEncode.cpp2
-rw-r--r--samplecode/SamplePicture.cpp2
-rw-r--r--src/core/SkImageGeneratorPriv.h39
-rw-r--r--src/lazy/SkDiscardablePixelRef.cpp9
-rw-r--r--src/lazy/SkDiscardablePixelRef.h3
-rw-r--r--tests/CachedDecodingPixelRefTest.cpp5
-rw-r--r--tests/DrawBitmapRectTest.cpp2
-rw-r--r--tests/ImageDecodingTest.cpp9
-rw-r--r--tests/PictureTest.cpp2
-rw-r--r--tools/LazyDecodeBitmap.cpp2
12 files changed, 61 insertions, 25 deletions
diff --git a/gm/factory.cpp b/gm/factory.cpp
index 29cf7eaa07..bd79c9d81e 100644
--- a/gm/factory.cpp
+++ b/gm/factory.cpp
@@ -12,7 +12,7 @@
#include "SkDiscardableMemoryPool.h"
#include "SkDiscardablePixelRef.h"
#include "SkImageDecoder.h"
-#include "SkImageGenerator.h"
+#include "SkImageGeneratorPriv.h"
#include "SkOSFile.h"
#include "SkStream.h"
diff --git a/include/core/SkImageGenerator.h b/include/core/SkImageGenerator.h
index 220973a0f8..f399ab538e 100644
--- a/include/core/SkImageGenerator.h
+++ b/include/core/SkImageGenerator.h
@@ -8,7 +8,6 @@
#ifndef SkImageGenerator_DEFINED
#define SkImageGenerator_DEFINED
-#include "SkDiscardableMemory.h"
#include "SkImageInfo.h"
class SkBitmap;
@@ -31,15 +30,9 @@ class SkImageGenerator;
* @param destination Upon success, this bitmap will be
* configured and have a pixelref installed.
*
- * @param factory If not NULL, this object will be used as a
- * source of discardable memory when decoding. If NULL, then
- * SkDiscardableMemory::Create() will be called.
- *
* @return true iff successful.
*/
-SK_API bool SkInstallDiscardablePixelRef(SkImageGenerator* generator,
- SkBitmap* destination,
- SkDiscardableMemory::Factory* factory = NULL);
+SK_API bool SkInstallDiscardablePixelRef(SkImageGenerator*, SkBitmap* destination);
/**
diff --git a/samplecode/SampleEncode.cpp b/samplecode/SampleEncode.cpp
index 080c05f5d7..e65b2d3855 100644
--- a/samplecode/SampleEncode.cpp
+++ b/samplecode/SampleEncode.cpp
@@ -196,7 +196,7 @@ protected:
if (!SkInstallDiscardablePixelRef(
SkDecodingImageGenerator::Create(encoded,
SkDecodingImageGenerator::Options()),
- &bm, NULL)) {
+ &bm)) {
SkDebugf("[%s:%d] failed to decode %s%s\n",
__FILE__, __LINE__,gConfigLabels[i], gExt[j]);
}
diff --git a/samplecode/SamplePicture.cpp b/samplecode/SamplePicture.cpp
index e6969037fd..f242c21944 100644
--- a/samplecode/SamplePicture.cpp
+++ b/samplecode/SamplePicture.cpp
@@ -41,7 +41,7 @@ static SkBitmap load_bitmap() {
SkAutoDataUnref data(SkData::NewFromFileName(path.c_str()));
if (data.get() != NULL) {
SkInstallDiscardablePixelRef(SkDecodingImageGenerator::Create(
- data, SkDecodingImageGenerator::Options()), &bm, NULL);
+ data, SkDecodingImageGenerator::Options()), &bm);
}
return bm;
}
diff --git a/src/core/SkImageGeneratorPriv.h b/src/core/SkImageGeneratorPriv.h
new file mode 100644
index 0000000000..e03294d3fa
--- /dev/null
+++ b/src/core/SkImageGeneratorPriv.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkImageGeneratorPriv_DEFINED
+#define SkImageGeneratorPriv_DEFINED
+
+#include "SkImageGenerator.h"
+#include "SkDiscardableMemory.h"
+
+/**
+ * Takes ownership of SkImageGenerator. If this method fails for
+ * whatever reason, it will return false and immediatetely delete
+ * the generator. If it succeeds, it will modify destination
+ * bitmap.
+ *
+ * If generator is NULL, will safely return false.
+ *
+ * If this fails or when the SkDiscardablePixelRef that is
+ * installed into destination is destroyed, it will call
+ * SkDELETE() on the generator. Therefore, generator should be
+ * allocated with SkNEW() or SkNEW_ARGS().
+ *
+ * @param destination Upon success, this bitmap will be
+ * configured and have a pixelref installed.
+ *
+ * @param factory If not NULL, this object will be used as a
+ * source of discardable memory when decoding. If NULL, then
+ * SkDiscardableMemory::Create() will be called.
+ *
+ * @return true iff successful.
+ */
+bool SkInstallDiscardablePixelRef(SkImageGenerator*, SkBitmap* destination,
+ SkDiscardableMemory::Factory* factory);
+
+#endif
diff --git a/src/lazy/SkDiscardablePixelRef.cpp b/src/lazy/SkDiscardablePixelRef.cpp
index 56b94b734e..267e097245 100644
--- a/src/lazy/SkDiscardablePixelRef.cpp
+++ b/src/lazy/SkDiscardablePixelRef.cpp
@@ -77,8 +77,7 @@ void SkDiscardablePixelRef::onUnlockPixels() {
fDiscardableMemory->unlock();
}
-bool SkInstallDiscardablePixelRef(SkImageGenerator* generator,
- SkBitmap* dst,
+bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst,
SkDiscardableMemory::Factory* factory) {
SkImageInfo info;
SkAutoTDelete<SkImageGenerator> autoGenerator(generator);
@@ -97,3 +96,9 @@ bool SkInstallDiscardablePixelRef(SkImageGenerator* generator,
dst->setPixelRef(ref);
return true;
}
+
+// This is the public API
+bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst) {
+ return SkInstallDiscardablePixelRef(generator, dst, NULL);
+}
+
diff --git a/src/lazy/SkDiscardablePixelRef.h b/src/lazy/SkDiscardablePixelRef.h
index cbc2a89ac4..e5e1c9f0e1 100644
--- a/src/lazy/SkDiscardablePixelRef.h
+++ b/src/lazy/SkDiscardablePixelRef.h
@@ -52,8 +52,7 @@ private:
size_t rowBytes,
SkDiscardableMemory::Factory* factory);
- friend bool SkInstallDiscardablePixelRef(SkImageGenerator*,
- SkBitmap*,
+ friend bool SkInstallDiscardablePixelRef(SkImageGenerator*, SkBitmap*,
SkDiscardableMemory::Factory*);
typedef SkPixelRef INHERITED;
diff --git a/tests/CachedDecodingPixelRefTest.cpp b/tests/CachedDecodingPixelRefTest.cpp
index 705f0666a4..10e33ba841 100644
--- a/tests/CachedDecodingPixelRefTest.cpp
+++ b/tests/CachedDecodingPixelRefTest.cpp
@@ -12,6 +12,7 @@
#include "SkDecodingImageGenerator.h"
#include "SkDiscardableMemoryPool.h"
#include "SkImageDecoder.h"
+#include "SkImageGeneratorPriv.h"
#include "SkScaledImageCache.h"
#include "SkStream.h"
#include "SkUtils.h"
@@ -152,7 +153,7 @@ static bool install_skDiscardablePixelRef(SkData* encoded, SkBitmap* dst) {
// Use system-default discardable memory.
return SkInstallDiscardablePixelRef(
SkDecodingImageGenerator::Create(
- encoded, SkDecodingImageGenerator::Options()), dst, NULL);
+ encoded, SkDecodingImageGenerator::Options()), dst);
}
////////////////////////////////////////////////////////////////////////////////
@@ -276,7 +277,7 @@ static void test_newlockdelete(skiatest::Reporter* reporter) {
SkBitmap bm;
SkImageGenerator* ig = new TestImageGenerator(
TestImageGenerator::kSucceedGetPixels_TestType, reporter);
- SkInstallDiscardablePixelRef(ig, &bm, NULL);
+ SkInstallDiscardablePixelRef(ig, &bm);
bm.pixelRef()->lockPixels();
}
diff --git a/tests/DrawBitmapRectTest.cpp b/tests/DrawBitmapRectTest.cpp
index e6cc781f18..f294ae7e6e 100644
--- a/tests/DrawBitmapRectTest.cpp
+++ b/tests/DrawBitmapRectTest.cpp
@@ -9,7 +9,7 @@
#include "SkCanvas.h"
#include "SkData.h"
#include "SkDiscardableMemoryPool.h"
-#include "SkImageGenerator.h"
+#include "SkImageGeneratorPriv.h"
#include "SkMatrixUtils.h"
#include "SkPaint.h"
#include "SkRandom.h"
diff --git a/tests/ImageDecodingTest.cpp b/tests/ImageDecodingTest.cpp
index 7f9ff3042e..21c774727d 100644
--- a/tests/ImageDecodingTest.cpp
+++ b/tests/ImageDecodingTest.cpp
@@ -16,7 +16,7 @@
#include "SkGradientShader.h"
#include "SkImageDecoder.h"
#include "SkImageEncoder.h"
-#include "SkImageGenerator.h"
+#include "SkImageGeneratorPriv.h"
#include "SkImagePriv.h"
#include "SkOSFile.h"
#include "SkPoint.h"
@@ -455,7 +455,7 @@ DEF_TEST(WebP, reporter) {
bool success = SkInstallDiscardablePixelRef(
SkDecodingImageGenerator::Create(encoded,
- SkDecodingImageGenerator::Options()), &bm, NULL);
+ SkDecodingImageGenerator::Options()), &bm);
REPORTER_ASSERT(reporter, success);
if (!success) {
@@ -584,14 +584,13 @@ static void test_options(skiatest::Reporter* reporter,
return;
}
success = SkInstallDiscardablePixelRef(
- SkDecodingImageGenerator::Create(encodedData, opts), &bm, NULL);
+ SkDecodingImageGenerator::Create(encodedData, opts), &bm);
} else {
if (NULL == encodedStream) {
return;
}
success = SkInstallDiscardablePixelRef(
- SkDecodingImageGenerator::Create(encodedStream->duplicate(), opts),
- &bm, NULL);
+ SkDecodingImageGenerator::Create(encodedStream->duplicate(), opts), &bm);
}
if (!success) {
if (opts.fUseRequestedColorType
diff --git a/tests/PictureTest.cpp b/tests/PictureTest.cpp
index 8467d6a082..ac44a5ce6d 100644
--- a/tests/PictureTest.cpp
+++ b/tests/PictureTest.cpp
@@ -1113,7 +1113,7 @@ static void test_bitmap_with_encoded_data(skiatest::Reporter* reporter) {
SkBitmap bm;
bool installSuccess = SkInstallDiscardablePixelRef(
- SkDecodingImageGenerator::Create(data, SkDecodingImageGenerator::Options()), &bm, NULL);
+ SkDecodingImageGenerator::Create(data, SkDecodingImageGenerator::Options()), &bm);
REPORTER_ASSERT(reporter, installSuccess);
// Write both bitmaps to pictures, and ensure that the resulting data streams are the same.
diff --git a/tools/LazyDecodeBitmap.cpp b/tools/LazyDecodeBitmap.cpp
index 83fca5f3b2..6c4160c09e 100644
--- a/tools/LazyDecodeBitmap.cpp
+++ b/tools/LazyDecodeBitmap.cpp
@@ -10,7 +10,7 @@
#include "SkData.h"
#include "SkDecodingImageGenerator.h"
#include "SkDiscardableMemoryPool.h"
-#include "SkImageGenerator.h"
+#include "SkImageGeneratorPriv.h"
#include "SkForceLinking.h"
#include "SkCommandLineFlags.h"