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

Side by Side Diff: tests/PictureTest.cpp

Issue 398183002: Fix alpha textures in NV ES3 contexts on Windows (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: suppress warning Created 6 years, 5 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 | « tests/ImageNewShaderTest.cpp ('k') | tests/SurfaceTest.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 "SkBlurImageFilter.h" 8 #include "SkBlurImageFilter.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 canvas->drawPath(path, paint); 773 canvas->drawPath(path, paint);
774 } 774 }
775 } 775 }
776 picture.reset(recorder.endRecording()); 776 picture.reset(recorder.endRecording());
777 // hairline stroked AA concave paths are fine for GPU rendering 777 // hairline stroked AA concave paths are fine for GPU rendering
778 REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(NULL)); 778 REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(NULL));
779 } 779 }
780 780
781 static void test_gpu_picture_optimization(skiatest::Reporter* reporter, 781 static void test_gpu_picture_optimization(skiatest::Reporter* reporter,
782 GrContextFactory* factory) { 782 GrContextFactory* factory) {
783 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) {
784 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext Type) i;
783 785
784 GrContext* context = factory->get(GrContextFactory::kNative_GLContextType); 786 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) {
785 787 continue;
786 static const int kWidth = 100;
787 static const int kHeight = 100;
788
789 SkAutoTUnref<SkPicture> pict;
790
791 // create a picture with the structure:
792 // 1)
793 // SaveLayer
794 // Restore
795 // 2)
796 // SaveLayer
797 // Translate
798 // SaveLayer w/ bound
799 // Restore
800 // Restore
801 // 3)
802 // SaveLayer w/ copyable paint
803 // Restore
804 // 4)
805 // SaveLayer w/ non-copyable paint
806 // Restore
807 {
808 SkPictureRecorder recorder;
809
810 SkCanvas* c = recorder.beginRecording(kWidth, kHeight);
811 // 1)
812 c->saveLayer(NULL, NULL);
813 c->restore();
814
815 // 2)
816 c->saveLayer(NULL, NULL);
817 c->translate(kWidth/2, kHeight/2);
818 SkRect r = SkRect::MakeXYWH(0, 0, kWidth/2, kHeight/2);
819 c->saveLayer(&r, NULL);
820 c->restore();
821 c->restore();
822
823 // 3)
824 {
825 SkPaint p;
826 p.setColor(SK_ColorRED);
827 c->saveLayer(NULL, &p);
828 c->restore();
829 }
830 // 4)
831 // TODO: this case will need to be removed once the paint's are immutabl e
832 {
833 SkPaint p;
834 SkAutoTUnref<SkColorFilter> cf(SkLumaColorFilter::Create());
835 p.setImageFilter(SkColorFilterImageFilter::Create(cf.get()))->unref( );
836 c->saveLayer(NULL, &p);
837 c->restore();
838 } 788 }
839 789
840 pict.reset(recorder.endRecording()); 790 GrContext* context = factory->get(glCtxType);
841 }
842 791
843 // Now test out the SaveLayer extraction 792 if (NULL == context) {
844 { 793 continue;
845 SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight); 794 }
846 795
847 SkAutoTUnref<SkSurface> surface(SkSurface::NewScratchRenderTarget(contex t, info)); 796 static const int kWidth = 100;
797 static const int kHeight = 100;
848 798
849 SkCanvas* canvas = surface->getCanvas(); 799 SkAutoTUnref<SkPicture> pict;
850 800
851 canvas->EXPERIMENTAL_optimize(pict); 801 // create a picture with the structure:
802 // 1)
803 // SaveLayer
804 // Restore
805 // 2)
806 // SaveLayer
807 // Translate
808 // SaveLayer w/ bound
809 // Restore
810 // Restore
811 // 3)
812 // SaveLayer w/ copyable paint
813 // Restore
814 // 4)
815 // SaveLayer w/ non-copyable paint
816 // Restore
817 {
818 SkPictureRecorder recorder;
852 819
853 SkPicture::AccelData::Key key = GPUAccelData::ComputeAccelDataKey(); 820 SkCanvas* c = recorder.beginRecording(kWidth, kHeight);
821 // 1)
822 c->saveLayer(NULL, NULL);
823 c->restore();
854 824
855 const SkPicture::AccelData* data = pict->EXPERIMENTAL_getAccelData(key); 825 // 2)
856 REPORTER_ASSERT(reporter, NULL != data); 826 c->saveLayer(NULL, NULL);
827 c->translate(kWidth/2, kHeight/2);
828 SkRect r = SkRect::MakeXYWH(0, 0, kWidth/2, kHeight/2);
829 c->saveLayer(&r, NULL);
830 c->restore();
831 c->restore();
857 832
858 const GPUAccelData *gpuData = static_cast<const GPUAccelData*>(data); 833 // 3)
859 REPORTER_ASSERT(reporter, 5 == gpuData->numSaveLayers()); 834 {
835 SkPaint p;
836 p.setColor(SK_ColorRED);
837 c->saveLayer(NULL, &p);
838 c->restore();
839 }
840 // 4)
841 // TODO: this case will need to be removed once the paint's are immu table
842 {
843 SkPaint p;
844 SkAutoTUnref<SkColorFilter> cf(SkLumaColorFilter::Create());
845 p.setImageFilter(SkColorFilterImageFilter::Create(cf.get()))->un ref();
846 c->saveLayer(NULL, &p);
847 c->restore();
848 }
860 849
861 const GPUAccelData::SaveLayerInfo& info0 = gpuData->saveLayerInfo(0); 850 pict.reset(recorder.endRecording());
862 // The parent/child layer appear in reverse order 851 }
863 const GPUAccelData::SaveLayerInfo& info1 = gpuData->saveLayerInfo(2); 852
864 const GPUAccelData::SaveLayerInfo& info2 = gpuData->saveLayerInfo(1); 853 // Now test out the SaveLayer extraction
865 const GPUAccelData::SaveLayerInfo& info3 = gpuData->saveLayerInfo(3); 854 {
855 SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight);
856
857 SkAutoTUnref<SkSurface> surface(SkSurface::NewScratchRenderTarget(co ntext, info));
858
859 SkCanvas* canvas = surface->getCanvas();
860
861 canvas->EXPERIMENTAL_optimize(pict);
862
863 SkPicture::AccelData::Key key = GPUAccelData::ComputeAccelDataKey();
864
865 const SkPicture::AccelData* data = pict->EXPERIMENTAL_getAccelData(k ey);
866 REPORTER_ASSERT(reporter, NULL != data);
867
868 const GPUAccelData *gpuData = static_cast<const GPUAccelData*>(data) ;
869 REPORTER_ASSERT(reporter, 5 == gpuData->numSaveLayers());
870
871 const GPUAccelData::SaveLayerInfo& info0 = gpuData->saveLayerInfo(0) ;
872 // The parent/child layer appear in reverse order
873 const GPUAccelData::SaveLayerInfo& info1 = gpuData->saveLayerInfo(2) ;
874 const GPUAccelData::SaveLayerInfo& info2 = gpuData->saveLayerInfo(1) ;
875 const GPUAccelData::SaveLayerInfo& info3 = gpuData->saveLayerInfo(3) ;
866 // const GPUAccelData::SaveLayerInfo& info4 = gpuData->saveLayerInfo(4); 876 // const GPUAccelData::SaveLayerInfo& info4 = gpuData->saveLayerInfo(4);
867 877
868 REPORTER_ASSERT(reporter, info0.fValid); 878 REPORTER_ASSERT(reporter, info0.fValid);
869 REPORTER_ASSERT(reporter, kWidth == info0.fSize.fWidth && kHeight == inf o0.fSize.fHeight); 879 REPORTER_ASSERT(reporter, kWidth == info0.fSize.fWidth && kHeight == info0.fSize.fHeight);
870 REPORTER_ASSERT(reporter, info0.fCTM.isIdentity()); 880 REPORTER_ASSERT(reporter, info0.fCTM.isIdentity());
871 REPORTER_ASSERT(reporter, 0 == info0.fOffset.fX && 0 == info0.fOffset.fY ); 881 REPORTER_ASSERT(reporter, 0 == info0.fOffset.fX && 0 == info0.fOffse t.fY);
872 REPORTER_ASSERT(reporter, NULL != info0.fPaint); 882 REPORTER_ASSERT(reporter, NULL != info0.fPaint);
873 REPORTER_ASSERT(reporter, !info0.fIsNested && !info0.fHasNestedLayers); 883 REPORTER_ASSERT(reporter, !info0.fIsNested && !info0.fHasNestedLayer s);
874 884
875 REPORTER_ASSERT(reporter, info1.fValid); 885 REPORTER_ASSERT(reporter, info1.fValid);
876 REPORTER_ASSERT(reporter, kWidth == info1.fSize.fWidth && kHeight == inf o1.fSize.fHeight); 886 REPORTER_ASSERT(reporter, kWidth == info1.fSize.fWidth && kHeight == info1.fSize.fHeight);
877 REPORTER_ASSERT(reporter, info1.fCTM.isIdentity()); 887 REPORTER_ASSERT(reporter, info1.fCTM.isIdentity());
878 REPORTER_ASSERT(reporter, 0 == info1.fOffset.fX && 0 == info1.fOffset.fY ); 888 REPORTER_ASSERT(reporter, 0 == info1.fOffset.fX && 0 == info1.fOffse t.fY);
879 REPORTER_ASSERT(reporter, NULL != info1.fPaint); 889 REPORTER_ASSERT(reporter, NULL != info1.fPaint);
880 REPORTER_ASSERT(reporter, !info1.fIsNested && info1.fHasNestedLayers); / / has a nested SL 890 REPORTER_ASSERT(reporter, !info1.fIsNested && info1.fHasNestedLayers ); // has a nested SL
881 891
882 REPORTER_ASSERT(reporter, info2.fValid); 892 REPORTER_ASSERT(reporter, info2.fValid);
883 REPORTER_ASSERT(reporter, kWidth/2 == info2.fSize.fWidth && 893 REPORTER_ASSERT(reporter, kWidth/2 == info2.fSize.fWidth &&
884 kHeight/2 == info2.fSize.fHeight); // bound re duces size 894 kHeight/2 == info2.fSize.fHeight); // boun d reduces size
885 REPORTER_ASSERT(reporter, info2.fCTM.isIdentity()); // translate d 895 REPORTER_ASSERT(reporter, info2.fCTM.isIdentity()); // trans lated
886 REPORTER_ASSERT(reporter, kWidth/2 == info2.fOffset.fX && 896 REPORTER_ASSERT(reporter, kWidth/2 == info2.fOffset.fX &&
887 kHeight/2 == info2.fOffset.fY); 897 kHeight/2 == info2.fOffset.fY);
888 REPORTER_ASSERT(reporter, NULL != info1.fPaint); 898 REPORTER_ASSERT(reporter, NULL != info1.fPaint);
889 REPORTER_ASSERT(reporter, info2.fIsNested && !info2.fHasNestedLayers); / / is nested 899 REPORTER_ASSERT(reporter, info2.fIsNested && !info2.fHasNestedLayers ); // is nested
890 900
891 REPORTER_ASSERT(reporter, info3.fValid); 901 REPORTER_ASSERT(reporter, info3.fValid);
892 REPORTER_ASSERT(reporter, kWidth == info3.fSize.fWidth && kHeight == inf o3.fSize.fHeight); 902 REPORTER_ASSERT(reporter, kWidth == info3.fSize.fWidth && kHeight == info3.fSize.fHeight);
893 REPORTER_ASSERT(reporter, info3.fCTM.isIdentity()); 903 REPORTER_ASSERT(reporter, info3.fCTM.isIdentity());
894 REPORTER_ASSERT(reporter, 0 == info3.fOffset.fX && 0 == info3.fOffset.fY ); 904 REPORTER_ASSERT(reporter, 0 == info3.fOffset.fX && 0 == info3.fOffse t.fY);
895 REPORTER_ASSERT(reporter, NULL != info3.fPaint); 905 REPORTER_ASSERT(reporter, NULL != info3.fPaint);
896 REPORTER_ASSERT(reporter, !info3.fIsNested && !info3.fHasNestedLayers); 906 REPORTER_ASSERT(reporter, !info3.fIsNested && !info3.fHasNestedLayer s);
897 907
898 #if 0 // needs more though for GrGatherCanvas 908 #if 0 // needs more though for GrGatherCanvas
899 REPORTER_ASSERT(reporter, !info4.fValid); // paint is/wa s uncopyable 909 REPORTER_ASSERT(reporter, !info4.fValid); // paint i s/was uncopyable
900 REPORTER_ASSERT(reporter, kWidth == info4.fSize.fWidth && kHeight == inf o4.fSize.fHeight); 910 REPORTER_ASSERT(reporter, kWidth == info4.fSize.fWidth && kHeight == info4.fSize.fHeight);
901 REPORTER_ASSERT(reporter, 0 == info4.fOffset.fX && 0 == info4.fOffset.fY ); 911 REPORTER_ASSERT(reporter, 0 == info4.fOffset.fX && 0 == info4.fOffse t.fY);
902 REPORTER_ASSERT(reporter, info4.fCTM.isIdentity()); 912 REPORTER_ASSERT(reporter, info4.fCTM.isIdentity());
903 REPORTER_ASSERT(reporter, NULL == info4.fPaint); // paint is/was unc opyable 913 REPORTER_ASSERT(reporter, NULL == info4.fPaint); // paint is/was uncopyable
904 REPORTER_ASSERT(reporter, !info4.fIsNested && !info4.fHasNestedLayers); 914 REPORTER_ASSERT(reporter, !info4.fIsNested && !info4.fHasNestedLayer s);
905 #endif 915 #endif
916 }
906 } 917 }
907 } 918 }
908 919
909 #endif 920 #endif
910 921
911 static void set_canvas_to_save_count_4(SkCanvas* canvas) { 922 static void set_canvas_to_save_count_4(SkCanvas* canvas) {
912 canvas->restoreToCount(1); 923 canvas->restoreToCount(1);
913 canvas->save(); 924 canvas->save();
914 canvas->save(); 925 canvas->save();
915 canvas->save(); 926 canvas->save();
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
1592 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 1603 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
1593 } 1604 }
1594 1605
1595 DEF_TEST(Canvas_EmptyBitmap, r) { 1606 DEF_TEST(Canvas_EmptyBitmap, r) {
1596 SkBitmap dst; 1607 SkBitmap dst;
1597 dst.allocN32Pixels(10, 10); 1608 dst.allocN32Pixels(10, 10);
1598 SkCanvas canvas(dst); 1609 SkCanvas canvas(dst);
1599 1610
1600 test_draw_bitmaps(&canvas); 1611 test_draw_bitmaps(&canvas);
1601 } 1612 }
OLDNEW
« no previous file with comments | « tests/ImageNewShaderTest.cpp ('k') | tests/SurfaceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698