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

Unified Diff: bench/MergeBench.cpp

Issue 1847583002: Update SkMergeImageFilter to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update to To Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « bench/ImageFilterDAGBench.cpp ('k') | gm/imagefiltersbase.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bench/MergeBench.cpp
diff --git a/bench/MergeBench.cpp b/bench/MergeBench.cpp
index e1f7d97b5eb5483293f5850567a38b1816c07990..061a4d36f3201478b230d590534168193ad235d3 100644
--- a/bench/MergeBench.cpp
+++ b/bench/MergeBench.cpp
@@ -16,6 +16,41 @@
#define FILTER_WIDTH_LARGE SkIntToScalar(256)
#define FILTER_HEIGHT_LARGE SkIntToScalar(256)
+static sk_sp<SkImage> make_bitmap() {
+ sk_sp<SkSurface> surface(SkSurface::MakeRasterN32Premul(80, 80));
+ surface->getCanvas()->clear(0x00000000);
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setColor(0xFF884422);
+ paint.setTextSize(SkIntToScalar(96));
+ const char* str = "g";
+ surface->getCanvas()->drawText(str, strlen(str), 15, 55, paint);
+ return surface->makeImageSnapshot();
+}
+
+static sk_sp<SkImage> make_checkerboard() {
+ sk_sp<SkSurface> surface(SkSurface::MakeRasterN32Premul(80, 80));
+ SkCanvas* canvas = surface->getCanvas();
+ canvas->clear(0x00000000);
+ SkPaint darkPaint;
+ darkPaint.setColor(0xFF804020);
+ SkPaint lightPaint;
+ lightPaint.setColor(0xFF244484);
+ for (int y = 0; y < 80; y += 16) {
+ for (int x = 0; x < 80; x += 16) {
+ canvas->save();
+ canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
+ canvas->drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint);
+ canvas->drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint);
+ canvas->drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint);
+ canvas->drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
+ canvas->restore();
+ }
+ }
+
+ return surface->makeImageSnapshot();
+}
+
class MergeBench : public Benchmark {
public:
MergeBench(bool small) : fIsSmall(small), fInitialized(false) { }
@@ -27,8 +62,8 @@ protected:
void onDelayedSetup() override {
if (!fInitialized) {
- make_bitmap();
- make_checkerboard();
+ fImage = make_bitmap();
+ fCheckerboard = make_checkerboard();
fInitialized = true;
}
}
@@ -37,52 +72,17 @@ protected:
SkRect r = fIsSmall ? SkRect::MakeWH(FILTER_WIDTH_SMALL, FILTER_HEIGHT_SMALL) :
SkRect::MakeWH(FILTER_WIDTH_LARGE, FILTER_HEIGHT_LARGE);
SkPaint paint;
- paint.setImageFilter(mergeBitmaps())->unref();
+ paint.setImageFilter(this->mergeBitmaps());
for (int i = 0; i < loops; i++) {
canvas->drawRect(r, paint);
}
}
private:
- SkImageFilter* mergeBitmaps() {
- SkAutoTUnref<SkImageFilter> first(SkImageSource::Create(fCheckerboard.get()));
- SkAutoTUnref<SkImageFilter> second(SkImageSource::Create(fImage.get()));
- return SkMergeImageFilter::Create(first, second);
- }
-
- void make_bitmap() {
- auto surface(SkSurface::MakeRasterN32Premul(80, 80));
- surface->getCanvas()->clear(0x00000000);
- SkPaint paint;
- paint.setAntiAlias(true);
- paint.setColor(0xFF884422);
- paint.setTextSize(SkIntToScalar(96));
- const char* str = "g";
- surface->getCanvas()->drawText(str, strlen(str), 15, 55, paint);
- fImage = surface->makeImageSnapshot();
- }
-
- void make_checkerboard() {
- auto surface(SkSurface::MakeRasterN32Premul(80, 80));
- SkCanvas* canvas = surface->getCanvas();
- canvas->clear(0x00000000);
- SkPaint darkPaint;
- darkPaint.setColor(0xFF804020);
- SkPaint lightPaint;
- lightPaint.setColor(0xFF244484);
- for (int y = 0; y < 80; y += 16) {
- for (int x = 0; x < 80; x += 16) {
- canvas->save();
- canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
- canvas->drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint);
- canvas->drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint);
- canvas->drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint);
- canvas->drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint);
- canvas->restore();
- }
- }
-
- fCheckerboard = surface->makeImageSnapshot();
+ sk_sp<SkImageFilter> mergeBitmaps() {
+ sk_sp<SkImageFilter> first(SkImageSource::Create(fCheckerboard.get()));
+ sk_sp<SkImageFilter> second(SkImageSource::Create(fImage.get()));
+ return SkMergeImageFilter::Make(std::move(first), std::move(second));
}
bool fIsSmall;
« no previous file with comments | « bench/ImageFilterDAGBench.cpp ('k') | gm/imagefiltersbase.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698