Make getColorAttachmentsForRender D3D-only.

This encapsulates the workaround in the D3D renderer, and also
optimizes the workaround to only compute a new set of attachments
when there is a change to the state.

BUG=angleproject:930

Change-Id: Ibdc15078236e2d19b544fae8e65b7f2554f31844
Reviewed-on: https://chromium-review.googlesource.com/254102
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Tested-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/renderer/d3d/FramebufferD3D.cpp b/src/libANGLE/renderer/d3d/FramebufferD3D.cpp
index 620b14a..31378bf 100644
--- a/src/libANGLE/renderer/d3d/FramebufferD3D.cpp
+++ b/src/libANGLE/renderer/d3d/FramebufferD3D.cpp
@@ -63,7 +63,8 @@
 FramebufferD3D::FramebufferD3D(const gl::Framebuffer::Data &data, RendererD3D *renderer)
     : FramebufferImpl(data),
       mRenderer(renderer),
-      mColorAttachmentsForRender(mData.mColorAttachments.size(), nullptr)
+      mColorAttachmentsForRender(mData.mColorAttachments.size(), nullptr),
+      mInvalidateColorAttachmentCache(true)
 {
     ASSERT(mRenderer != nullptr);
 }
@@ -74,6 +75,7 @@
 
 void FramebufferD3D::setColorAttachment(size_t, const gl::FramebufferAttachment *)
 {
+    mInvalidateColorAttachmentCache = true;
 }
 
 void FramebufferD3D::setDepthttachment(const gl::FramebufferAttachment *)
@@ -90,6 +92,7 @@
 
 void FramebufferD3D::setDrawBuffers(size_t, const GLenum *)
 {
+    mInvalidateColorAttachmentCache = true;
 }
 
 void FramebufferD3D::setReadBuffer(GLenum)
@@ -308,6 +311,16 @@
 
 const gl::AttachmentList &FramebufferD3D::getColorAttachmentsForRender(const Workarounds &workarounds) const
 {
+    if (!workarounds.mrtPerfWorkaround)
+    {
+        return mData.mColorAttachments;
+    }
+
+    if (!mInvalidateColorAttachmentCache)
+    {
+        return mColorAttachmentsForRender;
+    }
+
     // Does not actually free memory
     mColorAttachmentsForRender.clear();
 
@@ -321,12 +334,9 @@
             ASSERT(drawBufferState == GL_BACK || drawBufferState == (GL_COLOR_ATTACHMENT0_EXT + attachmentIndex));
             mColorAttachmentsForRender.push_back(colorAttachment);
         }
-        else if (!workarounds.mrtPerfWorkaround)
-        {
-            mColorAttachmentsForRender.push_back(nullptr);
-        }
     }
 
+    mInvalidateColorAttachmentCache = false;
     return mColorAttachmentsForRender;
 }