/*
 * Copyright 2015 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "GrDrawBatch.h"

GrDrawBatch::GrDrawBatch(uint32_t classID) : INHERITED(classID), fPipelineInstalled(false) { }

GrDrawBatch::~GrDrawBatch() {
    if (fPipelineInstalled) {
        this->pipeline()->~GrPipeline();
    }
}

void GrDrawBatch::getPipelineOptimizations(GrPipelineOptimizations* opt) const {
    GrInitInvariantOutput color;
    GrInitInvariantOutput coverage;
    this->computePipelineOptimizations(&color, &coverage, &opt->fOverrides);
    opt->fColorPOI.initUsingInvariantOutput(color);
    opt->fCoveragePOI.initUsingInvariantOutput(coverage);
}

bool GrDrawBatch::installPipeline(const GrPipeline::CreateArgs& args) {
    GrXPOverridesForBatch overrides;
    void* location = fPipelineStorage.get();
    if (!GrPipeline::CreateAt(location, args, &overrides)) {
        return false;
    }
    fPipelineInstalled = true;
    this->initBatchTracker(overrides);
    return true;
}

/*
 * Copyright 2015 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "GrDrawBatch.h"

GrDrawBatch::GrDrawBatch(uint32_t classID) : INHERITED(classID), fPipelineInstalled(false) { }

GrDrawBatch::~GrDrawBatch() {
    if (fPipelineInstalled) {
        this->pipeline()->~GrPipeline();
    }
}

void GrDrawBatch::getPipelineOptimizations(GrPipelineOptimizations* opt) const {
    GrInitInvariantOutput color;
    GrInitInvariantOutput coverage;
    this->computePipelineOptimizations(&color, &coverage, &opt->fOverrides);
    opt->fColorPOI.initUsingInvariantOutput(color);
    opt->fCoveragePOI.initUsingInvariantOutput(coverage);
}

bool GrDrawBatch::installPipeline(const GrPipeline::CreateArgs& args) {
    GrXPOverridesForBatch overrides;
    void* location = fPipelineStorage.get();
    if (!GrPipeline::CreateAt(location, args, &overrides)) {
        return false;
    }
    this->initBatchTracker(overrides);
    fPipelineInstalled = true;
    return true;
}

--- 
+++ 
@@ -29,7 +29,7 @@
     if (!GrPipeline::CreateAt(location, args, &overrides)) {
         return false;
     }
+    fPipelineInstalled = true;
     this->initBatchTracker(overrides);
-    fPipelineInstalled = true;
     return true;
 }
Fix assert accessing pipeline from initBatchTracker

Marks fPipelineInstalled as true before calling initBatchTracker. The
batch subclass ought to be able to access the newly constructed
pipeline object during its init.

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1666813002

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