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, ...@@ -3765,7 +3765,9 @@ void Context::readPixels(GLint x,
ASSERT(readFBO); ASSERT(readFBO);
Rectangle area(x, y, width, height); 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, void Context::readPixelsRobust(GLint x,
......
...@@ -1635,14 +1635,15 @@ angle::Result Framebuffer::readPixels(const Context *context, ...@@ -1635,14 +1635,15 @@ angle::Result Framebuffer::readPixels(const Context *context,
const Rectangle &area, const Rectangle &area,
GLenum format, GLenum format,
GLenum type, GLenum type,
const PixelPackState &pack,
Buffer *packBuffer,
void *pixels) 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 (packBuffer)
if (unpackBuffer)
{ {
unpackBuffer->onDataChanged(); packBuffer->onDataChanged();
} }
return angle::Result::Continue; return angle::Result::Continue;
......
...@@ -356,6 +356,8 @@ class Framebuffer final : public angle::ObserverInterface, ...@@ -356,6 +356,8 @@ class Framebuffer final : public angle::ObserverInterface,
const Rectangle &area, const Rectangle &area,
GLenum format, GLenum format,
GLenum type, GLenum type,
const PixelPackState &pack,
Buffer *packBuffer,
void *pixels); void *pixels);
angle::Result blit(const Context *context, angle::Result blit(const Context *context,
......
...@@ -16,10 +16,12 @@ ...@@ -16,10 +16,12 @@
namespace gl namespace gl
{ {
class State; class Buffer;
class Framebuffer; class Framebuffer;
class FramebufferAttachment; class FramebufferAttachment;
struct PixelPackState;
struct Rectangle; struct Rectangle;
class State;
} // namespace gl } // namespace gl
namespace rx namespace rx
...@@ -69,6 +71,8 @@ class FramebufferImpl : angle::NonCopyable ...@@ -69,6 +71,8 @@ class FramebufferImpl : angle::NonCopyable
const gl::Rectangle &area, const gl::Rectangle &area,
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
void *pixels) = 0; void *pixels) = 0;
virtual angle::Result blit(const gl::Context *context, virtual angle::Result blit(const gl::Context *context,
......
...@@ -34,8 +34,14 @@ class MockFramebufferImpl : public rx::FramebufferImpl ...@@ -34,8 +34,14 @@ class MockFramebufferImpl : public rx::FramebufferImpl
MOCK_METHOD4(clearBufferiv, angle::Result(const gl::Context *, GLenum, GLint, const GLint *)); 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(clearBufferfi, angle::Result(const gl::Context *, GLenum, GLint, GLfloat, GLint));
MOCK_METHOD5(readPixels, MOCK_METHOD7(readPixels,
angle::Result(const gl::Context *, const gl::Rectangle &, GLenum, GLenum, void *)); 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 *)); MOCK_CONST_METHOD3(getSamplePosition, angle::Result(const gl::Context *, size_t, GLfloat *));
......
...@@ -200,6 +200,8 @@ angle::Result FramebufferD3D::readPixels(const gl::Context *context, ...@@ -200,6 +200,8 @@ angle::Result FramebufferD3D::readPixels(const gl::Context *context,
const gl::Rectangle &area, const gl::Rectangle &area,
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
void *pixels) void *pixels)
{ {
// Clip read area to framebuffer. // Clip read area to framebuffer.
...@@ -212,24 +214,22 @@ angle::Result FramebufferD3D::readPixels(const gl::Context *context, ...@@ -212,24 +214,22 @@ angle::Result FramebufferD3D::readPixels(const gl::Context *context,
return angle::Result::Continue; return angle::Result::Continue;
} }
const gl::PixelPackState &packState = context->getState().getPackState();
const gl::InternalFormat &sizedFormatInfo = gl::GetInternalFormatInfo(format, type); const gl::InternalFormat &sizedFormatInfo = gl::GetInternalFormatInfo(format, type);
ContextD3D *contextD3D = GetImplAs<ContextD3D>(context); ContextD3D *contextD3D = GetImplAs<ContextD3D>(context);
GLuint outputPitch = 0; GLuint outputPitch = 0;
ANGLE_CHECK_GL_MATH(contextD3D, ANGLE_CHECK_GL_MATH(contextD3D,
sizedFormatInfo.computeRowPitch(type, area.width, packState.alignment, sizedFormatInfo.computeRowPitch(type, area.width, pack.alignment,
packState.rowLength, &outputPitch)); pack.rowLength, &outputPitch));
GLuint outputSkipBytes = 0; GLuint outputSkipBytes = 0;
ANGLE_CHECK_GL_MATH(contextD3D, sizedFormatInfo.computeSkipBytes( ANGLE_CHECK_GL_MATH(contextD3D, sizedFormatInfo.computeSkipBytes(type, outputPitch, 0, pack,
type, outputPitch, 0, packState, false, &outputSkipBytes)); false, &outputSkipBytes));
outputSkipBytes += (clippedArea.x - area.x) * sizedFormatInfo.pixelBytes + outputSkipBytes += (clippedArea.x - area.x) * sizedFormatInfo.pixelBytes +
(clippedArea.y - area.y) * outputPitch; (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); static_cast<uint8_t *>(pixels) + outputSkipBytes);
} }
......
...@@ -82,6 +82,8 @@ class FramebufferD3D : public FramebufferImpl ...@@ -82,6 +82,8 @@ class FramebufferD3D : public FramebufferImpl
const gl::Rectangle &area, const gl::Rectangle &area,
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
void *pixels) override; void *pixels) override;
angle::Result blit(const gl::Context *context, angle::Result blit(const gl::Context *context,
...@@ -115,6 +117,7 @@ class FramebufferD3D : public FramebufferImpl ...@@ -115,6 +117,7 @@ class FramebufferD3D : public FramebufferImpl
GLenum type, GLenum type,
size_t outputPitch, size_t outputPitch,
const gl::PixelPackState &pack, const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
uint8_t *pixels) = 0; uint8_t *pixels) = 0;
virtual angle::Result blitImpl(const gl::Context *context, virtual angle::Result blitImpl(const gl::Context *context,
......
...@@ -252,12 +252,12 @@ angle::Result Framebuffer11::readPixelsImpl(const gl::Context *context, ...@@ -252,12 +252,12 @@ angle::Result Framebuffer11::readPixelsImpl(const gl::Context *context,
GLenum type, GLenum type,
size_t outputPitch, size_t outputPitch,
const gl::PixelPackState &pack, const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
uint8_t *pixels) uint8_t *pixels)
{ {
const gl::FramebufferAttachment *readAttachment = mState.getReadPixelsAttachment(format); const gl::FramebufferAttachment *readAttachment = mState.getReadPixelsAttachment(format);
ASSERT(readAttachment); ASSERT(readAttachment);
gl::Buffer *packBuffer = context->getState().getTargetBuffer(gl::BufferBinding::PixelPack);
if (packBuffer != nullptr) if (packBuffer != nullptr)
{ {
Buffer11 *packBufferStorage = GetImplAs<Buffer11>(packBuffer); Buffer11 *packBufferStorage = GetImplAs<Buffer11>(packBuffer);
......
...@@ -70,6 +70,7 @@ class Framebuffer11 : public FramebufferD3D ...@@ -70,6 +70,7 @@ class Framebuffer11 : public FramebufferD3D
GLenum type, GLenum type,
size_t outputPitch, size_t outputPitch,
const gl::PixelPackState &pack, const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
uint8_t *pixels) override; uint8_t *pixels) override;
angle::Result blitImpl(const gl::Context *context, angle::Result blitImpl(const gl::Context *context,
......
...@@ -82,6 +82,7 @@ angle::Result Framebuffer9::readPixelsImpl(const gl::Context *context, ...@@ -82,6 +82,7 @@ angle::Result Framebuffer9::readPixelsImpl(const gl::Context *context,
GLenum type, GLenum type,
size_t outputPitch, size_t outputPitch,
const gl::PixelPackState &pack, const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
uint8_t *pixels) uint8_t *pixels)
{ {
const gl::FramebufferAttachment *colorbuffer = mState.getColorAttachment(0); const gl::FramebufferAttachment *colorbuffer = mState.getColorAttachment(0);
......
...@@ -65,6 +65,7 @@ class Framebuffer9 : public FramebufferD3D ...@@ -65,6 +65,7 @@ class Framebuffer9 : public FramebufferD3D
GLenum type, GLenum type,
size_t outputPitch, size_t outputPitch,
const gl::PixelPackState &pack, const gl::PixelPackState &pack,
gl::Buffer *packPixels,
uint8_t *pixels) override; uint8_t *pixels) override;
angle::Result blitImpl(const gl::Context *context, angle::Result blitImpl(const gl::Context *context,
......
...@@ -613,12 +613,15 @@ angle::Result FramebufferGL::readPixels(const gl::Context *context, ...@@ -613,12 +613,15 @@ angle::Result FramebufferGL::readPixels(const gl::Context *context,
const gl::Rectangle &area, const gl::Rectangle &area,
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
void *pixels) void *pixels)
{ {
ContextGL *contextGL = GetImplAs<ContextGL>(context); ContextGL *contextGL = GetImplAs<ContextGL>(context);
const FunctionsGL *functions = GetFunctionsGL(context); const FunctionsGL *functions = GetFunctionsGL(context);
StateManagerGL *stateManager = GetStateManagerGL(context); StateManagerGL *stateManager = GetStateManagerGL(context);
const angle::FeaturesGL &features = GetFeaturesGL(context); const angle::FeaturesGL &features = GetFeaturesGL(context);
gl::PixelPackState packState = pack;
// Clip read area to framebuffer. // Clip read area to framebuffer.
const auto *readAttachment = mState.getReadPixelsAttachment(format); const auto *readAttachment = mState.getReadPixelsAttachment(format);
...@@ -631,10 +634,6 @@ angle::Result FramebufferGL::readPixels(const gl::Context *context, ...@@ -631,10 +634,6 @@ angle::Result FramebufferGL::readPixels(const gl::Context *context,
return angle::Result::Continue; return angle::Result::Continue;
} }
PixelPackState packState = context->getState().getPackState();
const gl::Buffer *packBuffer =
context->getState().getTargetBuffer(gl::BufferBinding::PixelPack);
GLenum attachmentReadFormat = GLenum attachmentReadFormat =
readAttachment->getFormat().info->getReadPixelsFormat(context->getExtensions()); readAttachment->getFormat().info->getReadPixelsFormat(context->getExtensions());
nativegl::ReadPixelsFormat readPixelsFormat = nativegl::ReadPixelsFormat readPixelsFormat =
......
...@@ -62,6 +62,8 @@ class FramebufferGL : public FramebufferImpl ...@@ -62,6 +62,8 @@ class FramebufferGL : public FramebufferImpl
const gl::Rectangle &area, const gl::Rectangle &area,
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
void *pixels) override; void *pixels) override;
angle::Result blit(const gl::Context *context, angle::Result blit(const gl::Context *context,
......
...@@ -64,6 +64,8 @@ class FramebufferMtl : public FramebufferImpl ...@@ -64,6 +64,8 @@ class FramebufferMtl : public FramebufferImpl
const gl::Rectangle &area, const gl::Rectangle &area,
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
void *pixels) override; void *pixels) override;
angle::Result blit(const gl::Context *context, angle::Result blit(const gl::Context *context,
......
...@@ -150,6 +150,8 @@ angle::Result FramebufferMtl::readPixels(const gl::Context *context, ...@@ -150,6 +150,8 @@ angle::Result FramebufferMtl::readPixels(const gl::Context *context,
const gl::Rectangle &area, const gl::Rectangle &area,
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
void *pixels) void *pixels)
{ {
// Clip read area to framebuffer. // Clip read area to framebuffer.
...@@ -164,27 +166,25 @@ angle::Result FramebufferMtl::readPixels(const gl::Context *context, ...@@ -164,27 +166,25 @@ angle::Result FramebufferMtl::readPixels(const gl::Context *context,
} }
gl::Rectangle flippedArea = getReadPixelArea(clippedArea); gl::Rectangle flippedArea = getReadPixelArea(clippedArea);
ContextMtl *contextMtl = mtl::GetImpl(context); ContextMtl *contextMtl = mtl::GetImpl(context);
const gl::State &glState = context->getState();
const gl::PixelPackState &packState = glState.getPackState();
const gl::InternalFormat &sizedFormatInfo = gl::GetInternalFormatInfo(format, type); const gl::InternalFormat &sizedFormatInfo = gl::GetInternalFormatInfo(format, type);
GLuint outputPitch = 0; GLuint outputPitch = 0;
ANGLE_CHECK_GL_MATH(contextMtl, ANGLE_CHECK_GL_MATH(contextMtl,
sizedFormatInfo.computeRowPitch(type, area.width, packState.alignment, sizedFormatInfo.computeRowPitch(type, area.width, pack.alignment,
packState.rowLength, &outputPitch)); pack.rowLength, &outputPitch));
GLuint outputSkipBytes = 0; GLuint outputSkipBytes = 0;
ANGLE_CHECK_GL_MATH(contextMtl, sizedFormatInfo.computeSkipBytes( ANGLE_CHECK_GL_MATH(contextMtl, sizedFormatInfo.computeSkipBytes(type, outputPitch, 0, pack,
type, outputPitch, 0, packState, false, &outputSkipBytes)); false, &outputSkipBytes));
outputSkipBytes += (clippedArea.x - area.x) * sizedFormatInfo.pixelBytes + outputSkipBytes += (clippedArea.x - area.x) * sizedFormatInfo.pixelBytes +
(clippedArea.y - area.y) * outputPitch; (clippedArea.y - area.y) * outputPitch;
const angle::Format &angleFormat = GetFormatFromFormatType(format, type); const angle::Format &angleFormat = GetFormatFromFormatType(format, type);
PackPixelsParams params(flippedArea, angleFormat, outputPitch, packState.reverseRowOrder, PackPixelsParams params(flippedArea, angleFormat, outputPitch, pack.reverseRowOrder, packBuffer,
glState.getTargetBuffer(gl::BufferBinding::PixelPack), 0); 0);
if (mFlipY) if (mFlipY)
{ {
params.reverseRowOrder = !params.reverseRowOrder; params.reverseRowOrder = !params.reverseRowOrder;
......
...@@ -86,11 +86,10 @@ angle::Result FramebufferNULL::readPixels(const gl::Context *context, ...@@ -86,11 +86,10 @@ angle::Result FramebufferNULL::readPixels(const gl::Context *context,
const gl::Rectangle &origArea, const gl::Rectangle &origArea,
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
void *ptrOrOffset) 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 // Get the pointer to write to from the argument or the pack buffer
GLubyte *pixels = nullptr; GLubyte *pixels = nullptr;
if (packBuffer != nullptr) if (packBuffer != nullptr)
...@@ -120,13 +119,12 @@ angle::Result FramebufferNULL::readPixels(const gl::Context *context, ...@@ -120,13 +119,12 @@ angle::Result FramebufferNULL::readPixels(const gl::Context *context,
ContextNULL *contextNull = GetImplAs<ContextNULL>(context); ContextNULL *contextNull = GetImplAs<ContextNULL>(context);
GLuint rowBytes = 0; GLuint rowBytes = 0;
ANGLE_CHECK_GL_MATH(contextNull, ANGLE_CHECK_GL_MATH(contextNull, glFormat.computeRowPitch(type, origArea.width, pack.alignment,
glFormat.computeRowPitch(type, origArea.width, packState.alignment, pack.rowLength, &rowBytes));
packState.rowLength, &rowBytes));
GLuint skipBytes = 0; GLuint skipBytes = 0;
ANGLE_CHECK_GL_MATH(contextNull, ANGLE_CHECK_GL_MATH(contextNull,
glFormat.computeSkipBytes(type, rowBytes, 0, packState, false, &skipBytes)); glFormat.computeSkipBytes(type, rowBytes, 0, pack, false, &skipBytes));
pixels += skipBytes; pixels += skipBytes;
// Skip OOB region up to first in bounds pixel // Skip OOB region up to first in bounds pixel
......
...@@ -55,6 +55,8 @@ class FramebufferNULL : public FramebufferImpl ...@@ -55,6 +55,8 @@ class FramebufferNULL : public FramebufferImpl
const gl::Rectangle &area, const gl::Rectangle &area,
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
void *pixels) override; void *pixels) override;
angle::Result blit(const gl::Context *context, angle::Result blit(const gl::Context *context,
......
...@@ -521,6 +521,8 @@ angle::Result FramebufferVk::readPixels(const gl::Context *context, ...@@ -521,6 +521,8 @@ angle::Result FramebufferVk::readPixels(const gl::Context *context,
const gl::Rectangle &area, const gl::Rectangle &area,
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
void *pixels) void *pixels)
{ {
// Clip read area to framebuffer. // Clip read area to framebuffer.
...@@ -538,14 +540,10 @@ angle::Result FramebufferVk::readPixels(const gl::Context *context, ...@@ -538,14 +540,10 @@ angle::Result FramebufferVk::readPixels(const gl::Context *context,
// Flush any deferred clears. // Flush any deferred clears.
ANGLE_TRY(flushDeferredClears(contextVk, fbRect)); ANGLE_TRY(flushDeferredClears(contextVk, fbRect));
const gl::State &glState = contextVk->getState();
gl::Buffer *packBuffer = glState.getTargetBuffer(gl::BufferBinding::PixelPack);
GLuint outputSkipBytes = 0; GLuint outputSkipBytes = 0;
PackPixelsParams params; PackPixelsParams params;
ANGLE_TRY(vk::ImageHelper::GetReadPixelsParams(contextVk, glState.getPackState(), packBuffer, ANGLE_TRY(vk::ImageHelper::GetReadPixelsParams(contextVk, pack, packBuffer, format, type, area,
format, type, area, clippedArea, &params, clippedArea, &params, &outputSkipBytes));
&outputSkipBytes));
bool flipY = contextVk->isViewportFlipEnabledForReadFBO(); bool flipY = contextVk->isViewportFlipEnabledForReadFBO();
switch (params.rotation = contextVk->getRotationReadFramebuffer()) switch (params.rotation = contextVk->getRotationReadFramebuffer())
......
...@@ -75,6 +75,8 @@ class FramebufferVk : public FramebufferImpl ...@@ -75,6 +75,8 @@ class FramebufferVk : public FramebufferImpl
const gl::Rectangle &area, const gl::Rectangle &area,
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelPackState &pack,
gl::Buffer *packBuffer,
void *pixels) override; void *pixels) override;
angle::Result blit(const gl::Context *context, 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