Change D3D waitFence() to poll rather than wait.

Change-Id: I4931318d3ee25ec6166caceb1c5fe083d590767a
Bug: skia:9935
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/300645
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
Auto-Submit: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/d3d/GrD3DGpu.cpp b/src/gpu/d3d/GrD3DGpu.cpp
index 28edf5e..e555c00 100644
--- a/src/gpu/d3d/GrD3DGpu.cpp
+++ b/src/gpu/d3d/GrD3DGpu.cpp
@@ -78,7 +78,7 @@
     }
 
     // We need to make sure everything has finished on the queue.
-    this->waitFence(fCurrentFenceValue);
+    this->waitForQueueCompletion();
 
     SkDEBUGCODE(uint64_t fenceValue = fFence->GetCompletedValue();)
 
@@ -121,7 +121,7 @@
         return false;
     } else if (result == GrD3DDirectCommandList::SubmitResult::kNoWork) {
         if (sync == SyncQueue::kForce) {
-            this->waitFence(fCurrentFenceValue);
+            this->waitForQueueCompletion();
             this->checkForFinishedCommandLists();
         }
         return true;
@@ -136,7 +136,7 @@
             std::move(fCurrentDirectCommandList), fence);
 
     if (sync == SyncQueue::kForce) {
-        this->waitFence(fence);
+        this->waitForQueueCompletion();
     }
 
     fCurrentDirectCommandList = fResourceProvider.findOrCreateDirectCommandList();
@@ -169,6 +169,17 @@
     }
 }
 
+void GrD3DGpu::waitForQueueCompletion() {
+    if (fFence->GetCompletedValue() < fCurrentFenceValue) {
+        HANDLE fenceEvent;
+        fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
+        SkASSERT(fenceEvent);
+        GR_D3D_CALL_ERRCHECK(fFence->SetEventOnCompletion(fCurrentFenceValue, fenceEvent));
+        WaitForSingleObject(fenceEvent, INFINITE);
+        CloseHandle(fenceEvent);
+    }
+}
+
 void GrD3DGpu::submit(GrOpsRenderPass* renderPass) {
     SkASSERT(fCachedOpsRenderPass.get() == renderPass);
 
@@ -1207,14 +1218,5 @@
 }
 
 bool GrD3DGpu::waitFence(GrFence fence) {
-    if (fFence->GetCompletedValue() < fence) {
-        HANDLE fenceEvent;
-        fenceEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
-        SkASSERT(fenceEvent);
-        GR_D3D_CALL_ERRCHECK(fFence->SetEventOnCompletion(fence, fenceEvent));
-        WaitForSingleObject(fenceEvent, INFINITE);
-        CloseHandle(fenceEvent);
-    }
-
-    return true;
+    return (fFence->GetCompletedValue() >= fence);
 }
diff --git a/src/gpu/d3d/GrD3DGpu.h b/src/gpu/d3d/GrD3DGpu.h
index 3b11e1c..75bcab1 100644
--- a/src/gpu/d3d/GrD3DGpu.h
+++ b/src/gpu/d3d/GrD3DGpu.h
@@ -214,6 +214,7 @@
     bool submitDirectCommandList(SyncQueue sync);
 
     void checkForFinishedCommandLists();
+    void waitForQueueCompletion();
 
     void copySurfaceAsCopyTexture(GrSurface* dst, GrSurface* src, GrD3DTextureResource* dstResource,
                                   GrD3DTextureResource* srcResource, const SkIRect& srcRect,