8bc46f3cd2
Bug: skia:13036 Change-Id: I31ccc3d1cfb271a2c2000476b91a695390cef4a6 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/526518 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
58 lines
1.4 KiB
C++
58 lines
1.4 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.
|
|
*/
|
|
|
|
#include "tools/viewer/SKPSlide.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
#include "include/core/SkStream.h"
|
|
#include "src/core/SkOSFile.h"
|
|
|
|
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)) {
|
|
fName = name;
|
|
}
|
|
|
|
SKPSlide::~SKPSlide() {}
|
|
|
|
void SKPSlide::draw(SkCanvas* canvas) {
|
|
if (fPic) {
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
|
|
void SKPSlide::load(SkScalar, SkScalar) {
|
|
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 not parse SkPicture from skp stream for slide %s.\n", fName.c_str());
|
|
return;
|
|
}
|
|
fCullRect = fPic->cullRect().roundOut();
|
|
}
|
|
|
|
void SKPSlide::unload() {
|
|
fPic.reset(nullptr);
|
|
}
|