1162 {
1168
1170 ctx.canvas->restore();
1171 };
1173
1174
1175
1176
1177
1178
1179 ctx.canvas->DrawRect(
1182 ctx.canvas->Restore();
1183 };
1185
1186 ctx.canvas->restore();
1187 };
1189
1190 ctx.canvas->Restore();
1191 };
1194 CaseParameters(
1195 "With prior save/clip/restore",
1197 ctx.canvas->save();
1200 ctx.canvas->drawRect(
rect, p2);
1202 ctx.canvas->drawRect(
rect, p2);
1203 ctx.canvas->restore();
1204 },
1206 ctx.canvas->Save();
1209 ctx.canvas->DrawRect(
rect, p2);
1211 ctx.canvas->DrawRect(
rect, p2);
1212 ctx.canvas->Restore();
1213 }));
1215 CaseParameters(
1216 "saveLayer no paint, no bounds",
1218 ctx.canvas->saveLayer(nullptr, nullptr);
1219 },
1221 ctx.canvas->SaveLayer(nullptr, nullptr);
1222 })
1223 .with_restore(sk_safe_restore, dl_safe_restore, false));
1225 CaseParameters(
1226 "saveLayer no paint, with bounds",
1228 ctx.canvas->saveLayer(layer_bounds, nullptr);
1229 },
1231 ctx.canvas->SaveLayer(&layer_bounds, nullptr);
1232 })
1233 .with_restore(sk_safe_restore, dl_safe_restore, true));
1235 CaseParameters(
1236 "saveLayer with alpha, no bounds",
1240 ctx.canvas->saveLayer(nullptr, &save_p);
1241 },
1244 save_p.
setColor(alpha_layer_color);
1245 ctx.canvas->SaveLayer(nullptr, &save_p);
1246 })
1247 .with_restore(sk_safe_restore, dl_safe_restore, true));
1249 CaseParameters(
1250 "saveLayer with peephole alpha, no bounds",
1254 ctx.canvas->saveLayer(nullptr, &save_p);
1255 },
1258 save_p.
setColor(alpha_layer_color);
1259 ctx.canvas->SaveLayer(nullptr, &save_p);
1260 })
1261 .with_restore(sk_opt_restore, dl_opt_restore, true, true));
1263 CaseParameters(
1264 "saveLayer with alpha and bounds",
1268 ctx.canvas->saveLayer(layer_bounds, &save_p);
1269 },
1272 save_p.
setColor(alpha_layer_color);
1273 ctx.canvas->SaveLayer(&layer_bounds, &save_p);
1274 })
1275 .with_restore(sk_safe_restore, dl_safe_restore, true));
1276 {
1277
1278
1279
1280
1281
1282
1283
1284 RenderEnvironment backdrop_env =
1289 ctx.canvas->drawPaint(setup_p);
1290 };
1294 ctx.canvas->DrawPaint(setup_p);
1295 };
1297 ctx.paint.setAlpha(ctx.paint.getAlpha() / 2);
1298 };
1300 ctx.paint.setAlpha(ctx.paint.getAlpha() / 2);
1301 };
1302 backdrop_env.init_ref(sk_backdrop_setup, testP.sk_renderer(),
1303 dl_backdrop_setup, testP.dl_renderer(),
1304 testP.imp_renderer());
1306
1308 auto sk_backdrop =
1311 CaseParameters(
1312 "saveLayer with backdrop",
1314 sk_backdrop_setup(ctx);
1316 nullptr, nullptr, sk_backdrop.get(), 0));
1317 sk_content_setup(ctx);
1318 },
1320 dl_backdrop_setup(ctx);
1321 ctx.canvas->SaveLayer(nullptr, nullptr, &dl_backdrop);
1322 dl_content_setup(ctx);
1323 })
1324 .with_restore(sk_safe_restore, dl_safe_restore, true));
1326 CaseParameters(
1327 "saveLayer with bounds and backdrop",
1329 sk_backdrop_setup(ctx);
1331 &layer_bounds, nullptr, sk_backdrop.get(), 0));
1332 sk_content_setup(ctx);
1333 },
1335 dl_backdrop_setup(ctx);
1336 ctx.canvas->SaveLayer(&layer_bounds, nullptr,
1337 &dl_backdrop);
1338 dl_content_setup(ctx);
1339 })
1340 .with_restore(sk_safe_restore, dl_safe_restore, true));
1342 CaseParameters(
1343 "clipped saveLayer with backdrop",
1345 sk_backdrop_setup(ctx);
1346 ctx.canvas->clipRect(layer_bounds);
1348 nullptr, nullptr, sk_backdrop.get(), 0));
1349 sk_content_setup(ctx);
1350 },
1352 dl_backdrop_setup(ctx);
1353 ctx.canvas->ClipRect(layer_bounds);
1354 ctx.canvas->SaveLayer(nullptr, nullptr, &dl_backdrop);
1355 dl_content_setup(ctx);
1356 })
1357 .with_restore(sk_safe_restore, dl_safe_restore, true));
1358 }
1359
1360 {
1361
1362 constexpr float rotate_alpha_color_matrix[20] = {
1363 0, 1, 0, 0 , 0,
1364 0, 0, 1, 0 , 0,
1365 1, 0, 0, 0 , 0,
1366 0, 0, 0, 0.5, 0,
1367 };
1368
1369 DlMatrixColorFilter dl_alpha_rotate_filter(rotate_alpha_color_matrix);
1370 auto sk_alpha_rotate_filter =
1372 {
1374 CaseParameters(
1375 "saveLayer ColorFilter, no bounds",
1379 ctx.canvas->saveLayer(nullptr, &save_p);
1380 ctx.paint.setStrokeWidth(5.0);
1381 },
1385 ctx.canvas->SaveLayer(nullptr, &save_p);
1386 ctx.paint.setStrokeWidth(5.0);
1387 })
1388 .with_restore(sk_safe_restore, dl_safe_restore, true));
1389 }
1390 {
1392 CaseParameters(
1393 "saveLayer ColorFilter and bounds",
1398 ctx.paint.setStrokeWidth(5.0);
1399 },
1404 ctx.paint.setStrokeWidth(5.0);
1405 })
1406 .with_restore(sk_safe_restore, dl_safe_restore, true));
1407 }
1408 }
1409
1410 {
1411
1412 constexpr float color_matrix[20] = {
1413 0.5, 0, 0, 0, 0.5,
1414 0, 0.5, 0, 0, 0.5,
1415 0, 0, 0.5, 0, 0.5,
1416 0, 0, 0, 1, 0,
1417 };
1418
1419 DlMatrixColorFilter dl_color_filter(color_matrix);
1420 DlColorFilterImageFilter dl_cf_image_filter(dl_color_filter);
1423 {
1425 CaseParameters(
1426 "saveLayer ImageFilter, no bounds",
1430 ctx.canvas->saveLayer(nullptr, &save_p);
1431 ctx.paint.setStrokeWidth(5.0);
1432 },
1436 ctx.canvas->SaveLayer(nullptr, &save_p);
1437 ctx.paint.setStrokeWidth(5.0);
1438 })
1439 .with_restore(sk_safe_restore, dl_safe_restore, true));
1440 }
1441 {
1443 CaseParameters(
1444 "saveLayer ImageFilter and bounds",
1449 ctx.paint.setStrokeWidth(5.0);
1450 },
1455 ctx.paint.setStrokeWidth(5.0);
1456 })
1457 .with_restore(sk_safe_restore, dl_safe_restore, true));
1458 }
1459 }
1460 }
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
static sk_sp< SkImageFilter > ColorFilter(sk_sp< SkColorFilter > cf, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
void setColor(SkColor color)
void setImageFilter(sk_sp< SkImageFilter > imageFilter)
void setShader(sk_sp< SkShader > shader)
void setBlendMode(SkBlendMode mode)
void setColorFilter(sk_sp< SkColorFilter > colorFilter)
sk_sp< SkBlender > blender SkRect rect
const std::function< void(const SkRenderContext &)> SkRenderer
RenderContext< DlCanvas *, const DlPaint &, sk_sp< DlImage > > DlRenderContext
RenderContext< SkCanvas *, const SkPaint &, sk_sp< SkImage > > SkRenderContext
const std::function< void(const DlRenderContext &)> DlRenderer
SkPaint ToSk(const DlPaint &paint)
constexpr SkRect makeOffset(float dx, float dy) const
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)