Skip to content

Commit

Permalink
Add new bench for occluded blurmaskfilter draws
Browse files Browse the repository at this point in the history
w/ occluders
  44/44  MB     6       497us   500us   500us   502us   0%      .oOOooooOO      gpu     bluroccludedrrect

w/o occluders
  41/41  MB     5       1.08ms  1.09ms  1.12ms  1.47ms  11%     .........O      gpu     bluroccludedrrect

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2203153002

Review-Url: https://codereview.chromium.org/2203153002
  • Loading branch information
rphilli authored and Commit bot committed Aug 4, 2016
1 parent 15c42ca commit 276d328
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 0 deletions.
87 changes: 87 additions & 0 deletions bench/BlurOccludedRRectBench.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/

#include "Benchmark.h"
#include "SkBlurMaskFilter.h"
#include "SkCanvas.h"
#include "SkPaint.h"
#include "SkRRect.h"
#include "SkRect.h"
#include "sk_tool_utils.h"

class BlurOccludedRRectBench : public Benchmark {
public:
BlurOccludedRRectBench() {}

const char* onGetName() override {
return "bluroccludedrrect";
}

SkIPoint onGetSize() override {
return SkIPoint::Make(1024, 2048);
}

void onDraw(int loops, SkCanvas* canvas) override {
for (int l = 0; l < loops; ++l) {
canvas->clear(0xFFFAFAFA);

SkPaint opaque;
opaque.setAntiAlias(true);
opaque.setColor(SK_ColorWHITE);

const SkRect r = SkRect::MakeWH(480, 230);
const SkRRect rr = SkRRect::MakeRectXY(r, 8, 8);
//SkRect occRect = sk_tool_utils::compute_central_occluder(rr);

for (int i = 0; i < 2; ++i) {
canvas->save();

canvas->translate(i*502.0f+20, 10.0f);

for (int j = 0; j < 8; ++j) {
canvas->save();

canvas->translate(0.0f, j*256.0f);

SkPaint firstBlur;
firstBlur.setAntiAlias(true);
firstBlur.setColor(0x09000000);
firstBlur.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle,
2.5f));
//, occRect));

canvas->drawRRect(rr, firstBlur);

canvas->save();
canvas->translate(1.5f, 1.5f);

SkPaint secondBlur;
secondBlur.setAntiAlias(true);
secondBlur.setColor(0x30000000);
secondBlur.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle,
6.0f));
//, occRect));

canvas->drawRRect(rr, secondBlur);

canvas->restore();

canvas->drawRRect(rr, opaque);

canvas->restore();
}

canvas->restore();
}
}
}

private:
typedef Benchmark INHERITED;
};

DEF_BENCH(return new BlurOccludedRRectBench();)
50 changes: 50 additions & 0 deletions tools/sk_tool_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,4 +463,54 @@ SkBitmap slow_blur(const SkBitmap& src, float sigma) {
return dst;
}

// compute the intersection point between the diagonal and the ellipse in the
// lower right corner
static SkPoint intersection(SkScalar w, SkScalar h) {
SkASSERT(w > 0.0f || h > 0.0f);

return SkPoint::Make(w / SK_ScalarSqrt2, h / SK_ScalarSqrt2);
}

// Use the intersection of the corners' diagonals with their ellipses to shrink
// the bounding rect
SkRect compute_central_occluder(const SkRRect& rr) {
const SkRect r = rr.getBounds();

SkScalar newL = r.fLeft, newT = r.fTop, newR = r.fRight, newB = r.fBottom;

SkVector radii = rr.radii(SkRRect::kUpperLeft_Corner);
if (!radii.isZero()) {
SkPoint p = intersection(radii.fX, radii.fY);

newL = SkTMax(newL, r.fLeft + radii.fX - p.fX);
newT = SkTMax(newT, r.fTop + radii.fY - p.fY);
}

radii = rr.radii(SkRRect::kUpperRight_Corner);
if (!radii.isZero()) {
SkPoint p = intersection(radii.fX, radii.fY);

newR = SkTMin(newR, r.fRight + p.fX - radii.fX);
newT = SkTMax(newT, r.fTop + radii.fY - p.fY);
}

radii = rr.radii(SkRRect::kLowerRight_Corner);
if (!radii.isZero()) {
SkPoint p = intersection(radii.fX, radii.fY);

newR = SkTMin(newR, r.fRight + p.fX - radii.fX);
newB = SkTMin(newB, r.fBottom - radii.fY + p.fY);
}

radii = rr.radii(SkRRect::kLowerLeft_Corner);
if (!radii.isZero()) {
SkPoint p = intersection(radii.fX, radii.fY);

newL = SkTMax(newL, r.fLeft + radii.fX - p.fX);
newB = SkTMin(newB, r.fBottom - radii.fY + p.fY);
}

return SkRect::MakeLTRB(newL, newT, newR, newB);
}

} // namespace sk_tool_utils
3 changes: 3 additions & 0 deletions tools/sk_tool_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class SkBitmap;
class SkCanvas;
class SkPaint;
class SkPath;
class SkRRect;
class SkShader;
class SkTestFont;
class SkTextBlobBuilder;
Expand Down Expand Up @@ -130,6 +131,8 @@ namespace sk_tool_utils {
// so it is slow!
SkBitmap slow_blur(const SkBitmap& src, float sigma);

SkRect compute_central_occluder(const SkRRect& rr);

// A helper object to test the topological sorting code (TopoSortBench.cpp & TopoSortTest.cpp)
class TopoTestNode {
public:
Expand Down

0 comments on commit 276d328

Please sign in to comment.