Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: tools/vulkan/viewer/SKPSlide.cpp

Issue 1873733003: More cleanup in the Vulkan viewer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/vulkan/viewer/SKPSlide.h ('k') | tools/vulkan/viewer/Slide.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SKPSlide.h" 8 #include "SKPSlide.h"
9 9
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkCommonFlags.h"
12 #include "SkOSFile.h"
13 #include "SkStream.h"
11 14
12 SKPSlide::SKPSlide(const char* name, sk_sp<const SkPicture> pic) 15 SKPSlide::SKPSlide(const SkString& name, const SkString& path) : fPath(path) {
13 : fPic(pic)
14 , fCullRect(fPic->cullRect().roundOut()) {
15 fName = name; 16 fName = name;
16 } 17 }
17 18
18 SKPSlide::~SKPSlide() {} 19 SKPSlide::~SKPSlide() {}
19 20
20 void SKPSlide::draw(SkCanvas* canvas) { 21 void SKPSlide::draw(SkCanvas* canvas) {
21 bool isOffset = SkToBool(fCullRect.left() | fCullRect.top()); 22 if (fPic.get()) {
22 if (isOffset) { 23 bool isOffset = SkToBool(fCullRect.left() | fCullRect.top());
23 canvas->save(); 24 if (isOffset) {
24 canvas->translate(SkIntToScalar(-fCullRect.left()), SkIntToScalar(-fCull Rect.top())); 25 canvas->save();
26 canvas->translate(SkIntToScalar(-fCullRect.left()), SkIntToScalar(-f CullRect.top()));
27 }
28
29 canvas->drawPicture(fPic.get());
30
31 if (isOffset) {
32 canvas->restore();
33 }
34 }
35 }
36
37 static sk_sp<SkPicture> read_picture(const char path[]) {
38 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path));
39 if (stream.get() == nullptr) {
40 SkDebugf("Could not read %s.\n", path);
41 return nullptr;
25 } 42 }
26 43
27 canvas->drawPicture(fPic.get()); 44 auto pic = SkPicture::MakeFromStream(stream.get());
45 if (!pic) {
46 SkDebugf("Could not read %s as an SkPicture.\n", path);
47 }
48 return pic;
49 }
28 50
29 if (isOffset) { 51 void SKPSlide::load() {
30 canvas->restore(); 52 fPic = read_picture(fPath.c_str());
31 } 53 fCullRect = fPic->cullRect().roundOut();
32 } 54 }
55
56 void SKPSlide::unload() {
57 fPic.reset(nullptr);
58 }
OLDNEW
« no previous file with comments | « tools/vulkan/viewer/SKPSlide.h ('k') | tools/vulkan/viewer/Slide.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698