John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 17 | #include <cutils/log.h> |
| 18 | #include <gui/Surface.h> |
| 19 | #include <ui/PixelFormat.h> |
| 20 | |
| 21 | #include <AnimationContext.h> |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 22 | #include <DisplayListCanvas.h> |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 23 | #include <RenderNode.h> |
| 24 | #include <renderthread/RenderProxy.h> |
John Reck | 84e390c | 2015-01-05 09:42:52 -0800 | [diff] [blame] | 25 | #include <renderthread/RenderTask.h> |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 26 | |
| 27 | #include "TestContext.h" |
| 28 | |
John Reck | 7f2e5e3 | 2015-05-05 11:00:53 -0700 | [diff] [blame] | 29 | #include <stdio.h> |
| 30 | #include <unistd.h> |
| 31 | |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 32 | using namespace android; |
| 33 | using namespace android::uirenderer; |
| 34 | using namespace android::uirenderer::renderthread; |
John Reck | 84e390c | 2015-01-05 09:42:52 -0800 | [diff] [blame] | 35 | using namespace android::uirenderer::test; |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 36 | |
| 37 | class ContextFactory : public IContextFactory { |
| 38 | public: |
Chris Craik | d41c4d8 | 2015-01-05 15:51:13 -0800 | [diff] [blame] | 39 | virtual AnimationContext* createAnimationContext(renderthread::TimeLord& clock) override { |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 40 | return new AnimationContext(clock); |
| 41 | } |
| 42 | }; |
| 43 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 44 | static DisplayListCanvas* startRecording(RenderNode* node) { |
Derek Sollenberger | cc882b6 | 2015-07-09 15:51:20 -0400 | [diff] [blame^] | 45 | DisplayListCanvas* renderer = new DisplayListCanvas( |
| 46 | node->stagingProperties().getWidth(), node->stagingProperties().getHeight()); |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 47 | return renderer; |
| 48 | } |
| 49 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 50 | static void endRecording(DisplayListCanvas* renderer, RenderNode* node) { |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 51 | node->setStagingDisplayList(renderer->finishRecording()); |
| 52 | delete renderer; |
| 53 | } |
| 54 | |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 55 | class TreeContentAnimation { |
| 56 | public: |
| 57 | virtual ~TreeContentAnimation() {} |
Tim Murray | bfbcd88 | 2015-05-06 12:38:05 -0700 | [diff] [blame] | 58 | int frameCount = 150; |
| 59 | virtual int getFrameCount() { return frameCount; } |
| 60 | virtual void setFrameCount(int fc) { |
| 61 | if (fc > 0) { |
| 62 | frameCount = fc; |
| 63 | } |
| 64 | } |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 65 | virtual void createContent(int width, int height, DisplayListCanvas* renderer) = 0; |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 66 | virtual void doFrame(int frameNr) = 0; |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 67 | |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 68 | template <class T> |
Tim Murray | bfbcd88 | 2015-05-06 12:38:05 -0700 | [diff] [blame] | 69 | static void run(int frameCount) { |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 70 | T animation; |
Tim Murray | bfbcd88 | 2015-05-06 12:38:05 -0700 | [diff] [blame] | 71 | animation.setFrameCount(frameCount); |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 72 | |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 73 | TestContext testContext; |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 74 | |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 75 | // create the native surface |
| 76 | const int width = gDisplay.w; |
| 77 | const int height = gDisplay.h; |
| 78 | sp<Surface> surface = testContext.surface(); |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 79 | |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 80 | RenderNode* rootNode = new RenderNode(); |
| 81 | rootNode->incStrong(nullptr); |
| 82 | rootNode->mutateStagingProperties().setLeftTopRightBottom(0, 0, width, height); |
| 83 | rootNode->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y); |
| 84 | rootNode->mutateStagingProperties().setClipToBounds(false); |
| 85 | rootNode->setPropertyFieldsDirty(RenderNode::GENERIC); |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 86 | |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 87 | ContextFactory factory; |
| 88 | std::unique_ptr<RenderProxy> proxy(new RenderProxy(false, rootNode, &factory)); |
| 89 | proxy->loadSystemProperties(); |
| 90 | proxy->initialize(surface); |
| 91 | float lightX = width / 2.0; |
Alan Viverette | 50210d9 | 2015-05-14 18:05:36 -0700 | [diff] [blame] | 92 | proxy->setup(width, height, dp(800.0f), 255 * 0.075, 255 * 0.15); |
| 93 | proxy->setLightCenter((Vector3){lightX, dp(-200.0f), dp(800.0f)}); |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 94 | |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 95 | android::uirenderer::Rect DUMMY; |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 96 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 97 | DisplayListCanvas* renderer = startRecording(rootNode); |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 98 | animation.createContent(width, height, renderer); |
| 99 | endRecording(renderer, rootNode); |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 100 | |
John Reck | 7f2e5e3 | 2015-05-05 11:00:53 -0700 | [diff] [blame] | 101 | // Do a few cold runs then reset the stats so that the caches are all hot |
| 102 | for (int i = 0; i < 3; i++) { |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 103 | testContext.waitForVsync(); |
John Reck | 7f2e5e3 | 2015-05-05 11:00:53 -0700 | [diff] [blame] | 104 | proxy->syncAndDrawFrame(); |
| 105 | } |
| 106 | proxy->resetProfileInfo(); |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 107 | |
John Reck | 7f2e5e3 | 2015-05-05 11:00:53 -0700 | [diff] [blame] | 108 | for (int i = 0; i < animation.getFrameCount(); i++) { |
| 109 | testContext.waitForVsync(); |
| 110 | |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 111 | ATRACE_NAME("UI-Draw Frame"); |
John Reck | 7f2e5e3 | 2015-05-05 11:00:53 -0700 | [diff] [blame] | 112 | nsecs_t vsync = systemTime(CLOCK_MONOTONIC); |
| 113 | UiFrameInfoBuilder(proxy->frameInfo()) |
| 114 | .setVsync(vsync, vsync); |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 115 | animation.doFrame(i); |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 116 | proxy->syncAndDrawFrame(); |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 117 | } |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 118 | |
John Reck | 7f2e5e3 | 2015-05-05 11:00:53 -0700 | [diff] [blame] | 119 | proxy->dumpProfileInfo(STDOUT_FILENO, 0); |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 120 | rootNode->decStrong(nullptr); |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 121 | } |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 122 | }; |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 123 | |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 124 | class ShadowGridAnimation : public TreeContentAnimation { |
| 125 | public: |
| 126 | std::vector< sp<RenderNode> > cards; |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 127 | void createContent(int width, int height, DisplayListCanvas* renderer) override { |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 128 | renderer->drawColor(0xFFFFFFFF, SkXfermode::kSrcOver_Mode); |
| 129 | renderer->insertReorderBarrier(true); |
John Reck | 84e390c | 2015-01-05 09:42:52 -0800 | [diff] [blame] | 130 | |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 131 | for (int x = dp(16); x < (width - dp(116)); x += dp(116)) { |
| 132 | for (int y = dp(16); y < (height - dp(116)); y += dp(116)) { |
| 133 | sp<RenderNode> card = createCard(x, y, dp(100), dp(100)); |
Chris Craik | 956f340 | 2015-04-27 16:41:00 -0700 | [diff] [blame] | 134 | renderer->drawRenderNode(card.get()); |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 135 | cards.push_back(card); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | renderer->insertReorderBarrier(false); |
| 140 | } |
| 141 | void doFrame(int frameNr) override { |
Tim Murray | bfbcd88 | 2015-05-06 12:38:05 -0700 | [diff] [blame] | 142 | int curFrame = frameNr % 150; |
Andreas Gampe | 2ab8298 | 2014-11-21 14:19:06 -0800 | [diff] [blame] | 143 | for (size_t ci = 0; ci < cards.size(); ci++) { |
Tim Murray | bfbcd88 | 2015-05-06 12:38:05 -0700 | [diff] [blame] | 144 | cards[ci]->mutateStagingProperties().setTranslationX(curFrame); |
| 145 | cards[ci]->mutateStagingProperties().setTranslationY(curFrame); |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 146 | cards[ci]->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y); |
| 147 | } |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 148 | } |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 149 | private: |
| 150 | sp<RenderNode> createCard(int x, int y, int width, int height) { |
| 151 | sp<RenderNode> node = new RenderNode(); |
| 152 | node->mutateStagingProperties().setLeftTopRightBottom(x, y, x + width, y + height); |
| 153 | node->mutateStagingProperties().setElevation(dp(16)); |
| 154 | node->mutateStagingProperties().mutableOutline().setRoundRect(0, 0, width, height, dp(10), 1); |
| 155 | node->mutateStagingProperties().mutableOutline().setShouldClip(true); |
| 156 | node->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y | RenderNode::Z); |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 157 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 158 | DisplayListCanvas* renderer = startRecording(node.get()); |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 159 | renderer->drawColor(0xFFEEEEEE, SkXfermode::kSrcOver_Mode); |
| 160 | endRecording(renderer, node.get()); |
| 161 | return node; |
| 162 | } |
| 163 | }; |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 164 | |
Tim Murray | bfbcd88 | 2015-05-06 12:38:05 -0700 | [diff] [blame] | 165 | class ShadowGrid2Animation : public TreeContentAnimation { |
| 166 | public: |
| 167 | std::vector< sp<RenderNode> > cards; |
| 168 | void createContent(int width, int height, DisplayListCanvas* renderer) override { |
| 169 | renderer->drawColor(0xFFFFFFFF, SkXfermode::kSrcOver_Mode); |
| 170 | renderer->insertReorderBarrier(true); |
| 171 | |
| 172 | for (int x = dp(8); x < (width - dp(58)); x += dp(58)) { |
| 173 | for (int y = dp(8); y < (height - dp(58)); y += dp(58)) { |
| 174 | sp<RenderNode> card = createCard(x, y, dp(50), dp(50)); |
| 175 | renderer->drawRenderNode(card.get()); |
| 176 | cards.push_back(card); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | renderer->insertReorderBarrier(false); |
| 181 | } |
| 182 | void doFrame(int frameNr) override { |
| 183 | int curFrame = frameNr % 150; |
| 184 | for (size_t ci = 0; ci < cards.size(); ci++) { |
| 185 | cards[ci]->mutateStagingProperties().setTranslationX(curFrame); |
| 186 | cards[ci]->mutateStagingProperties().setTranslationY(curFrame); |
| 187 | cards[ci]->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y); |
| 188 | } |
| 189 | } |
| 190 | private: |
| 191 | sp<RenderNode> createCard(int x, int y, int width, int height) { |
| 192 | sp<RenderNode> node = new RenderNode(); |
| 193 | node->mutateStagingProperties().setLeftTopRightBottom(x, y, x + width, y + height); |
| 194 | node->mutateStagingProperties().setElevation(dp(16)); |
| 195 | node->mutateStagingProperties().mutableOutline().setRoundRect(0, 0, width, height, dp(6), 1); |
| 196 | node->mutateStagingProperties().mutableOutline().setShouldClip(true); |
| 197 | node->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y | RenderNode::Z); |
| 198 | |
| 199 | DisplayListCanvas* renderer = startRecording(node.get()); |
| 200 | renderer->drawColor(0xFFEEEEEE, SkXfermode::kSrcOver_Mode); |
| 201 | endRecording(renderer, node.get()); |
| 202 | return node; |
| 203 | } |
| 204 | }; |
| 205 | |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 206 | class RectGridAnimation : public TreeContentAnimation { |
| 207 | public: |
| 208 | sp<RenderNode> card; |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 209 | void createContent(int width, int height, DisplayListCanvas* renderer) override { |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 210 | renderer->drawColor(0xFFFFFFFF, SkXfermode::kSrcOver_Mode); |
| 211 | renderer->insertReorderBarrier(true); |
| 212 | |
| 213 | card = createCard(40, 40, 200, 200); |
Chris Craik | 956f340 | 2015-04-27 16:41:00 -0700 | [diff] [blame] | 214 | renderer->drawRenderNode(card.get()); |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 215 | |
| 216 | renderer->insertReorderBarrier(false); |
| 217 | } |
| 218 | void doFrame(int frameNr) override { |
Tim Murray | bfbcd88 | 2015-05-06 12:38:05 -0700 | [diff] [blame] | 219 | int curFrame = frameNr % 150; |
| 220 | card->mutateStagingProperties().setTranslationX(curFrame); |
| 221 | card->mutateStagingProperties().setTranslationY(curFrame); |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 222 | card->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y); |
| 223 | } |
| 224 | private: |
| 225 | sp<RenderNode> createCard(int x, int y, int width, int height) { |
| 226 | sp<RenderNode> node = new RenderNode(); |
| 227 | node->mutateStagingProperties().setLeftTopRightBottom(x, y, x + width, y + height); |
| 228 | node->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y); |
| 229 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 230 | DisplayListCanvas* renderer = startRecording(node.get()); |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 231 | renderer->drawColor(0xFFFF00FF, SkXfermode::kSrcOver_Mode); |
| 232 | |
| 233 | float rects[width * height]; |
| 234 | int index = 0; |
| 235 | for (int xOffset = 0; xOffset < width; xOffset+=2) { |
| 236 | for (int yOffset = 0; yOffset < height; yOffset+=2) { |
| 237 | rects[index++] = xOffset; |
| 238 | rects[index++] = yOffset; |
| 239 | rects[index++] = xOffset + 1; |
| 240 | rects[index++] = yOffset + 1; |
| 241 | } |
| 242 | } |
| 243 | int count = width * height; |
| 244 | |
| 245 | SkPaint paint; |
| 246 | paint.setColor(0xff00ffff); |
| 247 | renderer->drawRects(rects, count, &paint); |
| 248 | |
| 249 | endRecording(renderer, node.get()); |
| 250 | return node; |
| 251 | } |
| 252 | }; |
| 253 | |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 254 | class OvalAnimation : public TreeContentAnimation { |
| 255 | public: |
| 256 | sp<RenderNode> card; |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 257 | void createContent(int width, int height, DisplayListCanvas* renderer) override { |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 258 | renderer->drawColor(0xFFFFFFFF, SkXfermode::kSrcOver_Mode); |
| 259 | renderer->insertReorderBarrier(true); |
| 260 | |
Chris Craik | 08fa43f | 2015-02-09 18:58:32 -0800 | [diff] [blame] | 261 | card = createCard(40, 40, 400, 400); |
Chris Craik | 956f340 | 2015-04-27 16:41:00 -0700 | [diff] [blame] | 262 | renderer->drawRenderNode(card.get()); |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 263 | |
| 264 | renderer->insertReorderBarrier(false); |
| 265 | } |
| 266 | |
| 267 | void doFrame(int frameNr) override { |
Tim Murray | bfbcd88 | 2015-05-06 12:38:05 -0700 | [diff] [blame] | 268 | int curFrame = frameNr % 150; |
| 269 | card->mutateStagingProperties().setTranslationX(curFrame); |
| 270 | card->mutateStagingProperties().setTranslationY(curFrame); |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 271 | card->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y); |
| 272 | } |
| 273 | private: |
| 274 | sp<RenderNode> createCard(int x, int y, int width, int height) { |
| 275 | sp<RenderNode> node = new RenderNode(); |
| 276 | node->mutateStagingProperties().setLeftTopRightBottom(x, y, x + width, y + height); |
| 277 | node->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y); |
| 278 | |
Chris Craik | db663fe | 2015-04-20 13:34:45 -0700 | [diff] [blame] | 279 | DisplayListCanvas* renderer = startRecording(node.get()); |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 280 | |
| 281 | SkPaint paint; |
| 282 | paint.setAntiAlias(true); |
Chris Craik | 08fa43f | 2015-02-09 18:58:32 -0800 | [diff] [blame] | 283 | paint.setColor(0xFF000000); |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 284 | renderer->drawOval(0, 0, width, height, paint); |
| 285 | |
| 286 | endRecording(renderer, node.get()); |
| 287 | return node; |
| 288 | } |
| 289 | }; |
| 290 | |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 291 | struct cstr_cmp { |
| 292 | bool operator()(const char *a, const char *b) const { |
| 293 | return std::strcmp(a, b) < 0; |
| 294 | } |
| 295 | }; |
| 296 | |
Tim Murray | bfbcd88 | 2015-05-06 12:38:05 -0700 | [diff] [blame] | 297 | typedef void (*testProc)(int); |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 298 | |
| 299 | std::map<const char*, testProc, cstr_cmp> gTestMap { |
| 300 | {"shadowgrid", TreeContentAnimation::run<ShadowGridAnimation>}, |
Tim Murray | bfbcd88 | 2015-05-06 12:38:05 -0700 | [diff] [blame] | 301 | {"shadowgrid2", TreeContentAnimation::run<ShadowGrid2Animation>}, |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 302 | {"rectgrid", TreeContentAnimation::run<RectGridAnimation> }, |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 303 | {"oval", TreeContentAnimation::run<OvalAnimation> }, |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 304 | }; |
| 305 | |
| 306 | int main(int argc, char* argv[]) { |
| 307 | const char* testName = argc > 1 ? argv[1] : "shadowgrid"; |
| 308 | testProc proc = gTestMap[testName]; |
| 309 | if(!proc) { |
| 310 | printf("Error: couldn't find test %s\n", testName); |
| 311 | return 1; |
| 312 | } |
Tim Murray | 1a0f1c7 | 2015-05-06 11:37:37 -0700 | [diff] [blame] | 313 | int loopCount = 1; |
| 314 | if (argc > 2) { |
| 315 | loopCount = atoi(argv[2]); |
| 316 | if (!loopCount) { |
| 317 | printf("Invalid loop count!\n"); |
| 318 | return 1; |
| 319 | } |
| 320 | } |
Tim Murray | bfbcd88 | 2015-05-06 12:38:05 -0700 | [diff] [blame] | 321 | int frameCount = 150; |
| 322 | if (argc > 3) { |
| 323 | frameCount = atoi(argv[3]); |
| 324 | if (frameCount < 1) { |
| 325 | printf("Invalid frame count!\n"); |
| 326 | return 1; |
| 327 | } |
| 328 | } |
Tim Murray | 1a0f1c7 | 2015-05-06 11:37:37 -0700 | [diff] [blame] | 329 | if (loopCount < 0) { |
| 330 | loopCount = INT_MAX; |
| 331 | } |
| 332 | for (int i = 0; i < loopCount; i++) { |
Tim Murray | bfbcd88 | 2015-05-06 12:38:05 -0700 | [diff] [blame] | 333 | proc(frameCount); |
Tim Murray | 1a0f1c7 | 2015-05-06 11:37:37 -0700 | [diff] [blame] | 334 | } |
John Reck | 94c40fe | 2014-10-08 09:28:43 -0700 | [diff] [blame] | 335 | printf("Success!\n"); |
| 336 | return 0; |
| 337 | } |