| OLD | NEW |
| 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 1117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1128 SkCanvas canvas(bitmap); | 1128 SkCanvas canvas(bitmap); |
| 1129 GraphicsContext context(&canvas); | 1129 GraphicsContext context(&canvas); |
| 1130 | 1130 |
| 1131 SkCanvas controlCanvas(400, 400); | 1131 SkCanvas controlCanvas(400, 400); |
| 1132 GraphicsContext controlContext(&controlCanvas); | 1132 GraphicsContext controlContext(&controlCanvas); |
| 1133 | 1133 |
| 1134 EXPECT_EQ(context.getCTM(), controlContext.getCTM()); | 1134 EXPECT_EQ(context.getCTM(), controlContext.getCTM()); |
| 1135 DISPATCH2(context, controlContext, scale, 2, 2); | 1135 DISPATCH2(context, controlContext, scale, 2, 2); |
| 1136 EXPECT_EQ(context.getCTM(), controlContext.getCTM()); | 1136 EXPECT_EQ(context.getCTM(), controlContext.getCTM()); |
| 1137 | 1137 |
| 1138 RefPtr<DisplayList> displayList1 = DisplayList::create(FloatRect(0, 0, 200,
200)); |
| 1138 controlContext.save(); | 1139 controlContext.save(); |
| 1139 context.beginRecording(FloatRect(0, 0, 200, 200)); | 1140 context.beginRecording(displayList1); |
| 1140 DISPATCH2(context, controlContext, translate, 10, 10); | 1141 DISPATCH2(context, controlContext, translate, 10, 10); |
| 1141 EXPECT_EQ(context.getCTM(), controlContext.getCTM()); | 1142 EXPECT_EQ(context.getCTM(), controlContext.getCTM()); |
| 1142 | 1143 |
| 1144 RefPtr<DisplayList> displayList2 = DisplayList::create(FloatRect(10, 10, 100
, 100)); |
| 1143 controlContext.save(); | 1145 controlContext.save(); |
| 1144 context.beginRecording(FloatRect(10, 10, 100, 100)); | 1146 context.beginRecording(displayList2); |
| 1145 DISPATCH1(context, controlContext, rotate, 45); | 1147 DISPATCH1(context, controlContext, rotate, 45); |
| 1146 EXPECT_EQ(context.getCTM(), controlContext.getCTM()); | 1148 EXPECT_EQ(context.getCTM(), controlContext.getCTM()); |
| 1147 | 1149 |
| 1148 controlContext.restore(); | 1150 controlContext.restore(); |
| 1149 context.endRecording(); | 1151 context.endRecording(); |
| 1150 EXPECT_EQ(context.getCTM(), controlContext.getCTM()); | 1152 EXPECT_EQ(context.getCTM(), controlContext.getCTM()); |
| 1151 | 1153 |
| 1152 controlContext.restore(); | 1154 controlContext.restore(); |
| 1153 context.endRecording(); | 1155 context.endRecording(); |
| 1154 EXPECT_EQ(context.getCTM(), controlContext.getCTM()); | 1156 EXPECT_EQ(context.getCTM(), controlContext.getCTM()); |
| 1155 } | 1157 } |
| 1156 | 1158 |
| 1157 TEST(GraphicsContextTest, DisplayList) | 1159 TEST(GraphicsContextTest, DisplayList) |
| 1158 { | 1160 { |
| 1161 SkBitmap bitmap; |
| 1162 ASSERT_TRUE(bitmap.allocN32Pixels(1, 1)); |
| 1163 bitmap.eraseColor(0); |
| 1164 SkCanvas canvas(bitmap); |
| 1165 GraphicsContext context(&canvas); |
| 1166 |
| 1159 FloatRect rect(0, 0, 1, 1); | 1167 FloatRect rect(0, 0, 1, 1); |
| 1160 RefPtr<DisplayList> dl = adoptRef(new DisplayList(rect)); | 1168 RefPtr<DisplayList> dl = DisplayList::create(rect); |
| 1161 | 1169 |
| 1162 // picture() returns 0 initially | 1170 // picture() returns 0 initially |
| 1163 SkPicture* pic = dl->picture(); | 1171 SkPicture* pic = dl->picture(); |
| 1164 EXPECT_FALSE(pic); | 1172 EXPECT_FALSE(pic); |
| 1165 | 1173 |
| 1166 // endRecording without a beginRecording does nothing | |
| 1167 dl->endRecording(); | |
| 1168 pic = dl->picture(); | |
| 1169 EXPECT_FALSE(pic); | |
| 1170 | |
| 1171 // Two beginRecordings in a row generate two canvases. | 1174 // Two beginRecordings in a row generate two canvases. |
| 1172 // Unfortunately the new one could be allocated in the same | 1175 // 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. | 1176 // spot as the old one so ref the first one to prolong its life. |
| 1174 IntSize size(1, 1); | 1177 context.beginRecording(dl); |
| 1175 SkCanvas* canvas1 = dl->beginRecording(size); | 1178 SkCanvas* canvas1 = context.canvas(); |
| 1176 EXPECT_TRUE(canvas1); | 1179 EXPECT_TRUE(canvas1); |
| 1177 canvas1->ref(); | 1180 context.beginRecording(dl); |
| 1178 SkCanvas* canvas2 = dl->beginRecording(size); | 1181 SkCanvas* canvas2 = context.canvas(); |
| 1179 EXPECT_TRUE(canvas2); | 1182 EXPECT_TRUE(canvas2); |
| 1180 | 1183 |
| 1181 EXPECT_NE(canvas1, canvas2); | 1184 EXPECT_NE(canvas1, canvas2); |
| 1182 EXPECT_EQ(1, canvas1->getRefCnt()); | 1185 EXPECT_EQ(1, canvas1->getRefCnt()); |
| 1183 canvas1->unref(); | |
| 1184 | |
| 1185 EXPECT_TRUE(dl->isRecording()); | |
| 1186 | 1186 |
| 1187 // picture() returns 0 during recording | 1187 // picture() returns 0 during recording |
| 1188 pic = dl->picture(); | 1188 pic = dl->picture(); |
| 1189 EXPECT_FALSE(pic); | 1189 EXPECT_FALSE(pic); |
| 1190 | 1190 |
| 1191 // endRecording finally makes the picture accessible | 1191 // endRecording finally makes the picture accessible |
| 1192 dl->endRecording(); | 1192 context.endRecording(); |
| 1193 pic = dl->picture(); | 1193 pic = dl->picture(); |
| 1194 EXPECT_TRUE(pic); | 1194 EXPECT_TRUE(pic); |
| 1195 EXPECT_EQ(1, pic->getRefCnt()); | 1195 EXPECT_EQ(1, pic->getRefCnt()); |
| 1196 |
| 1197 context.endRecording(); |
| 1196 } | 1198 } |
| 1197 | 1199 |
| 1198 } // namespace | 1200 } // namespace |
| OLD | NEW |