OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkTaskGroup_DEFINED | 8 #ifndef SkTaskGroup_DEFINED |
9 #define SkTaskGroup_DEFINED | 9 #define SkTaskGroup_DEFINED |
10 | 10 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 const Func* f; | 62 const Func* f; |
63 int start, end; | 63 int start, end; |
64 }; | 64 }; |
65 | 65 |
66 // TODO(mtklein): this chunking strategy could probably use some tuning. | 66 // TODO(mtklein): this chunking strategy could probably use some tuning. |
67 int max_chunks = sk_num_cores() * 2, | 67 int max_chunks = sk_num_cores() * 2, |
68 stride = (end + max_chunks - 1 ) / max_chunks, | 68 stride = (end + max_chunks - 1 ) / max_chunks, |
69 nchunks = (end + stride - 1 ) / stride; | 69 nchunks = (end + stride - 1 ) / stride; |
70 SkASSERT(nchunks <= max_chunks); | 70 SkASSERT(nchunks <= max_chunks); |
71 | 71 |
| 72 #if defined(GOOGLE3) |
| 73 // Stack frame size is limited in GOOGLE3. |
| 74 SkAutoSTMalloc<512, Chunk> chunks(nchunks); |
| 75 #else |
72 // With the chunking strategy above this won't malloc until we have a machin
e with >512 cores. | 76 // With the chunking strategy above this won't malloc until we have a machin
e with >512 cores. |
73 SkAutoSTMalloc<1024, Chunk> chunks(nchunks); | 77 SkAutoSTMalloc<1024, Chunk> chunks(nchunks); |
| 78 #endif |
74 | 79 |
75 for (int i = 0; i < nchunks; i++) { | 80 for (int i = 0; i < nchunks; i++) { |
76 Chunk& c = chunks[i]; | 81 Chunk& c = chunks[i]; |
77 c.f = &f; | 82 c.f = &f; |
78 c.start = i * stride; | 83 c.start = i * stride; |
79 c.end = SkTMin(c.start + stride, end); | 84 c.end = SkTMin(c.start + stride, end); |
80 SkASSERT(c.start < c.end); // Nothing will break if start >= end, but i
t's a wasted chunk. | 85 SkASSERT(c.start < c.end); // Nothing will break if start >= end, but i
t's a wasted chunk. |
81 } | 86 } |
82 | 87 |
83 void(*run_chunk)(Chunk*) = [](Chunk* c) { | 88 void(*run_chunk)(Chunk*) = [](Chunk* c) { |
84 for (int i = c->start; i < c->end; i++) { | 89 for (int i = c->start; i < c->end; i++) { |
85 (*c->f)(i); | 90 (*c->f)(i); |
86 } | 91 } |
87 }; | 92 }; |
88 SkTaskGroup().batch(run_chunk, chunks.get(), nchunks); | 93 SkTaskGroup().batch(run_chunk, chunks.get(), nchunks); |
89 } | 94 } |
90 | 95 |
91 #endif//SkTaskGroup_DEFINED | 96 #endif//SkTaskGroup_DEFINED |
OLD | NEW |