Add srcData version of createBackendTexture API
Change-Id: I9679774d69e087a4ceb24de78e98585382bf8593
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/218553
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/GrContextPriv.cpp b/src/gpu/GrContextPriv.cpp
index 093acbf..174de02 100644
--- a/src/gpu/GrContextPriv.cpp
+++ b/src/gpu/GrContextPriv.cpp
@@ -367,3 +367,60 @@
return GrConfigConversionEffect::Make(std::move(fp), PMConversion::kToPremul);
}
+
+//////////////////////////////////////////////////////////////////////////////
+
+#include "src/core/SkMipMap.h"
+
+GrBackendTexture GrContextPriv::createBackendTexture(const SkPixmap srcData[], int numLevels,
+ GrRenderable renderable) {
+ if (!fContext->asDirectContext()) {
+ return {};
+ }
+
+ if (this->abandoned()) {
+ return {};
+ }
+
+ if (!srcData || !numLevels) {
+ return {};
+ }
+
+ int baseWidth = srcData[0].width();
+ int baseHeight = srcData[0].height();
+ SkColorType colorType = srcData[0].colorType();
+
+ if (numLevels > 1) {
+ if (numLevels != SkMipMap::ComputeLevelCount(baseWidth, baseHeight) + 1) {
+ return {};
+ }
+
+ int currentWidth = baseWidth;
+ int currentHeight = baseHeight;
+ for (int i = 1; i < numLevels; ++i) {
+ currentWidth = SkTMax(1, currentWidth / 2);
+ currentHeight = SkTMax(1, currentHeight / 2);
+
+ if (srcData[i].colorType() != colorType) {
+ return {};
+ }
+
+ if (srcData[i].width() != currentWidth || srcData[i].height() != currentHeight) {
+ return {};
+ }
+ }
+ }
+
+ GrBackendFormat backendFormat = this->caps()->getBackendFormatFromColorType(colorType);
+ if (!backendFormat.isValid()) {
+ return {};
+ }
+
+ GrGpu* gpu = fContext->fGpu.get();
+
+ // TODO: propagate the array of pixmaps interface to GrGpu
+ return gpu->createBackendTexture(baseWidth, baseHeight, backendFormat,
+ GrMipMapped::kNo, // TODO: use real mipmap setting here
+ renderable, srcData[0].addr(), srcData[0].rowBytes(),
+ nullptr);
+}