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 "tools/viewer/SKPSlide.h" 9 10 #include "include/core/SkCanvas.h" 11 #include "include/core/SkStream.h" 12 #include "src/core/SkOSFile.h" 13 SKPSlide(const SkString & name,const SkString & path)14SKPSlide::SKPSlide(const SkString& name, const SkString& path) : fPath(path) { 15 fName = name; 16 } 17 ~SKPSlide()18SKPSlide::~SKPSlide() {} 19 draw(SkCanvas * canvas)20void SKPSlide::draw(SkCanvas* canvas) { 21 if (fPic.get()) { 22 bool isOffset = SkToBool(fCullRect.left() | fCullRect.top()); 23 if (isOffset) { 24 canvas->save(); 25 canvas->translate(SkIntToScalar(-fCullRect.left()), SkIntToScalar(-fCullRect.top())); 26 } 27 28 canvas->drawPicture(fPic.get()); 29 30 if (isOffset) { 31 canvas->restore(); 32 } 33 } 34 } 35 read_picture(const char path[])36static sk_sp<SkPicture> read_picture(const char path[]) { 37 std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(path); 38 if (!stream) { 39 SkDebugf("Could not read %s.\n", path); 40 return nullptr; 41 } 42 43 auto pic = SkPicture::MakeFromStream(stream.get()); 44 if (!pic) { 45 SkDebugf("Could not read %s as an SkPicture.\n", path); 46 } 47 return pic; 48 } 49 load(SkScalar,SkScalar)50void SKPSlide::load(SkScalar, SkScalar) { 51 fPic = read_picture(fPath.c_str()); 52 fCullRect = fPic->cullRect().roundOut(); 53 } 54 unload()55void SKPSlide::unload() { 56 fPic.reset(nullptr); 57 } 58