[graphite] Simplify prep code around calling UploadSource::Make Bug: b/333909822 Change-Id: I2e44c56364840c092c1b8a6885ff6110f4a4e0fc Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1222817 Reviewed-by: Robert Phillips <robertphillips@google.com> Reviewed-by: Nicolette Prevost <nicolettep@google.com> Commit-Queue: Michael Ludwig <michaelludwig@google.com>
diff --git a/src/gpu/graphite/Device.cpp b/src/gpu/graphite/Device.cpp index b56265c..218c763 100644 --- a/src/gpu/graphite/Device.cpp +++ b/src/gpu/graphite/Device.cpp
@@ -726,21 +726,6 @@ // to backend textures const TextureProxy* target = fDC->target().proxy(); - - // TODO: add mipmap support for createBackendTexture - - if (src.colorType() == kUnknown_SkColorType) { - return false; - } - - // If one alpha type is unknown and the other isn't, it's too underspecified. - if ((src.alphaType() == kUnknown_SkAlphaType) != - (this->imageInfo().alphaType() == kUnknown_SkAlphaType)) { - return false; - } - - // TODO: canvas2DFastPath? - if (!fRecorder->priv().caps()->isCopyableDst(target->textureInfo())) { auto image = SkImages::RasterFromPixmap(src, nullptr, nullptr); image = SkImages::TextureFromImage(fRecorder, image.get()); @@ -759,7 +744,7 @@ return true; } - // TODO: check for flips and either handle here or pass info to UploadTask + SkASSERT(fDC->target().origin() == Origin::kTopLeft); // Determine rect to copy SkIRect dstRect = SkIRect::MakePtSize({x, y}, src.dimensions()); @@ -767,10 +752,8 @@ return false; } - // Set up copy location - const void* addr = src.addr(dstRect.fLeft - x, dstRect.fTop - y); - std::vector<MipLevel> levels; - levels.push_back({addr, src.rowBytes()}); + // Adjust the copy location for any change after intersection + MipLevel level{src.addr(dstRect.fLeft - x, dstRect.fTop - y), src.rowBytes()}; // The writePixels() still respects painter's order, so flush everything to tasks before this // recording the upload for the pixel data. @@ -782,7 +765,7 @@ fDC->target(), src.info().colorInfo(), this->imageInfo().colorInfo(), - levels, + SkSpan(&level, 1), dstRect); return fDC->recordUpload(fRecorder, uploadSource); }
diff --git a/src/gpu/graphite/DrawAtlas.cpp b/src/gpu/graphite/DrawAtlas.cpp index d8e13b2..a869331 100644 --- a/src/gpu/graphite/DrawAtlas.cpp +++ b/src/gpu/graphite/DrawAtlas.cpp
@@ -184,11 +184,10 @@ continue; } - std::vector<MipLevel> levels; - levels.push_back({dataPtr, plot->rowBytes()}); - + MipLevel level{dataPtr, plot->rowBytes()}; const UploadSource uploadSource = UploadSource::Make( - recorder->priv().caps(), view, colorInfo, colorInfo, levels, dstRect); + recorder->priv().caps(), view, colorInfo, colorInfo, + SkSpan(&level, 1), dstRect); if (!dc->recordUpload(recorder, uploadSource)) { return false; }
diff --git a/src/gpu/graphite/Recorder.cpp b/src/gpu/graphite/Recorder.cpp index a03e8f7..293d3c7 100644 --- a/src/gpu/graphite/Recorder.cpp +++ b/src/gpu/graphite/Recorder.cpp
@@ -392,34 +392,23 @@ return false; } - SkColorType ct = srcData[0].colorType(); - - TextureFormat format = TextureInfoPriv::ViewFormat(backendTex.info()); - if (!AreColorTypeAndFormatCompatible(ct, format)) { - return false; - } - sk_sp<Texture> texture = this->priv().resourceProvider()->createWrappedTexture(backendTex, ""); if (!texture) { return false; } texture->setReleaseCallback(std::move(releaseHelper)); - std::vector<MipLevel> mipLevels; - mipLevels.resize(numLevels); - + skia_private::STArray<16, MipLevel> mipLevels(numLevels); for (int i = 0; i < numLevels; ++i) { - SkASSERT(srcData[i].addr()); SkASSERT(srcData[i].info().colorInfo() == srcData[0].info().colorInfo()); - - mipLevels[i].fPixels = srcData[i].addr(); - mipLevels[i].fRowBytes = srcData[i].rowBytes(); + mipLevels.push_back({srcData[i].addr(), srcData[i].rowBytes()}); } // Src and dst colorInfo are the same const SkColorInfo& colorInfo = srcData[0].info().colorInfo(); + TextureFormat format = TextureInfoPriv::ViewFormat(backendTex.info()); TextureProxyView view{TextureProxy::Wrap(std::move(texture)), - ReadSwizzleForColorType(srcData[0].info().colorType(), format)}; + ReadSwizzleForColorType(colorInfo.colorType(), format)}; const SkIRect dimensions = SkIRect::MakeSize(backendTex.dimensions()); UploadSource uploadSource = UploadSource::Make( this->priv().caps(), std::move(view), colorInfo, colorInfo, mipLevels, dimensions);
diff --git a/src/gpu/graphite/TextureUtils.cpp b/src/gpu/graphite/TextureUtils.cpp index a2c419f..34991ab 100644 --- a/src/gpu/graphite/TextureUtils.cpp +++ b/src/gpu/graphite/TextureUtils.cpp
@@ -13,6 +13,7 @@ #include "include/core/SkPaint.h" #include "include/core/SkSurface.h" #include "include/effects/SkRuntimeEffect.h" +#include "include/private/base/SkTArray.h" #include "src/core/SkBlurEngine.h" #include "src/core/SkCompressedDataUtils.h" #include "src/core/SkDevice.h" @@ -275,33 +276,19 @@ SkMipmap::ComputeLevelCount(bitmap.width(), bitmap.height()) + 1 : 1; // setup MipLevels - sk_sp<SkMipmap> mipmaps; - std::vector<MipLevel> texels; - if (mipLevelCount == 1) { - texels.resize(mipLevelCount); - texels[0].fPixels = bitmap.getPixels(); - texels[0].fRowBytes = bitmap.rowBytes(); - } else { - mipmaps = SkToBool(mipmapsIn) - ? mipmapsIn - : sk_sp<SkMipmap>(SkMipmap::Build(bitmap.pixmap(), nullptr)); - if (!mipmaps) { + sk_sp<SkMipmap> mipmaps = mipmapsIn; + skia_private::STArray<16, MipLevel> levels(mipLevelCount); + levels.push_back({bitmap.getPixels(), bitmap.rowBytes()}); // base level is always included + if (mipLevelCount > 1) { + if (!mipmaps && !(mipmaps = sk_sp<SkMipmap>(SkMipmap::Build(bitmap.pixmap(), nullptr)))) { + SKGPU_LOG_E("Generating mipmaps failed"); return {}; } - SkASSERT(mipLevelCount == mipmaps->countLevels() + 1); - texels.resize(mipLevelCount); - - texels[0].fPixels = bitmap.getPixels(); - texels[0].fRowBytes = bitmap.rowBytes(); - for (int i = 1; i < mipLevelCount; ++i) { - SkMipmap::Level generatedMipLevel; - mipmaps->getLevel(i - 1, &generatedMipLevel); - texels[i].fPixels = generatedMipLevel.fPixmap.addr(); - texels[i].fRowBytes = generatedMipLevel.fPixmap.rowBytes(); - SkASSERT(texels[i].fPixels); - SkASSERT(generatedMipLevel.fPixmap.colorType() == bitmap.colorType()); + SkMipmap::Level mipLevel; + SkAssertResult(mipmaps->getLevel(i - 1, &mipLevel)); + levels.push_back({mipLevel.fPixmap.addr(), mipLevel.fPixmap.rowBytes()}); } } @@ -331,7 +318,7 @@ const SkIRect dimensions = SkIRect::MakeSize(bitmap.dimensions()); // Move the view into `uploadSource` so that it is the unique holder of the proxy UploadSource uploadSource = UploadSource::Make( - recorder->priv().caps(), std::move(view), colorInfo, colorInfo, texels, dimensions); + recorder->priv().caps(), std::move(view), colorInfo, colorInfo, levels, dimensions); if (!uploadSource.isValid()) { SKGPU_LOG_E("MakeBitmapProxyView: Could not create UploadSource"); return {};