2016-04-08 14:24:09 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/viewer/SKPSlide.h"
|
2016-04-08 14:24:09 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkStream.h"
|
|
|
|
#include "src/core/SkOSFile.h"
|
2016-04-08 14:24:09 +00:00
|
|
|
|
2020-05-27 23:31:12 +00:00
|
|
|
SKPSlide::SKPSlide(const SkString& name, const SkString& path)
|
|
|
|
: SKPSlide(name, SkStream::MakeFromFile(path.c_str())) {
|
|
|
|
}
|
|
|
|
|
|
|
|
SKPSlide::SKPSlide(const SkString& name, std::unique_ptr<SkStream> stream)
|
|
|
|
: fStream(std::move(stream)) {
|
2016-04-08 14:24:09 +00:00
|
|
|
fName = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
SKPSlide::~SKPSlide() {}
|
|
|
|
|
|
|
|
void SKPSlide::draw(SkCanvas* canvas) {
|
2016-04-08 19:51:45 +00:00
|
|
|
if (fPic.get()) {
|
|
|
|
bool isOffset = SkToBool(fCullRect.left() | fCullRect.top());
|
|
|
|
if (isOffset) {
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(SkIntToScalar(-fCullRect.left()), SkIntToScalar(-fCullRect.top()));
|
|
|
|
}
|
|
|
|
|
|
|
|
canvas->drawPicture(fPic.get());
|
|
|
|
|
|
|
|
if (isOffset) {
|
|
|
|
canvas->restore();
|
|
|
|
}
|
2016-04-08 14:24:09 +00:00
|
|
|
}
|
2016-04-08 19:51:45 +00:00
|
|
|
}
|
2016-04-08 14:24:09 +00:00
|
|
|
|
2016-06-16 16:52:35 +00:00
|
|
|
void SKPSlide::load(SkScalar, SkScalar) {
|
2020-05-27 23:31:12 +00:00
|
|
|
if (!fStream) {
|
|
|
|
SkDebugf("No skp stream for slide %s.\n", fName.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fStream->rewind();
|
|
|
|
fPic = SkPicture::MakeFromStream(fStream.get());
|
|
|
|
if (!fPic) {
|
|
|
|
SkDebugf("Could parse SkPicture from skp stream for slide %s.\n", fName.c_str());
|
|
|
|
return;
|
2019-09-09 20:53:39 +00:00
|
|
|
}
|
2020-05-27 23:31:12 +00:00
|
|
|
fCullRect = fPic->cullRect().roundOut();
|
2016-04-08 19:51:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SKPSlide::unload() {
|
|
|
|
fPic.reset(nullptr);
|
2016-04-08 14:24:09 +00:00
|
|
|
}
|