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

Side by Side Diff: tests/RecordReplaceDrawTest.cpp

Issue 767333002: Defer saves() until they're needed (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update tests 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 | « tests/RecordPatternTest.cpp ('k') | tests/RecordTestUtils.h » ('j') | 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 "Test.h" 10 #include "Test.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 pic.reset(recorder.endRecording()); 46 pic.reset(recorder.endRecording());
47 } 47 }
48 48
49 SkRecord rerecord; 49 SkRecord rerecord;
50 SkRecorder canvas(&rerecord, kWidth, kHeight); 50 SkRecorder canvas(&rerecord, kWidth, kHeight);
51 51
52 JustOneDraw callback; 52 JustOneDraw callback;
53 GrRecordReplaceDraw(pic, &canvas, NULL, SkMatrix::I(), &callback); 53 GrRecordReplaceDraw(pic, &canvas, NULL, SkMatrix::I(), &callback);
54 54
55 REPORTER_ASSERT(r, 3 == rerecord.count()); 55 switch (rerecord.count()) {
56 assert_type<SkRecords::Save>(r, rerecord, 0); 56 case 3:
57 assert_type<SkRecords::DrawRect>(r, rerecord, 1); 57 assert_type<SkRecords::Save>(r, rerecord, 0);
58 assert_type<SkRecords::Restore>(r, rerecord, 2); 58 assert_type<SkRecords::DrawRect>(r, rerecord, 1);
59 assert_type<SkRecords::Restore>(r, rerecord, 2);
60 break;
61 case 1:
62 assert_type<SkRecords::DrawRect>(r, rerecord, 0);
63 break;
64 default:
65 REPORTER_ASSERT(r, false);
66 }
59 } 67 }
60 68
61 // Make sure GrRecordReplaceDraw balances unbalanced saves 69 // Make sure GrRecordReplaceDraw balances unbalanced saves
62 DEF_TEST(RecordReplaceDraw_Unbalanced, r) { 70 DEF_TEST(RecordReplaceDraw_Unbalanced, r) {
63 SkAutoTUnref<const SkPicture> pic; 71 SkAutoTUnref<const SkPicture> pic;
64 72
65 { 73 {
66 SkPictureRecorder recorder; 74 SkPictureRecorder recorder;
67 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kWidth), SkIntT oScalar(kHeight)); 75 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kWidth), SkIntT oScalar(kHeight));
68 76
69 // We won't balance this, but GrRecordReplaceDraw will for us. 77 // We won't balance this, but GrRecordReplaceDraw will for us.
70 canvas->save(); 78 canvas->save();
71 79 canvas->scale(2, 2);
72 pic.reset(recorder.endRecording()); 80 pic.reset(recorder.endRecording());
73 } 81 }
74 82
75 SkRecord rerecord; 83 SkRecord rerecord;
76 SkRecorder canvas(&rerecord, kWidth, kHeight); 84 SkRecorder canvas(&rerecord, kWidth, kHeight);
77 85
78 GrRecordReplaceDraw(pic, &canvas, NULL, SkMatrix::I(), NULL/*callback*/); 86 GrRecordReplaceDraw(pic, &canvas, NULL, SkMatrix::I(), NULL/*callback*/);
79 87
80 REPORTER_ASSERT(r, 4 == rerecord.count()); 88 // ensure rerecord is balanced (in this case by checking that the count is e ven)
81 assert_type<SkRecords::Save>(r, rerecord, 0); 89 REPORTER_ASSERT(r, (rerecord.count() & 1) == 0);
82 assert_type<SkRecords::Save>(r, rerecord, 1);
83 assert_type<SkRecords::Restore>(r, rerecord, 2);
84 assert_type<SkRecords::Restore>(r, rerecord, 3);
85 } 90 }
86 91
87 // Test out the layer replacement functionality with and w/o a BBH 92 // Test out the layer replacement functionality with and w/o a BBH
88 void test_replacements(skiatest::Reporter* r, GrContext* context, bool useBBH) { 93 void test_replacements(skiatest::Reporter* r, GrContext* context, bool useBBH) {
89 SkAutoTUnref<const SkPicture> pic; 94 SkAutoTUnref<const SkPicture> pic;
90 95
91 { 96 {
92 SkRTreeFactory bbhFactory; 97 SkRTreeFactory bbhFactory;
93 SkPictureRecorder recorder; 98 SkPictureRecorder recorder;
94 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kWidth), SkIntT oScalar(kHeight), 99 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kWidth), SkIntT oScalar(kHeight),
(...skipping 25 matching lines...) Expand all
120 125
121 SkAutoTUnref<GrTexture> texture(context->createUncachedTexture(desc, NULL, 0 )); 126 SkAutoTUnref<GrTexture> texture(context->createUncachedTexture(desc, NULL, 0 ));
122 layer->setTexture(texture, SkIRect::MakeWH(kWidth, kHeight)); 127 layer->setTexture(texture, SkIRect::MakeWH(kWidth, kHeight));
123 128
124 SkAutoTUnref<SkBBoxHierarchy> bbh; 129 SkAutoTUnref<SkBBoxHierarchy> bbh;
125 130
126 SkRecord rerecord; 131 SkRecord rerecord;
127 SkRecorder canvas(&rerecord, kWidth, kHeight); 132 SkRecorder canvas(&rerecord, kWidth, kHeight);
128 GrRecordReplaceDraw(pic, &canvas, layerCache, SkMatrix::I(), NULL/*callback* /); 133 GrRecordReplaceDraw(pic, &canvas, layerCache, SkMatrix::I(), NULL/*callback* /);
129 134
130 REPORTER_ASSERT(r, 7 == rerecord.count()); 135 int recount = rerecord.count();
131 assert_type<SkRecords::Save>(r, rerecord, 0); 136 REPORTER_ASSERT(r, 5 == recount || 7 == recount);
132 assert_type<SkRecords::Save>(r, rerecord, 1); 137
133 assert_type<SkRecords::SetMatrix>(r, rerecord, 2); 138 int index = 0;
134 assert_type<SkRecords::DrawBitmapRectToRect>(r, rerecord, 3); 139 if (7 == recount) {
135 assert_type<SkRecords::Restore>(r, rerecord, 4); 140 assert_type<SkRecords::Save>(r, rerecord, 0);
136 assert_type<SkRecords::DrawRect>(r, rerecord, 5); 141 index += 1;
137 assert_type<SkRecords::Restore>(r, rerecord, 6); 142 }
143 assert_type<SkRecords::Save>(r, rerecord, index + 0);
144 assert_type<SkRecords::SetMatrix>(r, rerecord, index + 1);
145 assert_type<SkRecords::DrawBitmapRectToRect>(r, rerecord, index + 2);
146 assert_type<SkRecords::Restore>(r, rerecord, index + 3);
147 assert_type<SkRecords::DrawRect>(r, rerecord, index + 4);
148 if (7 == recount) {
149 assert_type<SkRecords::Restore>(r, rerecord, 6);
150 }
138 } 151 }
139 152
140 DEF_GPUTEST(RecordReplaceDraw, r, factory) { 153 DEF_GPUTEST(RecordReplaceDraw, r, factory) {
141 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { 154 for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
142 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G LContextType>(type); 155 GrContextFactory::GLContextType glType = static_cast<GrContextFactory::G LContextType>(type);
143 if (!GrContextFactory::IsRenderingGLContext(glType)) { 156 if (!GrContextFactory::IsRenderingGLContext(glType)) {
144 continue; 157 continue;
145 } 158 }
146 GrContext* context = factory->get(glType); 159 GrContext* context = factory->get(glType);
147 if (NULL == context) { 160 if (NULL == context) {
148 continue; 161 continue;
149 } 162 }
150 163
151 test_replacements(r, context, true); 164 test_replacements(r, context, true);
152 test_replacements(r, context, false); 165 test_replacements(r, context, false);
153 } 166 }
154 } 167 }
155 168
156 #endif 169 #endif
OLDNEW
« no previous file with comments | « tests/RecordPatternTest.cpp ('k') | tests/RecordTestUtils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698