aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/windowrectangles.cpp
diff options
context:
space:
mode:
authorGravatar caryclark <caryclark@google.com>2016-09-06 07:09:53 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-09-06 07:09:54 -0700
commitc3bfcb803abb1f45658e9eae9f75b428a4476e75 (patch)
tree0de062257da2561a36d294c19e8d1f0a30c2e3a2 /gm/windowrectangles.cpp
parente6088c6063b60f58411936af9c48841131a5e001 (diff)
Revert of Improve usage of window rectangles (patchset #9 id:160001 of https://codereview.chromium.org/2289363005/ )
Reason for revert: broke build. See https://build.chromium.org/p/client.skia/builders/Perf-Win8-MSVC-ShuttleA-GPU-GTX960-x86_64-Debug/builds/186 Original issue's description: > Improve usage of window rectangles > > * Skips non-AA diff rect elements and replaces them with window > rectangles. > * Places window rectangles in the interiors of antialiased diff rects. > * Arranges two overlapping window rectangles in a plus shape inside of > diff rounded rects. > * Enables window rectangles when clearing and generating clip masks. > > GTX 960 perf result (with vs. without window rectangles): > > glinst4 msaa16 gpu > keymobi_pinterest.skp 0.48 -> 0.17 [ 35%] 2.77 -> 1.49 [ 54%] 0.22 -> 0.16 [ 70%] > keymobi_digg_com.skp 0.42 -> 0.23 [ 55%] 2.34 -> 1.08 [ 46%] 0.25 -> 0.21 [ 83%] > desk_jsfiddlebigcar.skp 0.28 -> 0.16 [ 59%] 1.70 -> 0.96 [ 57%] 0.19 -> 0.14 [ 70%] > top25desk_wordpress.skp 0.45 -> 0.18 [ 40%] 2.78 -> 1.53 [ 55%] 0.21 -> 0.19 [ 94%] > top25desk_weather_com.skp 2.01 -> 1.93 [ 96%] 23.5 -> 2.54 [ 11%] 1.90 -> 1.68 [ 88%] > keymobi_blogger.skp 0.57 -> 0.37 [ 65%] 2.87 -> 1.54 [ 54%] 0.43 -> 0.33 [ 77%] > keymobi_linkedin.skp 0.32 -> 0.17 [ 51%] 1.93 -> 1.04 [ 54%] 0.17 -> 0.15 [ 91%] > keymobi_bing_com_search_... 0.29 -> 0.25 [ 83%] 1.85 -> 1.23 [ 66%] 0.50 -> 0.24 [ 48%] > keymobi_theverge_com_201... 1.00 -> 0.67 [ 68%] 9.46 -> 3.84 [ 41%] 0.72 -> 0.65 [ 90%] > keymobi_sfgate_com_.skp 1.56 -> 1.13 [ 72%] 4.49 -> 2.86 [ 64%] 1.54 -> 1.11 [ 72%] > keymobi_ftw_usatoday_com... 0.59 -> 0.34 [ 57%] 2.80 -> 1.54 [ 55%] 1.21 -> 1.20 [ 99%] > keymobi_shop_mobileweb_e... 0.46 -> 0.32 [ 70%] 2.60 -> 1.26 [ 48%] 0.35 -> 0.34 [ 97%] > keymobi_cnn_com.skp 0.68 -> 0.42 [ 63%] 3.40 -> 2.10 [ 62%] 0.49 -> 0.45 [ 93%] > keymobi_plus_google_com_... 0.77 -> 0.46 [ 60%] 4.83 -> 3.56 [ 74%] 0.52 -> 0.46 [ 89%] > keymobi_wordpress.skp 0.50 -> 0.40 [ 81%] 2.60 -> 1.31 [ 50%] 0.40 -> 0.37 [ 91%] > keymobi_androidpolice_co... 0.84 -> 0.73 [ 87%] 4.15 -> 2.05 [ 49%] 0.77 -> 0.67 [ 87%] > keymobi_online_wsj_com_h... 0.55 -> 0.43 [ 78%] 2.91 -> 1.66 [ 57%] 0.45 -> 0.41 [ 90%] > keymobi_iphone_capitolvo... 1.18 -> 0.96 [ 81%] 6.26 -> 4.96 [ 79%] 0.95 -> 0.92 [ 97%] > keymobi_wikipedia__1_tab... 0.46 -> 0.41 [ 89%] 2.51 -> 1.24 [ 49%] 0.40 -> 0.38 [ 95%] > keymobi_wikipedia__1_tab... 0.46 -> 0.42 [ 90%] 2.52 -> 1.25 [ 50%] 0.40 -> 0.38 [ 96%] > keymobi_boingboing_net.skp 0.62 -> 0.56 [ 90%] 3.15 -> 1.80 [ 57%] 0.61 -> 0.56 [ 92%] > keymobi_cnn_com_2012_10_... 0.86 -> 0.82 [ 95%] 2.81 -> 1.50 [ 53%] 0.91 -> 0.83 [ 91%] > top25desk_techcrunch_com... 0.61 -> 0.56 [ 92%] 3.03 -> 1.76 [ 58%] 0.62 -> 0.56 [ 91%] > top25desk_ebay_com.skp 1.18 -> 1.08 [ 92%] 2.23 -> 1.24 [ 56%] 1.14 -> 1.09 [ 96%] > desk_css3gradients.skp 0.64 -> 0.61 [ 95%] 2.99 -> 1.54 [ 52%] 0.62 -> 0.61 [ 99%] > top25desk_blogger.skp 0.61 -> 0.59 [ 96%] 2.50 -> 1.37 [ 55%] 0.60 -> 0.57 [ 95%] > keymobi_nytimes_com_.skp 0.65 -> 0.64 [ 98%] 2.69 -> 1.42 [ 53%] 0.62 -> 0.59 [ 96%] > keymobi_wowwiki_com_worl... 0.99 -> 0.92 [ 92%] 3.46 -> 2.06 [ 60%] 0.98 -> 0.95 [ 96%] > keymobi_cuteoverload_com... 1.37 -> 1.26 [ 92%] 3.24 -> 2.45 [ 76%] 1.38 -> 1.35 [ 98%] > keymobi_mobile_news_sand... 0.88 -> 0.81 [ 93%] 3.50 -> 2.07 [ 59%] 0.82 -> 0.81 [100%] > top25desk_linkedin.skp 0.87 -> 0.87 [100%] 2.92 -> 1.73 [ 59%] 0.94 -> 0.86 [ 91%] > top25desk_docs___1_open_... 1.43 -> 1.36 [ 95%] 1.87 -> 1.42 [ 76%] 0.73 -> 0.66 [ 91%] > keymobi_reddit_com_r_pro... 0.68 -> 0.66 [ 96%] 2.49 -> 1.23 [ 49%] 0.65 -> 0.66 [102%] > ... > > BUG=skia: > GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2289363005 > > Committed: https://skia.googlesource.com/skia/+/db42be9a326c747ff92ed1da8c3536c5b3e8e22b TBR=bsalomon@google.com,egdaniel@google.com,robertphillips@google.com,csmartdalton@google.com # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=skia: Review-Url: https://codereview.chromium.org/2312173002
Diffstat (limited to 'gm/windowrectangles.cpp')
-rw-r--r--gm/windowrectangles.cpp305
1 files changed, 0 insertions, 305 deletions
diff --git a/gm/windowrectangles.cpp b/gm/windowrectangles.cpp
deleted file mode 100644
index 96c4ea6e48..0000000000
--- a/gm/windowrectangles.cpp
+++ /dev/null
@@ -1,305 +0,0 @@
-/*
- * 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 "gm.h"
-#include "SkClipStack.h"
-#include "SkRRect.h"
-
-#if SK_SUPPORT_GPU
-# include "GrAppliedClip.h"
-# include "GrDrawContext.h"
-# include "GrDrawContextPriv.h"
-# include "GrFixedClip.h"
-# include "GrReducedClip.h"
-# include "GrRenderTargetPriv.h"
-# include "GrResourceProvider.h"
-# include "effects/GrTextureDomain.h"
-#endif
-
-constexpr static SkIRect kDeviceRect = {0, 0, 600, 600};
-constexpr static SkIRect kLayerRect = {25, 25, 575, 575};
-constexpr static SkIRect kCoverRect = {50, 50, 550, 550};
-
-namespace skiagm {
-
-////////////////////////////////////////////////////////////////////////////////////////////////////
-
-class WindowRectanglesBaseGM : public GM {
-protected:
- virtual void onCoverClipStack(const SkClipStack&, SkCanvas*) = 0;
-
-private:
- SkISize onISize() override { return SkISize::Make(kDeviceRect.width(), kDeviceRect.height()); }
- void onDraw(SkCanvas*) final;
-};
-
-void WindowRectanglesBaseGM::onDraw(SkCanvas* canvas) {
- sk_tool_utils::draw_checkerboard(canvas, 0xffffffff, 0xffc6c3c6, 25);
- canvas->saveLayer(SkRect::Make(kLayerRect), nullptr);
-
- SkClipStack stack;
- stack.clipDevRect(SkRect::MakeXYWH(370.75, 80.25, 149, 100), SkRegion::kDifference_Op, false);
- stack.clipDevRect(SkRect::MakeXYWH(80.25, 420.75, 150, 100), SkRegion::kDifference_Op, true);
- stack.clipDevRRect(SkRRect::MakeRectXY(SkRect::MakeXYWH(200, 200, 200, 200), 60, 45),
- SkRegion::kDifference_Op, true);
-
- SkRRect nine;
- nine.setNinePatch(SkRect::MakeXYWH(550 - 30.25 - 100, 370.75, 100, 150), 12, 35, 23, 20);
- stack.clipDevRRect(nine, SkRegion::kDifference_Op, true);
-
- SkRRect complx;
- SkVector complxRadii[4] = {{6, 4}, {8, 12}, {16, 24}, {48, 32}};
- complx.setRectRadii(SkRect::MakeXYWH(80.25, 80.75, 100, 149), complxRadii);
- stack.clipDevRRect(complx, SkRegion::kDifference_Op, false);
-
- this->onCoverClipStack(stack, canvas);
-
- canvas->restore();
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////
-
-/**
- * Draws a clip that will exercise window rectangles if they are supported.
- */
-class WindowRectanglesGM : public WindowRectanglesBaseGM {
-private:
- SkString onShortName() final { return SkString("windowrectangles"); }
- void onCoverClipStack(const SkClipStack&, SkCanvas*) final;
-};
-
-/**
- * This is a simple helper class for resetting a canvas's clip to our test’s SkClipStack.
- */
-class ReplayClipStackVisitor final : public SkCanvasClipVisitor {
-public:
- typedef SkRegion::Op Op;
- ReplayClipStackVisitor(SkCanvas* canvas) : fCanvas(canvas) {}
- void clipRect(const SkRect& r, Op op, bool aa) override { fCanvas->clipRect(r, op, aa); }
- void clipRRect(const SkRRect& rr, Op op, bool aa) override { fCanvas->clipRRect(rr, op, aa); }
- void clipPath(const SkPath&, Op, bool) override { SkFAIL("Not implemented"); }
-private:
- SkCanvas* const fCanvas;
-};
-
-void WindowRectanglesGM::onCoverClipStack(const SkClipStack& stack, SkCanvas* canvas) {
- SkPaint paint;
- paint.setColor(0xff00aa80);
-
- // Set up the canvas's clip to match our SkClipStack.
- ReplayClipStackVisitor visitor(canvas);
- SkClipStack::Iter iter(stack, SkClipStack::Iter::kBottom_IterStart);
- for (const SkClipStack::Element* element = iter.next(); element; element = iter.next()) {
- element->replay(&visitor);
- }
-
- canvas->drawRect(SkRect::Make(kCoverRect), paint);
-}
-
-DEF_GM( return new WindowRectanglesGM(); )
-
-////////////////////////////////////////////////////////////////////////////////////////////////////
-
-#if SK_SUPPORT_GPU
-
-constexpr static int kNumWindows = 8;
-
-/**
- * Visualizes the mask (alpha or stencil) for a clip with several window rectangles. The purpose of
- * this test is to verify that window rectangles are being used during clip mask generation, and to
- * visualize where the window rectangles are placed.
- *
- * We use window rectangles when generating the clip mask because there is no need to invest time
- * defining those regions where window rectangles will be in effect during the actual draw anyway.
- *
- * This test works by filling the entire clip mask with a small checkerboard pattern before drawing
- * it, and then covering the mask with a solid color once it has been generated. The regions inside
- * window rectangles or outside the scissor should still have the initial checkerboard intact.
- */
-class WindowRectanglesMaskGM : public WindowRectanglesBaseGM {
-private:
- constexpr static int kMaskCheckerSize = 5;
- SkString onShortName() final { return SkString("windowrectangles_mask"); }
- void onCoverClipStack(const SkClipStack&, SkCanvas*) final;
- void visualizeAlphaMask(GrContext*, GrDrawContext*, const GrReducedClip&, const GrPaint&);
- void visualizeStencilMask(GrContext*, GrDrawContext*, const GrReducedClip&, const GrPaint&);
- void stencilCheckerboard(GrDrawContext*, bool flip);
- void fail(SkCanvas*);
-};
-
-/**
- * Base class for GrClips that visualize a clip mask.
- */
-class MaskOnlyClipBase : public GrClip {
-private:
- bool quickContains(const SkRect&) const final { return false; }
- bool isRRect(const SkRect& rtBounds, SkRRect* rr, bool* aa) const final { return false; }
- void getConservativeBounds(int width, int height, SkIRect* rect, bool* iior) const final {
- rect->set(0, 0, width, height);
- if (iior) {
- *iior = false;
- }
- }
-};
-
-/**
- * This class clips a cover by an alpha mask. We use it to visualize the alpha clip mask.
- */
-class AlphaOnlyClip final : public MaskOnlyClipBase {
-public:
- AlphaOnlyClip(GrTexture* mask, int x, int y) {
- int w = mask->width(), h = mask->height();
- SkMatrix mat = SkMatrix::MakeScale(1.f / SkIntToScalar(w), 1.f / SkIntToScalar(h));
- mat.preTranslate(SkIntToScalar(-x), SkIntToScalar(-y));
- fFP = GrTextureDomainEffect::Make(
- mask, nullptr, mat,
- GrTextureDomain::MakeTexelDomain(mask, SkIRect::MakeWH(w, h)),
- GrTextureDomain::kDecal_Mode, GrTextureParams::kNone_FilterMode,
- kDevice_GrCoordSet);
-
- }
-private:
- bool apply(GrContext*, GrDrawContext*, bool, bool, GrAppliedClip* out) const override {
- out->addCoverageFP(fFP);
- return true;
- }
- sk_sp<GrFragmentProcessor> fFP;
-};
-
-/**
- * This class clips a cover by the stencil clip bit. We use it to visualize the stencil mask.
- */
-class StencilOnlyClip final : public MaskOnlyClipBase {
-private:
- bool apply(GrContext*, GrDrawContext*, bool, bool, GrAppliedClip* out) const override {
- out->addStencilClip();
- return true;
- }
-};
-
-void WindowRectanglesMaskGM::onCoverClipStack(const SkClipStack& stack, SkCanvas* canvas) {
- GrContext* ctx = canvas->getGrContext();
- GrDrawContext* dc = canvas->internal_private_accessTopLayerDrawContext();
-
- if (!ctx || !dc ||
- dc->accessRenderTarget()->renderTargetPriv().maxWindowRectangles() < kNumWindows) {
- this->fail(canvas);
- return;
- }
-
- const GrReducedClip reducedClip(stack, SkRect::Make(kCoverRect), kNumWindows);
-
- GrPaint paint;
- paint.setAntiAlias(true);
- if (!dc->isStencilBufferMultisampled()) {
- paint.setColor4f(GrColor4f(0, 0.25f, 1, 1));
- this->visualizeAlphaMask(ctx, dc, reducedClip, paint);
- } else {
- paint.setColor4f(GrColor4f(1, 0.25f, 0.25f, 1));
- this->visualizeStencilMask(ctx, dc, reducedClip, paint);
- }
-}
-
-void WindowRectanglesMaskGM::visualizeAlphaMask(GrContext* ctx, GrDrawContext* dc,
- const GrReducedClip& reducedClip,
- const GrPaint& paint) {
- GrPixelConfig config = kRGBA_8888_GrPixelConfig;
- if (ctx->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) {
- config = kAlpha_8_GrPixelConfig;
- }
-
- sk_sp<GrDrawContext> maskDC(ctx->makeDrawContext(SkBackingFit::kExact, kLayerRect.width(),
- kLayerRect.height(), config, nullptr));
- if (!maskDC ||
- !ctx->resourceProvider()->attachStencilAttachment(maskDC->accessRenderTarget())) {
- return;
- }
-
- // Draw a checker pattern into the alpha mask so we can visualize the regions left untouched by
- // the clip mask generation.
- this->stencilCheckerboard(maskDC.get(), true);
- maskDC->clear(nullptr, GrColorPackA4(0xff), true);
- maskDC->drawContextPriv().drawAndStencilRect(StencilOnlyClip(), &GrUserStencilSettings::kUnused,
- SkRegion::kDifference_Op, false, false,
- SkMatrix::I(),
- SkRect::MakeIWH(maskDC->width(), maskDC->height()));
- reducedClip.drawAlphaClipMask(maskDC.get());
- sk_sp<GrTexture> mask(maskDC->asTexture());
-
- int x = kCoverRect.x() - kLayerRect.x(),
- y = kCoverRect.y() - kLayerRect.y();
-
- // Now visualize the alpha mask by drawing a rect over the area where it is defined. The regions
- // inside window rectangles or outside the scissor should still have the initial checkerboard
- // intact. (This verifies we didn't spend any time modifying those pixels in the mask.)
- AlphaOnlyClip clip(mask.get(), x, y);
- dc->drawRect(clip, paint, SkMatrix::I(),
- SkRect::Make(SkIRect::MakeXYWH(x, y, mask->width(), mask->height())));
-}
-
-void WindowRectanglesMaskGM::visualizeStencilMask(GrContext* ctx, GrDrawContext* dc,
- const GrReducedClip& reducedClip,
- const GrPaint& paint) {
- if (!ctx->resourceProvider()->attachStencilAttachment(dc->accessRenderTarget())) {
- return;
- }
-
- // Draw a checker pattern into the stencil buffer so we can visualize the regions left untouched
- // by the clip mask generation.
- this->stencilCheckerboard(dc, false);
- reducedClip.drawStencilClipMask(ctx, dc, {kLayerRect.x(), kLayerRect.y()});
-
- // Now visualize the stencil mask by covering the entire render target. The regions inside
- // window rectangless or outside the scissor should still have the initial checkerboard intact.
- // (This verifies we didn't spend any time modifying those pixels in the mask.)
- dc->drawPaint(StencilOnlyClip(), paint, SkMatrix::I());
-}
-
-void WindowRectanglesMaskGM::stencilCheckerboard(GrDrawContext* dc, bool flip) {
- constexpr static GrUserStencilSettings kSetClip(
- GrUserStencilSettings::StaticInit<
- 0,
- GrUserStencilTest::kAlways,
- 0,
- GrUserStencilOp::kSetClipBit,
- GrUserStencilOp::kKeep,
- 0>()
- );
-
- dc->drawContextPriv().clearStencilClip(GrFixedClip::Disabled(), false);
-
- for (int y = 0; y < kLayerRect.height(); y += kMaskCheckerSize) {
- for (int x = (y & 1) == flip ? 0 : kMaskCheckerSize;
- x < kLayerRect.width(); x += 2 * kMaskCheckerSize) {
- SkIRect checker = SkIRect::MakeXYWH(x, y, kMaskCheckerSize, kMaskCheckerSize);
- dc->drawContextPriv().stencilRect(GrNoClip(), &kSetClip, false, SkMatrix::I(),
- SkRect::Make(checker));
- }
- }
-}
-
-void WindowRectanglesMaskGM::fail(SkCanvas* canvas) {
- SkPaint paint;
- paint.setAntiAlias(true);
- paint.setTextAlign(SkPaint::kCenter_Align);
- paint.setTextSize(20);
- sk_tool_utils::set_portable_typeface(&paint);
-
- SkString errorMsg;
- errorMsg.printf("Requires GPU with %i window rectangles", kNumWindows);
-
- canvas->clipRect(SkRect::Make(kCoverRect));
- canvas->clear(SK_ColorWHITE);
- canvas->drawText(errorMsg.c_str(), errorMsg.size(), SkIntToScalar(kCoverRect.centerX()),
- SkIntToScalar(kCoverRect.centerY() - 10), paint);
-}
-
-DEF_GM( return new WindowRectanglesMaskGM(); )
-
-#endif
-
-}