Remove SkSpan class template deduction guides
This effectively reverts a80ce1a36d8c3545661ffbfb02d8eb7255f0b6c2,
and goes back to using SkMakeSpan (which works in C++14).
Change-Id: Iaa63c86b5acaadbdd60588b0a5c703820e810770
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/406938
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index aec582a..06c5da0 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -2292,10 +2292,10 @@
SkGlyphRun glyphRun {
font,
- SkSpan(positions, count),
- SkSpan(glyphs, count),
- SkSpan(utf8text, textByteCount),
- SkSpan(clusters, count),
+ SkMakeSpan(positions, count),
+ SkMakeSpan(glyphs, count),
+ SkMakeSpan(utf8text, textByteCount),
+ SkMakeSpan(clusters, count),
SkSpan<SkVector>()
};
SkGlyphRunList glyphRunList {
@@ -2312,8 +2312,8 @@
SkGlyphRun glyphRun {
font,
- SkSpan(positions, count),
- SkSpan(glyphs, count),
+ SkMakeSpan(positions, count),
+ SkMakeSpan(glyphs, count),
SkSpan<const char>(),
SkSpan<const uint32_t>(),
SkSpan<SkVector>()
@@ -2330,12 +2330,13 @@
SkPoint origin, const SkFont& font, const SkPaint& paint) {
if (count <= 0) { return; }
- auto [positions, rotateScales] = fScratchGlyphRunBuilder->convertRSXForm(SkSpan(xforms, count));
+ auto [positions, rotateScales] =
+ fScratchGlyphRunBuilder->convertRSXForm(SkMakeSpan(xforms, count));
SkGlyphRun glyphRun {
font,
positions,
- SkSpan(glyphs, count),
+ SkMakeSpan(glyphs, count),
SkSpan<const char>(),
SkSpan<const uint32_t>(),
rotateScales
diff --git a/src/core/SkFont.cpp b/src/core/SkFont.cpp
index 4886077..6e066dd 100644
--- a/src/core/SkFont.cpp
+++ b/src/core/SkFont.cpp
@@ -226,7 +226,7 @@
SkStrikeSpec strikeSpec = SkStrikeSpec::MakeCanonicalized(*this, paint);
SkBulkGlyphMetrics metrics{strikeSpec};
- SkSpan<const SkGlyph*> glyphs = metrics.glyphs(SkSpan(glyphIDs, glyphCount));
+ SkSpan<const SkGlyph*> glyphs = metrics.glyphs(SkMakeSpan(glyphIDs, glyphCount));
SkScalar width = 0;
if (bounds) {
@@ -265,7 +265,7 @@
const SkPaint* paint) const {
SkStrikeSpec strikeSpec = SkStrikeSpec::MakeCanonicalized(*this, paint);
SkBulkGlyphMetrics metrics{strikeSpec};
- SkSpan<const SkGlyph*> glyphs = metrics.glyphs(SkSpan(glyphIDs, count));
+ SkSpan<const SkGlyph*> glyphs = metrics.glyphs(SkMakeSpan(glyphIDs, count));
SkScalar scale = strikeSpec.strikeToSourceRatio();
@@ -288,7 +288,7 @@
void SkFont::getPos(const SkGlyphID glyphIDs[], int count, SkPoint pos[], SkPoint origin) const {
SkStrikeSpec strikeSpec = SkStrikeSpec::MakeCanonicalized(*this);
SkBulkGlyphMetrics metrics{strikeSpec};
- SkSpan<const SkGlyph*> glyphs = metrics.glyphs(SkSpan(glyphIDs, count));
+ SkSpan<const SkGlyph*> glyphs = metrics.glyphs(SkMakeSpan(glyphIDs, count));
SkPoint sum = origin;
for (auto glyph : glyphs) {
@@ -302,7 +302,7 @@
SkStrikeSpec strikeSpec = SkStrikeSpec::MakeCanonicalized(*this);
SkBulkGlyphMetrics metrics{strikeSpec};
- SkSpan<const SkGlyph*> glyphs = metrics.glyphs(SkSpan(glyphIDs, count));
+ SkSpan<const SkGlyph*> glyphs = metrics.glyphs(SkMakeSpan(glyphIDs, count));
SkScalar loc = origin;
SkScalar* cursor = xpos;
@@ -320,7 +320,7 @@
SkStrikeSpec strikeSpec = SkStrikeSpec::MakeWithNoDevice(font);
SkBulkGlyphMetricsAndPaths paths{strikeSpec};
- SkSpan<const SkGlyph*> glyphs = paths.glyphs(SkSpan(glyphIDs, count));
+ SkSpan<const SkGlyph*> glyphs = paths.glyphs(SkMakeSpan(glyphIDs, count));
for (auto glyph : glyphs) {
proc(glyph->path(), mx, ctx);
diff --git a/src/core/SkGlyphRun.cpp b/src/core/SkGlyphRun.cpp
index a8b638f..40594e4 100644
--- a/src/core/SkGlyphRun.cpp
+++ b/src/core/SkGlyphRun.cpp
@@ -184,7 +184,7 @@
*positionCursor++ = endOfLastGlyph;
endOfLastGlyph += glyph->advanceVector();
}
- return SkSpan(buffer, glyphIDs.size());
+ return SkMakeSpan(buffer, glyphIDs.size());
}
const SkGlyphRunList& SkGlyphRunBuilder::textToGlyphRunList(
@@ -234,20 +234,20 @@
break;
}
case SkTextBlobRunIterator::kHorizontal_Positioning: {
- positions = SkSpan(positionCursor, runSize);
+ positions = SkMakeSpan(positionCursor, runSize);
for (auto x : SkSpan<const SkScalar>{it.pos(), glyphIDs.size()}) {
*positionCursor++ = SkPoint::Make(x, it.offset().y());
}
break;
}
case SkTextBlobRunIterator::kFull_Positioning: {
- positions = SkSpan(it.points(), runSize);
+ positions = SkMakeSpan(it.points(), runSize);
break;
}
case SkTextBlobRunIterator::kRSXform_Positioning: {
- positions = SkSpan(positionCursor, runSize);
- scaledRotations = SkSpan(scaledRotationsCursor, runSize);
- for (const SkRSXform& xform : SkSpan(it.xforms(), runSize)) {
+ positions = SkMakeSpan(positionCursor, runSize);
+ scaledRotations = SkMakeSpan(scaledRotationsCursor, runSize);
+ for (const SkRSXform& xform : SkMakeSpan(it.xforms(), runSize)) {
*positionCursor++ = {xform.fTx, xform.fTy};
*scaledRotationsCursor++ = {xform.fSCos, xform.fSSin};
}
@@ -271,8 +271,8 @@
SkGlyphRunBuilder::convertRSXForm(SkSpan<const SkRSXform> xforms) {
const int count = SkCount(xforms);
this->prepareBuffers(count, count);
- auto positions = SkSpan(fPositions.get(), count);
- auto scaledRotations = SkSpan(fScaledRotations.get(), count);
+ auto positions = SkMakeSpan(fPositions.get(), count);
+ auto scaledRotations = SkMakeSpan(fScaledRotations.get(), count);
for (auto [pos, sr, xform] : SkMakeZip(positions, scaledRotations, xforms)) {
auto [scos, ssin, tx, ty] = xform;
pos = {tx, ty};
@@ -317,7 +317,7 @@
if (count > 0) {
fScratchGlyphIDs.resize(count);
font.textToGlyphs(bytes, byteLength, encoding, fScratchGlyphIDs.data(), count);
- return SkSpan(fScratchGlyphIDs);
+ return SkMakeSpan(fScratchGlyphIDs);
} else {
return SkSpan<const SkGlyphID>();
}
@@ -349,5 +349,6 @@
const SkGlyphRunList& SkGlyphRunBuilder::makeGlyphRunList(
const SkTextBlob* blob, const SkRect& bounds, SkPoint origin) {
fGlyphRunList.~SkGlyphRunList();
- return *new (&fGlyphRunList) SkGlyphRunList{blob, bounds, origin, SkSpan(fGlyphRunListStorage)};
+ return *new (&fGlyphRunList)
+ SkGlyphRunList{blob, bounds, origin, SkMakeSpan(fGlyphRunListStorage)};
}
diff --git a/src/core/SkRuntimeEffect.cpp b/src/core/SkRuntimeEffect.cpp
index 4a72713..cb6ead5 100644
--- a/src/core/SkRuntimeEffect.cpp
+++ b/src/core/SkRuntimeEffect.cpp
@@ -464,7 +464,7 @@
skvm::Color result = SkSL::ProgramToSkVM(*fBaseProgram,
fMain,
&p,
- uniform,
+ SkMakeSpan(uniform),
/*device=*/zeroCoord,
/*local=*/zeroCoord,
inputColor,
@@ -607,7 +607,7 @@
uniform.push_back(p->uniform32(uniforms->push(bits)).id);
}
- return SkSL::ProgramToSkVM(*fEffect->fBaseProgram, fEffect->fMain, p, uniform,
+ return SkSL::ProgramToSkVM(*fEffect->fBaseProgram, fEffect->fMain, p, SkMakeSpan(uniform),
/*device=*/zeroCoord, /*local=*/zeroCoord, c, sampleChild);
}
@@ -782,7 +782,7 @@
uniform.push_back(p->uniform32(uniforms->push(bits)).id);
}
- return SkSL::ProgramToSkVM(*fEffect->fBaseProgram, fEffect->fMain, p, uniform,
+ return SkSL::ProgramToSkVM(*fEffect->fBaseProgram, fEffect->fMain, p, SkMakeSpan(uniform),
device, local, paint, sampleChild);
}
diff --git a/src/core/SkSpan.h b/src/core/SkSpan.h
index a61c04e..667959b 100644
--- a/src/core/SkSpan.h
+++ b/src/core/SkSpan.h
@@ -14,6 +14,10 @@
#include <utility>
#include "include/private/SkTLogic.h"
+/**
+ * With C++17, we could add template deduction guides that eliminate the need for SkMakeSpan:
+ * https://skia-review.googlesource.com/c/skia/+/320264
+ */
template <typename T>
class SkSpan {
public:
@@ -22,9 +26,6 @@
template <typename U, typename = typename std::enable_if<std::is_same<const U, T>::value>::type>
constexpr SkSpan(const SkSpan<U>& that) : fPtr(that.data()), fSize{that.size()} {}
constexpr SkSpan(const SkSpan& o) = default;
- template<size_t N> constexpr SkSpan(T(&a)[N]) : SkSpan{a, N} { }
- template<typename Container>
- constexpr SkSpan(Container& c) : SkSpan{skstd::data(c), skstd::size(c)} { }
constexpr SkSpan& operator=(const SkSpan& that) {
fPtr = that.fPtr;
@@ -64,8 +65,18 @@
size_t fSize;
};
-template<typename Container>
-SkSpan(Container&) -> SkSpan<std::remove_pointer_t<decltype(
- skstd::data(std::declval<Container&>()))>>;
+template <typename T, typename S> inline constexpr SkSpan<T> SkMakeSpan(T* p, S s) {
+ return SkSpan<T>{p, SkTo<size_t>(s)};
+}
+
+template <size_t N, typename T> inline constexpr SkSpan<T> SkMakeSpan(T (&a)[N]) {
+ return SkSpan<T>{a, N};
+}
+
+template <typename Container>
+inline auto SkMakeSpan(Container& c)
+ -> SkSpan<typename std::remove_reference<decltype(*(c.data()))>::type> {
+ return {c.data(), c.size()};
+}
#endif // SkSpan_DEFINED
diff --git a/src/core/SkZip.h b/src/core/SkZip.h
index e5a9c60..5cf6120 100644
--- a/src/core/SkZip.h
+++ b/src/core/SkZip.h
@@ -78,7 +78,7 @@
constexpr Iterator begin() const { return Iterator{this, 0}; }
constexpr Iterator end() const { return Iterator{this, this->size()}; }
template<size_t I> constexpr auto get() const {
- return SkSpan(std::get<I>(fPointers), fSize);
+ return SkMakeSpan(std::get<I>(fPointers), fSize);
}
constexpr std::tuple<Ts*...> data() const { return fPointers; }
constexpr SkZip first(size_t n) const {
diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp
index dec1726..4ce8c21 100644
--- a/src/gpu/GrDrawingManager.cpp
+++ b/src/gpu/GrDrawingManager.cpp
@@ -161,7 +161,7 @@
}
for (GrOnFlushCallbackObject* onFlushCBObject : fOnFlushCBObjects) {
- onFlushCBObject->preFlush(&onFlushProvider, fFlushingRenderTaskIDs);
+ onFlushCBObject->preFlush(&onFlushProvider, SkMakeSpan(fFlushingRenderTaskIDs));
}
for (const auto& onFlushRenderTask : fOnFlushRenderTasks) {
onFlushRenderTask->makeClosed(*fContext->priv().caps());
@@ -229,7 +229,8 @@
flushed = false;
}
for (GrOnFlushCallbackObject* onFlushCBObject : fOnFlushCBObjects) {
- onFlushCBObject->postFlush(fTokenTracker.nextTokenToFlush(), fFlushingRenderTaskIDs);
+ onFlushCBObject->postFlush(fTokenTracker.nextTokenToFlush(),
+ SkMakeSpan(fFlushingRenderTaskIDs));
flushed = true;
}
if (flushed) {
@@ -391,7 +392,7 @@
bool GrDrawingManager::reorderTasks(GrResourceAllocator* resourceAllocator) {
SkASSERT(fReduceOpsTaskSplitting);
SkTInternalLList<GrRenderTask> llist;
- bool clustered = GrClusterRenderTasks(fDAG, &llist);
+ bool clustered = GrClusterRenderTasks(SkMakeSpan(fDAG), &llist);
if (!clustered) {
return false;
}
diff --git a/src/gpu/GrRenderTask.h b/src/gpu/GrRenderTask.h
index 5c9d67f..b7cb305 100644
--- a/src/gpu/GrRenderTask.h
+++ b/src/gpu/GrRenderTask.h
@@ -78,8 +78,8 @@
*/
void addDependenciesFromOtherTask(GrRenderTask* otherTask);
- SkSpan<GrRenderTask*> dependencies() { return SkSpan<GrRenderTask*>(fDependencies); }
- SkSpan<GrRenderTask*> dependents() { return SkSpan<GrRenderTask*>(fDependents); }
+ SkSpan<GrRenderTask*> dependencies() { return SkMakeSpan(fDependencies); }
+ SkSpan<GrRenderTask*> dependents() { return SkMakeSpan(fDependents); }
void replaceDependency(const GrRenderTask* toReplace, GrRenderTask* replaceWith);
void replaceDependent(const GrRenderTask* toReplace, GrRenderTask* replaceWith);
diff --git a/src/gpu/text/GrTextBlob.cpp b/src/gpu/text/GrTextBlob.cpp
index 4e25999..8cb00bd 100644
--- a/src/gpu/text/GrTextBlob.cpp
+++ b/src/gpu/text/GrTextBlob.cpp
@@ -347,11 +347,11 @@
variants[i] = gv.glyph()->getPackedID();
}
- return GlyphVector{spec, SkSpan(variants, glyphs.size())};
+ return GlyphVector{spec, SkMakeSpan(variants, glyphs.size())};
}
SkSpan<const GrGlyph*> GlyphVector::glyphs() const {
- return SkSpan(reinterpret_cast<const GrGlyph**>(fGlyphs.data()), fGlyphs.size());
+ return SkMakeSpan(reinterpret_cast<const GrGlyph**>(fGlyphs.data()), fGlyphs.size());
}
void GlyphVector::packedGlyphIDToGrGlyph(GrStrikeCache* cache) {
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index 866bf5c..bc56b53 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -768,7 +768,7 @@
surfaceContext.writePixels(dContext, pixmap, {0, 0});
GrSurfaceProxy* p[1] = {surfaceContext.asSurfaceProxy()};
- drawingManager->flush(p, SkSurface::BackendSurfaceAccess::kNoAccess, {}, nullptr);
+ drawingManager->flush(SkMakeSpan(p), SkSurface::BackendSurfaceAccess::kNoAccess, {}, nullptr);
return image;
}
diff --git a/src/pdf/SkPDFMakeCIDGlyphWidthsArray.cpp b/src/pdf/SkPDFMakeCIDGlyphWidthsArray.cpp
index 84d47de..2696166 100644
--- a/src/pdf/SkPDFMakeCIDGlyphWidthsArray.cpp
+++ b/src/pdf/SkPDFMakeCIDGlyphWidthsArray.cpp
@@ -111,7 +111,7 @@
subset.getSetValues([&](unsigned index) {
glyphIDs.push_back(SkToU16(index));
});
- auto glyphs = paths.glyphs(SkSpan(glyphIDs));
+ auto glyphs = paths.glyphs(SkMakeSpan(glyphIDs));
#if defined(SK_PDF_CAN_USE_DW)
std::vector<int16_t> advances;
diff --git a/src/pdf/SkPDFType1Font.cpp b/src/pdf/SkPDFType1Font.cpp
index c0bac2d..4914300 100644
--- a/src/pdf/SkPDFType1Font.cpp
+++ b/src/pdf/SkPDFType1Font.cpp
@@ -310,7 +310,7 @@
}
SkStrikeSpec strikeSpec = SkStrikeSpec::MakePDFVector(*typeface, &emSize);
SkBulkGlyphMetrics metrics{strikeSpec};
- auto glyphs = metrics.glyphs(SkSpan(glyphIDs.get(), glyphRangeSize));
+ auto glyphs = metrics.glyphs(SkMakeSpan(glyphIDs.get(), glyphRangeSize));
for (int i = 0; i < glyphRangeSize; ++i) {
widths->appendScalar(from_font_units(glyphs[i]->advanceX(), SkToU16(emSize)));
}
diff --git a/src/sksl/codegen/SkSLVMCodeGenerator.cpp b/src/sksl/codegen/SkSLVMCodeGenerator.cpp
index 876f885..dcf052a 100644
--- a/src/sksl/codegen/SkSLVMCodeGenerator.cpp
+++ b/src/sksl/codegen/SkSLVMCodeGenerator.cpp
@@ -101,7 +101,7 @@
return fVals[i];
}
- SkSpan<skvm::Val> asSpan() { return fVals; }
+ SkSpan<skvm::Val> asSpan() { return SkMakeSpan(fVals); }
private:
SkSTArray<4, skvm::Val, true> fVals;
@@ -1218,7 +1218,7 @@
ScopedCondition m(this, ~currentFunction().fReturned);
SkASSERTF(f.function().definition(), "no definition for function '%s'",
f.function().description().c_str());
- this->writeFunction(*f.function().definition(), argVals, result.asSpan());
+ this->writeFunction(*f.function().definition(), SkMakeSpan(argVals), result.asSpan());
}
// Propagate new values of any 'out' params back to the original arguments
@@ -1645,7 +1645,7 @@
SkVMGenerator generator(
program, builder, uniforms, device, local, inputColor, std::move(sampleChild));
- generator.writeFunction(function, {args, argSlots}, result);
+ generator.writeFunction(function, {args, argSlots}, SkMakeSpan(result));
return skvm::Color{{builder, result[0]},
{builder, result[1]},
@@ -1687,7 +1687,7 @@
skvm::Color zeroColor = {zero, zero, zero, zero};
SkVMGenerator generator(program, b, uniforms, /*device=*/zeroCoord, /*local=*/zeroCoord,
/*inputColor=*/zeroColor, /*sampleChild=*/{});
- generator.writeFunction(function, argVals, returnVals);
+ generator.writeFunction(function, SkMakeSpan(argVals), SkMakeSpan(returnVals));
// generateCode has updated the contents of 'argVals' for any 'out' or 'inout' parameters.
// Propagate those changes back to our varying buffers:
@@ -1818,7 +1818,7 @@
skvm::Color inColor = builder->uniformColor(SkColors::kWhite, &uniforms);
skvm::Color result = SkSL::ProgramToSkVM(
- program, *main, builder, uniformVals, device, local, inColor, sampleChild);
+ program, *main, builder, SkMakeSpan(uniformVals), device, local, inColor, sampleChild);
storeF(builder->varying<float>(), result.r);
storeF(builder->varying<float>(), result.g);
diff --git a/src/utils/SkShaperJSONWriter.cpp b/src/utils/SkShaperJSONWriter.cpp
index e450505..bbeb4c3 100644
--- a/src/utils/SkShaperJSONWriter.cpp
+++ b/src/utils/SkShaperJSONWriter.cpp
@@ -100,8 +100,8 @@
} else {
VisualizeClusters(fUTF8.c_str(),
info.utf8Range.begin(), info.utf8Range.end(),
- SkSpan(fGlyphs),
- SkSpan(fClusters),
+ SkMakeSpan(fGlyphs),
+ SkMakeSpan(fClusters),
[this](size_t codePointCount, SkSpan<const char> utf1to1,
SkSpan<const SkGlyphID> glyph1to1) {
this->displayMToN(codePointCount, utf1to1, glyph1to1);