Clean up some gm factory use.

Mostly use unique_ptr more consistently.

Change-Id: I6e11b272a7904eb662dea59b03fbc309a4cfc25d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/233984
Commit-Queue: Ben Wagner <bungeman@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
This commit is contained in:
Ben Wagner 2019-08-12 16:39:24 -04:00 committed by Skia Commit-Bot
parent fb83927366
commit 406ff500a4
7 changed files with 12 additions and 16 deletions

View File

@ -7,12 +7,10 @@
#include "bench/GMBench.h"
GMBench::GMBench(skiagm::GM* gm) : fGM(gm) {
fName.printf("GM_%s", gm->getName());
GMBench::GMBench(std::unique_ptr<skiagm::GM> gm) : fGM(std::move(gm)) {
fName.printf("GM_%s", fGM->getName());
}
GMBench::~GMBench() { delete fGM; }
const char* GMBench::onGetName() {
return fName.c_str();
}

View File

@ -16,9 +16,7 @@
*/
class GMBench : public Benchmark {
public:
// Constructor takes ownership of the GM param.
GMBench(skiagm::GM* gm);
~GMBench() override;
GMBench(std::unique_ptr<skiagm::GM> gm);
void modifyGrContextOptions(GrContextOptions* options) override {
return fGM->modifyGrContextOptions(options);
@ -31,7 +29,7 @@ protected:
SkIPoint onGetSize() override;
private:
skiagm::GM* fGM;
std::unique_ptr<skiagm::GM> fGM;
SkString fName;
typedef Benchmark INHERITED;
};

View File

@ -749,12 +749,12 @@ public:
}
while (fGMs) {
std::unique_ptr<skiagm::GM> gm(fGMs->get()());
std::unique_ptr<skiagm::GM> gm = fGMs->get()();
fGMs = fGMs->next();
if (gm->runAsBench()) {
fSourceType = "gm";
fBenchType = "micro";
return new GMBench(gm.release());
return new GMBench(std::move(gm));
}
}

View File

@ -381,7 +381,7 @@ int main(int argc, char** argv) {
if (skiagm::GMFactory* factory = gm_factories.find(name)) {
std::shared_ptr<skiagm::GM> gm{(*factory)()};
source->name = name;
init(source, gm);
init(source, std::move(gm));
continue;
}

View File

@ -14,8 +14,8 @@
#include "include/core/SkCanvas.h"
#include "tools/viewer/GMSlide.h"
GMSlide::GMSlide(skiagm::GM* gm) : fGM(gm) {
fName.printf("GM_%s", gm->getName());
GMSlide::GMSlide(std::unique_ptr<skiagm::GM> gm) : fGM(std::move(gm)) {
fName.printf("GM_%s", fGM->getName());
}
GMSlide::~GMSlide() = default;

View File

@ -13,7 +13,7 @@
class GMSlide : public Slide {
public:
GMSlide(skiagm::GM* gm);
GMSlide(std::unique_ptr<skiagm::GM> gm);
~GMSlide() override;
SkISize getDimensions() const override { return fGM->getISize(); }

View File

@ -676,9 +676,9 @@ void Viewer::initSlides() {
// GMs
int firstGM = fSlides.count();
for (skiagm::GMFactory gmFactory : skiagm::GMRegistry::Range()) {
std::unique_ptr<skiagm::GM> gm(gmFactory());
std::unique_ptr<skiagm::GM> gm = gmFactory();
if (!CommandLineFlags::ShouldSkip(FLAGS_match, gm->getName())) {
sk_sp<Slide> slide(new GMSlide(gm.release()));
sk_sp<Slide> slide(new GMSlide(std::move(gm)));
fSlides.push_back(std::move(slide));
}
}