aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core
diff options
context:
space:
mode:
Diffstat (limited to 'include/core')
-rw-r--r--include/core/SkImageGenerator.h39
-rw-r--r--include/core/SkPixelRef.h39
-rw-r--r--include/core/SkYUVSizeInfo.h34
3 files changed, 86 insertions, 26 deletions
diff --git a/include/core/SkImageGenerator.h b/include/core/SkImageGenerator.h
index 86e3053a06..1a46f6b9cd 100644
--- a/include/core/SkImageGenerator.h
+++ b/include/core/SkImageGenerator.h
@@ -11,6 +11,7 @@
#include "SkBitmap.h"
#include "SkColor.h"
#include "SkImageInfo.h"
+#include "SkYUVSizeInfo.h"
class GrContext;
class GrTexture;
@@ -129,18 +130,26 @@ public:
bool getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes);
/**
- * If planes or rowBytes is NULL or if any entry in planes is NULL or if any entry in rowBytes
- * is 0, this imagegenerator should output the sizes and return true if it can efficiently
- * return YUV planar data. If it cannot, it should return false. Note that either planes and
- * rowBytes are both fully defined and non NULL/non 0 or they are both NULL or have NULL or 0
- * entries only. Having only partial planes/rowBytes information is not supported.
+ * If decoding to YUV is supported, this returns true. Otherwise, this
+ * returns false and does not modify any of the parameters.
*
- * If all planes and rowBytes entries are non NULL or non 0, then it should copy the
- * associated YUV data into those planes of memory supplied by the caller. It should validate
- * that the sizes match what it expected. If the sizes do not match, it should return false.
+ * @param sizeInfo Output parameter indicating the sizes and required
+ * allocation widths of the Y, U, and V planes.
+ * @param colorSpace Output parameter.
*/
- bool getYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
- SkYUVColorSpace* colorSpace);
+ bool queryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const;
+
+ /**
+ * Returns true on success and false on failure.
+ * This always attempts to perform a full decode. If the client only
+ * wants size, it should call queryYUV8().
+ *
+ * @param sizeInfo Needs to exactly match the values returned by the
+ * query, except the WidthBytes may be larger than the
+ * recommendation (but not smaller).
+ * @param planes Memory for each of the Y, U, and V planes.
+ */
+ bool getYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]);
/**
* If the generator can natively/efficiently return its pixels as a GPU image (backed by a
@@ -248,9 +257,13 @@ protected:
virtual bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
SkPMColor ctable[], int* ctableCount);
- virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3]);
- virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
- SkYUVColorSpace* colorSpace);
+
+ virtual bool onQueryYUV8(SkYUVSizeInfo*, SkYUVColorSpace*) const {
+ return false;
+ }
+ virtual bool onGetYUV8Planes(const SkYUVSizeInfo&, void*[3] /*planes*/) {
+ return false;
+ }
virtual GrTexture* onGenerateTexture(GrContext*, const SkIRect*) {
return nullptr;
diff --git a/include/core/SkPixelRef.h b/include/core/SkPixelRef.h
index e1ce6d4c7f..651176ebbb 100644
--- a/include/core/SkPixelRef.h
+++ b/include/core/SkPixelRef.h
@@ -18,6 +18,7 @@
#include "SkRefCnt.h"
#include "SkSize.h"
#include "SkString.h"
+#include "SkYUVSizeInfo.h"
class SkColorTable;
class SkData;
@@ -210,19 +211,28 @@ public:
virtual GrTexture* getTexture() { return NULL; }
/**
- * If any planes or rowBytes is NULL, this should output the sizes and return true
- * if it can efficiently return YUV planar data. If it cannot, it should return false.
+ * If this can efficiently return YUV data, this should return true.
+ * Otherwise this returns false and does not modify any of the parameters.
*
- * If all planes and rowBytes are not NULL, then it should copy the associated Y,U,V data
- * into those planes of memory supplied by the caller. It should validate that the sizes
- * match what it expected. If the sizes do not match, it should return false.
+ * @param sizeInfo Output parameter indicating the sizes and required
+ * allocation widths of the Y, U, and V planes.
+ * @param colorSpace Output parameter.
+ */
+ bool queryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const {
+ return this->onQueryYUV8(sizeInfo, colorSpace);
+ }
+
+ /**
+ * Returns true on success and false on failure.
+ * Copies YUV data into the provided YUV planes.
*
- * If colorSpace is not NULL, the YUV color space of the data should be stored in the address
- * it points at.
+ * @param sizeInfo Needs to exactly match the values returned by the
+ * query, except the WidthBytes may be larger than the
+ * recommendation (but not smaller).
+ * @param planes Memory for each of the Y, U, and V planes.
*/
- bool getYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
- SkYUVColorSpace* colorSpace) {
- return this->onGetYUV8Planes(sizes, planes, rowBytes, colorSpace);
+ bool getYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) {
+ return this->onGetYUV8Planes(sizeInfo, planes);
}
/** Populates dst with the pixels of this pixelRef, converting them to colorType. */
@@ -308,9 +318,12 @@ protected:
// default impl does nothing.
virtual void onNotifyPixelsChanged();
- // default impl returns false.
- virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
- SkYUVColorSpace* colorSpace);
+ virtual bool onQueryYUV8(SkYUVSizeInfo*, SkYUVColorSpace*) const {
+ return false;
+ }
+ virtual bool onGetYUV8Planes(const SkYUVSizeInfo&, void*[3] /*planes*/) {
+ return false;
+ }
/**
* Returns the size (in bytes) of the internally allocated memory.
diff --git a/include/core/SkYUVSizeInfo.h b/include/core/SkYUVSizeInfo.h
new file mode 100644
index 0000000000..2c5a51d794
--- /dev/null
+++ b/include/core/SkYUVSizeInfo.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkYUVSizeInfo_DEFINED
+#define SkYUVSizeInfo_DEFINED
+
+struct SkYUVSizeInfo {
+ enum {
+ kY = 0,
+ kU = 1,
+ kV = 2,
+ };
+ SkISize fSizes[3];
+
+ /**
+ * While the widths of the Y, U, and V planes are not restricted, the
+ * implementation often requires that the width of the memory allocated
+ * for each plane be a multiple of 8.
+ *
+ * This struct allows us to inform the client how many "widthBytes"
+ * that we need. Note that we use the new idea of "widthBytes"
+ * because this idea is distinct from "rowBytes" (used elsewhere in
+ * Skia). "rowBytes" allow the last row of the allocation to not
+ * include any extra padding, while, in this case, every single row of
+ * the allocation must be at least "widthBytes".
+ */
+ size_t fWidthBytes[3];
+};
+
+#endif // SkYUVSizeInfo_DEFINED