Index: tools/viewer/Viewer.cpp |
diff --git a/tools/viewer/Viewer.cpp b/tools/viewer/Viewer.cpp |
index 499673572b4d296541768aafcd1c08e84a3815e8..5a3af32e0fd57e5e86e23edd452096af95f981d3 100644 |
--- a/tools/viewer/Viewer.cpp |
+++ b/tools/viewer/Viewer.cpp |
@@ -9,12 +9,14 @@ |
#include "GMSlide.h" |
#include "SKPSlide.h" |
+#include "ImageSlide.h" |
#include "SkCanvas.h" |
#include "SkCommonFlags.h" |
#include "SkOSFile.h" |
#include "SkRandom.h" |
#include "SkStream.h" |
+#include "SkMetaData.h" |
msarett
2016/06/13 14:56:26
nit: alphabetical order
liyuqian
2016/06/13 16:10:40
Done.
|
using namespace sk_app; |
@@ -52,10 +54,13 @@ DEFINE_string2(match, m, nullptr, |
"^ and $ requires an exact match\n" |
"If a bench does not match any list entry,\n" |
"it is skipped unless some list entry starts with ~"); |
-DEFINE_string(skps, "skps", "Directory to read skps from."); |
#ifdef SK_BUILD_FOR_ANDROID |
+DEFINE_string(skps, "/data/local/tmp/skia", "Directory to read skps from."); |
+DEFINE_string(jpgs, "/data/local/tmp/skia", "Directory to read jpgs from."); |
DEFINE_bool(vulkan, false, "Run with Vulkan."); |
#else |
+DEFINE_string(skps, "skps", "Directory to read skps from."); |
+DEFINE_string(jpgs, "jpgs", "Directory to read jpgs from."); |
DEFINE_bool(vulkan, true, "Run with Vulkan."); |
#endif |
@@ -73,6 +78,9 @@ const char* kBackendStateName = "Backend"; |
const char* kSoftkeyStateName = "Softkey"; |
const char* kSoftkeyHint = "Please select a softkey"; |
const char* kFpsStateName = "FPS"; |
+const char* kSplitScreenStateName = "Split screen"; |
+const char* kON = "ON"; |
+const char* kOFF = "OFF"; |
Viewer::Viewer(int argc, char** argv, void* platformData) |
: fCurrentMeasurement(0) |
@@ -224,6 +232,19 @@ void Viewer::initSlides() { |
} |
} |
} |
+ |
+ // JPGs |
+ for (int i = 0; i < FLAGS_jpgs.count(); i++) { |
+ SkOSFile::Iter it(FLAGS_jpgs[i], ".jpg"); |
+ SkString skpName; |
msarett
2016/06/13 14:56:26
nit: More appropriate variable name?
liyuqian
2016/06/13 16:10:40
Done.
|
+ while (it.next(&skpName)) { |
+ SkString path = SkOSPath::Join(FLAGS_jpgs[i], skpName.c_str()); |
+ sk_sp<ImageSlide> slide(new ImageSlide(skpName, path)); |
+ if (slide) { |
+ fSlides.push_back(slide); |
+ } |
+ } |
+ } |
} |
@@ -247,6 +268,8 @@ void Viewer::setupCurrentSlide(int previousSlide) { |
return; // no change; do nothing |
} |
+ fSlides[fCurrentSlide]->load(); // prepare dimensions for image slides |
+ |
fGesture.reset(); |
fDefaultMatrix.reset(); |
fDefaultMatrixInv.reset(); |
@@ -272,7 +295,6 @@ void Viewer::setupCurrentSlide(int previousSlide) { |
this->updateTitle(); |
this->updateUIState(); |
- fSlides[fCurrentSlide]->load(); |
if (previousSlide >= 0) { |
fSlides[previousSlide]->unload(); |
} |
@@ -317,11 +339,14 @@ SkMatrix Viewer::computeMatrix() { |
return m; |
} |
-void Viewer::onPaint(SkCanvas* canvas) { |
+void Viewer::drawSlide(SkCanvas* canvas, bool inSplitScreen) { |
+ SkASSERT(!inSplitScreen || fWindow->supportsContentRect()); |
+ |
int count = canvas->save(); |
if (fWindow->supportsContentRect()) { |
SkRect contentRect = fWindow->getContentRect(); |
+ contentRect.fLeft += inSplitScreen ? (contentRect.fRight - contentRect.fLeft) * 0.5 : 0; |
msarett
2016/06/13 14:56:26
What's going on here? Are we upscaling?
liyuqian
2016/06/13 16:10:40
We are translating the image half screen to the ri
msarett
2016/06/13 16:57:35
Can you add a comment here?
liyuqian
2016/06/13 19:02:29
Done.
|
canvas->clipRect(contentRect); |
canvas->translate(contentRect.fLeft, contentRect.fTop); |
} |
@@ -330,8 +355,16 @@ void Viewer::onPaint(SkCanvas* canvas) { |
canvas->concat(fDefaultMatrix); |
canvas->concat(computeMatrix()); |
+ canvas->getMetaData().setBool(kImageColorXformMetaData, inSplitScreen); |
fSlides[fCurrentSlide]->draw(canvas); |
canvas->restoreToCount(count); |
+} |
+ |
+void Viewer::onPaint(SkCanvas* canvas) { |
+ drawSlide(canvas); |
+ if (fSplitScreen && fWindow->supportsContentRect()) { |
+ drawSlide(canvas, true); |
msarett
2016/06/13 14:56:26
Is it ok/intentional to call this twice?
liyuqian
2016/06/13 16:10:40
Yes, this is used to draw the same slide twice. Th
|
+ } |
if (fDisplayStats) { |
drawStats(canvas); |
@@ -461,11 +494,20 @@ void Viewer::updateUIState() { |
fpsState[kValue] = SkStringPrintf("%8.3lf ms", measurement).c_str(); |
fpsState[kOptions] = Json::Value(Json::arrayValue); |
+ // Split screen state |
+ Json::Value splitScreenState(Json::objectValue); |
+ splitScreenState[kName] = kSplitScreenStateName; |
+ splitScreenState[kValue] = fSplitScreen ? kON : kOFF; |
+ splitScreenState[kOptions] = Json::Value(Json::arrayValue); |
+ splitScreenState[kOptions].append(kON); |
+ splitScreenState[kOptions].append(kOFF); |
+ |
Json::Value state(Json::arrayValue); |
state.append(slideState); |
state.append(backendState); |
state.append(softkeyState); |
state.append(fpsState); |
+ state.append(splitScreenState); |
fWindow->setUIState(state); |
} |
@@ -508,6 +550,13 @@ void Viewer::onUIStateChanged(const SkString& stateName, const SkString& stateVa |
fCommands.onSoftkey(stateValue); |
updateUIState(); // This is still needed to reset the value to kSoftkeyHint |
} |
+ } else if (stateName.equals(kSplitScreenStateName)) { |
+ bool newSplitScreen = stateValue.equals(kON); |
+ if (newSplitScreen != fSplitScreen) { |
+ fSplitScreen = newSplitScreen; |
+ fWindow->inval(); |
+ updateUIState(); |
+ } |
} else { |
SkDebugf("Unknown stateName: %s", stateName.c_str()); |
} |