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

Side by Side Diff: tests/PictureTest.cpp

Issue 266203003: Infrastructure changes to support pull saveLayers forward task (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Fixed Android error Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | no next file » | 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 "SkBitmapDevice.h" 8 #include "SkBitmapDevice.h"
9 #if SK_SUPPORT_GPU
10 #include "SkBlurImageFilter.h"
11 #endif
9 #include "SkCanvas.h" 12 #include "SkCanvas.h"
10 #include "SkColorPriv.h" 13 #include "SkColorPriv.h"
11 #include "SkDashPathEffect.h" 14 #include "SkDashPathEffect.h"
12 #include "SkData.h" 15 #include "SkData.h"
13 #include "SkDecodingImageGenerator.h" 16 #include "SkDecodingImageGenerator.h"
14 #include "SkError.h" 17 #include "SkError.h"
18 #if SK_SUPPORT_GPU
19 #include "SkGpuDevice.h"
20 #endif
15 #include "SkImageEncoder.h" 21 #include "SkImageEncoder.h"
16 #include "SkImageGenerator.h" 22 #include "SkImageGenerator.h"
17 #include "SkPaint.h" 23 #include "SkPaint.h"
18 #include "SkPicture.h" 24 #include "SkPicture.h"
19 #include "SkPictureRecorder.h" 25 #include "SkPictureRecorder.h"
20 #include "SkPictureUtils.h" 26 #include "SkPictureUtils.h"
21 #include "SkRRect.h" 27 #include "SkRRect.h"
22 #include "SkRandom.h" 28 #include "SkRandom.h"
23 #include "SkShader.h" 29 #include "SkShader.h"
24 #include "SkStream.h" 30 #include "SkStream.h"
31
32 #if SK_SUPPORT_GPU
33 #include "SkSurface.h"
34 #include "GrContextFactory.h"
35 #include "GrPictureUtils.h"
36 #endif
25 #include "Test.h" 37 #include "Test.h"
26 38
27 static const int gColorScale = 30; 39 static const int gColorScale = 30;
28 static const int gColorOffset = 60; 40 static const int gColorOffset = 60;
29 41
30 static void make_bm(SkBitmap* bm, int w, int h, SkColor color, bool immutable) { 42 static void make_bm(SkBitmap* bm, int w, int h, SkColor color, bool immutable) {
31 bm->allocN32Pixels(w, h); 43 bm->allocN32Pixels(w, h);
32 bm->eraseColor(color); 44 bm->eraseColor(color);
33 if (immutable) { 45 if (immutable) {
34 bm->setImmutable(); 46 bm->setImmutable();
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 paint.setStyle(SkPaint::kStroke_Style); 770 paint.setStyle(SkPaint::kStroke_Style);
759 paint.setStrokeWidth(0); 771 paint.setStrokeWidth(0);
760 for (int i = 0; i < 50; ++i) { 772 for (int i = 0; i < 50; ++i) {
761 canvas->drawPath(path, paint); 773 canvas->drawPath(path, paint);
762 } 774 }
763 } 775 }
764 picture.reset(recorder.endRecording()); 776 picture.reset(recorder.endRecording());
765 // hairline stroked AA concave paths are fine for GPU rendering 777 // hairline stroked AA concave paths are fine for GPU rendering
766 REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(NULL)); 778 REPORTER_ASSERT(reporter, picture->suitableForGpuRasterization(NULL));
767 } 779 }
780
781 static void test_gpu_picture_optimization(skiatest::Reporter* reporter,
782 GrContextFactory* factory) {
783
784 GrContext* context = factory->get(GrContextFactory::kNative_GLContextType);
785
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, NULL, 0);
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 SkBitmap bmp;
835 bmp.allocN32Pixels(10, 10);
836 bmp.eraseColor(SK_ColorGREEN);
837 bmp.setAlphaType(kOpaque_SkAlphaType);
838 SkShader* shader = SkShader::CreateBitmapShader(bmp,
839 SkShader::kClamp_TileMode, SkShader::kClamp_ TileMode);
840 p.setShader(shader)->unref();
841
842 c->saveLayer(NULL, &p);
843 c->restore();
844 }
845
846 pict.reset(recorder.endRecording());
847 }
848
849 // Now test out the SaveLayer extraction
850 {
851 SkImageInfo info = SkImageInfo::MakeN32Premul(kWidth, kHeight);
852
853 SkAutoTUnref<SkSurface> surface(SkSurface::NewScratchRenderTarget(contex t, info));
854
855 SkCanvas* canvas = surface->getCanvas();
856
857 canvas->EXPERIMENTAL_optimize(pict);
858
859 SkPicture::AccelData::Key key = GPUAccelData::ComputeAccelDataKey();
860
861 const SkPicture::AccelData* data = pict->EXPERIMENTAL_getAccelData(key);
862 REPORTER_ASSERT(reporter, NULL != data);
863
864 const GPUAccelData *gpuData = static_cast<const GPUAccelData*>(data);
865 REPORTER_ASSERT(reporter, 5 == gpuData->numSaveLayers());
866
867 const GPUAccelData::SaveLayerInfo& info0 = gpuData->saveLayerInfo(0);
868 // The parent/child layer appear in reverse order
869 const GPUAccelData::SaveLayerInfo& info1 = gpuData->saveLayerInfo(2);
870 const GPUAccelData::SaveLayerInfo& info2 = gpuData->saveLayerInfo(1);
871 const GPUAccelData::SaveLayerInfo& info3 = gpuData->saveLayerInfo(3);
872 const GPUAccelData::SaveLayerInfo& info4 = gpuData->saveLayerInfo(4);
873
874 REPORTER_ASSERT(reporter, info0.fValid);
875 REPORTER_ASSERT(reporter, kWidth == info0.fSize.fWidth && kHeight == inf o0.fSize.fHeight);
876 REPORTER_ASSERT(reporter, info0.fCTM.isIdentity());
877 REPORTER_ASSERT(reporter, 0 == info0.fOffset.fX && 0 == info0.fOffset.fY );
878 REPORTER_ASSERT(reporter, NULL != info0.fPaint);
879 REPORTER_ASSERT(reporter, !info0.fIsNested && !info0.fHasNestedLayers);
880
881 REPORTER_ASSERT(reporter, info1.fValid);
882 REPORTER_ASSERT(reporter, kWidth == info1.fSize.fWidth && kHeight == inf o1.fSize.fHeight);
883 REPORTER_ASSERT(reporter, info1.fCTM.isIdentity());
884 REPORTER_ASSERT(reporter, 0 == info1.fOffset.fX && 0 == info1.fOffset.fY );
885 REPORTER_ASSERT(reporter, NULL != info1.fPaint);
886 REPORTER_ASSERT(reporter, !info1.fIsNested && info1.fHasNestedLayers); / / has a nested SL
887
888 REPORTER_ASSERT(reporter, info2.fValid);
889 REPORTER_ASSERT(reporter, kWidth/2 == info2.fSize.fWidth &&
890 kHeight/2 == info2.fSize.fHeight); // bound re duces size
891 REPORTER_ASSERT(reporter, info2.fCTM.isIdentity()); // translate d
892 REPORTER_ASSERT(reporter, 0 == info2.fOffset.fX && 0 == info2.fOffset.fY );
893 REPORTER_ASSERT(reporter, NULL != info1.fPaint);
894 REPORTER_ASSERT(reporter, info2.fIsNested && !info2.fHasNestedLayers); / / is nested
895
896 REPORTER_ASSERT(reporter, info3.fValid);
897 REPORTER_ASSERT(reporter, kWidth == info3.fSize.fWidth && kHeight == inf o3.fSize.fHeight);
898 REPORTER_ASSERT(reporter, info3.fCTM.isIdentity());
899 REPORTER_ASSERT(reporter, 0 == info3.fOffset.fX && 0 == info3.fOffset.fY );
900 REPORTER_ASSERT(reporter, NULL != info3.fPaint);
901 REPORTER_ASSERT(reporter, !info3.fIsNested && !info3.fHasNestedLayers);
902
903 REPORTER_ASSERT(reporter, !info4.fValid); // paint is/wa s uncopyable
904 REPORTER_ASSERT(reporter, kWidth == info4.fSize.fWidth && kHeight == inf o4.fSize.fHeight);
905 REPORTER_ASSERT(reporter, 0 == info4.fOffset.fX && 0 == info4.fOffset.fY );
906 REPORTER_ASSERT(reporter, info4.fCTM.isIdentity());
907 REPORTER_ASSERT(reporter, NULL == info4.fPaint); // paint is/was unc opyable
908 REPORTER_ASSERT(reporter, !info4.fIsNested && !info4.fHasNestedLayers);
909 }
910 }
911
768 #endif 912 #endif
769 913
770 static void set_canvas_to_save_count_4(SkCanvas* canvas) { 914 static void set_canvas_to_save_count_4(SkCanvas* canvas) {
771 canvas->restoreToCount(1); 915 canvas->restoreToCount(1);
772 canvas->save(); 916 canvas->save();
773 canvas->save(); 917 canvas->save();
774 canvas->save(); 918 canvas->save();
775 } 919 }
776 920
777 static void test_unbalanced_save_restores(skiatest::Reporter* reporter) { 921 static void test_unbalanced_save_restores(skiatest::Reporter* reporter) {
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 test_gatherpixelrefsandrects(reporter); 1421 test_gatherpixelrefsandrects(reporter);
1278 test_bitmap_with_encoded_data(reporter); 1422 test_bitmap_with_encoded_data(reporter);
1279 test_clone_empty(reporter); 1423 test_clone_empty(reporter);
1280 test_draw_empty(reporter); 1424 test_draw_empty(reporter);
1281 test_clip_bound_opt(reporter); 1425 test_clip_bound_opt(reporter);
1282 test_clip_expansion(reporter); 1426 test_clip_expansion(reporter);
1283 test_hierarchical(reporter); 1427 test_hierarchical(reporter);
1284 test_gen_id(reporter); 1428 test_gen_id(reporter);
1285 } 1429 }
1286 1430
1431 #if SK_SUPPORT_GPU
1432 DEF_GPUTEST(GPUPicture, reporter, factory) {
1433 test_gpu_picture_optimization(reporter, factory);
1434 }
1435 #endif
1436
1287 static void draw_bitmaps(const SkBitmap bitmap, SkCanvas* canvas) { 1437 static void draw_bitmaps(const SkBitmap bitmap, SkCanvas* canvas) {
1288 const SkPaint paint; 1438 const SkPaint paint;
1289 const SkRect rect = { 5.0f, 5.0f, 8.0f, 8.0f }; 1439 const SkRect rect = { 5.0f, 5.0f, 8.0f, 8.0f };
1290 const SkIRect irect = { 2, 2, 3, 3 }; 1440 const SkIRect irect = { 2, 2, 3, 3 };
1291 1441
1292 // Don't care what these record, as long as they're legal. 1442 // Don't care what these record, as long as they're legal.
1293 canvas->drawBitmap(bitmap, 0.0f, 0.0f, &paint); 1443 canvas->drawBitmap(bitmap, 0.0f, 0.0f, &paint);
1294 canvas->drawBitmapRectToRect(bitmap, &rect, rect, &paint, SkCanvas::kNone_Dr awBitmapRectFlag); 1444 canvas->drawBitmapRectToRect(bitmap, &rect, rect, &paint, SkCanvas::kNone_Dr awBitmapRectFlag);
1295 canvas->drawBitmapMatrix(bitmap, SkMatrix::I(), &paint); 1445 canvas->drawBitmapMatrix(bitmap, SkMatrix::I(), &paint);
1296 canvas->drawBitmapNine(bitmap, irect, rect, &paint); 1446 canvas->drawBitmapNine(bitmap, irect, rect, &paint);
(...skipping 13 matching lines...) Expand all
1310 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 1460 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
1311 } 1461 }
1312 1462
1313 DEF_TEST(Canvas_EmptyBitmap, r) { 1463 DEF_TEST(Canvas_EmptyBitmap, r) {
1314 SkBitmap dst; 1464 SkBitmap dst;
1315 dst.allocN32Pixels(10, 10); 1465 dst.allocN32Pixels(10, 10);
1316 SkCanvas canvas(dst); 1466 SkCanvas canvas(dst);
1317 1467
1318 test_draw_bitmaps(&canvas); 1468 test_draw_bitmaps(&canvas);
1319 } 1469 }
OLDNEW
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698