diff --git a/include/core/SkData.h b/include/core/SkData.h index eb845b5ad3..2a4b40d5f6 100644 --- a/include/core/SkData.h +++ b/include/core/SkData.h @@ -86,6 +86,12 @@ public: */ static sk_sp MakeUninitialized(size_t length); + /** + * Create a new data with zero-initialized contents. The caller should call writable_data() + * to write into the buffer, but this must be done before another ref() is made. + */ + static sk_sp MakeZeroInitialized(size_t length); + /** * Create a new dataref by copying the specified c-string * (a null-terminated array of bytes). The returned SkData will have size() diff --git a/include/effects/SkRuntimeEffect.h b/include/effects/SkRuntimeEffect.h index 15cf6e5e37..7226d0f0ff 100644 --- a/include/effects/SkRuntimeEffect.h +++ b/include/effects/SkRuntimeEffect.h @@ -380,7 +380,7 @@ protected: SkRuntimeEffectBuilder() = delete; explicit SkRuntimeEffectBuilder(sk_sp effect) : fEffect(std::move(effect)) - , fUniforms(SkData::MakeUninitialized(fEffect->uniformSize())) + , fUniforms(SkData::MakeZeroInitialized(fEffect->uniformSize())) , fChildren(fEffect->children().size()) {} SkRuntimeEffectBuilder(SkRuntimeEffectBuilder&&) = default; diff --git a/src/core/SkData.cpp b/src/core/SkData.cpp index f9575426a9..e33846b000 100644 --- a/src/core/SkData.cpp +++ b/src/core/SkData.cpp @@ -111,6 +111,14 @@ sk_sp SkData::MakeUninitialized(size_t length) { return PrivateNewWithCopy(nullptr, length); } +sk_sp SkData::MakeZeroInitialized(size_t length) { + auto data = MakeUninitialized(length); + if (length != 0) { + memset(data->writable_data(), 0, data->size()); + } + return data; +} + sk_sp SkData::MakeWithProc(const void* ptr, size_t length, ReleaseProc proc, void* ctx) { return sk_sp(new SkData(ptr, length, proc, ctx)); }