Revert of Use the GrCacheable ID to eliminate the need for notifications to GrGpuGL when textures and RTs areā€¦ (https://codereview.chromium.org/376703009/)

Reason for revert:
Trying to unblock roll wedged on 64 bit intrinsic call on XP

Original issue's description:
> Use the GrCacheable ID to eliminate the need for notifications to GrGpuGL when textures and RTs are deleted.
>
> Also, rename GrCacheable::getGenerationID() to getInstanceID() since it doesn't behave like other "generation" IDs.
>
> Committed: https://skia.googlesource.com/skia/+/91bdbcdbbdf5cdf0fdb4518a0d30206c964cfdf6

R=jvanverth@google.com, bsalomon@google.com
TBR=bsalomon@google.com, jvanverth@google.com
NOTREECHECKS=true
NOTRY=true

Author: robertphillips@google.com

Review URL: https://codereview.chromium.org/405023003
diff --git a/include/gpu/GrCacheable.h b/include/gpu/GrCacheable.h
index 5cd9b0d..344ae6b 100644
--- a/include/gpu/GrCacheable.h
+++ b/include/gpu/GrCacheable.h
@@ -46,12 +46,12 @@
      * not change when the content of the GrCacheable object changes. This will never return
      * 0.
      */
-    uint64_t getInstanceID() const { return fInstanceID; }
+    uint32_t getGenerationID() const;
 
 protected:
     GrCacheable()
         : fCacheEntry(NULL)
-        , fInstanceID(CreateInstanceID()) {}
+        , fGenID(0) {}
 
     bool isInCache() const { return NULL != fCacheEntry; }
 
@@ -64,10 +64,8 @@
     void didChangeGpuMemorySize() const;
 
 private:
-    static uint64_t CreateInstanceID();
-
     GrResourceCacheEntry*   fCacheEntry;  // NULL if not in cache
-    mutable uint64_t        fInstanceID;
+    mutable uint32_t        fGenID;
 
     typedef SkRefCnt INHERITED;
 };
diff --git a/src/gpu/GrBitmapTextContext.cpp b/src/gpu/GrBitmapTextContext.cpp
index 78b6174..25c13ec 100755
--- a/src/gpu/GrBitmapTextContext.cpp
+++ b/src/gpu/GrBitmapTextContext.cpp
@@ -56,7 +56,7 @@
 
     fCurrTexture = NULL;
     fCurrVertex = 0;
-    fEffectTextureInstanceID = 0;
+    fEffectTextureGenID = 0;
 
     fVertices = NULL;
     fMaxVertices = 0;
@@ -94,11 +94,11 @@
         SkASSERT(fCurrTexture);
         GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kNone_FilterMode);
 
-        uint64_t textureInstanceID = fCurrTexture->getInstanceID();
+        uint32_t textureGenID = fCurrTexture->getGenerationID();
         
-        if (textureInstanceID != fEffectTextureInstanceID) {
+        if (textureGenID != fEffectTextureGenID) {
             fCachedEffect.reset(GrCustomCoordsTextureEffect::Create(fCurrTexture, params));
-            fEffectTextureInstanceID = textureInstanceID;
+            fEffectTextureGenID = textureGenID;
         }
 
         // This effect could be stored with one of the cache objects (atlas?)
diff --git a/src/gpu/GrBitmapTextContext.h b/src/gpu/GrBitmapTextContext.h
index c9bb9fd..b9d5ce7 100644
--- a/src/gpu/GrBitmapTextContext.h
+++ b/src/gpu/GrBitmapTextContext.h
@@ -48,7 +48,7 @@
     int32_t                     fMaxVertices;
     GrTexture*                  fCurrTexture;
     SkAutoTUnref<GrEffect>      fCachedEffect;
-    uint64_t                    fEffectTextureInstanceID;
+    uint32_t                    fEffectTextureGenID;
     int                         fCurrVertex;
     SkRect                      fVertexBounds;
 };
diff --git a/src/gpu/GrCacheable.cpp b/src/gpu/GrCacheable.cpp
index 6047f39..120be78 100644
--- a/src/gpu/GrCacheable.cpp
+++ b/src/gpu/GrCacheable.cpp
@@ -8,11 +8,10 @@
 
 #include "GrCacheable.h"
 
-uint64_t GrCacheable::CreateInstanceID() {
-    static int64_t gCacheableID;
-    uint64_t id;
-    do {
-        id = static_cast<uint64_t>(sk_atomic_inc(&gCacheableID) + 1);
-    } while (!id);
-    return id;
+uint32_t GrCacheable::getGenerationID() const {
+    static int32_t gPathRefGenerationID;
+    while (!fGenID) {
+        fGenID = static_cast<uint32_t>(sk_atomic_inc(&gPathRefGenerationID) + 1);
+    }
+    return fGenID;
 }
diff --git a/src/gpu/gl/GrGLRenderTarget.cpp b/src/gpu/gl/GrGLRenderTarget.cpp
index 2486396..f2a0cdc 100644
--- a/src/gpu/gl/GrGLRenderTarget.cpp
+++ b/src/gpu/gl/GrGLRenderTarget.cpp
@@ -79,6 +79,7 @@
 }
 
 void GrGLRenderTarget::onRelease() {
+    GPUGL->notifyRenderTargetDelete(this);
     if (!this->isWrapped()) {
         if (fTexFBOID) {
             GL_CALL(DeleteFramebuffers(1, &fTexFBOID));
diff --git a/src/gpu/gl/GrGLTexture.cpp b/src/gpu/gl/GrGLTexture.cpp
index 255cdd9..856cfb1 100644
--- a/src/gpu/gl/GrGLTexture.cpp
+++ b/src/gpu/gl/GrGLTexture.cpp
@@ -49,6 +49,7 @@
 }
 
 void GrGLTexture::onRelease() {
+    GPUGL->notifyTextureDelete(this);
     fTexIDObj.reset(NULL);
     INHERITED::onRelease();
 }
diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp
index b62129f..6d47627 100644
--- a/src/gpu/gl/GrGpuGL.cpp
+++ b/src/gpu/gl/GrGpuGL.cpp
@@ -120,7 +120,7 @@
     SkASSERT(ctx.isInitialized());
     fCaps.reset(SkRef(ctx.caps()));
 
-    fHWBoundTextureInstanceIDs.reset(this->glCaps().maxFragmentTextureUnits());
+    fHWBoundTextures.reset(this->glCaps().maxFragmentTextureUnits());
     fHWPathTexGenSettings.reset(this->glCaps().maxFixedFunctionTextureCoords());
 
     GrGLClearErr(fGLContext.interface());
@@ -271,8 +271,8 @@
     fHWActiveTextureUnitIdx = -1; // invalid
 
     if (resetBits & kTextureBinding_GrGLBackendState) {
-        for (int s = 0; s < fHWBoundTextureInstanceIDs.count(); ++s) {
-            fHWBoundTextureInstanceIDs[s] = 0;
+        for (int s = 0; s < fHWBoundTextures.count(); ++s) {
+            fHWBoundTextures[s] = NULL;
         }
     }
 
@@ -296,7 +296,7 @@
     }
 
     if (resetBits & kRenderTarget_GrGLBackendState) {
-        fHWBoundRenderTargetInstanceID = 0;
+        fHWBoundRenderTarget = NULL;
     }
 
     if (resetBits & kPathRendering_GrGLBackendState) {
@@ -873,7 +873,7 @@
     }
 
     // below here we may bind the FBO
-    fHWBoundRenderTargetInstanceID = 0;
+    fHWBoundRenderTarget = NULL;
     if (desc->fRTFBOID != desc->fTexFBOID) {
         SkASSERT(desc->fSampleCnt > 0);
         GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER,
@@ -1258,7 +1258,7 @@
         GrGLStencilBuffer* glsb = static_cast<GrGLStencilBuffer*>(sb);
         GrGLuint rb = glsb->renderbufferID();
 
-        fHWBoundRenderTargetInstanceID = 0;
+        fHWBoundRenderTarget = NULL;
         GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo));
         GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
                                         GR_GL_STENCIL_ATTACHMENT,
@@ -1464,8 +1464,8 @@
     }
 
     GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(renderTarget);
-    if (renderTarget->getInstanceID() != fHWBoundRenderTargetInstanceID) {
-        fHWBoundRenderTargetInstanceID = 0;
+    if (renderTarget != fHWBoundRenderTarget) {
+        fHWBoundRenderTarget = NULL;
         GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, glRT->renderFBOID()));
     }
     switch (this->glCaps().invalidateFBType()) {
@@ -1728,8 +1728,7 @@
         static_cast<GrGLRenderTarget*>(this->drawState()->getRenderTarget());
     SkASSERT(NULL != rt);
 
-    uint64_t rtID = rt->getInstanceID();
-    if (fHWBoundRenderTargetInstanceID != rtID) {
+    if (fHWBoundRenderTarget != rt) {
         GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, rt->renderFBOID()));
 #ifdef SK_DEBUG
         // don't do this check in Chromium -- this is causing
@@ -1744,7 +1743,7 @@
             }
         }
 #endif
-        fHWBoundRenderTargetInstanceID = rtID;
+        fHWBoundRenderTarget = rt;
         const GrGLIRect& vp = rt->getViewport();
         if (fHWViewport != vp) {
             vp.pushToGLViewport(this->glInterface());
@@ -2011,7 +2010,7 @@
             GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, rt->textureFBOID()));
             // make sure we go through flushRenderTarget() since we've modified
             // the bound DRAW FBO ID.
-            fHWBoundRenderTargetInstanceID = 0;
+            fHWBoundRenderTarget = NULL;
             const GrGLIRect& vp = rt->getViewport();
             const SkIRect dirtyRect = rt->getResolveRect();
             GrGLIRect r;
@@ -2305,11 +2304,10 @@
         this->onResolveRenderTarget(texRT);
     }
 
-    uint64_t textureID = texture->getInstanceID();
-    if (fHWBoundTextureInstanceIDs[unitIdx] != textureID) {
+    if (fHWBoundTextures[unitIdx] != texture) {
         this->setTextureUnit(unitIdx);
         GL_CALL(BindTexture(GR_GL_TEXTURE_2D, texture->textureID()));
-        fHWBoundTextureInstanceIDs[unitIdx] = textureID;
+        fHWBoundTextures[unitIdx] = texture;
     }
 
     ResetTimestamp timestamp;
@@ -2537,6 +2535,23 @@
     }
 }
 
+void GrGpuGL::notifyRenderTargetDelete(GrRenderTarget* renderTarget) {
+    SkASSERT(NULL != renderTarget);
+    if (fHWBoundRenderTarget == renderTarget) {
+        fHWBoundRenderTarget = NULL;
+    }
+}
+
+void GrGpuGL::notifyTextureDelete(GrGLTexture* texture) {
+    for (int s = 0; s < fHWBoundTextures.count(); ++s) {
+        if (fHWBoundTextures[s] == texture) {
+            // deleting bound texture does implied bind to 0
+            fHWBoundTextures[s] = NULL;
+       }
+    }
+}
+
+
 GrGLuint GrGpuGL::createGLPathObject() {
     if (NULL == fPathNameAllocator.get()) {
         static const int range = 65536;
@@ -2707,7 +2722,7 @@
 }
 
 void GrGpuGL::setTextureUnit(int unit) {
-    SkASSERT(unit >= 0 && unit < fHWBoundTextureInstanceIDs.count());
+    SkASSERT(unit >= 0 && unit < fHWBoundTextures.count());
     if (unit != fHWActiveTextureUnitIdx) {
         GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + unit));
         fHWActiveTextureUnitIdx = unit;
@@ -2716,14 +2731,14 @@
 
 void GrGpuGL::setScratchTextureUnit() {
     // Bind the last texture unit since it is the least likely to be used by GrGLProgram.
-    int lastUnitIdx = fHWBoundTextureInstanceIDs.count() - 1;
+    int lastUnitIdx = fHWBoundTextures.count() - 1;
     if (lastUnitIdx != fHWActiveTextureUnitIdx) {
         GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + lastUnitIdx));
         fHWActiveTextureUnitIdx = lastUnitIdx;
     }
     // clear out the this field so that if a program does use this unit it will rebind the correct
     // texture.
-    fHWBoundTextureInstanceIDs[lastUnitIdx] = 0;
+    fHWBoundTextures[lastUnitIdx] = NULL;
 }
 
 namespace {
@@ -2860,7 +2875,7 @@
         GrGLTexture* dstTex = static_cast<GrGLTexture*>(dst->asTexture());
         SkASSERT(NULL != dstTex);
         // We modified the bound FBO
-        fHWBoundRenderTargetInstanceID = 0;
+        fHWBoundRenderTarget = NULL;
         GrGLIRect srcGLRect;
         srcGLRect.setRelativeTo(srcVP,
                                 srcRect.fLeft,
@@ -2902,7 +2917,7 @@
             dstFBO = bind_surface_as_fbo(this->glInterface(), dst, GR_GL_DRAW_FRAMEBUFFER, &dstVP);
             srcFBO = bind_surface_as_fbo(this->glInterface(), src, GR_GL_READ_FRAMEBUFFER, &srcVP);
             // We modified the bound FBO
-            fHWBoundRenderTargetInstanceID = 0;
+            fHWBoundRenderTarget = NULL;
             GrGLIRect srcGLRect;
             GrGLIRect dstGLRect;
             srcGLRect.setRelativeTo(srcVP,
diff --git a/src/gpu/gl/GrGpuGL.h b/src/gpu/gl/GrGpuGL.h
index 509c4c1..a2c636d 100644
--- a/src/gpu/gl/GrGpuGL.h
+++ b/src/gpu/gl/GrGpuGL.h
@@ -105,6 +105,8 @@
     void notifyIndexBufferDelete(GrGLuint id) {
         fHWGeometryState.notifyIndexBufferDelete(id);
     }
+    void notifyTextureDelete(GrGLTexture* texture);
+    void notifyRenderTargetDelete(GrRenderTarget* renderTarget);
 
     // These functions should be used to generate and delete GL path names. They have their own
     // allocator that runs on the client side, so they are much faster than going through GenPaths.
@@ -462,8 +464,8 @@
     GrDrawState::DrawFace       fHWDrawFace;
     TriState                    fHWWriteToColor;
     TriState                    fHWDitherEnabled;
-    uint64_t                    fHWBoundRenderTargetInstanceID;
-    SkTArray<uint64_t, true>    fHWBoundTextureInstanceIDs;
+    GrRenderTarget*             fHWBoundRenderTarget;
+    SkTArray<GrTexture*, true>  fHWBoundTextures;
 
     struct PathTexGenData {
         GrGLenum  fMode;