1 /*
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 "SkGraphics.h"
11 #include "SkTDArray.h"
12 
13 #define PATH_STR_SIZE 512
14 
15 class PathOpsThreadedRunnable;
16 
17 namespace skiatest {
18 class Reporter;
19 }
20 
21 struct PathOpsThreadState {
22     unsigned char fA;
23     unsigned char fB;
24     unsigned char fC;
25     unsigned char fD;
26     char* fPathStr;
27     const char* fKey;
28     char fSerialNo[256];
29     skiatest::Reporter* fReporter;
30     SkBitmap* fBitmap;
31 };
32 
33 class PathOpsThreadedTestRunner {
34 public:
PathOpsThreadedTestRunner(skiatest::Reporter * reporter)35     PathOpsThreadedTestRunner(skiatest::Reporter* reporter) : fReporter(reporter) {}
36 
37     ~PathOpsThreadedTestRunner();
38 
39     void render();
40 
41 public:
42     SkTDArray<PathOpsThreadedRunnable*> fRunnables;
43     skiatest::Reporter* fReporter;
44 };
45 
46 class PathOpsThreadedRunnable {
47 public:
PathOpsThreadedRunnable(void (* testFun)(PathOpsThreadState *),int a,int b,int c,int d,PathOpsThreadedTestRunner * runner)48     PathOpsThreadedRunnable(void (*testFun)(PathOpsThreadState*), int a, int b, int c, int d,
49             PathOpsThreadedTestRunner* runner) {
50         fState.fA = a;
51         fState.fB = b;
52         fState.fC = c;
53         fState.fD = d;
54         fState.fReporter = runner->fReporter;
55         fTestFun = testFun;
56     }
57 
PathOpsThreadedRunnable(void (* testFun)(PathOpsThreadState *),const char * str,PathOpsThreadedTestRunner * runner)58     PathOpsThreadedRunnable(void (*testFun)(PathOpsThreadState*), const char* str,
59             PathOpsThreadedTestRunner* runner) {
60         SkASSERT(strlen(str) < sizeof(fState.fSerialNo) - 1);
61         strcpy(fState.fSerialNo, str);
62         fState.fReporter = runner->fReporter;
63         fTestFun = testFun;
64     }
65 
PathOpsThreadedRunnable(void (* testFun)(PathOpsThreadState *),int dirNo,const char * str,PathOpsThreadedTestRunner * runner)66     PathOpsThreadedRunnable(void (*testFun)(PathOpsThreadState*), int dirNo, const char* str,
67             PathOpsThreadedTestRunner* runner) {
68         SkASSERT(strlen(str) < sizeof(fState.fSerialNo) - 1);
69         fState.fA = dirNo;
70         strcpy(fState.fSerialNo, str);
71         fState.fReporter = runner->fReporter;
72         fTestFun = testFun;
73     }
74 
operator()75     void operator()() {
76         SkBitmap bitmap;
77         fState.fBitmap = &bitmap;
78         char pathStr[PATH_STR_SIZE];
79         fState.fPathStr = pathStr;
80         SkGraphics::SetTLSFontCacheLimit(1 * 1024 * 1024);
81         (*fTestFun)(&fState);
82     }
83 
84 private:
85     PathOpsThreadState fState;
86     void (*fTestFun)(PathOpsThreadState*);
87 };
88 
89 #endif
90