Move ReadPixels to the Framebuffer object and Impl.

BUG=angle:841

Change-Id: I71deac9e755b5dfa010596cd1f8a213c24d895bf
Reviewed-on: https://chromium-review.googlesource.com/232691
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Tested-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/libANGLE/renderer/d3d/FramebufferD3D.cpp b/src/libANGLE/renderer/d3d/FramebufferD3D.cpp
index 0dd20e5..9dea27e 100644
--- a/src/libANGLE/renderer/d3d/FramebufferD3D.cpp
+++ b/src/libANGLE/renderer/d3d/FramebufferD3D.cpp
@@ -11,6 +11,7 @@
 #include "libANGLE/renderer/d3d/RendererD3D.h"
 #include "libANGLE/renderer/d3d/RenderbufferD3D.h"
 #include "libANGLE/renderer/RenderTarget.h"
+#include "libANGLE/formatutils.h"
 #include "libANGLE/FramebufferAttachment.h"
 
 namespace rx
@@ -69,7 +70,8 @@
       mColorBuffers(renderer->getRendererCaps().maxColorAttachments),
       mDepthbuffer(nullptr),
       mStencilbuffer(nullptr),
-      mDrawBuffers(renderer->getRendererCaps().maxDrawBuffers)
+      mDrawBuffers(renderer->getRendererCaps().maxDrawBuffers),
+      mReadBuffer(GL_COLOR_ATTACHMENT0)
 {
     ASSERT(mRenderer != nullptr);
 
@@ -114,6 +116,7 @@
 
 void FramebufferD3D::setReadBuffer(GLenum buffer)
 {
+    mReadBuffer = buffer;
 }
 
 gl::Error FramebufferD3D::invalidate(size_t, const GLenum *)
@@ -208,6 +211,47 @@
     return clear(state, clearParams);
 }
 
+GLenum FramebufferD3D::getImplementationColorReadFormat() const
+{
+    // Will require more logic if glReadBuffers is supported
+    ASSERT(mReadBuffer == GL_COLOR_ATTACHMENT0 || mReadBuffer == GL_BACK);
+
+    if (mColorBuffers[0] == nullptr)
+    {
+        return GL_NONE;
+    }
+
+    GLenum actualFormat = mColorBuffers[0]->getActualFormat();
+    const gl::InternalFormat &actualFormatInfo = gl::GetInternalFormatInfo(actualFormat);
+
+    return actualFormatInfo.format;
+}
+
+GLenum FramebufferD3D::getImplementationColorReadType() const
+{
+    // Will require more logic if glReadBuffers is supported
+    ASSERT(mReadBuffer == GL_COLOR_ATTACHMENT0 || mReadBuffer == GL_BACK);
+
+    if (mColorBuffers[0] == nullptr)
+    {
+        return GL_NONE;
+    }
+
+    GLenum actualFormat = mColorBuffers[0]->getActualFormat();
+    const gl::InternalFormat &actualFormatInfo = gl::GetInternalFormatInfo(actualFormat);
+
+    return actualFormatInfo.type;
+}
+
+gl::Error FramebufferD3D::readPixels(const gl::State &state, const gl::Rectangle &area, GLenum format, GLenum type, GLvoid *pixels) const
+{
+    GLenum sizedInternalFormat = gl::GetSizedInternalFormat(format, type);
+    const gl::InternalFormat &sizedFormatInfo = gl::GetInternalFormatInfo(sizedInternalFormat);
+    GLuint outputPitch = sizedFormatInfo.computeRowPitch(type, area.width, state.getPackAlignment());
+
+    return readPixels(area, format, type, outputPitch, state.getPackState(), reinterpret_cast<uint8_t*>(pixels));
+}
+
 GLenum FramebufferD3D::checkStatus() const
 {
     // D3D11 does not allow for overlapping RenderTargetViews, so ensure uniqueness