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

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: Rebase 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
« no previous file with comments | « src/core/SkRecordAnalysis.cpp ('k') | tests/RecordTest.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 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 if (!found) { 571 if (!found) {
572 SkData* data = SkPictureUtils::GatherPixelRefs(pic, r); 572 SkData* data = SkPictureUtils::GatherPixelRefs(pic, r);
573 size_t dataSize = data ? data->size() : 0; 573 size_t dataSize = data ? data->size() : 0;
574 } 574 }
575 #endif 575 #endif
576 } 576 }
577 } 577 }
578 } 578 }
579 } 579 }
580 580
581 #define GENERATE_CANVAS(recorder, x) \
582 (x) ? recorder.EXPERIMENTAL_beginRecording(100, 100) \
583 : recorder.beginRecording(100,100);
584
585 /* Hit a few SkPicture::Analysis cases not handled elsewhere. */
586 static void test_analysis(skiatest::Reporter* reporter, bool useNewPath) {
587 SkPictureRecorder recorder;
588
589 SkCanvas* canvas = GENERATE_CANVAS(recorder, useNewPath);
590 {
591 canvas->drawRect(SkRect::MakeWH(10, 10), SkPaint ());
592 }
593 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
594 REPORTER_ASSERT(reporter, !picture->willPlayBackBitmaps());
595
596 canvas = GENERATE_CANVAS(recorder, useNewPath);
597 {
598 SkPaint paint;
599 // CreateBitmapShader is too smart for us; an empty (or 1x1) bitmap shad er
600 // gets optimized into a non-bitmap form, so we create a 2x2 bitmap here .
601 SkBitmap bitmap;
602 bitmap.allocPixels(SkImageInfo::MakeN32Premul(2, 2));
603 bitmap.eraseColor(SK_ColorBLUE);
604 *(bitmap.getAddr32(0, 0)) = SK_ColorGREEN;
605 SkShader* shader = SkShader::CreateBitmapShader(bitmap, SkShader::kClamp _TileMode,
606 SkShader::kClamp_TileMod e);
607 paint.setShader(shader)->unref();
608 REPORTER_ASSERT(reporter,
609 shader->asABitmap(NULL, NULL, NULL) == SkShader::kDefaul t_BitmapType);
610
611 canvas->drawRect(SkRect::MakeWH(10, 10), paint);
612 }
613 picture.reset(recorder.endRecording());
614 REPORTER_ASSERT(reporter, picture->willPlayBackBitmaps());
615 }
616
617
581 static void test_gatherpixelrefsandrects(skiatest::Reporter* reporter) { 618 static void test_gatherpixelrefsandrects(skiatest::Reporter* reporter) {
582 const int IW = 32; 619 const int IW = 32;
583 const int IH = IW; 620 const int IH = IW;
584 const SkScalar W = SkIntToScalar(IW); 621 const SkScalar W = SkIntToScalar(IW);
585 const SkScalar H = W; 622 const SkScalar H = W;
586 623
587 static const int N = 4; 624 static const int N = 4;
588 SkBitmap bm[2*N]; 625 SkBitmap bm[2*N];
589 SkPixelRef* refs[2*N]; 626 SkPixelRef* refs[2*N];
590 SkTDArray<SkPixelRef*> analytic[N]; 627 SkTDArray<SkPixelRef*> analytic[N];
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 } else if (unit <= 0.9) { 736 } else if (unit <= 0.9) {
700 // SkDebugf("clip\n"); 737 // SkDebugf("clip\n");
701 canvas->clipRect(rect); 738 canvas->clipRect(rect);
702 } else { 739 } else {
703 // SkDebugf("draw\n"); 740 // SkDebugf("draw\n");
704 canvas->drawPaint(paint); 741 canvas->drawPaint(paint);
705 } 742 }
706 } 743 }
707 744
708 #if SK_SUPPORT_GPU 745 #if SK_SUPPORT_GPU
709 static void test_gpu_veto(skiatest::Reporter* reporter) { 746
747 static void test_gpu_veto(skiatest::Reporter* reporter,
748 bool useNewPath) {
710 749
711 SkPictureRecorder recorder; 750 SkPictureRecorder recorder;
712 751
713 SkCanvas* canvas = recorder.beginRecording(100, 100); 752 SkCanvas* canvas = GENERATE_CANVAS(recorder, useNewPath);
714 { 753 {
715 SkPath path; 754 SkPath path;
716 path.moveTo(0, 0); 755 path.moveTo(0, 0);
717 path.lineTo(50, 50); 756 path.lineTo(50, 50);
718 757
719 SkScalar intervals[] = { 1.0f, 1.0f }; 758 SkScalar intervals[] = { 1.0f, 1.0f };
720 SkAutoTUnref<SkDashPathEffect> dash(SkDashPathEffect::Create(intervals, 2, 0)); 759 SkAutoTUnref<SkDashPathEffect> dash(SkDashPathEffect::Create(intervals, 2, 0));
721 760
722 SkPaint paint; 761 SkPaint paint;
723 paint.setStyle(SkPaint::kStroke_Style); 762 paint.setStyle(SkPaint::kStroke_Style);
724 paint.setPathEffect(dash); 763 paint.setPathEffect(dash);
725 764
726 canvas->drawPath(path, paint); 765 canvas->drawPath(path, paint);
727 } 766 }
728 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 767 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
729 // path effects currently render an SkPicture undesireable for GPU rendering 768 // path effects currently render an SkPicture undesireable for GPU rendering
730 769
731 const char *reason = NULL; 770 const char *reason = NULL;
732 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL, &reaso n)); 771 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL, &reaso n));
733 REPORTER_ASSERT(reporter, NULL != reason); 772 REPORTER_ASSERT(reporter, NULL != reason);
734 773
735 canvas = recorder.beginRecording(100, 100); 774 canvas = GENERATE_CANVAS(recorder, useNewPath);
736 { 775 {
737 SkPath path; 776 SkPath path;
738 777
739 path.moveTo(0, 0); 778 path.moveTo(0, 0);
740 path.lineTo(0, 50); 779 path.lineTo(0, 50);
741 path.lineTo(25, 25); 780 path.lineTo(25, 25);
742 path.lineTo(50, 50); 781 path.lineTo(50, 50);
743 path.lineTo(50, 0); 782 path.lineTo(50, 0);
744 path.close(); 783 path.close();
745 REPORTER_ASSERT(reporter, !path.isConvex()); 784 REPORTER_ASSERT(reporter, !path.isConvex());
746 785
747 SkPaint paint; 786 SkPaint paint;
748 paint.setAntiAlias(true); 787 paint.setAntiAlias(true);
749 for (int i = 0; i < 50; ++i) { 788 for (int i = 0; i < 50; ++i) {
750 canvas->drawPath(path, paint); 789 canvas->drawPath(path, paint);
751 } 790 }
752 } 791 }
753 picture.reset(recorder.endRecording()); 792 picture.reset(recorder.endRecording());
754 // A lot of AA concave paths currently render an SkPicture undesireable for GPU rendering 793 // A lot of AA concave paths currently render an SkPicture undesireable for GPU rendering
755 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL)); 794 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL));
756 795
757 canvas = recorder.beginRecording(100, 100); 796 canvas = GENERATE_CANVAS(recorder, useNewPath);
758 { 797 {
759 SkPath path; 798 SkPath path;
760 799
761 path.moveTo(0, 0); 800 path.moveTo(0, 0);
762 path.lineTo(0, 50); 801 path.lineTo(0, 50);
763 path.lineTo(25, 25); 802 path.lineTo(25, 25);
764 path.lineTo(50, 50); 803 path.lineTo(50, 50);
765 path.lineTo(50, 0); 804 path.lineTo(50, 0);
766 path.close(); 805 path.close();
767 REPORTER_ASSERT(reporter, !path.isConvex()); 806 REPORTER_ASSERT(reporter, !path.isConvex());
768 807
769 SkPaint paint; 808 SkPaint paint;
770 paint.setAntiAlias(true); 809 paint.setAntiAlias(true);
771 paint.setStyle(SkPaint::kStroke_Style); 810 paint.setStyle(SkPaint::kStroke_Style);
772 paint.setStrokeWidth(0); 811 paint.setStrokeWidth(0);
773 for (int i = 0; i < 50; ++i) { 812 for (int i = 0; i < 50; ++i) {
774 canvas->drawPath(path, paint); 813 canvas->drawPath(path, paint);
775 } 814 }
776 } 815 }
777 picture.reset(recorder.endRecording()); 816 picture.reset(recorder.endRecording());
778 // hairline stroked AA concave paths are fine for GPU rendering 817 // hairline stroked AA concave paths are fine for GPU rendering
779 REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(NULL)); 818 REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(NULL));
819
820 canvas = GENERATE_CANVAS(recorder, useNewPath);
821 {
822 SkPaint paint;
823 SkScalar intervals [] = { 10, 20 };
824 SkPathEffect* pe = SkDashPathEffect::Create(intervals, 2, 25);
825 paint.setPathEffect(pe)->unref();
826
827 SkPoint points [2] = { { 0, 0 }, { 100, 0 } };
828 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, points, paint);
829 }
830 picture.reset(recorder.endRecording());
831 // fast-path dashed effects are fine for GPU rendering ...
832 REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(NULL));
833
834 canvas = GENERATE_CANVAS(recorder, useNewPath);
835 {
836 SkPaint paint;
837 SkScalar intervals [] = { 10, 20 };
838 SkPathEffect* pe = SkDashPathEffect::Create(intervals, 2, 25);
839 paint.setPathEffect(pe)->unref();
840
841 canvas->drawRect(SkRect::MakeWH(10, 10), paint);
842 }
843 picture.reset(recorder.endRecording());
844 // ... but only when applied to drawPoint() calls
845 REPORTER_ASSERT(reporter, !picture->suitableForGpuRasterization(NULL));
780 } 846 }
781 847
848 #undef GENERATE_CANVAS
849
782 static void test_gpu_picture_optimization(skiatest::Reporter* reporter, 850 static void test_gpu_picture_optimization(skiatest::Reporter* reporter,
783 GrContextFactory* factory) { 851 GrContextFactory* factory) {
784 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { 852 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) {
785 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext Type) i; 853 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext Type) i;
786 854
787 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { 855 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) {
788 continue; 856 continue;
789 } 857 }
790 858
791 GrContext* context = factory->get(glCtxType); 859 GrContext* context = factory->get(glCtxType);
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after
1610 DEF_TEST(Picture, reporter) { 1678 DEF_TEST(Picture, reporter) {
1611 #ifdef SK_DEBUG 1679 #ifdef SK_DEBUG
1612 test_deleting_empty_picture(); 1680 test_deleting_empty_picture();
1613 test_serializing_empty_picture(); 1681 test_serializing_empty_picture();
1614 #else 1682 #else
1615 test_bad_bitmap(); 1683 test_bad_bitmap();
1616 #endif 1684 #endif
1617 test_unbalanced_save_restores(reporter); 1685 test_unbalanced_save_restores(reporter);
1618 test_peephole(); 1686 test_peephole();
1619 #if SK_SUPPORT_GPU 1687 #if SK_SUPPORT_GPU
1620 test_gpu_veto(reporter); 1688 test_gpu_veto(reporter, false);
1689 test_gpu_veto(reporter, true);
1621 #endif 1690 #endif
1622 test_has_text(reporter); 1691 test_has_text(reporter);
1692 test_analysis(reporter, false);
1693 test_analysis(reporter, true);
1623 test_gatherpixelrefs(reporter); 1694 test_gatherpixelrefs(reporter);
1624 test_gatherpixelrefsandrects(reporter); 1695 test_gatherpixelrefsandrects(reporter);
1625 test_bitmap_with_encoded_data(reporter); 1696 test_bitmap_with_encoded_data(reporter);
1626 test_draw_empty(reporter); 1697 test_draw_empty(reporter);
1627 test_clip_bound_opt(reporter); 1698 test_clip_bound_opt(reporter);
1628 test_clip_expansion(reporter); 1699 test_clip_expansion(reporter);
1629 test_hierarchical(reporter); 1700 test_hierarchical(reporter);
1630 test_gen_id(reporter); 1701 test_gen_id(reporter);
1631 } 1702 }
1632 1703
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1756 SkAutoTUnref<const SkPicture> picture(recorder.endRecording()); 1827 SkAutoTUnref<const SkPicture> picture(recorder.endRecording());
1757 1828
1758 SkCanvas big(640, 480), small(300, 200); 1829 SkCanvas big(640, 480), small(300, 200);
1759 1830
1760 picture->draw(&big); 1831 picture->draw(&big);
1761 REPORTER_ASSERT(r, bbh.searchCalls == 0); 1832 REPORTER_ASSERT(r, bbh.searchCalls == 0);
1762 1833
1763 picture->draw(&small); 1834 picture->draw(&small);
1764 REPORTER_ASSERT(r, bbh.searchCalls == 1); 1835 REPORTER_ASSERT(r, bbh.searchCalls == 1);
1765 } 1836 }
OLDNEW
« no previous file with comments | « src/core/SkRecordAnalysis.cpp ('k') | tests/RecordTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698