hwcStress.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. /*
  2. * Copyright (C) 2010 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. */
  17. /*
  18. * Hardware Composer stress test
  19. *
  20. * Performs a pseudo-random (prandom) sequence of operations to the
  21. * Hardware Composer (HWC), for a specified number of passes or for
  22. * a specified period of time. By default the period of time is FLT_MAX,
  23. * so that the number of passes will take precedence.
  24. *
  25. * The passes are grouped together, where (pass / passesPerGroup) specifies
  26. * which group a particular pass is in. This causes every passesPerGroup
  27. * worth of sequential passes to be within the same group. Computationally
  28. * intensive operations are performed just once at the beginning of a group
  29. * of passes and then used by all the passes in that group. This is done
  30. * so as to increase both the average and peak rate of graphic operations,
  31. * by moving computationally intensive operations to the beginning of a group.
  32. * In particular, at the start of each group of passes a set of
  33. * graphic buffers are created, then used by the first and remaining
  34. * passes of that group of passes.
  35. *
  36. * The per-group initialization of the graphic buffers is performed
  37. * by a function called initFrames. This function creates an array
  38. * of smart pointers to the graphic buffers, in the form of a vector
  39. * of vectors. The array is accessed in row major order, so each
  40. * row is a vector of smart pointers. All the pointers of a single
  41. * row point to graphic buffers which use the same pixel format and
  42. * have the same dimension, although it is likely that each one is
  43. * filled with a different color. This is done so that after doing
  44. * the first HWC prepare then set call, subsequent set calls can
  45. * be made with each of the layer handles changed to a different
  46. * graphic buffer within the same row. Since the graphic buffers
  47. * in a particular row have the same pixel format and dimension,
  48. * additional HWC set calls can be made, without having to perform
  49. * an HWC prepare call.
  50. *
  51. * This test supports the following command-line options:
  52. *
  53. * -v Verbose
  54. * -s num Starting pass
  55. * -e num Ending pass
  56. * -p num Execute the single pass specified by num
  57. * -n num Number of set operations to perform after each prepare operation
  58. * -t float Maximum time in seconds to execute the test
  59. * -d float Delay in seconds performed after each set operation
  60. * -D float Delay in seconds performed after the last pass is executed
  61. *
  62. * Typically the test is executed for a large range of passes. By default
  63. * passes 0 through 99999 (100,000 passes) are executed. Although this test
  64. * does not validate the generated image, at times it is useful to reexecute
  65. * a particular pass and leave the displayed image on the screen for an
  66. * extended period of time. This can be done either by setting the -s
  67. * and -e options to the desired pass, along with a large value for -D.
  68. * This can also be done via the -p option, again with a large value for
  69. * the -D options.
  70. *
  71. * So far this test only contains code to create graphic buffers with
  72. * a continuous solid color. Although this test is unable to validate the
  73. * image produced, any image that contains other than rectangles of a solid
  74. * color are incorrect. Note that the rectangles may use a transparent
  75. * color and have a blending operation that causes the color in overlapping
  76. * rectangles to be mixed. In such cases the overlapping portions may have
  77. * a different color from the rest of the rectangle.
  78. */
  79. #include <algorithm>
  80. #include <assert.h>
  81. #include <cerrno>
  82. #include <cmath>
  83. #include <cstdlib>
  84. #include <ctime>
  85. #include <libgen.h>
  86. #include <sched.h>
  87. #include <sstream>
  88. #include <stdint.h>
  89. #include <string.h>
  90. #include <unistd.h>
  91. #include <vector>
  92. #include <sys/syscall.h>
  93. #include <sys/types.h>
  94. #include <sys/wait.h>
  95. #include <EGL/egl.h>
  96. #include <EGL/eglext.h>
  97. #include <GLES2/gl2.h>
  98. #include <GLES2/gl2ext.h>
  99. #include <ui/GraphicBuffer.h>
  100. #define LOG_TAG "hwcStressTest"
  101. #include <utils/Log.h>
  102. #include <testUtil.h>
  103. #include <hardware/hwcomposer.h>
  104. #include <glTestLib.h>
  105. #include "hwcTestLib.h"
  106. using namespace std;
  107. using namespace android;
  108. const float maxSizeRatio = 1.3; // Graphic buffers can be upto this munch
  109. // larger than the default screen size
  110. const unsigned int passesPerGroup = 10; // A group of passes all use the same
  111. // graphic buffers
  112. // Ratios at which rare and frequent conditions should be produced
  113. const float rareRatio = 0.1;
  114. const float freqRatio = 0.9;
  115. // Defaults for command-line options
  116. const bool defaultVerbose = false;
  117. const unsigned int defaultStartPass = 0;
  118. const unsigned int defaultEndPass = 99999;
  119. const unsigned int defaultPerPassNumSet = 10;
  120. const float defaultPerSetDelay = 0.0; // Default delay after each set
  121. // operation. Default delay of
  122. // zero used so as to perform the
  123. // the set operations as quickly
  124. // as possible.
  125. const float defaultEndDelay = 2.0; // Default delay between completion of
  126. // final pass and restart of framework
  127. const float defaultDuration = FLT_MAX; // A fairly long time, so that
  128. // range of passes will have
  129. // precedence
  130. // Command-line option settings
  131. static bool verbose = defaultVerbose;
  132. static unsigned int startPass = defaultStartPass;
  133. static unsigned int endPass = defaultEndPass;
  134. static unsigned int numSet = defaultPerPassNumSet;
  135. static float perSetDelay = defaultPerSetDelay;
  136. static float endDelay = defaultEndDelay;
  137. static float duration = defaultDuration;
  138. // Command-line mutual exclusion detection flags.
  139. // Corresponding flag set true once an option is used.
  140. bool eFlag, sFlag, pFlag;
  141. #define MAXSTR 100
  142. #define MAXCMD 200
  143. #define BITSPERBYTE 8 // TODO: Obtain from <values.h>, once
  144. // it has been added
  145. #define CMD_STOP_FRAMEWORK "stop 2>&1"
  146. #define CMD_START_FRAMEWORK "start 2>&1"
  147. #define NUMA(a) (sizeof(a) / sizeof(a [0]))
  148. #define MEMCLR(addr, size) do { \
  149. memset((addr), 0, (size)); \
  150. } while (0)
  151. // File scope constants
  152. const unsigned int blendingOps[] = {
  153. HWC_BLENDING_NONE,
  154. HWC_BLENDING_PREMULT,
  155. HWC_BLENDING_COVERAGE,
  156. };
  157. const unsigned int layerFlags[] = {
  158. HWC_SKIP_LAYER,
  159. };
  160. const vector<unsigned int> vecLayerFlags(layerFlags,
  161. layerFlags + NUMA(layerFlags));
  162. const unsigned int transformFlags[] = {
  163. HWC_TRANSFORM_FLIP_H,
  164. HWC_TRANSFORM_FLIP_V,
  165. HWC_TRANSFORM_ROT_90,
  166. // ROT_180 & ROT_270 intentionally not listed, because they
  167. // they are formed from combinations of the flags already listed.
  168. };
  169. const vector<unsigned int> vecTransformFlags(transformFlags,
  170. transformFlags + NUMA(transformFlags));
  171. // File scope globals
  172. static const int texUsage = GraphicBuffer::USAGE_HW_TEXTURE |
  173. GraphicBuffer::USAGE_SW_WRITE_RARELY;
  174. static hwc_composer_device_1_t *hwcDevice;
  175. static EGLDisplay dpy;
  176. static EGLSurface surface;
  177. static EGLint width, height;
  178. static vector <vector <sp<GraphicBuffer> > > frames;
  179. // File scope prototypes
  180. void init(void);
  181. void initFrames(unsigned int seed);
  182. template <class T> vector<T> vectorRandSelect(const vector<T>& vec, size_t num);
  183. template <class T> T vectorOr(const vector<T>& vec);
  184. /*
  185. * Main
  186. *
  187. * Performs the following high-level sequence of operations:
  188. *
  189. * 1. Command-line parsing
  190. *
  191. * 2. Initialization
  192. *
  193. * 3. For each pass:
  194. *
  195. * a. If pass is first pass or in a different group from the
  196. * previous pass, initialize the array of graphic buffers.
  197. *
  198. * b. Create a HWC list with room to specify a prandomly
  199. * selected number of layers.
  200. *
  201. * c. Select a subset of the rows from the graphic buffer array,
  202. * such that there is a unique row to be used for each
  203. * of the layers in the HWC list.
  204. *
  205. * d. Prandomly fill in the HWC list with handles
  206. * selected from any of the columns of the selected row.
  207. *
  208. * e. Pass the populated list to the HWC prepare call.
  209. *
  210. * f. Pass the populated list to the HWC set call.
  211. *
  212. * g. If additional set calls are to be made, then for each
  213. * additional set call, select a new set of handles and
  214. * perform the set call.
  215. */
  216. int
  217. main(int argc, char *argv[])
  218. {
  219. int rv, opt;
  220. char *chptr;
  221. unsigned int pass;
  222. char cmd[MAXCMD];
  223. struct timeval startTime, currentTime, delta;
  224. testSetLogCatTag(LOG_TAG);
  225. // Parse command line arguments
  226. while ((opt = getopt(argc, argv, "vp:d:D:n:s:e:t:?h")) != -1) {
  227. switch (opt) {
  228. case 'd': // Delay after each set operation
  229. perSetDelay = strtod(optarg, &chptr);
  230. if ((*chptr != '\0') || (perSetDelay < 0.0)) {
  231. testPrintE("Invalid command-line specified per pass delay of: "
  232. "%s", optarg);
  233. exit(1);
  234. }
  235. break;
  236. case 'D': // End of test delay
  237. // Delay between completion of final pass and restart
  238. // of framework
  239. endDelay = strtod(optarg, &chptr);
  240. if ((*chptr != '\0') || (endDelay < 0.0)) {
  241. testPrintE("Invalid command-line specified end of test delay "
  242. "of: %s", optarg);
  243. exit(2);
  244. }
  245. break;
  246. case 't': // Duration
  247. duration = strtod(optarg, &chptr);
  248. if ((*chptr != '\0') || (duration < 0.0)) {
  249. testPrintE("Invalid command-line specified duration of: %s",
  250. optarg);
  251. exit(3);
  252. }
  253. break;
  254. case 'n': // Num set operations per pass
  255. numSet = strtoul(optarg, &chptr, 10);
  256. if (*chptr != '\0') {
  257. testPrintE("Invalid command-line specified num set per pass "
  258. "of: %s", optarg);
  259. exit(4);
  260. }
  261. break;
  262. case 's': // Starting Pass
  263. sFlag = true;
  264. if (pFlag) {
  265. testPrintE("Invalid combination of command-line options.");
  266. testPrintE(" The -p option is mutually exclusive from the");
  267. testPrintE(" -s and -e options.");
  268. exit(5);
  269. }
  270. startPass = strtoul(optarg, &chptr, 10);
  271. if (*chptr != '\0') {
  272. testPrintE("Invalid command-line specified starting pass "
  273. "of: %s", optarg);
  274. exit(6);
  275. }
  276. break;
  277. case 'e': // Ending Pass
  278. eFlag = true;
  279. if (pFlag) {
  280. testPrintE("Invalid combination of command-line options.");
  281. testPrintE(" The -p option is mutually exclusive from the");
  282. testPrintE(" -s and -e options.");
  283. exit(7);
  284. }
  285. endPass = strtoul(optarg, &chptr, 10);
  286. if (*chptr != '\0') {
  287. testPrintE("Invalid command-line specified ending pass "
  288. "of: %s", optarg);
  289. exit(8);
  290. }
  291. break;
  292. case 'p': // Run a single specified pass
  293. pFlag = true;
  294. if (sFlag || eFlag) {
  295. testPrintE("Invalid combination of command-line options.");
  296. testPrintE(" The -p option is mutually exclusive from the");
  297. testPrintE(" -s and -e options.");
  298. exit(9);
  299. }
  300. startPass = endPass = strtoul(optarg, &chptr, 10);
  301. if (*chptr != '\0') {
  302. testPrintE("Invalid command-line specified pass of: %s",
  303. optarg);
  304. exit(10);
  305. }
  306. break;
  307. case 'v': // Verbose
  308. verbose = true;
  309. break;
  310. case 'h': // Help
  311. case '?':
  312. default:
  313. testPrintE(" %s [options]", basename(argv[0]));
  314. testPrintE(" options:");
  315. testPrintE(" -p Execute specified pass");
  316. testPrintE(" -s Starting pass");
  317. testPrintE(" -e Ending pass");
  318. testPrintE(" -t Duration");
  319. testPrintE(" -d Delay after each set operation");
  320. testPrintE(" -D End of test delay");
  321. testPrintE(" -n Num set operations per pass");
  322. testPrintE(" -v Verbose");
  323. exit(((optopt == 0) || (optopt == '?')) ? 0 : 11);
  324. }
  325. }
  326. if (endPass < startPass) {
  327. testPrintE("Unexpected ending pass before starting pass");
  328. testPrintE(" startPass: %u endPass: %u", startPass, endPass);
  329. exit(12);
  330. }
  331. if (argc != optind) {
  332. testPrintE("Unexpected command-line postional argument");
  333. testPrintE(" %s [-s start_pass] [-e end_pass] [-t duration]",
  334. basename(argv[0]));
  335. exit(13);
  336. }
  337. testPrintI("duration: %g", duration);
  338. testPrintI("startPass: %u", startPass);
  339. testPrintI("endPass: %u", endPass);
  340. testPrintI("numSet: %u", numSet);
  341. // Stop framework
  342. rv = snprintf(cmd, sizeof(cmd), "%s", CMD_STOP_FRAMEWORK);
  343. if (rv >= (signed) sizeof(cmd) - 1) {
  344. testPrintE("Command too long for: %s", CMD_STOP_FRAMEWORK);
  345. exit(14);
  346. }
  347. testExecCmd(cmd);
  348. testDelay(1.0); // TODO - need means to query whether asyncronous stop
  349. // framework operation has completed. For now, just wait
  350. // a long time.
  351. init();
  352. // For each pass
  353. gettimeofday(&startTime, NULL);
  354. for (pass = startPass; pass <= endPass; pass++) {
  355. // Stop if duration of work has already been performed
  356. gettimeofday(&currentTime, NULL);
  357. delta = tvDelta(&startTime, &currentTime);
  358. if (tv2double(&delta) > duration) { break; }
  359. // Regenerate a new set of test frames when this pass is
  360. // either the first pass or is in a different group then
  361. // the previous pass. A group of passes are passes that
  362. // all have the same quotient when their pass number is
  363. // divided by passesPerGroup.
  364. if ((pass == startPass)
  365. || ((pass / passesPerGroup) != ((pass - 1) / passesPerGroup))) {
  366. initFrames(pass / passesPerGroup);
  367. }
  368. testPrintI("==== Starting pass: %u", pass);
  369. // Cause deterministic sequence of prandom numbers to be
  370. // generated for this pass.
  371. srand48(pass);
  372. hwc_display_contents_1_t *list;
  373. list = hwcTestCreateLayerList(testRandMod(frames.size()) + 1);
  374. if (list == NULL) {
  375. testPrintE("hwcTestCreateLayerList failed");
  376. exit(20);
  377. }
  378. // Prandomly select a subset of frames to be used by this pass.
  379. vector <vector <sp<GraphicBuffer> > > selectedFrames;
  380. selectedFrames = vectorRandSelect(frames, list->numHwLayers);
  381. // Any transform tends to create a layer that the hardware
  382. // composer is unable to support and thus has to leave for
  383. // SurfaceFlinger. Place heavy bias on specifying no transforms.
  384. bool noTransform = testRandFract() > rareRatio;
  385. for (unsigned int n1 = 0; n1 < list->numHwLayers; n1++) {
  386. unsigned int idx = testRandMod(selectedFrames[n1].size());
  387. sp<GraphicBuffer> gBuf = selectedFrames[n1][idx];
  388. hwc_layer_1_t *layer = &list->hwLayers[n1];
  389. layer->handle = gBuf->handle;
  390. layer->blending = blendingOps[testRandMod(NUMA(blendingOps))];
  391. layer->flags = (testRandFract() > rareRatio) ? 0
  392. : vectorOr(vectorRandSelect(vecLayerFlags,
  393. testRandMod(vecLayerFlags.size() + 1)));
  394. layer->transform = (noTransform || testRandFract() > rareRatio) ? 0
  395. : vectorOr(vectorRandSelect(vecTransformFlags,
  396. testRandMod(vecTransformFlags.size() + 1)));
  397. layer->sourceCrop.left = testRandMod(gBuf->getWidth());
  398. layer->sourceCrop.top = testRandMod(gBuf->getHeight());
  399. layer->sourceCrop.right = layer->sourceCrop.left
  400. + testRandMod(gBuf->getWidth() - layer->sourceCrop.left) + 1;
  401. layer->sourceCrop.bottom = layer->sourceCrop.top
  402. + testRandMod(gBuf->getHeight() - layer->sourceCrop.top) + 1;
  403. layer->displayFrame.left = testRandMod(width);
  404. layer->displayFrame.top = testRandMod(height);
  405. layer->displayFrame.right = layer->displayFrame.left
  406. + testRandMod(width - layer->displayFrame.left) + 1;
  407. layer->displayFrame.bottom = layer->displayFrame.top
  408. + testRandMod(height - layer->displayFrame.top) + 1;
  409. // Increase the frequency that a scale factor of 1.0 from
  410. // the sourceCrop to displayFrame occurs. This is the
  411. // most common scale factor used by applications and would
  412. // be rarely produced by this stress test without this
  413. // logic.
  414. if (testRandFract() <= freqRatio) {
  415. // Only change to scale factor to 1.0 if both the
  416. // width and height will fit.
  417. int sourceWidth = layer->sourceCrop.right
  418. - layer->sourceCrop.left;
  419. int sourceHeight = layer->sourceCrop.bottom
  420. - layer->sourceCrop.top;
  421. if (((layer->displayFrame.left + sourceWidth) <= width)
  422. && ((layer->displayFrame.top + sourceHeight) <= height)) {
  423. layer->displayFrame.right = layer->displayFrame.left
  424. + sourceWidth;
  425. layer->displayFrame.bottom = layer->displayFrame.top
  426. + sourceHeight;
  427. }
  428. }
  429. layer->visibleRegionScreen.numRects = 1;
  430. layer->visibleRegionScreen.rects = &layer->displayFrame;
  431. }
  432. // Perform prepare operation
  433. if (verbose) { testPrintI("Prepare:"); hwcTestDisplayList(list); }
  434. hwcDevice->prepare(hwcDevice, 1, &list);
  435. if (verbose) {
  436. testPrintI("Post Prepare:");
  437. hwcTestDisplayListPrepareModifiable(list);
  438. }
  439. // Turn off the geometry changed flag
  440. list->flags &= ~HWC_GEOMETRY_CHANGED;
  441. // Perform the set operation(s)
  442. if (verbose) {testPrintI("Set:"); }
  443. for (unsigned int n1 = 0; n1 < numSet; n1++) {
  444. if (verbose) { hwcTestDisplayListHandles(list); }
  445. list->dpy = dpy;
  446. list->sur = surface;
  447. hwcDevice->set(hwcDevice, 1, &list);
  448. // Prandomly select a new set of handles
  449. for (unsigned int n1 = 0; n1 < list->numHwLayers; n1++) {
  450. unsigned int idx = testRandMod(selectedFrames[n1].size());
  451. sp<GraphicBuffer> gBuf = selectedFrames[n1][idx];
  452. hwc_layer_1_t *layer = &list->hwLayers[n1];
  453. layer->handle = (native_handle_t *) gBuf->handle;
  454. }
  455. testDelay(perSetDelay);
  456. }
  457. hwcTestFreeLayerList(list);
  458. testPrintI("==== Completed pass: %u", pass);
  459. }
  460. testDelay(endDelay);
  461. // Start framework
  462. rv = snprintf(cmd, sizeof(cmd), "%s", CMD_START_FRAMEWORK);
  463. if (rv >= (signed) sizeof(cmd) - 1) {
  464. testPrintE("Command too long for: %s", CMD_START_FRAMEWORK);
  465. exit(21);
  466. }
  467. testExecCmd(cmd);
  468. testPrintI("Successfully completed %u passes", pass - startPass);
  469. return 0;
  470. }
  471. void init(void)
  472. {
  473. srand48(0); // Defensively set pseudo random number generator.
  474. // Should not need to set this, because a stress test
  475. // sets the seed on each pass. Defensively set it here
  476. // so that future code that uses pseudo random numbers
  477. // before the first pass will be deterministic.
  478. hwcTestInitDisplay(verbose, &dpy, &surface, &width, &height);
  479. hwcTestOpenHwc(&hwcDevice);
  480. }
  481. /*
  482. * Initialize Frames
  483. *
  484. * Creates an array of graphic buffers, within the global variable
  485. * named frames. The graphic buffers are contained within a vector of
  486. * vectors. All the graphic buffers in a particular row are of the same
  487. * format and dimension. Each graphic buffer is uniformly filled with a
  488. * prandomly selected color. It is likely that each buffer, even
  489. * in the same row, will be filled with a unique color.
  490. */
  491. void initFrames(unsigned int seed)
  492. {
  493. int rv;
  494. const size_t maxRows = 5;
  495. const size_t minCols = 2; // Need at least double buffering
  496. const size_t maxCols = 4; // One more than triple buffering
  497. if (verbose) { testPrintI("initFrames seed: %u", seed); }
  498. srand48(seed);
  499. size_t rows = testRandMod(maxRows) + 1;
  500. frames.clear();
  501. frames.resize(rows);
  502. for (unsigned int row = 0; row < rows; row++) {
  503. // All frames within a row have to have the same format and
  504. // dimensions. Width and height need to be >= 1.
  505. unsigned int formatIdx = testRandMod(NUMA(hwcTestGraphicFormat));
  506. const struct hwcTestGraphicFormat *formatPtr
  507. = &hwcTestGraphicFormat[formatIdx];
  508. int format = formatPtr->format;
  509. // Pick width and height, which must be >= 1 and the size
  510. // mod the wMod/hMod value must be equal to 0.
  511. size_t w = (width * maxSizeRatio) * testRandFract();
  512. size_t h = (height * maxSizeRatio) * testRandFract();
  513. w = max(size_t(1u), w);
  514. h = max(size_t(1u), h);
  515. if ((w % formatPtr->wMod) != 0) {
  516. w += formatPtr->wMod - (w % formatPtr->wMod);
  517. }
  518. if ((h % formatPtr->hMod) != 0) {
  519. h += formatPtr->hMod - (h % formatPtr->hMod);
  520. }
  521. if (verbose) {
  522. testPrintI(" frame %u width: %u height: %u format: %u %s",
  523. row, w, h, format, hwcTestGraphicFormat2str(format));
  524. }
  525. size_t cols = testRandMod((maxCols + 1) - minCols) + minCols;
  526. frames[row].resize(cols);
  527. for (unsigned int col = 0; col < cols; col++) {
  528. ColorFract color(testRandFract(), testRandFract(), testRandFract());
  529. float alpha = testRandFract();
  530. frames[row][col] = new GraphicBuffer(w, h, format, texUsage);
  531. if ((rv = frames[row][col]->initCheck()) != NO_ERROR) {
  532. testPrintE("GraphicBuffer initCheck failed, rv: %i", rv);
  533. testPrintE(" frame %u width: %u height: %u format: %u %s",
  534. row, w, h, format, hwcTestGraphicFormat2str(format));
  535. exit(80);
  536. }
  537. hwcTestFillColor(frames[row][col].get(), color, alpha);
  538. if (verbose) {
  539. testPrintI(" buf: %p handle: %p color: %s alpha: %f",
  540. frames[row][col].get(), frames[row][col]->handle,
  541. string(color).c_str(), alpha);
  542. }
  543. }
  544. }
  545. }
  546. /*
  547. * Vector Random Select
  548. *
  549. * Prandomly selects and returns num elements from vec.
  550. */
  551. template <class T>
  552. vector<T> vectorRandSelect(const vector<T>& vec, size_t num)
  553. {
  554. vector<T> rv = vec;
  555. while (rv.size() > num) {
  556. rv.erase(rv.begin() + testRandMod(rv.size()));
  557. }
  558. return rv;
  559. }
  560. /*
  561. * Vector Or
  562. *
  563. * Or's togethen the values of each element of vec and returns the result.
  564. */
  565. template <class T>
  566. T vectorOr(const vector<T>& vec)
  567. {
  568. T rv = 0;
  569. for (size_t n1 = 0; n1 < vec.size(); n1++) {
  570. rv |= vec[n1];
  571. }
  572. return rv;
  573. }