OLD | NEW |
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 882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
893 // optimize away | 893 // optimize away |
894 SkScalar blueToRedMatrix[20] = { 0 }; | 894 SkScalar blueToRedMatrix[20] = { 0 }; |
895 blueToRedMatrix[2] = blueToRedMatrix[18] = SK_Scalar1; | 895 blueToRedMatrix[2] = blueToRedMatrix[18] = SK_Scalar1; |
896 SkAutoTUnref<SkColorFilter> blueToRed(SkColorMatrixFilter::Create(blueTo
RedMatrix)); | 896 SkAutoTUnref<SkColorFilter> blueToRed(SkColorMatrixFilter::Create(blueTo
RedMatrix)); |
897 SkAutoTUnref<SkImageFilter> filter(SkColorFilterImageFilter::Create(blue
ToRed.get())); | 897 SkAutoTUnref<SkImageFilter> filter(SkColorFilterImageFilter::Create(blue
ToRed.get())); |
898 | 898 |
899 SkPaint complexPaint; | 899 SkPaint complexPaint; |
900 complexPaint.setImageFilter(filter); | 900 complexPaint.setImageFilter(filter); |
901 | 901 |
902 SkAutoTUnref<SkPicture> pict, child; | 902 SkAutoTUnref<SkPicture> pict, child; |
| 903 SkRTreeFactory bbhFactory; |
903 | 904 |
904 { | 905 { |
905 SkPictureRecorder recorder; | 906 SkPictureRecorder recorder; |
906 | 907 |
907 SkCanvas* c = recorder.beginRecording(SkIntToScalar(kWidth), SkIntTo
Scalar(kHeight)); | 908 SkCanvas* c = recorder.beginRecording(SkIntToScalar(kWidth), SkIntTo
Scalar(kHeight), |
| 909 &bbhFactory, |
| 910 SkPictureRecorder::kComputeSav
eLayerInfo_RecordFlag); |
908 | 911 |
909 c->saveLayer(NULL, &complexPaint); | 912 c->saveLayer(NULL, &complexPaint); |
910 c->restore(); | 913 c->restore(); |
911 | 914 |
912 child.reset(recorder.endRecording()); | 915 child.reset(recorder.endRecording()); |
913 } | 916 } |
914 | 917 |
915 // create a picture with the structure: | 918 // create a picture with the structure: |
916 // 1) | 919 // 1) |
917 // SaveLayer | 920 // SaveLayer |
(...skipping 12 matching lines...) Expand all Loading... |
930 // DrawPicture (which has a SaveLayer/Restore pair) | 933 // DrawPicture (which has a SaveLayer/Restore pair) |
931 // Restore | 934 // Restore |
932 // 5) | 935 // 5) |
933 // SaveLayer | 936 // SaveLayer |
934 // DrawPicture with Matrix & Paint (with SaveLayer/Restore pair
) | 937 // DrawPicture with Matrix & Paint (with SaveLayer/Restore pair
) |
935 // Restore | 938 // Restore |
936 { | 939 { |
937 SkPictureRecorder recorder; | 940 SkPictureRecorder recorder; |
938 | 941 |
939 SkCanvas* c = recorder.beginRecording(SkIntToScalar(kWidth), | 942 SkCanvas* c = recorder.beginRecording(SkIntToScalar(kWidth), |
940 SkIntToScalar(kHeight)); | 943 SkIntToScalar(kHeight), |
| 944 &bbhFactory, |
| 945 SkPictureRecorder::kComputeSav
eLayerInfo_RecordFlag); |
941 // 1) | 946 // 1) |
942 c->saveLayer(NULL, &complexPaint); // layer #0 | 947 c->saveLayer(NULL, &complexPaint); // layer #0 |
943 c->restore(); | 948 c->restore(); |
944 | 949 |
945 // 2) | 950 // 2) |
946 c->saveLayer(NULL, NULL); // layer #1 | 951 c->saveLayer(NULL, NULL); // layer #1 |
947 c->translate(kWidth/2.0f, kHeight/2.0f); | 952 c->translate(kWidth/2.0f, kHeight/2.0f); |
948 SkRect r = SkRect::MakeXYWH(0, 0, kWidth/2, kHeight/2); | 953 SkRect r = SkRect::MakeXYWH(0, 0, kWidth/2, kHeight/2); |
949 c->saveLayer(&r, &complexPaint); // layer #2 | 954 c->saveLayer(&r, &complexPaint); // layer #2 |
950 c->restore(); | 955 c->restore(); |
(...skipping 22 matching lines...) Expand all Loading... |
973 c->saveLayer(NULL, &layerPaint); // layer #6 | 978 c->saveLayer(NULL, &layerPaint); // layer #6 |
974 c->drawPicture(child, &trans, &picturePaint); // layer #7 in
side picture | 979 c->drawPicture(child, &trans, &picturePaint); // layer #7 in
side picture |
975 c->restore(); | 980 c->restore(); |
976 } | 981 } |
977 | 982 |
978 pict.reset(recorder.endRecording()); | 983 pict.reset(recorder.endRecording()); |
979 } | 984 } |
980 | 985 |
981 // Now test out the SaveLayer extraction | 986 // Now test out the SaveLayer extraction |
982 { | 987 { |
983 SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight); | |
984 | |
985 SkAutoTUnref<SkSurface> surface(SkSurface::NewScratchRenderTarget(co
ntext, info)); | |
986 | |
987 SkCanvas* canvas = surface->getCanvas(); | |
988 | |
989 canvas->EXPERIMENTAL_optimize(pict); | |
990 | |
991 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); | 988 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); |
992 | 989 |
993 const SkPicture::AccelData* data = pict->EXPERIMENTAL_getAccelData(k
ey); | 990 const SkPicture::AccelData* data = pict->EXPERIMENTAL_getAccelData(k
ey); |
994 REPORTER_ASSERT(reporter, data); | 991 REPORTER_ASSERT(reporter, data); |
995 | 992 |
996 const GrAccelData *gpuData = static_cast<const GrAccelData*>(data); | 993 const GrAccelData *gpuData = static_cast<const GrAccelData*>(data); |
997 REPORTER_ASSERT(reporter, 8 == gpuData->numSaveLayers()); | 994 REPORTER_ASSERT(reporter, 8 == gpuData->numSaveLayers()); |
998 | 995 |
999 const GrAccelData::SaveLayerInfo& info0 = gpuData->saveLayerInfo(0); | 996 const GrAccelData::SaveLayerInfo& info0 = gpuData->saveLayerInfo(0); |
1000 // The parent/child layers appear in reverse order | 997 // The parent/child layers appear in reverse order |
(...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1909 | 1906 |
1910 // The picture shares the immutable pixels but copies the mutable ones. | 1907 // The picture shares the immutable pixels but copies the mutable ones. |
1911 REPORTER_ASSERT(r, mut.pixelRef()->unique()); | 1908 REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
1912 REPORTER_ASSERT(r, !immut.pixelRef()->unique()); | 1909 REPORTER_ASSERT(r, !immut.pixelRef()->unique()); |
1913 | 1910 |
1914 // When the picture goes away, it's just our bitmaps holding the refs. | 1911 // When the picture goes away, it's just our bitmaps holding the refs. |
1915 pic.reset(NULL); | 1912 pic.reset(NULL); |
1916 REPORTER_ASSERT(r, mut.pixelRef()->unique()); | 1913 REPORTER_ASSERT(r, mut.pixelRef()->unique()); |
1917 REPORTER_ASSERT(r, immut.pixelRef()->unique()); | 1914 REPORTER_ASSERT(r, immut.pixelRef()->unique()); |
1918 } | 1915 } |
OLD | NEW |