Commit 86e0b7f7 by Jamie Madill Committed by Commit Bot

Clean up PackPixels.

BUG=angleproject:1455 Change-Id: I263719cc77ff80580a551683d062e862dee1bdab Reviewed-on: https://chromium-review.googlesource.com/365826Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent a5ac1e16
...@@ -3788,14 +3788,11 @@ gl::Error Renderer11::packPixels(const TextureHelper11 &textureHelper, ...@@ -3788,14 +3788,11 @@ gl::Error Renderer11::packPixels(const TextureHelper11 &textureHelper,
int inputPitch = static_cast<int>(mapping.RowPitch); int inputPitch = static_cast<int>(mapping.RowPitch);
const auto &angleFormatInfo = textureHelper.getFormatSet(); const auto &angleFormatInfo = textureHelper.getFormatSet();
ASSERT(angleFormatInfo.format.glInternalFormat != GL_NONE);
const gl::InternalFormat &sourceFormatInfo =
gl::GetInternalFormatInfo(angleFormatInfo.format.glInternalFormat);
const auto &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(textureHelper.getFormat()); const auto &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(textureHelper.getFormat());
ColorReadFunction colorReadFunction = angleFormatInfo.format.colorReadFunction; ASSERT(angleFormatInfo.format.glInternalFormat != GL_NONE);
PackPixels(params, sourceFormatInfo, dxgiFormatInfo.fastCopyFunctions, colorReadFunction, PackPixels(params, angleFormatInfo.format, dxgiFormatInfo.fastCopyFunctions, inputPitch, source,
inputPitch, source, pixelsOut); pixelsOut);
mDeviceContext->Unmap(readResource, 0); mDeviceContext->Unmap(readResource, 0);
......
...@@ -192,10 +192,7 @@ gl::Error Framebuffer9::readPixelsImpl(const gl::Rectangle &area, ...@@ -192,10 +192,7 @@ gl::Error Framebuffer9::readPixelsImpl(const gl::Rectangle &area,
int inputPitch = lock.Pitch; int inputPitch = lock.Pitch;
const d3d9::D3DFormat &d3dFormatInfo = d3d9::GetD3DFormatInfo(desc.Format); const d3d9::D3DFormat &d3dFormatInfo = d3d9::GetD3DFormatInfo(desc.Format);
const gl::InternalFormat &sourceFormatInfo =
gl::GetInternalFormatInfo(d3dFormatInfo.info->glInternalFormat);
gl::FormatType formatType(format, type); gl::FormatType formatType(format, type);
ColorReadFunction colorReadFunction = d3dFormatInfo.info->colorReadFunction;
// TODO(jmadill): Maybe we can avoid a copy of pack parameters here? // TODO(jmadill): Maybe we can avoid a copy of pack parameters here?
PackPixelsParams packParams; PackPixelsParams packParams;
...@@ -208,8 +205,8 @@ gl::Error Framebuffer9::readPixelsImpl(const gl::Rectangle &area, ...@@ -208,8 +205,8 @@ gl::Error Framebuffer9::readPixelsImpl(const gl::Rectangle &area,
packParams.outputPitch = static_cast<GLuint>(outputPitch); packParams.outputPitch = static_cast<GLuint>(outputPitch);
packParams.pack = pack; packParams.pack = pack;
PackPixels(packParams, sourceFormatInfo, d3dFormatInfo.fastCopyFunctions, colorReadFunction, PackPixels(packParams, *d3dFormatInfo.info, d3dFormatInfo.fastCopyFunctions, inputPitch, source,
inputPitch, source, pixels); pixels);
systemSurface->UnlockRect(); systemSurface->UnlockRect();
SafeRelease(systemSurface); SafeRelease(systemSurface);
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "image_util/imageformats.h" #include "image_util/imageformats.h"
#include "libANGLE/formatutils.h" #include "libANGLE/formatutils.h"
#include "libANGLE/renderer/Format.h"
#include <string.h> #include <string.h>
...@@ -170,9 +171,8 @@ PackPixelsParams::PackPixelsParams(const gl::Rectangle &areaIn, ...@@ -170,9 +171,8 @@ PackPixelsParams::PackPixelsParams(const gl::Rectangle &areaIn,
} }
void PackPixels(const PackPixelsParams &params, void PackPixels(const PackPixelsParams &params,
const gl::InternalFormat &sourceFormatInfo, const angle::Format &sourceFormat,
const FastCopyFunctionMap &fastCopyFunctionsMap, const FastCopyFunctionMap &fastCopyFunctionsMap,
ColorReadFunction colorReadFunction,
int inputPitchIn, int inputPitchIn,
const uint8_t *sourceIn, const uint8_t *sourceIn,
uint8_t *destWithoutOffset) uint8_t *destWithoutOffset)
...@@ -188,18 +188,20 @@ void PackPixels(const PackPixelsParams &params, ...@@ -188,18 +188,20 @@ void PackPixels(const PackPixelsParams &params,
inputPitch = -inputPitch; inputPitch = -inputPitch;
} }
if (sourceFormatInfo.format == params.format && sourceFormatInfo.type == params.type) const auto &sourceGLInfo = gl::GetInternalFormatInfo(sourceFormat.glInternalFormat);
if (sourceGLInfo.format == params.format && sourceGLInfo.type == params.type)
{ {
// Direct copy possible // Direct copy possible
for (int y = 0; y < params.area.height; ++y) for (int y = 0; y < params.area.height; ++y)
{ {
memcpy(destWithOffset + y * params.outputPitch, source + y * inputPitch, memcpy(destWithOffset + y * params.outputPitch, source + y * inputPitch,
params.area.width * sourceFormatInfo.pixelBytes); params.area.width * sourceGLInfo.pixelBytes);
} }
return; return;
} }
ASSERT(sourceFormatInfo.pixelBytes > 0); ASSERT(sourceGLInfo.pixelBytes > 0);
gl::FormatType formatType(params.format, params.type); gl::FormatType formatType(params.format, params.type);
ColorCopyFunction fastCopyFunc = GetFastCopyFunction(fastCopyFunctionsMap, formatType); ColorCopyFunction fastCopyFunc = GetFastCopyFunction(fastCopyFunctionsMap, formatType);
...@@ -215,7 +217,7 @@ void PackPixels(const PackPixelsParams &params, ...@@ -215,7 +217,7 @@ void PackPixels(const PackPixelsParams &params,
{ {
uint8_t *dest = uint8_t *dest =
destWithOffset + y * params.outputPitch + x * destFormatInfo.pixelBytes; destWithOffset + y * params.outputPitch + x * destFormatInfo.pixelBytes;
const uint8_t *src = source + y * inputPitch + x * sourceFormatInfo.pixelBytes; const uint8_t *src = source + y * inputPitch + x * sourceGLInfo.pixelBytes;
fastCopyFunc(src, dest); fastCopyFunc(src, dest);
} }
...@@ -231,12 +233,14 @@ void PackPixels(const PackPixelsParams &params, ...@@ -231,12 +233,14 @@ void PackPixels(const PackPixelsParams &params,
sizeof(temp) >= sizeof(gl::ColorI), sizeof(temp) >= sizeof(gl::ColorI),
"Unexpected size of gl::Color struct."); "Unexpected size of gl::Color struct.");
const auto &colorReadFunction = sourceFormat.colorReadFunction;
for (int y = 0; y < params.area.height; ++y) for (int y = 0; y < params.area.height; ++y)
{ {
for (int x = 0; x < params.area.width; ++x) for (int x = 0; x < params.area.width; ++x)
{ {
uint8_t *dest = destWithOffset + y * params.outputPitch + x * destFormatInfo.pixelBytes; uint8_t *dest = destWithOffset + y * params.outputPitch + x * destFormatInfo.pixelBytes;
const uint8_t *src = source + y * inputPitch + x * sourceFormatInfo.pixelBytes; const uint8_t *src = source + y * inputPitch + x * sourceGLInfo.pixelBytes;
// readFunc and writeFunc will be using the same type of color, CopyTexImage // readFunc and writeFunc will be using the same type of color, CopyTexImage
// will not allow the copy otherwise. // will not allow the copy otherwise.
......
...@@ -16,6 +16,11 @@ ...@@ -16,6 +16,11 @@
#include "libANGLE/angletypes.h" #include "libANGLE/angletypes.h"
namespace angle
{
struct Format;
}
namespace gl namespace gl
{ {
struct FormatType; struct FormatType;
...@@ -61,9 +66,8 @@ struct PackPixelsParams ...@@ -61,9 +66,8 @@ struct PackPixelsParams
}; };
void PackPixels(const PackPixelsParams &params, void PackPixels(const PackPixelsParams &params,
const gl::InternalFormat &sourceFormatInfo, const angle::Format &sourceFormat,
const FastCopyFunctionMap &fastCopyFunctionsMap, const FastCopyFunctionMap &fastCopyFunctionsMap,
ColorReadFunction colorReadFunction,
int inputPitch, int inputPitch,
const uint8_t *source, const uint8_t *source,
uint8_t *destination); uint8_t *destination);
......
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