f3242c44cf
The new loader works by checking for a "slide" flag, and if it ends in ".skp", then we treat the slide name as a URL and try to pull it in with an HTTP request and parse it as an SkPicture. It is the user's responsibility to copy or link skps into their canvaskit server directory. Change-Id: Iaafa84300d36d2d5a0bb29c47761ec67076c0f50 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/292204 Commit-Queue: Chris Dalton <csmartdalton@google.com> Reviewed-by: Kevin Lubick <kjlubick@google.com> Reviewed-by: Florin Malita <fmalita@chromium.org>
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.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();
|
|
}
|
|
}
|
|
}
|
|
|
|
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 parse SkPicture from skp stream for slide %s.\n", fName.c_str());
|
|
return;
|
|
}
|
|
fCullRect = fPic->cullRect().roundOut();
|
|
}
|
|
|
|
void SKPSlide::unload() {
|
|
fPic.reset(nullptr);
|
|
}
|