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

Side by Side Diff: tests/PictureTest.cpp

Issue 777643003: use ClipOp instead of SkRegion for clipping (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years 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
« no previous file with comments | « tests/PictureBBHTest.cpp ('k') | tests/ReadPixelsTest.cpp » ('j') | 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 "SkBBoxHierarchy.h" 8 #include "SkBBoxHierarchy.h"
9 #include "SkBlurImageFilter.h" 9 #include "SkBlurImageFilter.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 int count, 315 int count,
316 DrawBitmapProc proc) { 316 DrawBitmapProc proc) {
317 SkPictureRecorder recorder; 317 SkPictureRecorder recorder;
318 SkCanvas* canvas = recorder.beginRecording(1000, 1000); 318 SkCanvas* canvas = recorder.beginRecording(1000, 1000);
319 for (int i = 0; i < count; ++i) { 319 for (int i = 0; i < count; ++i) {
320 analytic[i].rewind(); 320 analytic[i].rewind();
321 canvas->save(); 321 canvas->save();
322 SkRect clipRect = SkRect::MakeXYWH(pos[i].fX, pos[i].fY, 322 SkRect clipRect = SkRect::MakeXYWH(pos[i].fX, pos[i].fY,
323 SkIntToScalar(bm[i].width()), 323 SkIntToScalar(bm[i].width()),
324 SkIntToScalar(bm[i].height())); 324 SkIntToScalar(bm[i].height()));
325 canvas->clipRect(clipRect, SkRegion::kIntersect_Op); 325 canvas->clipRect(clipRect);
326 proc(canvas, bm[i], bm[count+i], pos[i], &analytic[i]); 326 proc(canvas, bm[i], bm[count+i], pos[i], &analytic[i]);
327 canvas->restore(); 327 canvas->restore();
328 } 328 }
329 return recorder.endRecording(); 329 return recorder.endRecording();
330 } 330 }
331 331
332 static void rand_rect(SkRect* rect, SkRandom& rand, SkScalar W, SkScalar H) { 332 static void rand_rect(SkRect* rect, SkRandom& rand, SkScalar W, SkScalar H) {
333 rect->fLeft = rand.nextRangeScalar(-W, 2*W); 333 rect->fLeft = rand.nextRangeScalar(-W, 2*W);
334 rect->fTop = rand.nextRangeScalar(-H, 2*H); 334 rect->fTop = rand.nextRangeScalar(-H, 2*H);
335 rect->fRight = rect->fLeft + rand.nextRangeScalar(0, W); 335 rect->fRight = rect->fLeft + rand.nextRangeScalar(0, W);
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after
1213 recorder->partialReplay(canvas); 1213 recorder->partialReplay(canvas);
1214 1214
1215 return recorder2.endRecording(); 1215 return recorder2.endRecording();
1216 } 1216 }
1217 }; 1217 };
1218 1218
1219 static void create_imbalance(SkCanvas* canvas) { 1219 static void create_imbalance(SkCanvas* canvas) {
1220 SkRect clipRect = SkRect::MakeWH(2, 2); 1220 SkRect clipRect = SkRect::MakeWH(2, 2);
1221 SkRect drawRect = SkRect::MakeWH(10, 10); 1221 SkRect drawRect = SkRect::MakeWH(10, 10);
1222 canvas->save(); 1222 canvas->save();
1223 canvas->clipRect(clipRect, SkRegion::kReplace_Op); 1223 canvas->legacyClipRect(clipRect, SkRegion::kReplace_Op);
1224 canvas->translate(1.0f, 1.0f); 1224 canvas->translate(1.0f, 1.0f);
1225 SkPaint p; 1225 SkPaint p;
1226 p.setColor(SK_ColorGREEN); 1226 p.setColor(SK_ColorGREEN);
1227 canvas->drawRect(drawRect, p); 1227 canvas->drawRect(drawRect, p);
1228 // no restore 1228 // no restore
1229 } 1229 }
1230 1230
1231 // This tests that replaying a potentially unbalanced picture into a canvas 1231 // This tests that replaying a potentially unbalanced picture into a canvas
1232 // doesn't affect the canvas' save count or matrix/clip state. 1232 // doesn't affect the canvas' save count or matrix/clip state.
1233 static void check_balance(skiatest::Reporter* reporter, SkPicture* picture) { 1233 static void check_balance(skiatest::Reporter* reporter, SkPicture* picture) {
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
1524 SkPath path; 1524 SkPath path;
1525 path.addOval(rect2); 1525 path.addOval(rect2);
1526 SkPath path2; 1526 SkPath path2;
1527 path2.addOval(rect3); 1527 path2.addOval(rect3);
1528 SkIRect clipBounds; 1528 SkIRect clipBounds;
1529 SkPictureRecorder recorder; 1529 SkPictureRecorder recorder;
1530 1530
1531 // Testing conservative-raster-clip that is enabled by PictureRecord 1531 // Testing conservative-raster-clip that is enabled by PictureRecord
1532 { 1532 {
1533 SkCanvas* canvas = recorder.beginRecording(10, 10); 1533 SkCanvas* canvas = recorder.beginRecording(10, 10);
1534 canvas->clipPath(invPath, SkRegion::kIntersect_Op); 1534 canvas->clipPath(invPath);
1535 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); 1535 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds);
1536 REPORTER_ASSERT(reporter, true == nonEmpty); 1536 REPORTER_ASSERT(reporter, true == nonEmpty);
1537 REPORTER_ASSERT(reporter, 0 == clipBounds.fLeft); 1537 REPORTER_ASSERT(reporter, 0 == clipBounds.fLeft);
1538 REPORTER_ASSERT(reporter, 0 == clipBounds.fTop); 1538 REPORTER_ASSERT(reporter, 0 == clipBounds.fTop);
1539 REPORTER_ASSERT(reporter, 10 == clipBounds.fBottom); 1539 REPORTER_ASSERT(reporter, 10 == clipBounds.fBottom);
1540 REPORTER_ASSERT(reporter, 10 == clipBounds.fRight); 1540 REPORTER_ASSERT(reporter, 10 == clipBounds.fRight);
1541 } 1541 }
1542 { 1542 {
1543 SkCanvas* canvas = recorder.beginRecording(10, 10); 1543 SkCanvas* canvas = recorder.beginRecording(10, 10);
1544 canvas->clipPath(path, SkRegion::kIntersect_Op); 1544 canvas->clipPath(path);
1545 canvas->clipPath(invPath, SkRegion::kIntersect_Op); 1545 canvas->clipPath(invPath);
1546 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); 1546 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds);
1547 REPORTER_ASSERT(reporter, true == nonEmpty); 1547 REPORTER_ASSERT(reporter, true == nonEmpty);
1548 REPORTER_ASSERT(reporter, 7 == clipBounds.fLeft); 1548 REPORTER_ASSERT(reporter, 7 == clipBounds.fLeft);
1549 REPORTER_ASSERT(reporter, 7 == clipBounds.fTop); 1549 REPORTER_ASSERT(reporter, 7 == clipBounds.fTop);
1550 REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom); 1550 REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom);
1551 REPORTER_ASSERT(reporter, 8 == clipBounds.fRight); 1551 REPORTER_ASSERT(reporter, 8 == clipBounds.fRight);
1552 } 1552 }
1553 { 1553 {
1554 SkCanvas* canvas = recorder.beginRecording(10, 10); 1554 SkCanvas* canvas = recorder.beginRecording(10, 10);
1555 canvas->clipPath(path, SkRegion::kIntersect_Op); 1555 canvas->clipPath(path);
1556 canvas->clipPath(invPath, SkRegion::kUnion_Op); 1556 canvas->legacyClipPath(invPath, SkRegion::kUnion_Op);
1557 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); 1557 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds);
1558 REPORTER_ASSERT(reporter, true == nonEmpty); 1558 REPORTER_ASSERT(reporter, true == nonEmpty);
1559 REPORTER_ASSERT(reporter, 0 == clipBounds.fLeft); 1559 REPORTER_ASSERT(reporter, 0 == clipBounds.fLeft);
1560 REPORTER_ASSERT(reporter, 0 == clipBounds.fTop); 1560 REPORTER_ASSERT(reporter, 0 == clipBounds.fTop);
1561 REPORTER_ASSERT(reporter, 10 == clipBounds.fBottom); 1561 REPORTER_ASSERT(reporter, 10 == clipBounds.fBottom);
1562 REPORTER_ASSERT(reporter, 10 == clipBounds.fRight); 1562 REPORTER_ASSERT(reporter, 10 == clipBounds.fRight);
1563 } 1563 }
1564 { 1564 {
1565 SkCanvas* canvas = recorder.beginRecording(10, 10); 1565 SkCanvas* canvas = recorder.beginRecording(10, 10);
1566 canvas->clipPath(path, SkRegion::kDifference_Op); 1566 canvas->clipPath(path, kDifference_SkClipOp);
1567 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); 1567 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds);
1568 REPORTER_ASSERT(reporter, true == nonEmpty); 1568 REPORTER_ASSERT(reporter, true == nonEmpty);
1569 REPORTER_ASSERT(reporter, 0 == clipBounds.fLeft); 1569 REPORTER_ASSERT(reporter, 0 == clipBounds.fLeft);
1570 REPORTER_ASSERT(reporter, 0 == clipBounds.fTop); 1570 REPORTER_ASSERT(reporter, 0 == clipBounds.fTop);
1571 REPORTER_ASSERT(reporter, 10 == clipBounds.fBottom); 1571 REPORTER_ASSERT(reporter, 10 == clipBounds.fBottom);
1572 REPORTER_ASSERT(reporter, 10 == clipBounds.fRight); 1572 REPORTER_ASSERT(reporter, 10 == clipBounds.fRight);
1573 } 1573 }
1574 { 1574 {
1575 SkCanvas* canvas = recorder.beginRecording(10, 10); 1575 SkCanvas* canvas = recorder.beginRecording(10, 10);
1576 canvas->clipPath(path, SkRegion::kReverseDifference_Op); 1576 canvas->legacyClipPath(path, SkRegion::kReverseDifference_Op);
1577 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); 1577 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds);
1578 // True clip is actually empty in this case, but the best 1578 // True clip is actually empty in this case, but the best
1579 // determination we can make using only bounds as input is that the 1579 // determination we can make using only bounds as input is that the
1580 // clip is included in the bounds of 'path'. 1580 // clip is included in the bounds of 'path'.
1581 REPORTER_ASSERT(reporter, true == nonEmpty); 1581 REPORTER_ASSERT(reporter, true == nonEmpty);
1582 REPORTER_ASSERT(reporter, 7 == clipBounds.fLeft); 1582 REPORTER_ASSERT(reporter, 7 == clipBounds.fLeft);
1583 REPORTER_ASSERT(reporter, 7 == clipBounds.fTop); 1583 REPORTER_ASSERT(reporter, 7 == clipBounds.fTop);
1584 REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom); 1584 REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom);
1585 REPORTER_ASSERT(reporter, 8 == clipBounds.fRight); 1585 REPORTER_ASSERT(reporter, 8 == clipBounds.fRight);
1586 } 1586 }
1587 { 1587 {
1588 SkCanvas* canvas = recorder.beginRecording(10, 10); 1588 SkCanvas* canvas = recorder.beginRecording(10, 10);
1589 canvas->clipPath(path, SkRegion::kIntersect_Op); 1589 canvas->clipPath(path);
1590 canvas->clipPath(path2, SkRegion::kXOR_Op); 1590 canvas->legacyClipPath(path2, SkRegion::kXOR_Op);
1591 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds); 1591 bool nonEmpty = canvas->getClipDeviceBounds(&clipBounds);
1592 REPORTER_ASSERT(reporter, true == nonEmpty); 1592 REPORTER_ASSERT(reporter, true == nonEmpty);
1593 REPORTER_ASSERT(reporter, 6 == clipBounds.fLeft); 1593 REPORTER_ASSERT(reporter, 6 == clipBounds.fLeft);
1594 REPORTER_ASSERT(reporter, 6 == clipBounds.fTop); 1594 REPORTER_ASSERT(reporter, 6 == clipBounds.fTop);
1595 REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom); 1595 REPORTER_ASSERT(reporter, 8 == clipBounds.fBottom);
1596 REPORTER_ASSERT(reporter, 8 == clipBounds.fRight); 1596 REPORTER_ASSERT(reporter, 8 == clipBounds.fRight);
1597 } 1597 }
1598 } 1598 }
1599 1599
1600 /** 1600 /**
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1638 private: 1638 private:
1639 unsigned fClipCount; 1639 unsigned fClipCount;
1640 1640
1641 typedef SkCanvas INHERITED; 1641 typedef SkCanvas INHERITED;
1642 }; 1642 };
1643 1643
1644 static void test_clip_expansion(skiatest::Reporter* reporter) { 1644 static void test_clip_expansion(skiatest::Reporter* reporter) {
1645 SkPictureRecorder recorder; 1645 SkPictureRecorder recorder;
1646 SkCanvas* canvas = recorder.beginRecording(10, 10); 1646 SkCanvas* canvas = recorder.beginRecording(10, 10);
1647 1647
1648 canvas->clipRect(SkRect::MakeEmpty(), SkRegion::kReplace_Op); 1648 canvas->legacyClipRect(SkRect::MakeEmpty(), SkRegion::kReplace_Op);
1649 // The following expanding clip should not be skipped. 1649 // The following expanding clip should not be skipped.
1650 canvas->clipRect(SkRect::MakeXYWH(4, 4, 3, 3), SkRegion::kUnion_Op); 1650 canvas->legacyClipRect(SkRect::MakeXYWH(4, 4, 3, 3), SkRegion::kUnion_Op);
1651 // Draw something so the optimizer doesn't just fold the world. 1651 // Draw something so the optimizer doesn't just fold the world.
1652 SkPaint p; 1652 SkPaint p;
1653 p.setColor(SK_ColorBLUE); 1653 p.setColor(SK_ColorBLUE);
1654 canvas->drawPaint(p); 1654 canvas->drawPaint(p);
1655 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 1655 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
1656 1656
1657 ClipCountingCanvas testCanvas(10, 10); 1657 ClipCountingCanvas testCanvas(10, 10);
1658 picture->playback(&testCanvas); 1658 picture->playback(&testCanvas);
1659 1659
1660 // Both clips should be present on playback. 1660 // Both clips should be present on playback.
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
1919 1919
1920 // The picture shares the immutable pixels but copies the mutable ones. 1920 // The picture shares the immutable pixels but copies the mutable ones.
1921 REPORTER_ASSERT(r, mut.pixelRef()->unique()); 1921 REPORTER_ASSERT(r, mut.pixelRef()->unique());
1922 REPORTER_ASSERT(r, !immut.pixelRef()->unique()); 1922 REPORTER_ASSERT(r, !immut.pixelRef()->unique());
1923 1923
1924 // When the picture goes away, it's just our bitmaps holding the refs. 1924 // When the picture goes away, it's just our bitmaps holding the refs.
1925 pic.reset(NULL); 1925 pic.reset(NULL);
1926 REPORTER_ASSERT(r, mut.pixelRef()->unique()); 1926 REPORTER_ASSERT(r, mut.pixelRef()->unique());
1927 REPORTER_ASSERT(r, immut.pixelRef()->unique()); 1927 REPORTER_ASSERT(r, immut.pixelRef()->unique());
1928 } 1928 }
OLDNEW
« no previous file with comments | « tests/PictureBBHTest.cpp ('k') | tests/ReadPixelsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698