OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "Benchmark.h" | 8 #include "Benchmark.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkImageSource.h" | 10 #include "SkImageSource.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 SkRect::MakeWH(FILTER_WIDTH_LARGE, FILTER_HEIGHT_L
ARGE); | 38 SkRect::MakeWH(FILTER_WIDTH_LARGE, FILTER_HEIGHT_L
ARGE); |
39 SkPaint paint; | 39 SkPaint paint; |
40 paint.setImageFilter(mergeBitmaps())->unref(); | 40 paint.setImageFilter(mergeBitmaps())->unref(); |
41 for (int i = 0; i < loops; i++) { | 41 for (int i = 0; i < loops; i++) { |
42 canvas->drawRect(r, paint); | 42 canvas->drawRect(r, paint); |
43 } | 43 } |
44 } | 44 } |
45 | 45 |
46 private: | 46 private: |
47 SkImageFilter* mergeBitmaps() { | 47 SkImageFilter* mergeBitmaps() { |
48 SkAutoTUnref<SkImageFilter> first(SkImageSource::Create(fCheckerboard)); | 48 SkAutoTUnref<SkImageFilter> first(SkImageSource::Create(fCheckerboard.ge
t())); |
49 SkAutoTUnref<SkImageFilter> second(SkImageSource::Create(fImage)); | 49 SkAutoTUnref<SkImageFilter> second(SkImageSource::Create(fImage.get())); |
50 return SkMergeImageFilter::Create(first, second); | 50 return SkMergeImageFilter::Create(first, second); |
51 } | 51 } |
52 | 52 |
53 void make_bitmap() { | 53 void make_bitmap() { |
54 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(80, 80)); | 54 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(80, 80)); |
55 surface->getCanvas()->clear(0x00000000); | 55 surface->getCanvas()->clear(0x00000000); |
56 SkPaint paint; | 56 SkPaint paint; |
57 paint.setAntiAlias(true); | 57 paint.setAntiAlias(true); |
58 paint.setColor(0xFF884422); | 58 paint.setColor(0xFF884422); |
59 paint.setTextSize(SkIntToScalar(96)); | 59 paint.setTextSize(SkIntToScalar(96)); |
60 const char* str = "g"; | 60 const char* str = "g"; |
61 surface->getCanvas()->drawText(str, strlen(str), 15, 55, paint); | 61 surface->getCanvas()->drawText(str, strlen(str), 15, 55, paint); |
62 fImage.reset(surface->newImageSnapshot()); | 62 fImage = surface->makeImageSnapshot(); |
63 } | 63 } |
64 | 64 |
65 void make_checkerboard() { | 65 void make_checkerboard() { |
66 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(80, 80)); | 66 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(80, 80)); |
67 SkCanvas* canvas = surface->getCanvas(); | 67 SkCanvas* canvas = surface->getCanvas(); |
68 canvas->clear(0x00000000); | 68 canvas->clear(0x00000000); |
69 SkPaint darkPaint; | 69 SkPaint darkPaint; |
70 darkPaint.setColor(0xFF804020); | 70 darkPaint.setColor(0xFF804020); |
71 SkPaint lightPaint; | 71 SkPaint lightPaint; |
72 lightPaint.setColor(0xFF244484); | 72 lightPaint.setColor(0xFF244484); |
73 for (int y = 0; y < 80; y += 16) { | 73 for (int y = 0; y < 80; y += 16) { |
74 for (int x = 0; x < 80; x += 16) { | 74 for (int x = 0; x < 80; x += 16) { |
75 canvas->save(); | 75 canvas->save(); |
76 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); | 76 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
77 canvas->drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint); | 77 canvas->drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint); |
78 canvas->drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint); | 78 canvas->drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint); |
79 canvas->drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint); | 79 canvas->drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint); |
80 canvas->drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); | 80 canvas->drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); |
81 canvas->restore(); | 81 canvas->restore(); |
82 } | 82 } |
83 } | 83 } |
84 | 84 |
85 fCheckerboard.reset(surface->newImageSnapshot()); | 85 fCheckerboard = surface->makeImageSnapshot(); |
86 } | 86 } |
87 | 87 |
88 bool fIsSmall; | 88 bool fIsSmall; |
89 bool fInitialized; | 89 bool fInitialized; |
90 SkAutoTUnref<SkImage> fImage, fCheckerboard; | 90 sk_sp<SkImage> fImage, fCheckerboard; |
91 | 91 |
92 typedef Benchmark INHERITED; | 92 typedef Benchmark INHERITED; |
93 }; | 93 }; |
94 | 94 |
95 /////////////////////////////////////////////////////////////////////////////// | 95 /////////////////////////////////////////////////////////////////////////////// |
96 | 96 |
97 DEF_BENCH( return new MergeBench(true); ) | 97 DEF_BENCH( return new MergeBench(true); ) |
98 DEF_BENCH( return new MergeBench(false); ) | 98 DEF_BENCH( return new MergeBench(false); ) |
OLD | NEW |