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
|
|
|
|
2016-04-08 19:51:45 +00:00
|
|
|
SKPSlide::SKPSlide(const SkString& name, const SkString& path) : fPath(path) {
|
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-04-08 19:51:45 +00:00
|
|
|
static sk_sp<SkPicture> read_picture(const char path[]) {
|
2016-09-16 13:24:20 +00:00
|
|
|
std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(path);
|
|
|
|
if (!stream) {
|
2016-04-08 19:51:45 +00:00
|
|
|
SkDebugf("Could not read %s.\n", path);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-04-08 14:24:09 +00:00
|
|
|
|
2016-04-08 19:51:45 +00:00
|
|
|
auto pic = SkPicture::MakeFromStream(stream.get());
|
|
|
|
if (!pic) {
|
|
|
|
SkDebugf("Could not read %s as an SkPicture.\n", path);
|
2016-04-08 14:24:09 +00:00
|
|
|
}
|
2016-04-08 19:51:45 +00:00
|
|
|
return pic;
|
|
|
|
}
|
|
|
|
|
2016-06-16 16:52:35 +00:00
|
|
|
void SKPSlide::load(SkScalar, SkScalar) {
|
2016-04-08 19:51:45 +00:00
|
|
|
fPic = read_picture(fPath.c_str());
|
2019-09-09 20:53:39 +00:00
|
|
|
if (fPic) {
|
|
|
|
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
|
|
|
}
|