Simplify the poly union.
authorherb <herb@google.com>
Mon, 29 Feb 2016 21:21:33 +0000 (13:21 -0800)
committerCommit bot <commit-bot@chromium.org>
Mon, 29 Feb 2016 21:21:33 +0000 (13:21 -0800)
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1752433002

Review URL: https://codereview.chromium.org/1752433002

src/core/SkLinearBitmapPipeline.cpp
src/core/SkLinearBitmapPipeline.h

index 347803c..4d4a4cf 100644 (file)
@@ -273,21 +273,6 @@ private:
     Strategy fStrategy;
 };
 
-class SkippedStage final : public SkLinearBitmapPipeline::BilerpProcessorInterface {
-    void VECTORCALL pointListFew(int n, Sk4s xs, Sk4s ys) override {
-        SkFAIL("Skipped stage.");
-    }
-    void VECTORCALL pointList4(Sk4s xs, Sk4s ys) override {
-        SkFAIL("Skipped stage.");
-    }
-    void VECTORCALL bilerpList(Sk4s xs, Sk4s ys) override {
-        SkFAIL("Skipped stage.");
-    }
-    void pointSpan(Span span) override {
-        SkFAIL("Skipped stage.");
-    }
-};
-
 class TranslateMatrixStrategy {
 public:
     TranslateMatrixStrategy(SkVector offset)
@@ -390,7 +375,6 @@ static SkLinearBitmapPipeline::PointProcessorInterface* choose_matrix(
             next,
             SkVector{inverse.getTranslateX(), inverse.getTranslateY()});
     } else {
-        matrixProc->Initialize<SkippedStage>();
         return next;
     }
     return matrixProc->get();
@@ -447,7 +431,6 @@ static SkLinearBitmapPipeline::PointProcessorInterface* choose_filter(
     SkFilterQuality filterQuailty,
     SkLinearBitmapPipeline::FilterStage* filterProc) {
     if (SkFilterQuality::kNone_SkFilterQuality == filterQuailty) {
-        filterProc->Initialize<SkippedStage>();
         return next;
     } else {
         filterProc->Initialize<ExpandBilerp<>>(next);
@@ -689,7 +672,6 @@ static SkLinearBitmapPipeline::BilerpProcessorInterface* choose_tiler(
                 SkFAIL("Not implemented.");
                 break;
         }
-        tileProcY->Initialize<SkippedStage>();
     } else {
         switch (yMode) {
             case SkShader::kClamp_TileMode:
index 3d5dd31..c65b753 100644 (file)
@@ -29,9 +29,13 @@ public:
     template<typename Base, size_t kSize>
     class PolymorphicUnion {
     public:
-        PolymorphicUnion() {}
+        PolymorphicUnion() : fIsInitialized{false} {}
 
-        ~PolymorphicUnion() { get()->~Base(); }
+        ~PolymorphicUnion() {
+            if (fIsInitialized) {
+                get()->~Base();
+            }
+        }
 
         template<typename Variant, typename... Args>
         void Initialize(Args&&... args) {
@@ -39,6 +43,7 @@ public:
                       "Size Variant: %d, Space: %d", sizeof(Variant), sizeof(fSpace));
 
             new(&fSpace) Variant(std::forward<Args>(args)...);
+            fIsInitialized = true;
         };
 
         Base* get() const { return reinterpret_cast<Base*>(&fSpace); }
@@ -49,6 +54,7 @@ public:
         struct SK_STRUCT_ALIGN(16) Space {
             char space[kSize];
         };
+        bool fIsInitialized;
         mutable Space fSpace;
     };