blob: d1f6ff0f139714c308a6856c4add274e00ae2f5b [file] [log] [blame]
caryclark@google.com66089e42013-04-10 15:55:37 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7#ifndef PathOpsThreadedCommon_DEFINED
8#define PathOpsThreadedCommon_DEFINED
9
10#include "SkCountdown.h"
11#include "SkRunnable.h"
12#include "SkTDArray.h"
13#include "SkThreadPool.h"
14
15#define PATH_STR_SIZE 512
16
17class PathOpsThreadedRunnable;
caryclark@google.come942bc32013-04-10 18:53:01 +000018
19namespace skiatest {
20class Reporter;
21}
caryclark@google.com66089e42013-04-10 15:55:37 +000022
23struct PathOpsThreadState {
24 unsigned char fA;
25 unsigned char fB;
26 unsigned char fC;
27 unsigned char fD;
28 char* fPathStr;
caryclark@google.com03610322013-04-18 15:58:21 +000029 const char* fKey;
30 char fSerialNo[9];
caryclark@google.com66089e42013-04-10 15:55:37 +000031 skiatest::Reporter* fReporter;
32 SkBitmap* fBitmap;
33};
34
35class PathOpsThreadedTestRunner {
36public:
37 PathOpsThreadedTestRunner(skiatest::Reporter* reporter, int threadCount)
38 : fNumThreads(threadCount)
39 , fThreadPool(threadCount)
40 , fCountdown(threadCount)
41 , fReporter(reporter) {
42 }
43
44 ~PathOpsThreadedTestRunner();
45
46 void render();
47
48public:
49 int fNumThreads;
50 SkTDArray<PathOpsThreadedRunnable*> fRunnables;
51 SkThreadPool fThreadPool;
52 SkCountdown fCountdown;
53 skiatest::Reporter* fReporter;
54};
55
56class PathOpsThreadedRunnable : public SkRunnable {
57public:
58 PathOpsThreadedRunnable(void (*testFun)(PathOpsThreadState*), int a, int b, int c, int d,
59 PathOpsThreadedTestRunner* runner) {
60 fState.fA = a;
61 fState.fB = b;
62 fState.fC = c;
63 fState.fD = d;
64 fState.fReporter = runner->fReporter;
65 fTestFun = testFun;
66 fDone = &runner->fCountdown;
67 }
68
69 virtual void run() SK_OVERRIDE {
70 SkBitmap bitmap;
71 fState.fBitmap = &bitmap;
72 char pathStr[PATH_STR_SIZE];
73 fState.fPathStr = pathStr;
74 (*fTestFun)(&fState);
75 fDone->run();
76 }
77
78private:
79 PathOpsThreadState fState;
80 void (*fTestFun)(PathOpsThreadState*);
81 SkRunnable* fDone;
82};
83
84#endif