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

Side by Side Diff: tests/PictureTest.cpp

Issue 222683002: Add generation ID to SkPicture (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Fix Ubuntu compiler complaint Created 6 years, 8 months 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 | Annotate | Revision Log
« include/core/SkPicture.h ('K') | « src/core/SkPicture.cpp ('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 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 #include "SkBitmapDevice.h" 8 #include "SkBitmapDevice.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 REPORTER_ASSERT(reporter, parentWBP.willPlayBackBitmaps()); // 1 1135 REPORTER_ASSERT(reporter, parentWBP.willPlayBackBitmaps()); // 1
1136 1136
1137 SkPicture parentWBWB; 1137 SkPicture parentWBWB;
1138 canvas = parentWBWB.beginRecording(10, 10); 1138 canvas = parentWBWB.beginRecording(10, 10);
1139 canvas->drawBitmap(bm, 0, 0); 1139 canvas->drawBitmap(bm, 0, 0);
1140 canvas->drawPicture(childWithBitmap); 1140 canvas->drawPicture(childWithBitmap);
1141 parentWBWB.endRecording(); 1141 parentWBWB.endRecording();
1142 REPORTER_ASSERT(reporter, parentWBWB.willPlayBackBitmaps()); // 2 1142 REPORTER_ASSERT(reporter, parentWBWB.willPlayBackBitmaps()); // 2
1143 } 1143 }
1144 1144
1145 static void test_gen_id(skiatest::Reporter* reporter) {
1146
1147 SkPicture hasData, empty, midRecord;
1148
1149 uint32_t beforeID = hasData.getGenerationID();
1150 REPORTER_ASSERT(reporter, SkPicture::kInvalidGenID != beforeID);
1151
1152 // all 3 pictures should have different ids
1153 REPORTER_ASSERT(reporter, beforeID != empty.getGenerationID());
1154 REPORTER_ASSERT(reporter, beforeID != midRecord.getGenerationID());
1155 REPORTER_ASSERT(reporter, empty.getGenerationID() != midRecord.getGeneration ID());
1156
1157 hasData.beginRecording(1, 1);
1158 // gen ID should be invalid mid-record
1159 REPORTER_ASSERT(reporter, SkPicture::kInvalidGenID == hasData.getGenerationI D());
1160 hasData.endRecording();
1161 // picture should get a new (non-zero) id after recording
1162 REPORTER_ASSERT(reporter, hasData.getGenerationID() != beforeID);
1163 REPORTER_ASSERT(reporter, hasData.getGenerationID() != SkPicture::kInvalidGe nID);
1164
1165 midRecord.beginRecording(1, 1);
1166 REPORTER_ASSERT(reporter, SkPicture::kInvalidGenID == midRecord.getGeneratio nID());
1167
1168 // test out copy constructor
1169 SkPicture copyWithData(hasData);
1170 REPORTER_ASSERT(reporter, hasData.getGenerationID() == copyWithData.getGener ationID());
1171
1172 SkPicture emptyCopy(empty);
1173 REPORTER_ASSERT(reporter, empty.getGenerationID() != emptyCopy.getGeneration ID());
1174
1175 SkPicture copyMidRecord(midRecord);
1176 REPORTER_ASSERT(reporter, midRecord.getGenerationID() != copyMidRecord.getGe nerationID());
1177 REPORTER_ASSERT(reporter, copyMidRecord.getGenerationID() != SkPicture::kInv alidGenID);
1178
1179 // test out swap
1180 beforeID = copyMidRecord.getGenerationID();
1181 copyWithData.swap(copyMidRecord);
1182 REPORTER_ASSERT(reporter, copyWithData.getGenerationID() == beforeID);
1183 REPORTER_ASSERT(reporter, copyMidRecord.getGenerationID() == hasData.getGene rationID());
1184
1185 // test out clone
1186 SkAutoTUnref<SkPicture> cloneWithData(hasData.clone());
1187 REPORTER_ASSERT(reporter, hasData.getGenerationID() == cloneWithData->getGen erationID());
1188
1189 SkAutoTUnref<SkPicture> emptyClone(empty.clone());
1190 REPORTER_ASSERT(reporter, empty.getGenerationID() != emptyClone->getGenerati onID());
1191
1192 SkAutoTUnref<SkPicture> cloneMidRecord(midRecord.clone());
1193 REPORTER_ASSERT(reporter, midRecord.getGenerationID() != cloneMidRecord->get GenerationID());
1194 REPORTER_ASSERT(reporter, cloneMidRecord->getGenerationID() != SkPicture::kI nvalidGenID);
1195 }
1196
1145 DEF_TEST(Picture, reporter) { 1197 DEF_TEST(Picture, reporter) {
1146 #ifdef SK_DEBUG 1198 #ifdef SK_DEBUG
1147 test_deleting_empty_playback(); 1199 test_deleting_empty_playback();
1148 test_serializing_empty_picture(); 1200 test_serializing_empty_picture();
1149 #else 1201 #else
1150 test_bad_bitmap(); 1202 test_bad_bitmap();
1151 #endif 1203 #endif
1152 test_unbalanced_save_restores(reporter); 1204 test_unbalanced_save_restores(reporter);
1153 test_peephole(); 1205 test_peephole();
1154 test_gatherpixelrefs(reporter); 1206 test_gatherpixelrefs(reporter);
1155 test_gatherpixelrefsandrects(reporter); 1207 test_gatherpixelrefsandrects(reporter);
1156 test_bitmap_with_encoded_data(reporter); 1208 test_bitmap_with_encoded_data(reporter);
1157 test_clone_empty(reporter); 1209 test_clone_empty(reporter);
1158 test_draw_empty(reporter); 1210 test_draw_empty(reporter);
1159 test_clip_bound_opt(reporter); 1211 test_clip_bound_opt(reporter);
1160 test_clip_expansion(reporter); 1212 test_clip_expansion(reporter);
1161 test_hierarchical(reporter); 1213 test_hierarchical(reporter);
1214 test_gen_id(reporter);
1162 } 1215 }
1163 1216
1164 static void draw_bitmaps(const SkBitmap bitmap, SkCanvas* canvas) { 1217 static void draw_bitmaps(const SkBitmap bitmap, SkCanvas* canvas) {
1165 const SkPaint paint; 1218 const SkPaint paint;
1166 const SkRect rect = { 5.0f, 5.0f, 8.0f, 8.0f }; 1219 const SkRect rect = { 5.0f, 5.0f, 8.0f, 8.0f };
1167 const SkIRect irect = { 2, 2, 3, 3 }; 1220 const SkIRect irect = { 2, 2, 3, 3 };
1168 1221
1169 // Don't care what these record, as long as they're legal. 1222 // Don't care what these record, as long as they're legal.
1170 canvas->drawBitmap(bitmap, 0.0f, 0.0f, &paint); 1223 canvas->drawBitmap(bitmap, 0.0f, 0.0f, &paint);
1171 canvas->drawBitmapRectToRect(bitmap, &rect, rect, &paint, SkCanvas::kNone_Dr awBitmapRectFlag); 1224 canvas->drawBitmapRectToRect(bitmap, &rect, rect, &paint, SkCanvas::kNone_Dr awBitmapRectFlag);
(...skipping 15 matching lines...) Expand all
1187 picture.endRecording(); 1240 picture.endRecording();
1188 } 1241 }
1189 1242
1190 DEF_TEST(Canvas_EmptyBitmap, r) { 1243 DEF_TEST(Canvas_EmptyBitmap, r) {
1191 SkBitmap dst; 1244 SkBitmap dst;
1192 dst.allocN32Pixels(10, 10); 1245 dst.allocN32Pixels(10, 10);
1193 SkCanvas canvas(dst); 1246 SkCanvas canvas(dst);
1194 1247
1195 test_draw_bitmaps(&canvas); 1248 test_draw_bitmaps(&canvas);
1196 } 1249 }
OLDNEW
« include/core/SkPicture.h ('K') | « src/core/SkPicture.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698