summaryrefslogtreecommitdiffstats
path: root/gfx/skia/skia/src/android/SkBitmapRegionDecoder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gfx/skia/skia/src/android/SkBitmapRegionDecoder.cpp')
-rw-r--r--gfx/skia/skia/src/android/SkBitmapRegionDecoder.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/gfx/skia/skia/src/android/SkBitmapRegionDecoder.cpp b/gfx/skia/skia/src/android/SkBitmapRegionDecoder.cpp
new file mode 100644
index 000000000..6dd48c5f8
--- /dev/null
+++ b/gfx/skia/skia/src/android/SkBitmapRegionDecoder.cpp
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkBitmapRegionCodec.h"
+#include "SkBitmapRegionDecoder.h"
+#include "SkAndroidCodec.h"
+#include "SkCodec.h"
+#include "SkCodecPriv.h"
+
+SkBitmapRegionDecoder* SkBitmapRegionDecoder::Create(
+ sk_sp<SkData> data, Strategy strategy) {
+ return SkBitmapRegionDecoder::Create(new SkMemoryStream(data),
+ strategy);
+}
+
+SkBitmapRegionDecoder* SkBitmapRegionDecoder::Create(
+ SkStreamRewindable* stream, Strategy strategy) {
+ SkAutoTDelete<SkStreamRewindable> streamDeleter(stream);
+ switch (strategy) {
+ case kAndroidCodec_Strategy: {
+ SkAutoTDelete<SkAndroidCodec> codec =
+ SkAndroidCodec::NewFromStream(streamDeleter.release());
+ if (nullptr == codec) {
+ SkCodecPrintf("Error: Failed to create codec.\n");
+ return NULL;
+ }
+
+ SkEncodedFormat format = codec->getEncodedFormat();
+ switch (format) {
+ case SkEncodedFormat::kJPEG_SkEncodedFormat:
+ case SkEncodedFormat::kPNG_SkEncodedFormat:
+ case SkEncodedFormat::kWEBP_SkEncodedFormat:
+ break;
+ default:
+ return nullptr;
+ }
+
+ return new SkBitmapRegionCodec(codec.release());
+ }
+ default:
+ SkASSERT(false);
+ return nullptr;
+ }
+}