Revert "Revert "Restore GL_UNPACK_ROW_LENGTH to 0 between MIP levles""
This reverts commit abb5a315af45cdfc13fbe71265e8630041f8d845.
Two fixes:
1) GMs pass valid rowBytes when calling directly to GrGpu.
2) Check for non-null data before trying to set UNPACK_ROW_LENGTH
Bug: chromium:981254
Change-Id: I24e46b0d2b14562d6b84a29fefe3410ce5c06c94
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/226498
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/gm/wacky_yuv_formats.cpp b/gm/wacky_yuv_formats.cpp
index 37b174c..d7c9682 100644
--- a/gm/wacky_yuv_formats.cpp
+++ b/gm/wacky_yuv_formats.cpp
@@ -917,11 +917,12 @@
static void make_RG_88(const GrCaps* caps,
const SkBitmap& bm, YUVFormat yuvFormat,
SkAutoTMalloc<uint8_t>* pixels,
- GrBackendFormat* format) {
+ GrBackendFormat* format, size_t* rowBytes) {
SkASSERT(kNV12_YUVFormat == yuvFormat || kNV21_YUVFormat == yuvFormat);
SkASSERT(kRGBA_8888_SkColorType == bm.colorType()); // uv stored in rg
- pixels->reset(2 * sizeof(uint8_t) * bm.width() * bm.height());
+ *rowBytes = bm.width() * 2 * sizeof(uint8_t);
+ pixels->reset(*rowBytes * bm.height());
uint8_t* currPixel = pixels->get();
for (int y = 0; y < bm.height(); ++y) {
for (int x = 0; x < bm.width(); ++x) {
@@ -940,12 +941,13 @@
static void make_RG_1616(const GrCaps* caps,
const SkBitmap& bm, YUVFormat yuvFormat,
SkAutoTMalloc<uint8_t>* pixels,
- GrBackendFormat* format) {
+ GrBackendFormat* format, size_t* rowBytes) {
SkASSERT(kP016_YUVFormat == yuvFormat || kP010_YUVFormat == yuvFormat);
SkASSERT(kRGBA_8888_SkColorType == bm.colorType()); // uv stored in rg
uint16_t u16, v16;
- pixels->reset(2 * sizeof(uint16_t) * bm.width() * bm.height());
+ *rowBytes = bm.width() * 2 * sizeof(uint16_t);
+ pixels->reset(*rowBytes * bm.height());
uint16_t* currPixel = (uint16_t*) pixels->get();
for (int y = 0; y < bm.height(); ++y) {
for (int x = 0; x < bm.width(); ++x) {
@@ -974,12 +976,14 @@
const SkBitmap& bm,
YUVFormat yuvFormat,
SkAutoTMalloc<uint8_t>* pixels,
- GrBackendFormat* format) {
+ GrBackendFormat* format,
+ size_t* rowBytes) {
SkASSERT(kY416_YUVFormat == yuvFormat);
SkASSERT(kRGBA_8888_SkColorType == bm.colorType());
uint16_t y16, u16, v16, a16;
- pixels->reset(4 * sizeof(uint16_t) * bm.width() * bm.height());
+ *rowBytes = 4 * sizeof(uint16_t) * bm.width();
+ pixels->reset(*rowBytes * bm.height());
uint16_t* currPixel = (uint16_t*) pixels->get();
for (int y = 0; y < bm.height(); ++y) {
for (int x = 0; x < bm.width(); ++x) {
@@ -1006,12 +1010,14 @@
const SkBitmap& bm,
YUVFormat yuvFormat,
SkAutoTMalloc<uint8_t>* pixels,
- GrBackendFormat* format) {
+ GrBackendFormat* format,
+ size_t* rowBytes) {
SkASSERT(kP016_YUVFormat == yuvFormat || kP010_YUVFormat == yuvFormat);
SkASSERT(kAlpha_8_SkColorType == bm.colorType());
uint16_t y16;
- pixels->reset(sizeof(uint16_t) * bm.width() * bm.height());
+ *rowBytes = sizeof(uint16_t) * bm.width();
+ pixels->reset(*rowBytes * bm.height());
uint16_t* currPixel = (uint16_t*) pixels->get();
for (int y = 0; y < bm.height(); ++y) {
for (int x = 0; x < bm.width(); ++x) {
@@ -1052,24 +1058,25 @@
SkAutoTMalloc<uint8_t> pixels;
GrBackendFormat format;
+ size_t rowBytes;
if (2 == channelCount) {
if (format_uses_16_bpp(yuvFormat)) {
- make_RG_1616(caps, bm, yuvFormat, &pixels, &format);
+ make_RG_1616(caps, bm, yuvFormat, &pixels, &format, &rowBytes);
} else {
- make_RG_88(caps, bm, yuvFormat, &pixels, &format);
+ make_RG_88(caps, bm, yuvFormat, &pixels, &format, &rowBytes);
}
} else {
if (kRGBA_8888_SkColorType == bm.colorType()) {
- make_RGBA_16(caps, bm, yuvFormat, &pixels, &format);
+ make_RGBA_16(caps, bm, yuvFormat, &pixels, &format, &rowBytes);
} else {
- make_R_16(caps, bm, yuvFormat, &pixels, &format);
+ make_R_16(caps, bm, yuvFormat, &pixels, &format, &rowBytes);
}
}
tex = gpu->createBackendTexture(bm.width(), bm.height(), format,
GrMipMapped::kNo, GrRenderable::kNo,
- pixels, 0, nullptr, GrProtected::kNo);
+ pixels, rowBytes, nullptr, GrProtected::kNo);
} else {
tex = context->priv().createBackendTexture(&bm.pixmap(), 1,
GrRenderable::kNo, GrProtected::kNo);