Flutter Engine
The Flutter Engine
SKPSlide.cpp
Go to the documentation of this file.
1/*
2* Copyright 2016 Google Inc.
3*
4* Use of this source code is governed by a BSD-style license that can be
5* found in the LICENSE file.
6*/
7
9
16
17#include <utility>
18
20 : SKPSlide(name, SkStream::MakeFromFile(path.c_str())) {
21}
22
23SKPSlide::SKPSlide(const SkString& name, std::unique_ptr<SkStream> stream)
24 : fStream(std::move(stream)) {
25 fName = name;
26}
27
29
30void SKPSlide::draw(SkCanvas* canvas) {
31 if (fPic) {
32 bool isOffset = SkToBool(fCullRect.left() | fCullRect.top());
33 if (isOffset) {
34 canvas->save();
35 canvas->translate(SkIntToScalar(-fCullRect.left()), SkIntToScalar(-fCullRect.top()));
36 }
37
38 canvas->drawPicture(fPic.get());
39
40 if (isOffset) {
41 canvas->restore();
42 }
43 }
44}
45
47 if (!fStream) {
48 SkDebugf("No skp stream for slide %s.\n", fName.c_str());
49 return;
50 }
51 fStream->rewind();
52 fPic = SkPicture::MakeFromStream(fStream.get());
53 if (!fPic) {
54 SkDebugf("Could not parse SkPicture from skp stream for slide %s.\n", fName.c_str());
55 return;
56 }
57 fCullRect = fPic->cullRect().roundOut();
58}
59
61 fPic.reset(nullptr);
62}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
#define SkIntToScalar(x)
Definition: SkScalar.h:57
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
void draw(SkCanvas *canvas) override
Definition: SKPSlide.cpp:30
void unload() override
Definition: SKPSlide.cpp:60
SKPSlide(const SkString &name, const SkString &path)
Definition: SKPSlide.cpp:19
void load(SkScalar winWidth, SkScalar winHeight) override
Definition: SKPSlide.cpp:46
~SKPSlide() override
Definition: SKPSlide.cpp:28
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
int save()
Definition: SkCanvas.cpp:447
void drawPicture(const SkPicture *picture)
Definition: SkCanvas.h:1961
virtual SkRect cullRect() const =0
static sk_sp< SkPicture > MakeFromStream(SkStream *stream, const SkDeserialProcs *procs=nullptr)
Definition: SkPicture.cpp:147
const char * c_str() const
Definition: SkString.h:133
SkString fName
Definition: Slide.h:54
T * get() const
Definition: SkRefCnt.h:303
void reset(T *ptr=nullptr)
Definition: SkRefCnt.h:310
float SkScalar
Definition: extension.cpp:12
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
Definition: ref_ptr.h:256
constexpr int32_t top() const
Definition: SkRect.h:120
constexpr int32_t left() const
Definition: SkRect.h:113
void roundOut(SkIRect *dst) const
Definition: SkRect.h:1241