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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/vulkan/viewer/SKPSlide.h ('k') | tools/vulkan/viewer/Slide.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/vulkan/viewer/SKPSlide.cpp
diff --git a/tools/vulkan/viewer/SKPSlide.cpp b/tools/vulkan/viewer/SKPSlide.cpp
index 72f68b5cb5e3f5930fc30182b6a1d840d4662505..6a9899b92fbe29ff01dfaca22ee6130e32847e05 100644
--- a/tools/vulkan/viewer/SKPSlide.cpp
+++ b/tools/vulkan/viewer/SKPSlide.cpp
@@ -8,25 +8,51 @@
#include "SKPSlide.h"
#include "SkCanvas.h"
+#include "SkCommonFlags.h"
+#include "SkOSFile.h"
+#include "SkStream.h"
-SKPSlide::SKPSlide(const char* name, sk_sp<const SkPicture> pic)
- : fPic(pic)
- , fCullRect(fPic->cullRect().roundOut()) {
+SKPSlide::SKPSlide(const SkString& name, const SkString& path) : fPath(path) {
fName = name;
}
SKPSlide::~SKPSlide() {}
void SKPSlide::draw(SkCanvas* canvas) {
- bool isOffset = SkToBool(fCullRect.left() | fCullRect.top());
- if (isOffset) {
- canvas->save();
- canvas->translate(SkIntToScalar(-fCullRect.left()), SkIntToScalar(-fCullRect.top()));
+ if (fPic.get()) {
+ bool isOffset = SkToBool(fCullRect.left() | fCullRect.top());
+ if (isOffset) {
+ canvas->save();
+ canvas->translate(SkIntToScalar(-fCullRect.left()), SkIntToScalar(-fCullRect.top()));
+ }
+
+ canvas->drawPicture(fPic.get());
+
+ if (isOffset) {
+ canvas->restore();
+ }
}
+}
- canvas->drawPicture(fPic.get());
+static sk_sp<SkPicture> read_picture(const char path[]) {
+ SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path));
+ if (stream.get() == nullptr) {
+ SkDebugf("Could not read %s.\n", path);
+ return nullptr;
+ }
- if (isOffset) {
- canvas->restore();
+ auto pic = SkPicture::MakeFromStream(stream.get());
+ if (!pic) {
+ SkDebugf("Could not read %s as an SkPicture.\n", path);
}
+ return pic;
+}
+
+void SKPSlide::load() {
+ fPic = read_picture(fPath.c_str());
+ fCullRect = fPic->cullRect().roundOut();
+}
+
+void SKPSlide::unload() {
+ fPic.reset(nullptr);
}
« 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