Commit d4874cb3 by Manh Nguyen Committed by Commit Bot

Reformat Framebuffer::readPixels

Reformat Framebuffer::readPixels and its overriding methods to the following method signature angle::Result readPixels(const Context *context, const Rectangle &area, GLenum format, GLenum type, const PixelPackState &pack, Buffer *packBuffer void *pixels); This will allow capture replay tool to use its own PixelPackState to read pixels from framebuffer without having to set the global states Bug: angleproject:4787 Change-Id: Idc64179d8e8f6b5163ef0747f239cd5172a2491b Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2267417 Commit-Queue: Manh Nguyen <nguyenmh@google.com> Reviewed-by: 's avatarCody Northrop <cnorthrop@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent b067db75
......@@ -3765,7 +3765,9 @@ void Context::readPixels(GLint x,
ASSERT(readFBO);
Rectangle area(x, y, width, height);
ANGLE_CONTEXT_TRY(readFBO->readPixels(this, area, format, type, pixels));
PixelPackState packState = mState.getPackState();
Buffer *packBuffer = mState.getTargetBuffer(gl::BufferBinding::PixelPack);
ANGLE_CONTEXT_TRY(readFBO->readPixels(this, area, format, type, packState, packBuffer, pixels));
}
void Context::readPixelsRobust(GLint x,
......
......@@ -1635,14 +1635,15 @@ angle::Result Framebuffer::readPixels(const Context *context,
const Rectangle &area,
GLenum format,
GLenum type,
const PixelPackState &pack,
Buffer *packBuffer,
void *pixels)
{
ANGLE_TRY(mImpl->readPixels(context, area, format, type, pixels));
ANGLE_TRY(mImpl->readPixels(context, area, format, type, pack, packBuffer, pixels));
Buffer *unpackBuffer = context->getState().getTargetBuffer(BufferBinding::PixelUnpack);
if (unpackBuffer)
if (packBuffer)
{
unpackBuffer->onDataChanged();
packBuffer->onDataChanged();
}
return angle::Result::Continue;
......
......@@ -356,6 +356,8 @@ class Framebuffer final : public angle::ObserverInterface,
const Rectangle &area,
GLenum format,
GLenum type,
const PixelPackState &pack,
Buffer *packBuffer,
void *pixels);
angle::Result blit(const Context *context,
......
......@@ -16,10 +16,12 @@
namespace gl
{
class State;
class Buffer;
class Framebuffer;
class FramebufferAttachment;
struct PixelPackState;
struct Rectangle;
class State;
} // namespace gl
namespace rx
......@@ -69,6 +71,8 @@ class FramebufferImpl : angle::NonCopyable
const gl::Rectangle &area,
GLenum format,
GLenum type,
const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
void *pixels) = 0;
virtual angle::Result blit(const gl::Context *context,
......
......@@ -34,8 +34,14 @@ class MockFramebufferImpl : public rx::FramebufferImpl
MOCK_METHOD4(clearBufferiv, angle::Result(const gl::Context *, GLenum, GLint, const GLint *));
MOCK_METHOD5(clearBufferfi, angle::Result(const gl::Context *, GLenum, GLint, GLfloat, GLint));
MOCK_METHOD5(readPixels,
angle::Result(const gl::Context *, const gl::Rectangle &, GLenum, GLenum, void *));
MOCK_METHOD7(readPixels,
angle::Result(const gl::Context *,
const gl::Rectangle &,
GLenum,
GLenum,
const gl::PixelPackState &,
gl::Buffer *,
void *));
MOCK_CONST_METHOD3(getSamplePosition, angle::Result(const gl::Context *, size_t, GLfloat *));
......
......@@ -200,6 +200,8 @@ angle::Result FramebufferD3D::readPixels(const gl::Context *context,
const gl::Rectangle &area,
GLenum format,
GLenum type,
const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
void *pixels)
{
// Clip read area to framebuffer.
......@@ -212,24 +214,22 @@ angle::Result FramebufferD3D::readPixels(const gl::Context *context,
return angle::Result::Continue;
}
const gl::PixelPackState &packState = context->getState().getPackState();
const gl::InternalFormat &sizedFormatInfo = gl::GetInternalFormatInfo(format, type);
ContextD3D *contextD3D = GetImplAs<ContextD3D>(context);
GLuint outputPitch = 0;
ANGLE_CHECK_GL_MATH(contextD3D,
sizedFormatInfo.computeRowPitch(type, area.width, packState.alignment,
packState.rowLength, &outputPitch));
sizedFormatInfo.computeRowPitch(type, area.width, pack.alignment,
pack.rowLength, &outputPitch));
GLuint outputSkipBytes = 0;
ANGLE_CHECK_GL_MATH(contextD3D, sizedFormatInfo.computeSkipBytes(
type, outputPitch, 0, packState, false, &outputSkipBytes));
ANGLE_CHECK_GL_MATH(contextD3D, sizedFormatInfo.computeSkipBytes(type, outputPitch, 0, pack,
false, &outputSkipBytes));
outputSkipBytes += (clippedArea.x - area.x) * sizedFormatInfo.pixelBytes +
(clippedArea.y - area.y) * outputPitch;
return readPixelsImpl(context, clippedArea, format, type, outputPitch, packState,
return readPixelsImpl(context, clippedArea, format, type, outputPitch, pack, packBuffer,
static_cast<uint8_t *>(pixels) + outputSkipBytes);
}
......
......@@ -82,6 +82,8 @@ class FramebufferD3D : public FramebufferImpl
const gl::Rectangle &area,
GLenum format,
GLenum type,
const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
void *pixels) override;
angle::Result blit(const gl::Context *context,
......@@ -115,6 +117,7 @@ class FramebufferD3D : public FramebufferImpl
GLenum type,
size_t outputPitch,
const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
uint8_t *pixels) = 0;
virtual angle::Result blitImpl(const gl::Context *context,
......
......@@ -252,12 +252,12 @@ angle::Result Framebuffer11::readPixelsImpl(const gl::Context *context,
GLenum type,
size_t outputPitch,
const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
uint8_t *pixels)
{
const gl::FramebufferAttachment *readAttachment = mState.getReadPixelsAttachment(format);
ASSERT(readAttachment);
gl::Buffer *packBuffer = context->getState().getTargetBuffer(gl::BufferBinding::PixelPack);
if (packBuffer != nullptr)
{
Buffer11 *packBufferStorage = GetImplAs<Buffer11>(packBuffer);
......
......@@ -70,6 +70,7 @@ class Framebuffer11 : public FramebufferD3D
GLenum type,
size_t outputPitch,
const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
uint8_t *pixels) override;
angle::Result blitImpl(const gl::Context *context,
......
......@@ -82,6 +82,7 @@ angle::Result Framebuffer9::readPixelsImpl(const gl::Context *context,
GLenum type,
size_t outputPitch,
const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
uint8_t *pixels)
{
const gl::FramebufferAttachment *colorbuffer = mState.getColorAttachment(0);
......
......@@ -65,6 +65,7 @@ class Framebuffer9 : public FramebufferD3D
GLenum type,
size_t outputPitch,
const gl::PixelPackState &pack,
gl::Buffer *packPixels,
uint8_t *pixels) override;
angle::Result blitImpl(const gl::Context *context,
......
......@@ -613,12 +613,15 @@ angle::Result FramebufferGL::readPixels(const gl::Context *context,
const gl::Rectangle &area,
GLenum format,
GLenum type,
const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
void *pixels)
{
ContextGL *contextGL = GetImplAs<ContextGL>(context);
const FunctionsGL *functions = GetFunctionsGL(context);
StateManagerGL *stateManager = GetStateManagerGL(context);
const angle::FeaturesGL &features = GetFeaturesGL(context);
gl::PixelPackState packState = pack;
// Clip read area to framebuffer.
const auto *readAttachment = mState.getReadPixelsAttachment(format);
......@@ -631,10 +634,6 @@ angle::Result FramebufferGL::readPixels(const gl::Context *context,
return angle::Result::Continue;
}
PixelPackState packState = context->getState().getPackState();
const gl::Buffer *packBuffer =
context->getState().getTargetBuffer(gl::BufferBinding::PixelPack);
GLenum attachmentReadFormat =
readAttachment->getFormat().info->getReadPixelsFormat(context->getExtensions());
nativegl::ReadPixelsFormat readPixelsFormat =
......
......@@ -62,6 +62,8 @@ class FramebufferGL : public FramebufferImpl
const gl::Rectangle &area,
GLenum format,
GLenum type,
const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
void *pixels) override;
angle::Result blit(const gl::Context *context,
......
......@@ -64,6 +64,8 @@ class FramebufferMtl : public FramebufferImpl
const gl::Rectangle &area,
GLenum format,
GLenum type,
const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
void *pixels) override;
angle::Result blit(const gl::Context *context,
......
......@@ -150,6 +150,8 @@ angle::Result FramebufferMtl::readPixels(const gl::Context *context,
const gl::Rectangle &area,
GLenum format,
GLenum type,
const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
void *pixels)
{
// Clip read area to framebuffer.
......@@ -164,27 +166,25 @@ angle::Result FramebufferMtl::readPixels(const gl::Context *context,
}
gl::Rectangle flippedArea = getReadPixelArea(clippedArea);
ContextMtl *contextMtl = mtl::GetImpl(context);
const gl::State &glState = context->getState();
const gl::PixelPackState &packState = glState.getPackState();
ContextMtl *contextMtl = mtl::GetImpl(context);
const gl::InternalFormat &sizedFormatInfo = gl::GetInternalFormatInfo(format, type);
GLuint outputPitch = 0;
ANGLE_CHECK_GL_MATH(contextMtl,
sizedFormatInfo.computeRowPitch(type, area.width, packState.alignment,
packState.rowLength, &outputPitch));
sizedFormatInfo.computeRowPitch(type, area.width, pack.alignment,
pack.rowLength, &outputPitch));
GLuint outputSkipBytes = 0;
ANGLE_CHECK_GL_MATH(contextMtl, sizedFormatInfo.computeSkipBytes(
type, outputPitch, 0, packState, false, &outputSkipBytes));
ANGLE_CHECK_GL_MATH(contextMtl, sizedFormatInfo.computeSkipBytes(type, outputPitch, 0, pack,
false, &outputSkipBytes));
outputSkipBytes += (clippedArea.x - area.x) * sizedFormatInfo.pixelBytes +
(clippedArea.y - area.y) * outputPitch;
const angle::Format &angleFormat = GetFormatFromFormatType(format, type);
PackPixelsParams params(flippedArea, angleFormat, outputPitch, packState.reverseRowOrder,
glState.getTargetBuffer(gl::BufferBinding::PixelPack), 0);
PackPixelsParams params(flippedArea, angleFormat, outputPitch, pack.reverseRowOrder, packBuffer,
0);
if (mFlipY)
{
params.reverseRowOrder = !params.reverseRowOrder;
......
......@@ -86,11 +86,10 @@ angle::Result FramebufferNULL::readPixels(const gl::Context *context,
const gl::Rectangle &origArea,
GLenum format,
GLenum type,
const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
void *ptrOrOffset)
{
const gl::PixelPackState &packState = context->getState().getPackState();
gl::Buffer *packBuffer = context->getState().getTargetBuffer(gl::BufferBinding::PixelPack);
// Get the pointer to write to from the argument or the pack buffer
GLubyte *pixels = nullptr;
if (packBuffer != nullptr)
......@@ -120,13 +119,12 @@ angle::Result FramebufferNULL::readPixels(const gl::Context *context,
ContextNULL *contextNull = GetImplAs<ContextNULL>(context);
GLuint rowBytes = 0;
ANGLE_CHECK_GL_MATH(contextNull,
glFormat.computeRowPitch(type, origArea.width, packState.alignment,
packState.rowLength, &rowBytes));
ANGLE_CHECK_GL_MATH(contextNull, glFormat.computeRowPitch(type, origArea.width, pack.alignment,
pack.rowLength, &rowBytes));
GLuint skipBytes = 0;
ANGLE_CHECK_GL_MATH(contextNull,
glFormat.computeSkipBytes(type, rowBytes, 0, packState, false, &skipBytes));
glFormat.computeSkipBytes(type, rowBytes, 0, pack, false, &skipBytes));
pixels += skipBytes;
// Skip OOB region up to first in bounds pixel
......
......@@ -55,6 +55,8 @@ class FramebufferNULL : public FramebufferImpl
const gl::Rectangle &area,
GLenum format,
GLenum type,
const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
void *pixels) override;
angle::Result blit(const gl::Context *context,
......
......@@ -521,6 +521,8 @@ angle::Result FramebufferVk::readPixels(const gl::Context *context,
const gl::Rectangle &area,
GLenum format,
GLenum type,
const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
void *pixels)
{
// Clip read area to framebuffer.
......@@ -538,14 +540,10 @@ angle::Result FramebufferVk::readPixels(const gl::Context *context,
// Flush any deferred clears.
ANGLE_TRY(flushDeferredClears(contextVk, fbRect));
const gl::State &glState = contextVk->getState();
gl::Buffer *packBuffer = glState.getTargetBuffer(gl::BufferBinding::PixelPack);
GLuint outputSkipBytes = 0;
PackPixelsParams params;
ANGLE_TRY(vk::ImageHelper::GetReadPixelsParams(contextVk, glState.getPackState(), packBuffer,
format, type, area, clippedArea, &params,
&outputSkipBytes));
ANGLE_TRY(vk::ImageHelper::GetReadPixelsParams(contextVk, pack, packBuffer, format, type, area,
clippedArea, &params, &outputSkipBytes));
bool flipY = contextVk->isViewportFlipEnabledForReadFBO();
switch (params.rotation = contextVk->getRotationReadFramebuffer())
......
......@@ -75,6 +75,8 @@ class FramebufferVk : public FramebufferImpl
const gl::Rectangle &area,
GLenum format,
GLenum type,
const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
void *pixels) override;
angle::Result blit(const gl::Context *context,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment