skia2/tools/viewer/SvgSlide.cpp
Robert Phillips 2af13c135b Reland "Fix compilation w/ "skia_enable_svg = false" (take 2)"
This reverts commit 44b7568c8a.

Reason for revert: Google 3 CL has landed

Original change's description:
> Revert "Fix compilation w/ "skia_enable_svg = false" (take 2)"
>
> This reverts commit 30a6b101f4.
>
> Reason for revert: Maybe blocking G3 roll?
>
> Original change's description:
> > Fix compilation w/ "skia_enable_svg = false" (take 2)
> >
> > Change-Id: I036ae171809af56cc9594704b44705ebd095ec80
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/443898
> > Reviewed-by: Florin Malita <fmalita@chromium.org>
> > Commit-Queue: Robert Phillips <robertphillips@google.com>
>
> TBR=robertphillips@google.com,fmalita@chromium.org,fmalita@google.com,skcq-be@skia-corp.google.com.iam.gserviceaccount.com
>
> Change-Id: Ibee3819e073b04efdf9736058c1f9b288249620c
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/444216
> Reviewed-by: Robert Phillips <robertphillips@google.com>
> Commit-Queue: Robert Phillips <robertphillips@google.com>

# Not skipping CQ checks because this is a reland.

Change-Id: Idf73d864108067ee1c34e88ee4e5236847abd582
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/444501
Reviewed-by: Florin Malita <fmalita@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
2021-09-01 17:54:08 +00:00

68 lines
1.6 KiB
C++

/*
* Copyright 2018 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/SvgSlide.h"
#if defined(SK_ENABLE_SVG)
#include "include/core/SkCanvas.h"
#include "include/core/SkStream.h"
#include "modules/skresources/include/SkResources.h"
#include "modules/svg/include/SkSVGDOM.h"
#include "modules/svg/include/SkSVGNode.h"
#include "src/utils/SkOSPath.h"
SvgSlide::SvgSlide(const SkString& name, const SkString& path)
: fPath(path)
{
fName = name;
}
void SvgSlide::load(SkScalar w, SkScalar h) {
auto stream = SkStream::MakeFromFile(fPath.c_str());
if (!stream) {
SkDebugf("Could not open %s.\n", fPath.c_str());
return;
}
fWinSize = SkSize::Make(w, h);
auto rp = skresources::DataURIResourceProviderProxy::Make(
skresources::FileResourceProvider::Make(SkOSPath::Dirname(fPath.c_str()),
/*predecode=*/true),
/*predecode=*/true);
fDom = SkSVGDOM::Builder().setResourceProvider(std::move(rp)).make(*stream);
if (fDom) {
fDom->setContainerSize(fWinSize);
}
}
void SvgSlide::unload() {
fDom.reset();
}
void SvgSlide::resize(SkScalar w, SkScalar h) {
fWinSize = { w, h };
if (fDom) {
fDom->setContainerSize(fWinSize);
}
}
SkISize SvgSlide::getDimensions() const {
// We always scale to fill the window.
return fWinSize.toCeil();
}
void SvgSlide::draw(SkCanvas* canvas) {
if (fDom) {
fDom->render(canvas);
}
}
#endif // defined(SK_ENABLE_SVG)