Initiate MSAA resolves during DAG generation

Adds an "fIsMSAADirty" flag to GrRenderTargetProxy and switches to
resolving MSAA in GrTextureResolveRenderTask. This completes our push
to resolve textures outside of render passes.

For the time being, we only store a dirty flag on the proxy and still
rely on the GrRenderTarget itself to track the actual dirty rect. This
will be followed by a CL that moves the dirty rect out of
GrRenderTarget and into the proxy.

Bug: skia:
Change-Id: I21219a58028bdb4590940210e565133093cd34b3
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/235672
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/GrTextureResolveRenderTask.cpp b/src/gpu/GrTextureResolveRenderTask.cpp
index 1e52b87..0064fe6 100644
--- a/src/gpu/GrTextureResolveRenderTask.cpp
+++ b/src/gpu/GrTextureResolveRenderTask.cpp
@@ -10,6 +10,7 @@
 #include "src/gpu/GrGpu.h"
 #include "src/gpu/GrMemoryPool.h"
 #include "src/gpu/GrOpFlushState.h"
+#include "src/gpu/GrRenderTarget.h"
 #include "src/gpu/GrResourceAllocator.h"
 #include "src/gpu/GrTexturePriv.h"
 
@@ -19,6 +20,24 @@
     sk_sp<GrTextureResolveRenderTask> resolveTask(
             new GrTextureResolveRenderTask(std::move(textureProxy), flags));
 
+    // Ensure the last render task that operated on the textureProxy is closed. That's where msaa
+    // and mipmaps should have been marked dirty.
+    SkASSERT(!textureProxyPtr->getLastRenderTask() ||
+             textureProxyPtr->getLastRenderTask()->isClosed());
+
+    if (GrTextureResolveFlags::kMSAA & flags) {
+        GrRenderTargetProxy* renderTargetProxy = textureProxyPtr->asRenderTargetProxy();
+        SkASSERT(renderTargetProxy);
+        SkASSERT(renderTargetProxy->isMSAADirty());
+        renderTargetProxy->markMSAAResolved();
+    }
+
+    if (GrTextureResolveFlags::kMipMaps & flags) {
+        SkASSERT(GrMipMapped::kYes == textureProxyPtr->mipMapped());
+        SkASSERT(textureProxyPtr->mipMapsAreDirty());
+        textureProxyPtr->markMipMapsClean();
+    }
+
     // Add the target as a dependency: We will read the existing contents of this texture while
     // generating mipmap levels and/or resolving MSAA.
     //
@@ -30,13 +49,7 @@
     // We only resolve the texture; nobody should try to do anything else with this opsTask.
     resolveTask->makeClosed(caps);
 
-    if (GrTextureResolveFlags::kMipMaps & flags) {
-        SkASSERT(GrMipMapped::kYes == textureProxyPtr->mipMapped());
-        SkASSERT(textureProxyPtr->mipMapsAreDirty());
-        textureProxyPtr->markMipMapsClean();
-    }
-
-    return resolveTask;
+    return std::move(resolveTask);
 }
 
 void GrTextureResolveRenderTask::gatherProxyIntervals(GrResourceAllocator* alloc) const {
@@ -49,10 +62,17 @@
 }
 
 bool GrTextureResolveRenderTask::onExecute(GrOpFlushState* flushState) {
-    GrTexture* texture = fTarget->peekTexture();
-    SkASSERT(texture);
+    // Resolve msaa before regenerating mipmaps.
+    if (GrTextureResolveFlags::kMSAA & fResolveFlags) {
+        GrRenderTarget* renderTarget = fTarget->peekRenderTarget();
+        SkASSERT(renderTarget);
+        SkASSERT(renderTarget->needsResolve());
+        flushState->gpu()->resolveRenderTarget(renderTarget);
+    }
 
     if (GrTextureResolveFlags::kMipMaps & fResolveFlags) {
+        GrTexture* texture = fTarget->peekTexture();
+        SkASSERT(texture);
         SkASSERT(texture->texturePriv().mipMapsAreDirty());
         flushState->gpu()->regenerateMipMapLevels(texture);
     }