Add 'Save to SKP' option to Viewer

Bug: skia:
Change-Id: Iea3794ce8710c84f2529b78b21655f2bf6aaa90e
Reviewed-on: https://skia-review.googlesource.com/79160
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Osman 2017-12-01 11:23:53 -05:00 committed by Skia Commit-Bot
parent 762d5e7e1c
commit 3ac99cfaa2
2 changed files with 25 additions and 0 deletions

View File

@ -30,6 +30,7 @@
#include "SkOnce.h"
#include "SkOSFile.h"
#include "SkOSPath.h"
#include "SkPictureRecorder.h"
#include "SkRandom.h"
#include "SkScan.h"
#include "SkStream.h"
@ -265,6 +266,7 @@ Viewer::Viewer(int argc, char** argv, void* platformData)
, fCumulativeMeasurementCount(0)
, fDisplayStats(false)
, fRefresh(false)
, fSaveToSKP(false)
, fShowImGuiDebugWindow(false)
, fShowSlidePicker(false)
, fShowImGuiTestWindow(false)
@ -481,6 +483,10 @@ Viewer::Viewer(int argc, char** argv, void* platformData)
this->updateTitle();
fWindow->inval();
});
fCommands.addCommand('K', "IO", "Save slide to SKP", [this]() {
fSaveToSKP = true;
fWindow->inval();
});
// set up slides
this->initSlides();
@ -866,6 +872,23 @@ void Viewer::drawSlide(SkCanvas* canvas) {
}
}
if (fSaveToSKP) {
SkPictureRecorder recorder;
SkCanvas* recorderCanvas = recorder.beginRecording(
SkRect::Make(fSlides[fCurrentSlide]->getDimensions()));
// In xform-canvas mode, record the transformed output
std::unique_ptr<SkCanvas> xformCanvas = nullptr;
if (ColorMode::kColorManagedSRGB8888_NonLinearBlending == fColorMode) {
xformCanvas = SkCreateColorSpaceXformCanvas(recorderCanvas, cs);
recorderCanvas = xformCanvas.get();
}
fSlides[fCurrentSlide]->draw(recorderCanvas);
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
SkFILEWStream stream("sample_app.skp");
picture->serialize(&stream);
fSaveToSKP = false;
}
// If we're in F16, or we're zooming, or we're in color correct 8888 and the gamut isn't sRGB,
// we need to render offscreen. We also need to render offscreen if we're in any raster mode,
// because the window surface is actually GL.

View File

@ -81,6 +81,8 @@ private:
bool fDisplayStats;
bool fRefresh; // whether to continuously refresh for measuring render time
bool fSaveToSKP;
SkPaint fImGuiFontPaint;
SkPaint fImGuiGamutPaint;
bool fShowImGuiDebugWindow;