blob: ee9339065feb549af2950a511caa10bad9eb5705 [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
caryclark@google.com7eaa53d2013-10-02 14:49:34 +000010#include "SkGraphics.h"
caryclark@google.com66089e42013-04-10 15:55:37 +000011#include "SkRunnable.h"
12#include "SkTDArray.h"
caryclark@google.com66089e42013-04-10 15:55:37 +000013
14#define PATH_STR_SIZE 512
15
16class PathOpsThreadedRunnable;
caryclark@google.come942bc32013-04-10 18:53:01 +000017
18namespace skiatest {
19class Reporter;
20}
caryclark@google.com66089e42013-04-10 15:55:37 +000021
22struct PathOpsThreadState {
23 unsigned char fA;
24 unsigned char fB;
25 unsigned char fC;
26 unsigned char fD;
27 char* fPathStr;
caryclark@google.com03610322013-04-18 15:58:21 +000028 const char* fKey;
caryclark@google.com7eaa53d2013-10-02 14:49:34 +000029 char fSerialNo[256];
caryclark@google.com66089e42013-04-10 15:55:37 +000030 skiatest::Reporter* fReporter;
31 SkBitmap* fBitmap;
32};
33
34class PathOpsThreadedTestRunner {
35public:
36 PathOpsThreadedTestRunner(skiatest::Reporter* reporter, int threadCount)
37 : fNumThreads(threadCount)
caryclark@google.com66089e42013-04-10 15:55:37 +000038 , fReporter(reporter) {
39 }
40
41 ~PathOpsThreadedTestRunner();
42
43 void render();
44
45public:
46 int fNumThreads;
47 SkTDArray<PathOpsThreadedRunnable*> fRunnables;
caryclark@google.com66089e42013-04-10 15:55:37 +000048 skiatest::Reporter* fReporter;
49};
50
51class PathOpsThreadedRunnable : public SkRunnable {
52public:
53 PathOpsThreadedRunnable(void (*testFun)(PathOpsThreadState*), int a, int b, int c, int d,
54 PathOpsThreadedTestRunner* runner) {
55 fState.fA = a;
56 fState.fB = b;
57 fState.fC = c;
58 fState.fD = d;
59 fState.fReporter = runner->fReporter;
60 fTestFun = testFun;
caryclark@google.com66089e42013-04-10 15:55:37 +000061 }
62
caryclark@google.com07e97fc2013-07-08 17:17:02 +000063 PathOpsThreadedRunnable(void (*testFun)(PathOpsThreadState*), const char* str,
64 PathOpsThreadedTestRunner* runner) {
65 SkASSERT(strlen(str) < sizeof(fState.fSerialNo) - 1);
66 strcpy(fState.fSerialNo, str);
67 fState.fReporter = runner->fReporter;
68 fTestFun = testFun;
69 }
70
caryclark@google.com66089e42013-04-10 15:55:37 +000071 virtual void run() SK_OVERRIDE {
72 SkBitmap bitmap;
73 fState.fBitmap = &bitmap;
74 char pathStr[PATH_STR_SIZE];
75 fState.fPathStr = pathStr;
caryclark@google.com7eaa53d2013-10-02 14:49:34 +000076 SkGraphics::SetTLSFontCacheLimit(1 * 1024 * 1024);
caryclark@google.com66089e42013-04-10 15:55:37 +000077 (*fTestFun)(&fState);
caryclark@google.com66089e42013-04-10 15:55:37 +000078 }
79
80private:
81 PathOpsThreadState fState;
82 void (*fTestFun)(PathOpsThreadState*);
caryclark@google.com66089e42013-04-10 15:55:37 +000083};
84
85#endif