aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar msarett <msarett@google.com>2016-03-10 05:44:43 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-03-10 05:44:43 -0800
commit4984c3c95f18eda44492a2126c9958e447f2cca8 (patch)
treeadd5bdca2495968a8acc1affd10e5cfe225ff4d0 /src
parentd6215cf4a5f416cf0b64a4fbba95c519f03fe467 (diff)
Update Skia's YUV API
Diffstat (limited to 'src')
-rw-r--r--src/codec/SkCodecImageGenerator.cpp47
-rw-r--r--src/codec/SkCodecImageGenerator.h11
-rw-r--r--src/codec/SkJpegCodec.cpp60
-rw-r--r--src/codec/SkJpegCodec.h4
-rw-r--r--src/core/SkImageCacherator.cpp9
-rw-r--r--src/core/SkImageGenerator.cpp66
-rw-r--r--src/core/SkPixelRef.cpp5
-rw-r--r--src/core/SkYUVPlanesCache.h11
-rw-r--r--src/gpu/GrYUVProvider.cpp48
-rw-r--r--src/gpu/GrYUVProvider.h34
-rw-r--r--src/gpu/SkGr.cpp9
-rw-r--r--src/lazy/SkDiscardablePixelRef.h16
12 files changed, 124 insertions, 196 deletions
diff --git a/src/codec/SkCodecImageGenerator.cpp b/src/codec/SkCodecImageGenerator.cpp
index e6e164ef61..e579da92f6 100644
--- a/src/codec/SkCodecImageGenerator.cpp
+++ b/src/codec/SkCodecImageGenerator.cpp
@@ -28,9 +28,6 @@ SkCodecImageGenerator::SkCodecImageGenerator(SkCodec* codec, SkData* data)
: INHERITED(make_premul(codec->getInfo()))
, fCodec(codec)
, fData(SkRef(data))
- , fYWidth(0)
- , fUWidth(0)
- , fVWidth(0)
{}
SkData* SkCodecImageGenerator::onRefEncodedData(SK_REFENCODEDDATA_CTXPARAM) {
@@ -51,47 +48,13 @@ bool SkCodecImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, s
}
}
-bool SkCodecImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
- SkYUVColorSpace* colorSpace) {
- // TODO (msarett): Change the YUV API in ImageGenerator to match SkCodec.
- // This function is currently a hack to match the implementation
- // in SkCodec with the old API.
- SkCodec::YUVSizeInfo sizeInfo;
-
- // If planes is NULL, we just need to return the size.
- if (nullptr == planes) {
- bool result = fCodec->queryYUV8(&sizeInfo, colorSpace);
- if (result) {
- // Save the true widths
- fYWidth = sizeInfo.fYSize.width();
- fUWidth = sizeInfo.fUSize.width();
- fVWidth = sizeInfo.fVSize.width();
-
- // Set the sizes so that the client allocates enough memory
- sizes[0].fWidth = (int) sizeInfo.fYWidthBytes;
- sizes[0].fHeight = sizeInfo.fYSize.height();
- sizes[1].fWidth = (int) sizeInfo.fUWidthBytes;
- sizes[1].fHeight = sizeInfo.fUSize.height();
- sizes[2].fWidth = (int) sizeInfo.fVWidthBytes;
- sizes[2].fHeight = sizeInfo.fVSize.height();
- }
- return result;
- }
-
- // Set the sizeInfo with the true widths and heights
- SkASSERT(fYWidth != 0 && fUWidth != 0 && fVWidth != 0);
- sizeInfo.fYSize.set(fYWidth, sizes[0].height());
- sizeInfo.fUSize.set(fUWidth, sizes[1].height());
- sizeInfo.fVSize.set(fVWidth, sizes[2].height());
+bool SkCodecImageGenerator::onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const
+{
+ return fCodec->queryYUV8(sizeInfo, colorSpace);
+}
- // Set the sizeInfo with the allocated widths
- sizeInfo.fYWidthBytes = sizes[0].width();
- sizeInfo.fUWidthBytes = sizes[1].width();
- sizeInfo.fVWidthBytes = sizes[2].width();
+bool SkCodecImageGenerator::onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) {
SkCodec::Result result = fCodec->getYUV8Planes(sizeInfo, planes);
- if ((result == SkCodec::kSuccess || result == SkCodec::kIncompleteInput) && colorSpace) {
- *colorSpace = kJPEG_SkYUVColorSpace;
- }
switch (result) {
case SkCodec::kSuccess:
diff --git a/src/codec/SkCodecImageGenerator.h b/src/codec/SkCodecImageGenerator.h
index d2c74ab482..6d34223110 100644
--- a/src/codec/SkCodecImageGenerator.h
+++ b/src/codec/SkCodecImageGenerator.h
@@ -26,8 +26,9 @@ protected:
bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor ctable[],
int* ctableCount) override;
- bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
- SkYUVColorSpace* colorSpace) override;
+ bool onQueryYUV8(SkYUVSizeInfo*, SkYUVColorSpace*) const override;
+
+ bool onGetYUV8Planes(const SkYUVSizeInfo&, void* planes[3]) override;
private:
/*
@@ -39,11 +40,5 @@ private:
SkAutoTDelete<SkCodec> fCodec;
SkAutoTUnref<SkData> fData;
- // FIXME: These fields are necessary only until we change the API of SkImageGenerator
- // to match SkCodec. Once the API is changed, they should be removed.
- int fYWidth;
- int fUWidth;
- int fVWidth;
-
typedef SkImageGenerator INHERITED;
};
diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp
index b5780c5581..f1b55df06e 100644
--- a/src/codec/SkJpegCodec.cpp
+++ b/src/codec/SkJpegCodec.cpp
@@ -594,21 +594,21 @@ static bool is_yuv_supported(jpeg_decompress_struct* dinfo) {
(4 == hSampY && 2 == vSampY);
}
-bool SkJpegCodec::onQueryYUV8(YUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const {
+bool SkJpegCodec::onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const {
jpeg_decompress_struct* dinfo = fDecoderMgr->dinfo();
if (!is_yuv_supported(dinfo)) {
return false;
}
- sizeInfo->fYSize.set(dinfo->comp_info[0].downsampled_width,
- dinfo->comp_info[0].downsampled_height);
- sizeInfo->fUSize.set(dinfo->comp_info[1].downsampled_width,
- dinfo->comp_info[1].downsampled_height);
- sizeInfo->fVSize.set(dinfo->comp_info[2].downsampled_width,
- dinfo->comp_info[2].downsampled_height);
- sizeInfo->fYWidthBytes = dinfo->comp_info[0].width_in_blocks * DCTSIZE;
- sizeInfo->fUWidthBytes = dinfo->comp_info[1].width_in_blocks * DCTSIZE;
- sizeInfo->fVWidthBytes = dinfo->comp_info[2].width_in_blocks * DCTSIZE;
+ sizeInfo->fSizes[SkYUVSizeInfo::kY].set(dinfo->comp_info[0].downsampled_width,
+ dinfo->comp_info[0].downsampled_height);
+ sizeInfo->fSizes[SkYUVSizeInfo::kU].set(dinfo->comp_info[1].downsampled_width,
+ dinfo->comp_info[1].downsampled_height);
+ sizeInfo->fSizes[SkYUVSizeInfo::kV].set(dinfo->comp_info[2].downsampled_width,
+ dinfo->comp_info[2].downsampled_height);
+ sizeInfo->fWidthBytes[SkYUVSizeInfo::kY] = dinfo->comp_info[0].width_in_blocks * DCTSIZE;
+ sizeInfo->fWidthBytes[SkYUVSizeInfo::kU] = dinfo->comp_info[1].width_in_blocks * DCTSIZE;
+ sizeInfo->fWidthBytes[SkYUVSizeInfo::kV] = dinfo->comp_info[2].width_in_blocks * DCTSIZE;
if (colorSpace) {
*colorSpace = kJPEG_SkYUVColorSpace;
@@ -617,17 +617,18 @@ bool SkJpegCodec::onQueryYUV8(YUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace
return true;
}
-SkCodec::Result SkJpegCodec::onGetYUV8Planes(const YUVSizeInfo& sizeInfo, void* pixels[3]) {
- YUVSizeInfo defaultInfo;
+SkCodec::Result SkJpegCodec::onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) {
+ SkYUVSizeInfo defaultInfo;
// This will check is_yuv_supported(), so we don't need to here.
bool supportsYUV = this->onQueryYUV8(&defaultInfo, nullptr);
- if (!supportsYUV || sizeInfo.fYSize != defaultInfo.fYSize ||
- sizeInfo.fUSize != defaultInfo.fUSize ||
- sizeInfo.fVSize != defaultInfo.fVSize ||
- sizeInfo.fYWidthBytes < defaultInfo.fYWidthBytes ||
- sizeInfo.fUWidthBytes < defaultInfo.fUWidthBytes ||
- sizeInfo.fVWidthBytes < defaultInfo.fVWidthBytes) {
+ if (!supportsYUV ||
+ sizeInfo.fSizes[SkYUVSizeInfo::kY] != defaultInfo.fSizes[SkYUVSizeInfo::kY] ||
+ sizeInfo.fSizes[SkYUVSizeInfo::kU] != defaultInfo.fSizes[SkYUVSizeInfo::kU] ||
+ sizeInfo.fSizes[SkYUVSizeInfo::kV] != defaultInfo.fSizes[SkYUVSizeInfo::kV] ||
+ sizeInfo.fWidthBytes[SkYUVSizeInfo::kY] < defaultInfo.fWidthBytes[SkYUVSizeInfo::kY] ||
+ sizeInfo.fWidthBytes[SkYUVSizeInfo::kU] < defaultInfo.fWidthBytes[SkYUVSizeInfo::kU] ||
+ sizeInfo.fWidthBytes[SkYUVSizeInfo::kV] < defaultInfo.fWidthBytes[SkYUVSizeInfo::kV]) {
return fDecoderMgr->returnFailure("onGetYUV8Planes", kInvalidInput);
}
@@ -651,9 +652,9 @@ SkCodec::Result SkJpegCodec::onGetYUV8Planes(const YUVSizeInfo& sizeInfo, void*
// Currently, we require that the Y plane dimensions match the image dimensions
// and that the U and V planes are the same dimensions.
- SkASSERT(sizeInfo.fUSize == sizeInfo.fVSize);
- SkASSERT((uint32_t) sizeInfo.fYSize.width() == dinfo->output_width &&
- (uint32_t) sizeInfo.fYSize.height() == dinfo->output_height);
+ SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kU] == sizeInfo.fSizes[SkYUVSizeInfo::kV]);
+ SkASSERT((uint32_t) sizeInfo.fSizes[SkYUVSizeInfo::kY].width() == dinfo->output_width &&
+ (uint32_t) sizeInfo.fSizes[SkYUVSizeInfo::kY].height() == dinfo->output_height);
// Build a JSAMPIMAGE to handle output from libjpeg-turbo. A JSAMPIMAGE has
// a 2-D array of pixels for each of the components (Y, U, V) in the image.
@@ -670,17 +671,20 @@ SkCodec::Result SkJpegCodec::onGetYUV8Planes(const YUVSizeInfo& sizeInfo, void*
// Initialize rowptrs.
int numYRowsPerBlock = DCTSIZE * dinfo->comp_info[0].v_samp_factor;
for (int i = 0; i < numYRowsPerBlock; i++) {
- rowptrs[i] = SkTAddOffset<JSAMPLE>(pixels[0], i * sizeInfo.fYWidthBytes);
+ rowptrs[i] = SkTAddOffset<JSAMPLE>(planes[SkYUVSizeInfo::kY],
+ i * sizeInfo.fWidthBytes[SkYUVSizeInfo::kY]);
}
for (int i = 0; i < DCTSIZE; i++) {
- rowptrs[i + 2 * DCTSIZE] = SkTAddOffset<JSAMPLE>(pixels[1], i * sizeInfo.fUWidthBytes);
- rowptrs[i + 3 * DCTSIZE] = SkTAddOffset<JSAMPLE>(pixels[2], i * sizeInfo.fVWidthBytes);
+ rowptrs[i + 2 * DCTSIZE] = SkTAddOffset<JSAMPLE>(planes[SkYUVSizeInfo::kU],
+ i * sizeInfo.fWidthBytes[SkYUVSizeInfo::kU]);
+ rowptrs[i + 3 * DCTSIZE] = SkTAddOffset<JSAMPLE>(planes[SkYUVSizeInfo::kV],
+ i * sizeInfo.fWidthBytes[SkYUVSizeInfo::kV]);
}
// After each loop iteration, we will increment pointers to Y, U, and V.
- size_t blockIncrementY = numYRowsPerBlock * sizeInfo.fYWidthBytes;
- size_t blockIncrementU = DCTSIZE * sizeInfo.fUWidthBytes;
- size_t blockIncrementV = DCTSIZE * sizeInfo.fVWidthBytes;
+ size_t blockIncrementY = numYRowsPerBlock * sizeInfo.fWidthBytes[SkYUVSizeInfo::kY];
+ size_t blockIncrementU = DCTSIZE * sizeInfo.fWidthBytes[SkYUVSizeInfo::kU];
+ size_t blockIncrementV = DCTSIZE * sizeInfo.fWidthBytes[SkYUVSizeInfo::kV];
uint32_t numRowsPerBlock = numYRowsPerBlock;
@@ -713,7 +717,7 @@ SkCodec::Result SkJpegCodec::onGetYUV8Planes(const YUVSizeInfo& sizeInfo, void*
// this requirement using a dummy row buffer.
// FIXME: Should SkCodec have an extra memory buffer that can be shared among
// all of the implementations that use temporary/garbage memory?
- SkAutoTMalloc<JSAMPLE> dummyRow(sizeInfo.fYWidthBytes);
+ SkAutoTMalloc<JSAMPLE> dummyRow(sizeInfo.fWidthBytes[SkYUVSizeInfo::kY]);
for (int i = remainingRows; i < numYRowsPerBlock; i++) {
rowptrs[i] = dummyRow.get();
}
diff --git a/src/codec/SkJpegCodec.h b/src/codec/SkJpegCodec.h
index e3448e9dd1..049c3c956a 100644
--- a/src/codec/SkJpegCodec.h
+++ b/src/codec/SkJpegCodec.h
@@ -46,9 +46,9 @@ protected:
Result onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes, const Options&,
SkPMColor*, int*, int*) override;
- bool onQueryYUV8(YUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const override;
+ bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const override;
- Result onGetYUV8Planes(const YUVSizeInfo& sizeInfo, void* pixels[3]) override;
+ Result onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) override;
SkEncodedFormat onGetEncodedFormat() const override {
return kJPEG_SkEncodedFormat;
diff --git a/src/core/SkImageCacherator.cpp b/src/core/SkImageCacherator.cpp
index ea4d4c2bab..e9b7f6a82a 100644
--- a/src/core/SkImageCacherator.cpp
+++ b/src/core/SkImageCacherator.cpp
@@ -213,12 +213,11 @@ public:
Generator_GrYUVProvider(SkImageGenerator* gen) : fGen(gen) {}
uint32_t onGetID() override { return fGen->uniqueID(); }
- bool onGetYUVSizes(SkISize sizes[3]) override {
- return fGen->getYUV8Planes(sizes, nullptr, nullptr, nullptr);
+ bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const override {
+ return fGen->queryYUV8(sizeInfo, colorSpace);
}
- bool onGetYUVPlanes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
- SkYUVColorSpace* space) override {
- return fGen->getYUV8Planes(sizes, planes, rowBytes, space);
+ bool onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) override {
+ return fGen->getYUV8Planes(sizeInfo, planes);
}
};
diff --git a/src/core/SkImageGenerator.cpp b/src/core/SkImageGenerator.cpp
index 7d71b6701c..c8c94c2270 100644
--- a/src/core/SkImageGenerator.cpp
+++ b/src/core/SkImageGenerator.cpp
@@ -52,56 +52,28 @@ bool SkImageGenerator::getPixels(const SkImageInfo& info, void* pixels, size_t r
return this->getPixels(info, pixels, rowBytes, nullptr, nullptr);
}
-bool SkImageGenerator::getYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
- SkYUVColorSpace* colorSpace) {
-#ifdef SK_DEBUG
- // In all cases, we need the sizes array
- SkASSERT(sizes);
-
- bool isValidWithPlanes = (planes) && (rowBytes) &&
- ((planes[0]) && (planes[1]) && (planes[2]) &&
- (0 != rowBytes[0]) && (0 != rowBytes[1]) && (0 != rowBytes[2]));
- bool isValidWithoutPlanes =
- ((nullptr == planes) ||
- ((nullptr == planes[0]) && (nullptr == planes[1]) && (nullptr == planes[2]))) &&
- ((nullptr == rowBytes) ||
- ((0 == rowBytes[0]) && (0 == rowBytes[1]) && (0 == rowBytes[2])));
-
- // Either we have all planes and rowBytes information or we have none of it
- // Having only partial information is not supported
- SkASSERT(isValidWithPlanes || isValidWithoutPlanes);
-
- // If we do have planes information, make sure all sizes are non 0
- // and all rowBytes are valid
- SkASSERT(!isValidWithPlanes ||
- ((sizes[0].fWidth >= 0) &&
- (sizes[0].fHeight >= 0) &&
- (sizes[1].fWidth >= 0) &&
- (sizes[1].fHeight >= 0) &&
- (sizes[2].fWidth >= 0) &&
- (sizes[2].fHeight >= 0) &&
- (rowBytes[0] >= (size_t)sizes[0].fWidth) &&
- (rowBytes[1] >= (size_t)sizes[1].fWidth) &&
- (rowBytes[2] >= (size_t)sizes[2].fWidth)));
-#endif
+bool SkImageGenerator::queryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const {
+ SkASSERT(sizeInfo);
- return this->onGetYUV8Planes(sizes, planes, rowBytes, colorSpace);
+ return this->onQueryYUV8(sizeInfo, colorSpace);
}
-bool SkImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3]) {
- return false;
-}
-
-bool SkImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
- SkYUVColorSpace* colorSpace) {
- // In order to maintain compatibility with clients that implemented the original
- // onGetYUV8Planes interface, we assume that the color space is JPEG.
- // TODO(rileya): remove this and the old onGetYUV8Planes once clients switch over to
- // the new interface.
- if (colorSpace) {
- *colorSpace = kJPEG_SkYUVColorSpace;
- }
- return this->onGetYUV8Planes(sizes, planes, rowBytes);
+bool SkImageGenerator::getYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) {
+ SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kY].fWidth >= 0);
+ SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight >= 0);
+ SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kU].fWidth >= 0);
+ SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kU].fHeight >= 0);
+ SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kV].fWidth >= 0);
+ SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kV].fHeight >= 0);
+ SkASSERT(sizeInfo.fWidthBytes[SkYUVSizeInfo::kY] >=
+ (size_t) sizeInfo.fSizes[SkYUVSizeInfo::kY].fWidth);
+ SkASSERT(sizeInfo.fWidthBytes[SkYUVSizeInfo::kU] >=
+ (size_t) sizeInfo.fSizes[SkYUVSizeInfo::kU].fWidth);
+ SkASSERT(sizeInfo.fWidthBytes[SkYUVSizeInfo::kV] >=
+ (size_t) sizeInfo.fSizes[SkYUVSizeInfo::kV].fWidth);
+ SkASSERT(planes && planes[0] && planes[1] && planes[2]);
+
+ return this->onGetYUV8Planes(sizeInfo, planes);
}
GrTexture* SkImageGenerator::generateTexture(GrContext* ctx, const SkIRect* subset) {
diff --git a/src/core/SkPixelRef.cpp b/src/core/SkPixelRef.cpp
index 0825760ccd..cdc318b2a8 100644
--- a/src/core/SkPixelRef.cpp
+++ b/src/core/SkPixelRef.cpp
@@ -323,11 +323,6 @@ SkData* SkPixelRef::onRefEncodedData() {
return nullptr;
}
-bool SkPixelRef::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
- SkYUVColorSpace* colorSpace) {
- return false;
-}
-
size_t SkPixelRef::getAllocatedSizeInBytes() const {
return 0;
}
diff --git a/src/core/SkYUVPlanesCache.h b/src/core/SkYUVPlanesCache.h
index a024192d07..1c866a2d2b 100644
--- a/src/core/SkYUVPlanesCache.h
+++ b/src/core/SkYUVPlanesCache.h
@@ -10,6 +10,7 @@
#include "SkCachedData.h"
#include "SkImageInfo.h"
+#include "SkYUVSizeInfo.h"
class SkResourceCache;
@@ -19,17 +20,11 @@ public:
* The Info struct contains data about the 3 Y, U and V planes of memory stored
* contiguously, in that order, as a single block of memory within SkYUVPlanesCache.
*
- * fSize: Width and height of each of the 3 planes (in pixels).
- * fSizeInMemory: Amount of memory allocated for each plane (may be different from
- "height * rowBytes", depending on the jpeg decoder's block size).
- * The sum of these is the total size stored within SkYUVPlanesCache.
- * fRowBytes: rowBytes for each of the 3 planes (in bytes).
+ * fSizeInfo: fWidth, fHeight, and fWidthBytes of each of the Y, U, and V planes.
* fColorSpace: color space that will be used for the YUV -> RGB conversion.
*/
struct Info {
- SkISize fSize[3];
- size_t fSizeInMemory[3];
- size_t fRowBytes[3];
+ SkYUVSizeInfo fSizeInfo;
SkYUVColorSpace fColorSpace;
};
/**
diff --git a/src/gpu/GrYUVProvider.cpp b/src/gpu/GrYUVProvider.cpp
index f889641849..708cbecb11 100644
--- a/src/gpu/GrYUVProvider.cpp
+++ b/src/gpu/GrYUVProvider.cpp
@@ -40,21 +40,20 @@ bool YUVScoper::init(GrYUVProvider* provider, SkYUVPlanesCache::Info* yuvInfo, v
if (fCachedData.get()) {
planes[0] = (void*)fCachedData->data();
- planes[1] = (uint8_t*)planes[0] + yuvInfo->fSizeInMemory[0];
- planes[2] = (uint8_t*)planes[1] + yuvInfo->fSizeInMemory[1];
+ planes[1] = (uint8_t*)planes[0] + (yuvInfo->fSizeInfo.fWidthBytes[SkYUVSizeInfo::kY] *
+ yuvInfo->fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight);
+ planes[2] = (uint8_t*)planes[1] + (yuvInfo->fSizeInfo.fWidthBytes[SkYUVSizeInfo::kU] *
+ yuvInfo->fSizeInfo.fSizes[SkYUVSizeInfo::kU].fHeight);
} else {
- // Fetch yuv plane sizes for memory allocation. Here, width and height can be
- // rounded up to JPEG block size and be larger than the image's width and height.
- if (!provider->onGetYUVSizes(yuvInfo->fSize)) {
+ // Fetch yuv plane sizes for memory allocation.
+ if (!provider->onQueryYUV8(&yuvInfo->fSizeInfo, &yuvInfo->fColorSpace)) {
return false;
}
// Allocate the memory for YUV
size_t totalSize(0);
- for (int i = 0; i < GrYUVProvider::kPlaneCount; ++i) {
- yuvInfo->fRowBytes[i] = yuvInfo->fSize[i].fWidth; // we assume snug fit: rb == width
- yuvInfo->fSizeInMemory[i] = yuvInfo->fRowBytes[i] * yuvInfo->fSize[i].fHeight;
- totalSize += yuvInfo->fSizeInMemory[i];
+ for (int i = 0; i < 3; i++) {
+ totalSize += yuvInfo->fSizeInfo.fWidthBytes[i] * yuvInfo->fSizeInfo.fSizes[i].fHeight;
}
if (useCache) {
fCachedData.reset(SkResourceCache::NewCachedData(totalSize));
@@ -63,12 +62,13 @@ bool YUVScoper::init(GrYUVProvider* provider, SkYUVPlanesCache::Info* yuvInfo, v
fStorage.reset(totalSize);
planes[0] = fStorage.get();
}
- planes[1] = (uint8_t*)planes[0] + yuvInfo->fSizeInMemory[0];
- planes[2] = (uint8_t*)planes[1] + yuvInfo->fSizeInMemory[1];
+ planes[1] = (uint8_t*)planes[0] + (yuvInfo->fSizeInfo.fWidthBytes[SkYUVSizeInfo::kY] *
+ yuvInfo->fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight);
+ planes[2] = (uint8_t*)planes[1] + (yuvInfo->fSizeInfo.fWidthBytes[SkYUVSizeInfo::kU] *
+ yuvInfo->fSizeInfo.fSizes[SkYUVSizeInfo::kU].fHeight);
- // Get the YUV planes and update plane sizes to actual image size
- if (!provider->onGetYUVPlanes(yuvInfo->fSize, planes, yuvInfo->fRowBytes,
- &yuvInfo->fColorSpace)) {
+ // Get the YUV planes.
+ if (!provider->onGetYUV8Planes(yuvInfo->fSizeInfo, planes)) {
return false;
}
@@ -91,20 +91,21 @@ GrTexture* GrYUVProvider::refAsTexture(GrContext* ctx, const GrSurfaceDesc& desc
GrSurfaceDesc yuvDesc;
yuvDesc.fConfig = kAlpha_8_GrPixelConfig;
SkAutoTUnref<GrTexture> yuvTextures[3];
- for (int i = 0; i < 3; ++i) {
- yuvDesc.fWidth = yuvInfo.fSize[i].fWidth;
- yuvDesc.fHeight = yuvInfo.fSize[i].fHeight;
+ for (int i = 0; i < 3; i++) {
+ yuvDesc.fWidth = yuvInfo.fSizeInfo.fSizes[i].fWidth;
+ yuvDesc.fHeight = yuvInfo.fSizeInfo.fSizes[i].fHeight;
// TODO: why do we need this check?
- bool needsExactTexture = (yuvDesc.fWidth != yuvInfo.fSize[0].fWidth) ||
- (yuvDesc.fHeight != yuvInfo.fSize[0].fHeight);
+ bool needsExactTexture =
+ (yuvDesc.fWidth != yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fWidth) ||
+ (yuvDesc.fHeight != yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight);
if (needsExactTexture) {
yuvTextures[i].reset(ctx->textureProvider()->createTexture(yuvDesc, SkBudgeted::kYes));
} else {
yuvTextures[i].reset(ctx->textureProvider()->createApproxTexture(yuvDesc));
}
if (!yuvTextures[i] ||
- !yuvTextures[i]->writePixels(0, 0, yuvDesc.fWidth, yuvDesc.fHeight,
- yuvDesc.fConfig, planes[i], yuvInfo.fRowBytes[i])) {
+ !yuvTextures[i]->writePixels(0, 0, yuvDesc.fWidth, yuvDesc.fHeight, yuvDesc.fConfig,
+ planes[i], yuvInfo.fSizeInfo.fWidthBytes[i])) {
return nullptr;
}
}
@@ -126,11 +127,12 @@ GrTexture* GrYUVProvider::refAsTexture(GrContext* ctx, const GrSurfaceDesc& desc
GrYUVEffect::CreateYUVToRGB(yuvTextures[0],
yuvTextures[1],
yuvTextures[2],
- yuvInfo.fSize,
+ yuvInfo.fSizeInfo.fSizes,
yuvInfo.fColorSpace));
paint.addColorFragmentProcessor(yuvToRgbProcessor);
paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
- const SkRect r = SkRect::MakeIWH(yuvInfo.fSize[0].fWidth, yuvInfo.fSize[0].fHeight);
+ const SkRect r = SkRect::MakeIWH(yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fWidth,
+ yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight);
SkAutoTUnref<GrDrawContext> drawContext(ctx->drawContext(renderTarget));
if (!drawContext) {
diff --git a/src/gpu/GrYUVProvider.h b/src/gpu/GrYUVProvider.h
index 869e1fd00d..85b238d098 100644
--- a/src/gpu/GrYUVProvider.h
+++ b/src/gpu/GrYUVProvider.h
@@ -10,6 +10,7 @@
#include "GrTypes.h"
#include "SkImageInfo.h"
+#include "SkYUVSizeInfo.h"
class GrContext;
class GrTexture;
@@ -38,32 +39,29 @@ public:
virtual uint32_t onGetID() = 0;
- enum {
- kY_Index = 0,
- kU_Index = 1,
- kV_Index = 2,
-
- kPlaneCount = 3
- };
-
// These are not meant to be called by a client, only by the implementation
/**
- * Return the 3 dimensions for each plane and return true. On failure, return false and
- * ignore the sizes parameter. Typical failure is that the provider does not contain YUV
- * data, and may just be an RGB src.
+ * If decoding to YUV is supported, this returns true. Otherwise, this
+ * returns false and does not modify any of the parameters.
+ *
+ * @param sizeInfo Output parameter indicating the sizes and required
+ * allocation widths of the Y, U, and V planes.
+ * @param colorSpace Output parameter.
*/
- virtual bool onGetYUVSizes(SkISize sizes[kPlaneCount]) = 0;
+ virtual bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const = 0;
/**
- * On success, return true, and set sizes, rowbytes and colorspace to the appropriate values.
- * planes[] will have already been allocated by the client (based on the worst-case sizes
- * returned by onGetYUVSizes(). This method copies its planar data into those buffers.
+ * 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 onQueryYUV8().
*
- * On failure, return false and ignore other parameters.
+ * @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.
*/
- virtual bool onGetYUVPlanes(SkISize sizes[kPlaneCount], void* planes[kPlaneCount],
- size_t rowBytes[kPlaneCount], SkYUVColorSpace*) = 0;
+ virtual bool onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) = 0;
};
#endif
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 81a3502455..1463336c49 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -173,12 +173,11 @@ public:
PixelRef_GrYUVProvider(SkPixelRef* pr) : fPR(pr) {}
uint32_t onGetID() override { return fPR->getGenerationID(); }
- bool onGetYUVSizes(SkISize sizes[3]) override {
- return fPR->getYUV8Planes(sizes, nullptr, nullptr, nullptr);
+ bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const override {
+ return fPR->queryYUV8(sizeInfo, colorSpace);
}
- bool onGetYUVPlanes(SkISize sizes[3], void* planes[3], size_t rowBytes[3],
- SkYUVColorSpace* space) override {
- return fPR->getYUV8Planes(sizes, planes, rowBytes, space);
+ bool onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) override {
+ return fPR->getYUV8Planes(sizeInfo, planes);
}
};
diff --git a/src/lazy/SkDiscardablePixelRef.h b/src/lazy/SkDiscardablePixelRef.h
index 695d441d2b..73a2b08250 100644
--- a/src/lazy/SkDiscardablePixelRef.h
+++ b/src/lazy/SkDiscardablePixelRef.h
@@ -54,16 +54,22 @@ private:
size_t rowBytes,
SkDiscardableMemory::Factory* factory);
- bool onGetYUV8Planes(SkISize sizes[3],
- void* planes[3],
- size_t rowBytes[3],
- SkYUVColorSpace* colorSpace) override {
+ bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const override {
// If the image was already decoded with lockPixels(), favor not
// re-decoding to YUV8 planes.
if (fDiscardableMemory) {
return false;
}
- return fGenerator->getYUV8Planes(sizes, planes, rowBytes, colorSpace);
+ return fGenerator->queryYUV8(sizeInfo, colorSpace);
+ }
+
+ bool onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) override {
+ // If the image was already decoded with lockPixels(), favor not
+ // re-decoding to YUV8 planes.
+ if (fDiscardableMemory) {
+ return false;
+ }
+ return fGenerator->getYUV8Planes(sizeInfo, planes);
}
friend bool SkDEPRECATED_InstallDiscardablePixelRef(SkImageGenerator*, const SkIRect*, SkBitmap*,