blob: 8ff7d180e3f54768fef44585fe4ac50046fa1b68 [file] [log] [blame]
liyuqian6f163d22016-06-13 12:26:45 -07001/*
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
8#include "ImageSlide.h"
9
liyuqian6f163d22016-06-13 12:26:45 -070010#include "SkCanvas.h"
11#include "SkData.h"
12#include "SkImage.h"
liyuqian6f163d22016-06-13 12:26:45 -070013
14ImageSlide::ImageSlide(const SkString& name, const SkString& path) : fPath(path) {
15 fName = name;
16}
17
18SkISize ImageSlide::getDimensions() const {
19 return fImage ? fImage->dimensions() : SkISize::Make(0, 0);
20}
21
22void ImageSlide::draw(SkCanvas* canvas) {
Christopher Dalton443ec1b2017-02-24 13:22:53 -070023 SkASSERT(fImage);
Brian Osmanf750fbc2017-02-08 10:47:28 -050024 canvas->drawImage(fImage, 0, 0);
liyuqian6f163d22016-06-13 12:26:45 -070025}
26
jvanverthc7027ab2016-06-16 09:52:35 -070027void ImageSlide::load(SkScalar, SkScalar) {
liyuqian6f163d22016-06-13 12:26:45 -070028 sk_sp<SkData> encoded = SkData::MakeFromFileName(fPath.c_str());
Brian Osmanf750fbc2017-02-08 10:47:28 -050029 fImage = SkImage::MakeFromEncoded(encoded);
liyuqian6f163d22016-06-13 12:26:45 -070030}
31
32void ImageSlide::unload() {
33 fImage.reset(nullptr);
34}