OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 // This tests a Gr class | 8 // This tests a Gr class |
9 #if SK_SUPPORT_GPU | 9 #if SK_SUPPORT_GPU |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 public: | 34 public: |
35 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { | 35 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { |
36 return backend == kNonRendering_Backend; | 36 return backend == kNonRendering_Backend; |
37 } | 37 } |
38 | 38 |
39 protected: | 39 protected: |
40 virtual const char* onGetName() { | 40 virtual const char* onGetName() { |
41 return "grmemorypool_stack"; | 41 return "grmemorypool_stack"; |
42 } | 42 } |
43 | 43 |
44 virtual void onDraw(SkCanvas*) { | 44 virtual void onDraw(const int loops, SkCanvas*) { |
45 SkRandom r; | 45 SkRandom r; |
46 enum { | 46 enum { |
47 kMaxObjects = 4 * (1 << 10), | 47 kMaxObjects = 4 * (1 << 10), |
48 }; | 48 }; |
49 A* objects[kMaxObjects]; | 49 A* objects[kMaxObjects]; |
50 | 50 |
51 // We delete if a random [-1, 1] fixed pt is < the thresh. Otherwise, | 51 // We delete if a random [-1, 1] fixed pt is < the thresh. Otherwise, |
52 // we allocate. We start allocate-biased and ping-pong to delete-biased | 52 // we allocate. We start allocate-biased and ping-pong to delete-biased |
53 SkFixed delThresh = -SK_FixedHalf; | 53 SkFixed delThresh = -SK_FixedHalf; |
54 const int kSwitchThreshPeriod = this->getLoops() / (2 * kMaxObjects); | 54 const int kSwitchThreshPeriod = loops / (2 * kMaxObjects); |
55 int s = 0; | 55 int s = 0; |
56 | 56 |
57 int count = 0; | 57 int count = 0; |
58 for (int i = 0; i < this->getLoops(); i++, ++s) { | 58 for (int i = 0; i < loops; i++, ++s) { |
59 if (kSwitchThreshPeriod == s) { | 59 if (kSwitchThreshPeriod == s) { |
60 delThresh = -delThresh; | 60 delThresh = -delThresh; |
61 s = 0; | 61 s = 0; |
62 } | 62 } |
63 SkFixed del = r.nextSFixed1(); | 63 SkFixed del = r.nextSFixed1(); |
64 if (count && | 64 if (count && |
65 (kMaxObjects == count || del < delThresh)) { | 65 (kMaxObjects == count || del < delThresh)) { |
66 delete objects[count-1]; | 66 delete objects[count-1]; |
67 --count; | 67 --count; |
68 } else { | 68 } else { |
(...skipping 17 matching lines...) Expand all Loading... |
86 public: | 86 public: |
87 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { | 87 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { |
88 return backend == kNonRendering_Backend; | 88 return backend == kNonRendering_Backend; |
89 } | 89 } |
90 | 90 |
91 protected: | 91 protected: |
92 virtual const char* onGetName() { | 92 virtual const char* onGetName() { |
93 return "grmemorypool_random"; | 93 return "grmemorypool_random"; |
94 } | 94 } |
95 | 95 |
96 virtual void onDraw(SkCanvas*) { | 96 virtual void onDraw(const int loops, SkCanvas*) { |
97 SkRandom r; | 97 SkRandom r; |
98 enum { | 98 enum { |
99 kMaxObjects = 4 * (1 << 10), | 99 kMaxObjects = 4 * (1 << 10), |
100 }; | 100 }; |
101 SkAutoTDelete<A> objects[kMaxObjects]; | 101 SkAutoTDelete<A> objects[kMaxObjects]; |
102 | 102 |
103 for (int i = 0; i < this->getLoops(); i++) { | 103 for (int i = 0; i < loops; i++) { |
104 uint32_t idx = r.nextRangeU(0, kMaxObjects-1); | 104 uint32_t idx = r.nextRangeU(0, kMaxObjects-1); |
105 if (NULL == objects[idx].get()) { | 105 if (NULL == objects[idx].get()) { |
106 objects[idx].reset(new A); | 106 objects[idx].reset(new A); |
107 } else { | 107 } else { |
108 objects[idx].free(); | 108 objects[idx].free(); |
109 } | 109 } |
110 } | 110 } |
111 } | 111 } |
112 | 112 |
113 private: | 113 private: |
(...skipping 10 matching lines...) Expand all Loading... |
124 public: | 124 public: |
125 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { | 125 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { |
126 return backend == kNonRendering_Backend; | 126 return backend == kNonRendering_Backend; |
127 } | 127 } |
128 | 128 |
129 protected: | 129 protected: |
130 virtual const char* onGetName() { | 130 virtual const char* onGetName() { |
131 return "grmemorypool_queue"; | 131 return "grmemorypool_queue"; |
132 } | 132 } |
133 | 133 |
134 virtual void onDraw(SkCanvas*) { | 134 virtual void onDraw(const int loops, SkCanvas*) { |
135 SkRandom r; | 135 SkRandom r; |
136 A* objects[M]; | 136 A* objects[M]; |
137 for (int i = 0; i < this->getLoops(); i++) { | 137 for (int i = 0; i < loops; i++) { |
138 uint32_t count = r.nextRangeU(0, M-1); | 138 uint32_t count = r.nextRangeU(0, M-1); |
139 for (uint32_t i = 0; i < count; i++) { | 139 for (uint32_t i = 0; i < count; i++) { |
140 objects[i] = new A; | 140 objects[i] = new A; |
141 } | 141 } |
142 for (uint32_t i = 0; i < count; i++) { | 142 for (uint32_t i = 0; i < count; i++) { |
143 delete objects[i]; | 143 delete objects[i]; |
144 } | 144 } |
145 } | 145 } |
146 } | 146 } |
147 | 147 |
148 private: | 148 private: |
149 typedef SkBenchmark INHERITED; | 149 typedef SkBenchmark INHERITED; |
150 }; | 150 }; |
151 | 151 |
152 /////////////////////////////////////////////////////////////////////////////// | 152 /////////////////////////////////////////////////////////////////////////////// |
153 | 153 |
154 DEF_BENCH( return new GrMemoryPoolBenchStack(); ) | 154 DEF_BENCH( return new GrMemoryPoolBenchStack(); ) |
155 DEF_BENCH( return new GrMemoryPoolBenchRandom(); ) | 155 DEF_BENCH( return new GrMemoryPoolBenchRandom(); ) |
156 DEF_BENCH( return new GrMemoryPoolBenchQueue(); ) | 156 DEF_BENCH( return new GrMemoryPoolBenchQueue(); ) |
157 | 157 |
158 #endif | 158 #endif |
OLD | NEW |