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

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

Powered by Google App Engine
This is Rietveld 408576698