Move GrRenderTargetPriv::maxWindowRectangles to GrRenderTargetContextPriv & GrRenderTargetProxy

This removes a reason to call accessRenderTarget on the GrRenderTargetContext

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

Change-Id: I6e8a53ffd5c1fea80f542b70e05744e2991f70f8
Reviewed-on: https://skia-review.googlesource.com/4583
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/gm/windowrectangles.cpp b/gm/windowrectangles.cpp
index 47bc3c9..3949b3f 100644
--- a/gm/windowrectangles.cpp
+++ b/gm/windowrectangles.cpp
@@ -182,8 +182,7 @@
     GrContext* ctx = canvas->getGrContext();
     GrRenderTargetContext* rtc = canvas->internal_private_accessTopLayerRenderTargetContext();
 
-    if (!ctx || !rtc ||
-        rtc->accessRenderTarget()->renderTargetPriv().maxWindowRectangles() < kNumWindows) {
+    if (!ctx || !rtc || rtc->priv().maxWindowRectangles() < kNumWindows) {
         this->fail(canvas);
         return;
     }
diff --git a/include/private/GrRenderTargetProxy.h b/include/private/GrRenderTargetProxy.h
index 3c2597b..bfc6e05 100644
--- a/include/private/GrRenderTargetProxy.h
+++ b/include/private/GrRenderTargetProxy.h
@@ -49,6 +49,8 @@
      */
     int numColorSamples() const { return this->isMixedSampled() ? 0 : fDesc.fSampleCnt; }
 
+    int maxWindowRectangles(const GrCaps& caps) const;
+
     GrRenderTarget::Flags testingOnly_getFlags() const;
 
     GrRenderTargetOpList* getLastRenderTargetOpList() {
diff --git a/src/gpu/GrClipStackClip.cpp b/src/gpu/GrClipStackClip.cpp
index 669a9c2..133c4f7 100644
--- a/src/gpu/GrClipStackClip.cpp
+++ b/src/gpu/GrClipStackClip.cpp
@@ -273,14 +273,12 @@
         return false;
     }
 
-    GrRenderTarget* rt = renderTargetContext->accessRenderTarget();
-
     const SkScalar clipX = SkIntToScalar(fOrigin.x()),
                    clipY = SkIntToScalar(fOrigin.y());
 
     SkRect clipSpaceDevBounds = devBounds.makeOffset(clipX, clipY);
     const GrReducedClip reducedClip(*fStack, clipSpaceDevBounds,
-                                    rt->renderTargetPriv().maxWindowRectangles());
+                                    renderTargetContext->priv().maxWindowRectangles());
 
     if (reducedClip.hasIBounds() &&
         !GrClip::IsInsideClip(reducedClip.ibounds(), clipSpaceDevBounds)) {
@@ -357,6 +355,8 @@
         // if alpha clip mask creation fails fall through to the non-AA code paths
     }
 
+    GrRenderTarget* rt = renderTargetContext->accessRenderTarget();
+
     // use the stencil clip if we can't represent the clip as a rectangle.
     if (!context->resourceProvider()->attachStencilAttachment(rt)) {
         SkDebugf("WARNING: failed to attach stencil buffer for clip mask. Clip will be ignored.\n");
diff --git a/src/gpu/GrRenderTarget.cpp b/src/gpu/GrRenderTarget.cpp
index f15e3b0..f495cd3 100644
--- a/src/gpu/GrRenderTarget.cpp
+++ b/src/gpu/GrRenderTarget.cpp
@@ -118,8 +118,3 @@
     return specs;
 }
 
-int GrRenderTargetPriv::maxWindowRectangles() const {
-    return (this->flags() & Flags::kWindowRectsSupport) ?
-           fRenderTarget->getGpu()->caps()->maxWindowRectangles() : 0;
-}
-
diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp
index 4c86cbc..3bc6ad3 100644
--- a/src/gpu/GrRenderTargetContext.cpp
+++ b/src/gpu/GrRenderTargetContext.cpp
@@ -579,6 +579,11 @@
     this->internalDrawPath(clip, paint, viewMatrix, path, *style);
 }
 
+int GrRenderTargetContextPriv::maxWindowRectangles() const {
+    return fRenderTargetContext->fRenderTargetProxy->maxWindowRectangles(
+                                                    *fRenderTargetContext->fContext->caps());
+}
+
 void GrRenderTargetContextPriv::clearStencilClip(const GrFixedClip& clip, bool insideStencilMask) {
     ASSERT_SINGLE_OWNER_PRIV
     RETURN_IF_ABANDONED_PRIV
diff --git a/src/gpu/GrRenderTargetContextPriv.h b/src/gpu/GrRenderTargetContextPriv.h
index 83a334b..802cba0 100644
--- a/src/gpu/GrRenderTargetContextPriv.h
+++ b/src/gpu/GrRenderTargetContextPriv.h
@@ -80,6 +80,8 @@
 
     SkBudgeted isBudgeted() const;
 
+    int maxWindowRectangles() const;
+
     void testingOnly_drawBatch(const GrPaint&,
                                GrDrawBatch* batch,
                                const GrUserStencilSettings* = nullptr,
diff --git a/src/gpu/GrRenderTargetPriv.h b/src/gpu/GrRenderTargetPriv.h
index 19e7263..89f4d52 100644
--- a/src/gpu/GrRenderTargetPriv.h
+++ b/src/gpu/GrRenderTargetPriv.h
@@ -40,7 +40,6 @@
     typedef GrRenderTarget::Flags Flags;
 
     Flags flags() const { return fRenderTarget->fFlags; }
-    int maxWindowRectangles() const;
 
 private:
     explicit GrRenderTargetPriv(GrRenderTarget* renderTarget) : fRenderTarget(renderTarget) {}
diff --git a/src/gpu/GrRenderTargetProxy.cpp b/src/gpu/GrRenderTargetProxy.cpp
index 669f422..8eb335d 100644
--- a/src/gpu/GrRenderTargetProxy.cpp
+++ b/src/gpu/GrRenderTargetProxy.cpp
@@ -36,6 +36,10 @@
     , fFlags(fTarget->asRenderTarget()->renderTargetPriv().flags()) {
 }
 
+int GrRenderTargetProxy::maxWindowRectangles(const GrCaps& caps) const {
+    return (fFlags & GrRenderTarget::Flags::kWindowRectsSupport) ? caps.maxWindowRectangles() : 0;
+}
+
 GrRenderTarget* GrRenderTargetProxy::instantiate(GrTextureProvider* texProvider) {
     SkASSERT(fDesc.fFlags & GrSurfaceFlags::kRenderTarget_GrSurfaceFlag);
 
diff --git a/tests/ProxyTest.cpp b/tests/ProxyTest.cpp
index 17a3dad..618941e 100644
--- a/tests/ProxyTest.cpp
+++ b/tests/ProxyTest.cpp
@@ -34,10 +34,13 @@
 }
 
 static void check_rendertarget(skiatest::Reporter* reporter,
+                               const GrCaps& caps,
                                GrTextureProvider* provider,
                                GrRenderTargetProxy* rtProxy,
                                int numSamples,
-                               SkBackingFit fit) {
+                               SkBackingFit fit,
+                               int expectedMaxWindowRects) {
+    REPORTER_ASSERT(reporter, rtProxy->maxWindowRectangles(caps) == expectedMaxWindowRects);
     REPORTER_ASSERT(reporter, rtProxy->numStencilSamples() == numSamples);
 
     GrRenderTarget* rt = rtProxy->instantiate(provider);
@@ -110,9 +113,9 @@
                                 check_surface(reporter, sProxy.get(), origin,
                                               widthHeight, widthHeight, config,
                                               SK_InvalidUniqueID, budgeted);
-                                check_rendertarget(reporter, provider,
+                                check_rendertarget(reporter, caps, provider,
                                                    sProxy->asRenderTargetProxy(), 
-                                                   numSamples, fit);
+                                                   numSamples, fit, caps.maxWindowRectangles());
                             }
 
                             desc.fFlags = kNone_GrSurfaceFlags;
@@ -166,15 +169,13 @@
 
                         sk_sp<GrRenderTarget> defaultFBO(
                             provider->wrapBackendRenderTarget(backendDesc));
-                        REPORTER_ASSERT(reporter,
-                                        !defaultFBO->renderTargetPriv().maxWindowRectangles());
 
                         sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeWrapped(defaultFBO));
                         check_surface(reporter, sProxy.get(), origin,
                                       kWidthHeight, kWidthHeight, config,
                                       defaultFBO->uniqueID(), SkBudgeted::kNo);
-                        check_rendertarget(reporter, provider, sProxy->asRenderTargetProxy(),
-                                           numSamples, SkBackingFit::kExact);
+                        check_rendertarget(reporter, caps, provider, sProxy->asRenderTargetProxy(),
+                                           numSamples, SkBackingFit::kExact, 0);
                     }
 
                     sk_sp<GrTexture> tex;
@@ -184,16 +185,14 @@
                         desc.fFlags = kRenderTarget_GrSurfaceFlag;
                         tex.reset(provider->createTexture(desc, budgeted));
                         sk_sp<GrRenderTarget> rt(sk_ref_sp(tex->asRenderTarget()));
-                        REPORTER_ASSERT(reporter,
-                                        caps.maxWindowRectangles() ==
-                                        rt->renderTargetPriv().maxWindowRectangles());
 
                         sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeWrapped(rt));
                         check_surface(reporter, sProxy.get(), origin,
                                       kWidthHeight, kWidthHeight, config,
                                       rt->uniqueID(), budgeted);
-                        check_rendertarget(reporter, provider, sProxy->asRenderTargetProxy(),
-                                           numSamples, SkBackingFit::kExact);
+                        check_rendertarget(reporter, caps, provider, sProxy->asRenderTargetProxy(),
+                                           numSamples, SkBackingFit::kExact,
+                                           caps.maxWindowRectangles());
                     }
 
                     if (!tex) {