skia2/tools/viewer/GMSlide.cpp
Adlai Holler e3ad527e3f Add a convenience to downcast contexts into GrDirectContext
This pattern of needing a safe downcast will continue to grow as we
add more explicit use of GrDirectContext and it's causing long ternary
operations that span multiple lines.

Change-Id: I9e2ebe5156e4245524a52d7c92ed3a8509e53151
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/300901
Commit-Queue: Adlai Holler <adlai@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
Auto-Submit: Adlai Holler <adlai@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
2020-07-07 18:13:50 +00:00

55 lines
1.3 KiB
C++

/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/*
* Copyright 2014 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "include/core/SkCanvas.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "tools/viewer/GMSlide.h"
GMSlide::GMSlide(std::unique_ptr<skiagm::GM> gm) : fGM(std::move(gm)) {
fGM->setMode(skiagm::GM::kSample_Mode);
fName.printf("GM_%s", fGM->getName());
}
GMSlide::~GMSlide() = default;
void GMSlide::gpuTeardown() {
fGM->gpuTeardown();
}
void GMSlide::draw(SkCanvas* canvas) {
SkString msg;
auto direct = GrAsDirectContext(canvas->recordingContext());
auto result = fGM->gpuSetup(direct, canvas, &msg);
if (result != skiagm::GM::DrawResult::kOk) {
return;
}
fGM->draw(canvas, &msg);
}
bool GMSlide::animate(double nanos) { return fGM->animate(nanos); }
bool GMSlide::onChar(SkUnichar c) { return fGM->onChar(c); }
bool GMSlide::onGetControls(SkMetaData* controls) {
return fGM->getControls(controls);
}
void GMSlide::onSetControls(const SkMetaData& controls) {
fGM->setControls(controls);
}