Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: tests/GrTRecorderTest.cpp

Issue 750613002: Add pop_back to GrTRecorder.h (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add comments Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrTRecorder.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #if SK_SUPPORT_GPU 8 #if SK_SUPPORT_GPU
9 9
10 #include "GrTRecorder.h"
10 #include "SkMatrix.h" 11 #include "SkMatrix.h"
12 #include "SkRandom.h"
11 #include "SkString.h" 13 #include "SkString.h"
12 #include "GrTRecorder.h"
13 #include "Test.h" 14 #include "Test.h"
14 15
15 //////////////////////////////////////////////////////////////////////////////// 16 ////////////////////////////////////////////////////////////////////////////////
16 17
17 static int activeRecorderItems = 0; 18 static int activeRecorderItems = 0;
18 19
19 class IntWrapper { 20 class IntWrapper {
20 public: 21 public:
21 IntWrapper() {} 22 IntWrapper() {}
22 IntWrapper(int value) : fValue(value) {} 23 IntWrapper(int value) : fValue(value) {}
23 operator int() { return fValue; } 24 operator int() { return fValue; }
24 private: 25 private:
25 int fValue; 26 int fValue;
26 }; 27 };
27 28
28 static void test_empty_back(skiatest::Reporter* reporter) { 29 static void test_empty_back_and_pop(skiatest::Reporter* reporter) {
29 GrTRecorder<IntWrapper, int> recorder(0); 30 SkRandom rand;
31 for (int data = 0; data < 2; ++data) {
32 // Do this with different starting sizes to have different alignment bet ween blocks and pops.
33 // pops. We want to test poping the first guy off, guys in the middle of the block, and the
34 // first guy on a non-head block.
35 for (int j = 0; j < 8; ++j) {
36 GrTRecorder<IntWrapper, int> recorder(j);
30 37
31 REPORTER_ASSERT(reporter, recorder.empty()); 38 REPORTER_ASSERT(reporter, recorder.empty());
32 39
33 for (int i = 0; i < 100; ++i) { 40 for (int i = 0; i < 100; ++i) {
34 REPORTER_ASSERT(reporter, i == *GrNEW_APPEND_TO_RECORDER(recorder, IntWr apper, (i))); 41 if (data) {
35 REPORTER_ASSERT(reporter, !recorder.empty()); 42 REPORTER_ASSERT(reporter, i == *GrNEW_APPEND_TO_RECORDER(rec order,
36 REPORTER_ASSERT(reporter, i == recorder.back()); 43 Int Wrapper, (i)));
44 } else {
45 REPORTER_ASSERT(reporter, i ==
46 *GrNEW_APPEND_WITH_DATA_TO_RECORDER(recorder ,
47 IntWrapp er, (i),
48 rand.nex tULessThan(10)));
49 }
50 REPORTER_ASSERT(reporter, !recorder.empty());
51 REPORTER_ASSERT(reporter, i == recorder.back());
52 if (0 == (i % 7)) {
53 recorder.pop_back();
54 if (i > 0) {
55 REPORTER_ASSERT(reporter, !recorder.empty());
56 REPORTER_ASSERT(reporter, i-1 == recorder.back());
57 }
58 }
59 }
60
61 REPORTER_ASSERT(reporter, !recorder.empty());
62 recorder.reset();
63 REPORTER_ASSERT(reporter, recorder.empty());
64 }
37 } 65 }
38
39 REPORTER_ASSERT(reporter, !recorder.empty());
40
41 recorder.reset();
42
43 REPORTER_ASSERT(reporter, recorder.empty());
44 } 66 }
45 67
46 struct ExtraData { 68 struct ExtraData {
47 typedef GrTRecorder<ExtraData, int> Recorder; 69 typedef GrTRecorder<ExtraData, int> Recorder;
48 70
49 ExtraData(int i) : fData(i) { 71 ExtraData(int i) : fData(i) {
50 int* extraData = this->extraData(); 72 int* extraData = this->extraData();
51 for (int j = 0; j < i; j++) { 73 for (int j = 0; j < i; j++) {
52 extraData[j] = i; 74 extraData[j] = i;
53 } 75 }
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 REPORTER_ASSERT(reporter, iter.next()); 248 REPORTER_ASSERT(reporter, iter.next());
227 REPORTER_ASSERT(reporter, order.next() == iter->getType()); 249 REPORTER_ASSERT(reporter, order.next() == iter->getType());
228 iter->validate(reporter); 250 iter->validate(reporter);
229 } 251 }
230 REPORTER_ASSERT(reporter, !iter.next()); 252 REPORTER_ASSERT(reporter, !iter.next());
231 253
232 // Don't reset the recorder. It should automatically destruct all its items. 254 // Don't reset the recorder. It should automatically destruct all its items.
233 } 255 }
234 256
235 DEF_GPUTEST(GrTRecorder, reporter, factory) { 257 DEF_GPUTEST(GrTRecorder, reporter, factory) {
236 test_empty_back(reporter); 258 test_empty_back_and_pop(reporter);
237 259
238 test_extra_data(reporter); 260 test_extra_data(reporter);
239 REPORTER_ASSERT(reporter, 0 == activeRecorderItems); // test_extra_data shou ld call reset(). 261 REPORTER_ASSERT(reporter, 0 == activeRecorderItems); // test_extra_data shou ld call reset().
240 262
241 test_subclasses(reporter); 263 test_subclasses(reporter);
242 REPORTER_ASSERT(reporter, 0 == activeRecorderItems); // Ensure ~GrTRecorder invokes dtors. 264 REPORTER_ASSERT(reporter, 0 == activeRecorderItems); // Ensure ~GrTRecorder invokes dtors.
243 } 265 }
244 266
245 #endif 267 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrTRecorder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698