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 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1110 | 1110 |
1111 // For opaque preserving mode and deviceClip is rect | 1111 // For opaque preserving mode and deviceClip is rect |
1112 // we will intersect device clip rect with src opaque rect. | 1112 // we will intersect device clip rect with src opaque rect. |
1113 context.setCompositeOperation(CompositeSourceOver); | 1113 context.setCompositeOperation(CompositeSourceOver); |
1114 context.beginTransparencyLayer(0.5); | 1114 context.beginTransparencyLayer(0.5); |
1115 context.endLayer(); | 1115 context.endLayer(); |
1116 EXPECT_EQ_RECT(IntRect(20, 20, 30, 30), context.opaqueRegion().asRect()); | 1116 EXPECT_EQ_RECT(IntRect(20, 20, 30, 30), context.opaqueRegion().asRect()); |
1117 EXPECT_PIXELS_MATCH(bitmap, context.opaqueRegion().asRect()); | 1117 EXPECT_PIXELS_MATCH(bitmap, context.opaqueRegion().asRect()); |
1118 } | 1118 } |
1119 | 1119 |
1120 #define DISPATCH1(c1, c2, op, param1) do { c1.op(param1); c2.op(param1); } while
(0); | |
1121 #define DISPATCH2(c1, c2, op, param1, param2) do { c1.op(param1, param2); c2.op(
param1, param2); } while (0); | |
1122 | |
1123 TEST(GraphicsContextTest, RecordingTotalMatrix) | |
1124 { | |
1125 SkBitmap bitmap; | |
1126 bitmap.allocN32Pixels(400, 400); | |
1127 bitmap.eraseColor(0); | |
1128 SkCanvas canvas(bitmap); | |
1129 GraphicsContext context(&canvas); | |
1130 | |
1131 SkCanvas controlCanvas(400, 400); | |
1132 GraphicsContext controlContext(&controlCanvas); | |
1133 | |
1134 EXPECT_EQ(context.getCTM(), controlContext.getCTM()); | |
1135 DISPATCH2(context, controlContext, scale, 2, 2); | |
1136 EXPECT_EQ(context.getCTM(), controlContext.getCTM()); | |
1137 | |
1138 controlContext.save(); | |
1139 context.beginRecording(FloatRect(0, 0, 200, 200)); | |
1140 DISPATCH2(context, controlContext, translate, 10, 10); | |
1141 EXPECT_EQ(context.getCTM(), controlContext.getCTM()); | |
1142 | |
1143 controlContext.save(); | |
1144 context.beginRecording(FloatRect(10, 10, 100, 100)); | |
1145 DISPATCH1(context, controlContext, rotate, 45); | |
1146 EXPECT_EQ(context.getCTM(), controlContext.getCTM()); | |
1147 | |
1148 controlContext.restore(); | |
1149 context.endRecording(); | |
1150 EXPECT_EQ(context.getCTM(), controlContext.getCTM()); | |
1151 | |
1152 controlContext.restore(); | |
1153 context.endRecording(); | |
1154 EXPECT_EQ(context.getCTM(), controlContext.getCTM()); | |
1155 } | |
1156 | |
1157 TEST(GraphicsContextTest, DisplayList) | |
1158 { | |
1159 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 | |
1171 // Two beginRecordings in a row generate two canvases. | |
1172 // 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. | |
1174 IntSize size(1, 1); | |
1175 SkCanvas* canvas1 = dl->beginRecording(size); | |
1176 EXPECT_TRUE(canvas1); | |
1177 canvas1->ref(); | |
1178 SkCanvas* canvas2 = dl->beginRecording(size); | |
1179 EXPECT_TRUE(canvas2); | |
1180 | |
1181 EXPECT_NE(canvas1, canvas2); | |
1182 EXPECT_TRUE(canvas1->unique()); | |
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 | |
1191 // endRecording finally makes the picture accessible | |
1192 dl->endRecording(); | |
1193 pic = dl->picture(); | |
1194 EXPECT_TRUE(pic); | |
1195 EXPECT_TRUE(pic->unique()); | |
1196 } | |
1197 | |
1198 } // namespace | 1120 } // namespace |
OLD | NEW |