Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(536)

Unified Diff: src/effects/gradients/SkGradientShaderPriv.h

Issue 2397473003: Harden degenerate gradient context handling (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/effects/gradients/SkGradientShader.cpp ('k') | src/effects/gradients/SkLinearGradient.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/gradients/SkGradientShaderPriv.h
diff --git a/src/effects/gradients/SkGradientShaderPriv.h b/src/effects/gradients/SkGradientShaderPriv.h
index f850994761e02eea77aac6e6516794a60c00a55f..61a44184ff27d006accd60dc6babdac4156398df 100644
--- a/src/effects/gradients/SkGradientShaderPriv.h
+++ b/src/effects/gradients/SkGradientShaderPriv.h
@@ -115,7 +115,6 @@ public:
SkAutoMalloc fDynamicStorage;
};
-public:
SkGradientShaderBase(const Descriptor& desc, const SkMatrix& ptsToUnit);
virtual ~SkGradientShaderBase();
@@ -159,6 +158,8 @@ public:
uint32_t getFlags() const override { return fFlags; }
+ bool isValid() const;
+
protected:
SkMatrix fDstToIndex;
SkMatrix::MapXYProc fDstToIndexProc;
@@ -233,6 +234,16 @@ protected:
SkColor* colorSrc, Rec* recSrc,
int count);
+ template <typename T, typename... Args>
+ static Context* CheckedCreateContext(void* storage, Args&&... args) {
+ auto* ctx = new (storage) T(std::forward<Args>(args)...);
+ if (!ctx->isValid()) {
+ ctx->~T();
+ return nullptr;
+ }
+ return ctx;
+ }
+
private:
enum {
kColorStorageCount = 4, // more than this many colors, and we'll use sk_malloc for the space
« no previous file with comments | « src/effects/gradients/SkGradientShader.cpp ('k') | src/effects/gradients/SkLinearGradient.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698