liyuqian | 6f163d2 | 2016-06-13 12:26:45 -0700 | [diff] [blame] | 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 | |
| 8 | #include "ImageSlide.h" |
| 9 | |
liyuqian | 6f163d2 | 2016-06-13 12:26:45 -0700 | [diff] [blame] | 10 | #include "SkCanvas.h" |
| 11 | #include "SkData.h" |
| 12 | #include "SkImage.h" |
liyuqian | 6f163d2 | 2016-06-13 12:26:45 -0700 | [diff] [blame] | 13 | |
| 14 | ImageSlide::ImageSlide(const SkString& name, const SkString& path) : fPath(path) { |
| 15 | fName = name; |
| 16 | } |
| 17 | |
| 18 | SkISize ImageSlide::getDimensions() const { |
| 19 | return fImage ? fImage->dimensions() : SkISize::Make(0, 0); |
| 20 | } |
| 21 | |
| 22 | void ImageSlide::draw(SkCanvas* canvas) { |
Christopher Dalton | 443ec1b | 2017-02-24 13:22:53 -0700 | [diff] [blame] | 23 | SkASSERT(fImage); |
Brian Osman | f750fbc | 2017-02-08 10:47:28 -0500 | [diff] [blame] | 24 | canvas->drawImage(fImage, 0, 0); |
liyuqian | 6f163d2 | 2016-06-13 12:26:45 -0700 | [diff] [blame] | 25 | } |
| 26 | |
jvanverth | c7027ab | 2016-06-16 09:52:35 -0700 | [diff] [blame] | 27 | void ImageSlide::load(SkScalar, SkScalar) { |
liyuqian | 6f163d2 | 2016-06-13 12:26:45 -0700 | [diff] [blame] | 28 | sk_sp<SkData> encoded = SkData::MakeFromFileName(fPath.c_str()); |
Brian Osman | f750fbc | 2017-02-08 10:47:28 -0500 | [diff] [blame] | 29 | fImage = SkImage::MakeFromEncoded(encoded); |
liyuqian | 6f163d2 | 2016-06-13 12:26:45 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | void ImageSlide::unload() { |
| 33 | fImage.reset(nullptr); |
| 34 | } |