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

Side by Side Diff: Source/platform/graphics/GraphicsContextTest.cpp

Issue 536573002: Modifications to DisplayList for better Slimming Paint (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Return DisplayList from endRecording Created 6 years, 3 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 EXPECT_EQ(context.getCTM(), controlContext.getCTM()); 1146 EXPECT_EQ(context.getCTM(), controlContext.getCTM());
1147 1147
1148 controlContext.restore(); 1148 controlContext.restore();
1149 context.endRecording(); 1149 context.endRecording();
1150 EXPECT_EQ(context.getCTM(), controlContext.getCTM()); 1150 EXPECT_EQ(context.getCTM(), controlContext.getCTM());
1151 1151
1152 controlContext.restore(); 1152 controlContext.restore();
1153 context.endRecording(); 1153 context.endRecording();
1154 EXPECT_EQ(context.getCTM(), controlContext.getCTM()); 1154 EXPECT_EQ(context.getCTM(), controlContext.getCTM());
1155 } 1155 }
1156 1156
chrishtr 2014/09/05 18:28:13 Add a test with clips or transforms?
Stephen Chennney 2014/09/05 18:36:19 Can do, but not trivial because you can't inspect
chrishtr 2014/09/05 18:40:58 Ok. For now we can test that clips & transforms ar
1157 TEST(GraphicsContextTest, DisplayList) 1157 TEST(GraphicsContextTest, RecordingCanvas)
1158 { 1158 {
1159 SkBitmap bitmap;
1160 ASSERT_TRUE(bitmap.allocN32Pixels(1, 1));
1161 bitmap.eraseColor(0);
1162 SkCanvas canvas(bitmap);
1163 GraphicsContext context(&canvas);
1164
1159 FloatRect rect(0, 0, 1, 1); 1165 FloatRect rect(0, 0, 1, 1);
1160 RefPtr<DisplayList> dl = adoptRef(new DisplayList(rect));
1161
1162 // picture() returns 0 initially
1163 SkPicture* pic = dl->picture();
1164 EXPECT_FALSE(pic);
1165
1166 // endRecording without a beginRecording does nothing
1167 dl->endRecording();
1168 pic = dl->picture();
1169 EXPECT_FALSE(pic);
1170 1166
1171 // Two beginRecordings in a row generate two canvases. 1167 // Two beginRecordings in a row generate two canvases.
1172 // Unfortunately the new one could be allocated in the same 1168 // Unfortunately the new one could be allocated in the same
1173 // spot as the old one so ref the first one to prolong its life. 1169 // spot as the old one so ref the first one to prolong its life.
1174 IntSize size(1, 1); 1170 context.beginRecording(rect);
1175 SkCanvas* canvas1 = dl->beginRecording(size); 1171 SkCanvas* canvas1 = context.canvas();
1176 EXPECT_TRUE(canvas1); 1172 EXPECT_TRUE(canvas1);
1177 canvas1->ref(); 1173 context.beginRecording(rect);
1178 SkCanvas* canvas2 = dl->beginRecording(size); 1174 SkCanvas* canvas2 = context.canvas();
1179 EXPECT_TRUE(canvas2); 1175 EXPECT_TRUE(canvas2);
1180 1176
1181 EXPECT_NE(canvas1, canvas2); 1177 EXPECT_NE(canvas1, canvas2);
1182 EXPECT_EQ(1, canvas1->getRefCnt()); 1178 EXPECT_EQ(1, canvas1->getRefCnt());
1183 canvas1->unref();
1184
1185 EXPECT_TRUE(dl->isRecording());
1186
1187 // picture() returns 0 during recording
1188 pic = dl->picture();
1189 EXPECT_FALSE(pic);
1190 1179
1191 // endRecording finally makes the picture accessible 1180 // endRecording finally makes the picture accessible
1192 dl->endRecording(); 1181 RefPtr<DisplayList> dl = context.endRecording();
1193 pic = dl->picture(); 1182 SkPicture* pic = dl->picture();
1194 EXPECT_TRUE(pic); 1183 EXPECT_TRUE(pic);
1195 EXPECT_EQ(1, pic->getRefCnt()); 1184 EXPECT_EQ(1, pic->getRefCnt());
1185
1186 context.endRecording();
1196 } 1187 }
1197 1188
1198 } // namespace 1189 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698