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

Side by Side Diff: tests/PictureTest.cpp

Issue 364823009: Port suitableForGpuRasterization to SkRecord (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Reed review complete Created 6 years, 4 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 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 "SkBlurImageFilter.h" 8 #include "SkBlurImageFilter.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 if (!found) { 570 if (!found) {
571 SkData* data = SkPictureUtils::GatherPixelRefs(pic, r); 571 SkData* data = SkPictureUtils::GatherPixelRefs(pic, r);
572 size_t dataSize = data ? data->size() : 0; 572 size_t dataSize = data ? data->size() : 0;
573 } 573 }
574 #endif 574 #endif
575 } 575 }
576 } 576 }
577 } 577 }
578 } 578 }
579 579
580 #define GENERATE_CANVAS(recorder, x) \
581 (x) ? recorder.EXPERIMENTAL_beginRecording(100, 100) \
582 : recorder.beginRecording(100,100);
583
584 /* Hit a few SkPicture::Analysis cases not handled elsewhere. */
585 static void test_analysis(skiatest::Reporter* reporter, bool useNewPath) {
586 SkPictureRecorder recorder;
587
588 SkCanvas* canvas = GENERATE_CANVAS(recorder, useNewPath);
589 {
590 canvas->drawRect(SkRect::MakeWH(10, 10), SkPaint ());
591 }
592 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
593 REPORTER_ASSERT(reporter, !picture->willPlayBackBitmaps());
594
595 canvas = GENERATE_CANVAS(recorder, useNewPath);
596 {
597 SkPaint paint;
598 // CreateBitmapShader is too smart for us; an empty (or 1x1) bitmap shad er
599 // gets optimized into a non-bitmap form, so we create a 2x2 bitmap here .
600 SkBitmap bitmap;
601 bitmap.allocPixels(SkImageInfo::MakeN32Premul(2, 2));
602 bitmap.eraseColor(SK_ColorBLUE);
603 *(bitmap.getAddr32(0, 0)) = SK_ColorGREEN;
604 SkShader* shader = SkShader::CreateBitmapShader(bitmap, SkShader::kClamp _TileMode,
605 SkShader::kClamp_TileMod e);
606 paint.setShader(shader)->unref();
607 REPORTER_ASSERT(reporter,
608 shader->asABitmap(NULL, NULL, NULL) == SkShader::kDefaul t_BitmapType);
609
610 canvas->drawRect(SkRect::MakeWH(10, 10), paint);
611 }
612 picture.reset(recorder.endRecording());
613 REPORTER_ASSERT(reporter, picture->willPlayBackBitmaps());
614 }
615
616 #undef GENERATE_CANVAS
617
580 static void test_gatherpixelrefsandrects(skiatest::Reporter* reporter) { 618 static void test_gatherpixelrefsandrects(skiatest::Reporter* reporter) {
581 const int IW = 32; 619 const int IW = 32;
582 const int IH = IW; 620 const int IH = IW;
583 const SkScalar W = SkIntToScalar(IW); 621 const SkScalar W = SkIntToScalar(IW);
584 const SkScalar H = W; 622 const SkScalar H = W;
585 623
586 static const int N = 4; 624 static const int N = 4;
587 SkBitmap bm[2*N]; 625 SkBitmap bm[2*N];
588 SkPixelRef* refs[2*N]; 626 SkPixelRef* refs[2*N];
589 SkTDArray<SkPixelRef*> analytic[N]; 627 SkTDArray<SkPixelRef*> analytic[N];
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 } else if (unit <= 0.9) { 736 } else if (unit <= 0.9) {
699 // SkDebugf("clip\n"); 737 // SkDebugf("clip\n");
700 canvas->clipRect(rect); 738 canvas->clipRect(rect);
701 } else { 739 } else {
702 // SkDebugf("draw\n"); 740 // SkDebugf("draw\n");
703 canvas->drawPaint(paint); 741 canvas->drawPaint(paint);
704 } 742 }
705 } 743 }
706 744
707 #if SK_SUPPORT_GPU 745 #if SK_SUPPORT_GPU
708 static void test_gpu_veto(skiatest::Reporter* reporter) { 746 #define GENERATE_CANVAS(recorder, x) \
747 (x) ? recorder.EXPERIMENTAL_beginRecording(100, 100) \
748 : recorder.beginRecording(100,100);
749
750 static void test_gpu_veto(skiatest::Reporter* reporter,
751 bool useNewPath) {
709 752
710 SkPictureRecorder recorder; 753 SkPictureRecorder recorder;
711 754
712 SkCanvas* canvas = recorder.beginRecording(100, 100); 755 SkCanvas* canvas = GENERATE_CANVAS(recorder, useNewPath);
713 { 756 {
714 SkPath path; 757 SkPath path;
715 path.moveTo(0, 0); 758 path.moveTo(0, 0);
716 path.lineTo(50, 50); 759 path.lineTo(50, 50);
717 760
718 SkScalar intervals[] = { 1.0f, 1.0f }; 761 SkScalar intervals[] = { 1.0f, 1.0f };
719 SkAutoTUnref<SkDashPathEffect> dash(SkDashPathEffect::Create(intervals, 2, 0)); 762 SkAutoTUnref<SkDashPathEffect> dash(SkDashPathEffect::Create(intervals, 2, 0));
720 763
721 SkPaint paint; 764 SkPaint paint;
722 paint.setStyle(SkPaint::kStroke_Style); 765 paint.setStyle(SkPaint::kStroke_Style);
723 paint.setPathEffect(dash); 766 paint.setPathEffect(dash);
724 767
725 canvas->drawPath(path, paint); 768 canvas->drawPath(path, paint);
726 } 769 }
727 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 770 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
728 // path effects currently render an SkPicture undesireable for GPU rendering 771 // path effects currently render an SkPicture undesireable for GPU rendering
729 772
730 const char *reason = NULL; 773 const char *reason = NULL;
731 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL, &reaso n)); 774 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL, &reaso n));
732 REPORTER_ASSERT(reporter, NULL != reason); 775 REPORTER_ASSERT(reporter, NULL != reason);
733 776
734 canvas = recorder.beginRecording(100, 100); 777 canvas = GENERATE_CANVAS(recorder, useNewPath);
735 { 778 {
736 SkPath path; 779 SkPath path;
737 780
738 path.moveTo(0, 0); 781 path.moveTo(0, 0);
739 path.lineTo(0, 50); 782 path.lineTo(0, 50);
740 path.lineTo(25, 25); 783 path.lineTo(25, 25);
741 path.lineTo(50, 50); 784 path.lineTo(50, 50);
742 path.lineTo(50, 0); 785 path.lineTo(50, 0);
743 path.close(); 786 path.close();
744 REPORTER_ASSERT(reporter, !path.isConvex()); 787 REPORTER_ASSERT(reporter, !path.isConvex());
745 788
746 SkPaint paint; 789 SkPaint paint;
747 paint.setAntiAlias(true); 790 paint.setAntiAlias(true);
748 for (int i = 0; i < 50; ++i) { 791 for (int i = 0; i < 50; ++i) {
749 canvas->drawPath(path, paint); 792 canvas->drawPath(path, paint);
750 } 793 }
751 } 794 }
752 picture.reset(recorder.endRecording()); 795 picture.reset(recorder.endRecording());
753 // A lot of AA concave paths currently render an SkPicture undesireable for GPU rendering 796 // A lot of AA concave paths currently render an SkPicture undesireable for GPU rendering
754 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL)); 797 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL));
755 798
756 canvas = recorder.beginRecording(100, 100); 799 canvas = GENERATE_CANVAS(recorder, useNewPath);
757 { 800 {
758 SkPath path; 801 SkPath path;
759 802
760 path.moveTo(0, 0); 803 path.moveTo(0, 0);
761 path.lineTo(0, 50); 804 path.lineTo(0, 50);
762 path.lineTo(25, 25); 805 path.lineTo(25, 25);
763 path.lineTo(50, 50); 806 path.lineTo(50, 50);
764 path.lineTo(50, 0); 807 path.lineTo(50, 0);
765 path.close(); 808 path.close();
766 REPORTER_ASSERT(reporter, !path.isConvex()); 809 REPORTER_ASSERT(reporter, !path.isConvex());
767 810
768 SkPaint paint; 811 SkPaint paint;
769 paint.setAntiAlias(true); 812 paint.setAntiAlias(true);
770 paint.setStyle(SkPaint::kStroke_Style); 813 paint.setStyle(SkPaint::kStroke_Style);
771 paint.setStrokeWidth(0); 814 paint.setStrokeWidth(0);
772 for (int i = 0; i < 50; ++i) { 815 for (int i = 0; i < 50; ++i) {
773 canvas->drawPath(path, paint); 816 canvas->drawPath(path, paint);
774 } 817 }
775 } 818 }
776 picture.reset(recorder.endRecording()); 819 picture.reset(recorder.endRecording());
777 // hairline stroked AA concave paths are fine for GPU rendering 820 // hairline stroked AA concave paths are fine for GPU rendering
778 REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(NULL)); 821 REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(NULL));
822
823 canvas = GENERATE_CANVAS(recorder, useNewPath);
824 {
825 SkPaint paint;
826 SkScalar intervals [] = { 10, 20 };
827 SkPathEffect* pe = SkDashPathEffect::Create(intervals, 2, 25);
828 paint.setPathEffect(pe)->unref();
829
830 SkPoint points [2] = { { 0, 0 }, { 100, 0 } };
831 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, points, paint);
832 }
833 picture.reset(recorder.endRecording());
834 // fast-path dashed effects are fine for GPU rendering ...
835 REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(NULL));
836
837 canvas = GENERATE_CANVAS(recorder, useNewPath);
838 {
839 SkPaint paint;
840 SkScalar intervals [] = { 10, 20 };
841 SkPathEffect* pe = SkDashPathEffect::Create(intervals, 2, 25);
842 paint.setPathEffect(pe)->unref();
843
844 canvas->drawRect(SkRect::MakeWH(10, 10), paint);
845 }
846 picture.reset(recorder.endRecording());
847 // ... but only when applied to drawPoint() calls
848 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL));
779 } 849 }
780 850
851 #undef GENERATE_CANVAS
852
781 static void test_gpu_picture_optimization(skiatest::Reporter* reporter, 853 static void test_gpu_picture_optimization(skiatest::Reporter* reporter,
782 GrContextFactory* factory) { 854 GrContextFactory* factory) {
783 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { 855 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) {
784 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext Type) i; 856 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext Type) i;
785 857
786 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { 858 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) {
787 continue; 859 continue;
788 } 860 }
789 861
790 GrContext* context = factory->get(glCtxType); 862 GrContext* context = factory->get(glCtxType);
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after
1552 DEF_TEST(Picture, reporter) { 1624 DEF_TEST(Picture, reporter) {
1553 #ifdef SK_DEBUG 1625 #ifdef SK_DEBUG
1554 test_deleting_empty_picture(); 1626 test_deleting_empty_picture();
1555 test_serializing_empty_picture(); 1627 test_serializing_empty_picture();
1556 #else 1628 #else
1557 test_bad_bitmap(); 1629 test_bad_bitmap();
1558 #endif 1630 #endif
1559 test_unbalanced_save_restores(reporter); 1631 test_unbalanced_save_restores(reporter);
1560 test_peephole(); 1632 test_peephole();
1561 #if SK_SUPPORT_GPU 1633 #if SK_SUPPORT_GPU
1562 test_gpu_veto(reporter); 1634 test_gpu_veto(reporter, false);
1635 test_gpu_veto(reporter, true);
1563 #endif 1636 #endif
1637 test_analysis(reporter, false);
1638 test_analysis(reporter, true);
1564 test_gatherpixelrefs(reporter); 1639 test_gatherpixelrefs(reporter);
1565 test_gatherpixelrefsandrects(reporter); 1640 test_gatherpixelrefsandrects(reporter);
1566 test_bitmap_with_encoded_data(reporter); 1641 test_bitmap_with_encoded_data(reporter);
1567 test_draw_empty(reporter); 1642 test_draw_empty(reporter);
1568 test_clip_bound_opt(reporter); 1643 test_clip_bound_opt(reporter);
1569 test_clip_expansion(reporter); 1644 test_clip_expansion(reporter);
1570 test_hierarchical(reporter); 1645 test_hierarchical(reporter);
1571 test_gen_id(reporter); 1646 test_gen_id(reporter);
1572 } 1647 }
1573 1648
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1651 make_bm(&replayBM, 100, 100, SK_ColorBLACK, false); 1726 make_bm(&replayBM, 100, 100, SK_ColorBLACK, false);
1652 SkCanvas replayCanvas(replayBM); 1727 SkCanvas replayCanvas(replayBM);
1653 picture->draw(&replayCanvas); 1728 picture->draw(&replayCanvas);
1654 replayCanvas.flush(); 1729 replayCanvas.flush();
1655 1730
1656 // With the bug present, at (55, 55) we would get a fully opaque red 1731 // With the bug present, at (55, 55) we would get a fully opaque red
1657 // intead of a dark red. 1732 // intead of a dark red.
1658 REPORTER_ASSERT(reporter, replayBM.getColor(30, 30) == 0xff000080); 1733 REPORTER_ASSERT(reporter, replayBM.getColor(30, 30) == 0xff000080);
1659 REPORTER_ASSERT(reporter, replayBM.getColor(55, 55) == 0xff800000); 1734 REPORTER_ASSERT(reporter, replayBM.getColor(55, 55) == 0xff800000);
1660 } 1735 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698