aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/images
diff options
context:
space:
mode:
authorGravatar halcanary@google.com <halcanary@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-11-21 15:32:08 +0000
committerGravatar halcanary@google.com <halcanary@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-11-21 15:32:08 +0000
commitad04eb49f5d3f324e6b85411c776d7466c1fef92 (patch)
tree72ec9bb693a1da847d1b3f6d1958ea2f0638e5c2 /src/images
parent8b656c6db40a99af241e38eae853f887413040cc (diff)
Add SkImageGenerator Interface
- Add SkDiscardablePixelRef class that uses SkDiscardableMemory and a SkImageGenerator. - Add SkDecodingImageGenerator class as an example of a SkImageGenerator. - Add DecodingImageGenerator unit test. - Add SkBasicDiscardableMemory implmentation for unit tests only. R=reed@google.com, scroggo@google.com Review URL: https://codereview.chromium.org/74793011 git-svn-id: http://skia.googlecode.com/svn/trunk@12341 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/images')
-rw-r--r--src/images/SkDecodingImageGenerator.cpp52
-rw-r--r--src/images/SkDecodingImageGenerator.h45
2 files changed, 97 insertions, 0 deletions
diff --git a/src/images/SkDecodingImageGenerator.cpp b/src/images/SkDecodingImageGenerator.cpp
new file mode 100644
index 0000000000..65fa6fd561
--- /dev/null
+++ b/src/images/SkDecodingImageGenerator.cpp
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkDecodingImageGenerator.h"
+
+#include "SkBitmapFactory.h"
+#include "SkData.h"
+#include "SkDiscardablePixelRef.h"
+#include "SkImageDecoder.h"
+
+SkDecodingImageGenerator::SkDecodingImageGenerator(SkData* data)
+ : fData(data) {
+ SkASSERT(fData != NULL);
+ fData->ref();
+}
+
+SkDecodingImageGenerator::~SkDecodingImageGenerator() {
+ fData->unref();
+}
+
+SkData* SkDecodingImageGenerator::refEncodedData() {
+ fData->ref();
+ return fData;
+}
+
+bool SkDecodingImageGenerator::getInfo(SkImageInfo* info) {
+ SkASSERT(info != NULL);
+ return SkImageDecoder::DecodeMemoryToTarget(fData->data(),
+ fData->size(),
+ info, NULL);
+}
+
+bool SkDecodingImageGenerator::getPixels(const SkImageInfo& info,
+ void* pixels,
+ size_t rowBytes) {
+ SkASSERT(pixels != NULL);
+ SkBitmapFactory::Target target = {pixels, rowBytes};
+ SkImageInfo tmpInfo = info;
+ return SkImageDecoder::DecodeMemoryToTarget(fData->data(),
+ fData->size(),
+ &tmpInfo, &target);
+}
+bool SkDecodingImageGenerator::Install(SkData* data, SkBitmap* dst) {
+ SkASSERT(data != NULL);
+ SkASSERT(dst != NULL);
+ SkImageGenerator* gen(SkNEW_ARGS(SkDecodingImageGenerator, (data)));
+ return SkDiscardablePixelRef::Install(gen, dst);
+}
diff --git a/src/images/SkDecodingImageGenerator.h b/src/images/SkDecodingImageGenerator.h
new file mode 100644
index 0000000000..682aeb619c
--- /dev/null
+++ b/src/images/SkDecodingImageGenerator.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkDecodingImageGenerator_DEFINED
+#define SkDecodingImageGenerator_DEFINED
+
+#include "SkImageGenerator.h"
+
+class SkBitmap;
+
+/**
+ * Calls into SkImageDecoder::DecodeMemoryToTarget to implement a
+ * SkImageGenerator
+ */
+class SkDecodingImageGenerator : public SkImageGenerator {
+public:
+ /*
+ * The constructor will take a reference to the SkData. The
+ * destructor will unref() it.
+ */
+ SkDecodingImageGenerator(SkData* data);
+ virtual ~SkDecodingImageGenerator();
+
+ virtual SkData* refEncodedData() SK_OVERRIDE;
+
+ virtual bool getInfo(SkImageInfo* info) SK_OVERRIDE;
+
+ virtual bool getPixels(const SkImageInfo& info,
+ void* pixels,
+ size_t rowBytes) SK_OVERRIDE;
+
+ /**
+ * Install the SkData into the destination bitmap, using a new
+ * SkDiscardablePixelRef and a new SkDecodingImageGenerator.
+ */
+ static bool Install(SkData* data, SkBitmap* destination);
+
+private:
+ SkData* fData;
+};
+#endif // SkDecodingImageGenerator_DEFINED