aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/android
diff options
context:
space:
mode:
authorGravatar msarett <msarett@google.com>2015-11-13 06:11:09 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-11-13 06:11:09 -0800
commit506e19a4c8395178e8da81576b3c37616593e560 (patch)
tree0877d660a91ef6322059269e7020988459e91ded /include/android
parent9c8605144a0f15e3e69a4e1dcd5d3e63f339380e (diff)
Move SkBitmapRegionDecoder to include/android and src/android
This will expose the BitmapRegionDecoder API as a public include and move the implementation to src. This makes this code more naturally exposed in Android and easier to test in DM and nanobench. BUG=skia: Review URL: https://codereview.chromium.org/1438873002
Diffstat (limited to 'include/android')
-rw-r--r--include/android/SkBRDAllocator.h29
-rw-r--r--include/android/SkBitmapRegionDecoder.h90
2 files changed, 119 insertions, 0 deletions
diff --git a/include/android/SkBRDAllocator.h b/include/android/SkBRDAllocator.h
new file mode 100644
index 0000000000..3ca30c9b41
--- /dev/null
+++ b/include/android/SkBRDAllocator.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkBRDAllocator_DEFINED
+#define SkBRDAllocator_DEFINED
+
+#include "SkBitmap.h"
+#include "SkCodec.h"
+
+/**
+ * Abstract subclass of SkBitmap's allocator.
+ * Allows the allocator to indicate if the memory it allocates
+ * is zero initialized.
+ */
+class SkBRDAllocator : public SkBitmap::Allocator {
+public:
+
+ /**
+ * Indicates if the memory allocated by this allocator is
+ * zero initialized.
+ */
+ virtual SkCodec::ZeroInitialized zeroInit() const = 0;
+};
+
+#endif // SkBRDAllocator_DEFINED
diff --git a/include/android/SkBitmapRegionDecoder.h b/include/android/SkBitmapRegionDecoder.h
new file mode 100644
index 0000000000..575ad9dc01
--- /dev/null
+++ b/include/android/SkBitmapRegionDecoder.h
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkBitmapRegionDecoder_DEFINED
+#define SkBitmapRegionDecoder_DEFINED
+
+#include "SkBitmap.h"
+#include "SkBRDAllocator.h"
+#include "SkEncodedFormat.h"
+#include "SkStream.h"
+
+/*
+ * This class aims to provide an interface to test multiple implementations of
+ * SkBitmapRegionDecoder.
+ */
+class SkBitmapRegionDecoder {
+public:
+
+ enum Strategy {
+ kCanvas_Strategy, // Draw to the canvas, uses SkCodec
+ kAndroidCodec_Strategy, // Uses SkAndroidCodec for scaling and subsetting
+ };
+
+ /*
+ * @param data Refs the data while this object exists, unrefs on destruction
+ * @param strategy Strategy used for scaling and subsetting
+ * @return Tries to create an SkBitmapRegionDecoder, returns NULL on failure
+ */
+ static SkBitmapRegionDecoder* Create(
+ SkData* data, Strategy strategy);
+
+ /*
+ * @param stream Takes ownership of the stream
+ * @param strategy Strategy used for scaling and subsetting
+ * @return Tries to create an SkBitmapRegionDecoder, returns NULL on failure
+ */
+ static SkBitmapRegionDecoder* Create(
+ SkStreamRewindable* stream, Strategy strategy);
+
+ /*
+ * Decode a scaled region of the encoded image stream
+ *
+ * @param bitmap Container for decoded pixels. It is assumed that the pixels
+ * are initially unallocated and will be allocated by this function.
+ * @param allocator Allocator for the pixels. If this is NULL, the default
+ * allocator (HeapAllocator) will be used.
+ * @param desiredSubset Subset of the original image to decode.
+ * @param sampleSize An integer downscaling factor for the decode.
+ * @param colorType Preferred output colorType.
+ * New implementations should return NULL if they do not support
+ * decoding to this color type.
+ * The old kOriginal_Strategy will decode to a default color type
+ * if this color type is unsupported.
+ * @param requireUnpremul If the image is not opaque, we will use this to determine the
+ * alpha type to use.
+ *
+ */
+ virtual bool decodeRegion(SkBitmap* bitmap, SkBRDAllocator* allocator,
+ const SkIRect& desiredSubset, int sampleSize,
+ SkColorType colorType, bool requireUnpremul) = 0;
+ /*
+ * @param Requested destination color type
+ * @return true if we support the requested color type and false otherwise
+ */
+ virtual bool conversionSupported(SkColorType colorType) = 0;
+
+ virtual SkEncodedFormat getEncodedFormat() = 0;
+
+ int width() const { return fWidth; }
+ int height() const { return fHeight; }
+
+ virtual ~SkBitmapRegionDecoder() {}
+
+protected:
+
+ SkBitmapRegionDecoder(int width, int height)
+ : fWidth(width)
+ , fHeight(height)
+ {}
+
+private:
+ const int fWidth;
+ const int fHeight;
+};
+
+#endif