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,
int inputPitch = static_cast<int>(mapping.RowPitch);
const auto &angleFormatInfo = textureHelper.getFormatSet();
const auto &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(textureHelper.getFormat());
ASSERT(angleFormatInfo.format.glInternalFormat != GL_NONE);
const gl::InternalFormat &sourceFormatInfo =
gl::GetInternalFormatInfo(angleFormatInfo.format.glInternalFormat);
const auto &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(textureHelper.getFormat());
ColorReadFunction colorReadFunction = angleFormatInfo.format.colorReadFunction;
PackPixels(params, sourceFormatInfo, dxgiFormatInfo.fastCopyFunctions, colorReadFunction,
inputPitch, source, pixelsOut);
PackPixels(params, angleFormatInfo.format, dxgiFormatInfo.fastCopyFunctions, inputPitch, source,
pixelsOut);
mDeviceContext->Unmap(readResource, 0);
......
......@@ -192,10 +192,7 @@ gl::Error Framebuffer9::readPixelsImpl(const gl::Rectangle &area,
int inputPitch = lock.Pitch;
const d3d9::D3DFormat &d3dFormatInfo = d3d9::GetD3DFormatInfo(desc.Format);
const gl::InternalFormat &sourceFormatInfo =
gl::GetInternalFormatInfo(d3dFormatInfo.info->glInternalFormat);
gl::FormatType formatType(format, type);
ColorReadFunction colorReadFunction = d3dFormatInfo.info->colorReadFunction;
// TODO(jmadill): Maybe we can avoid a copy of pack parameters here?
PackPixelsParams packParams;
......@@ -208,8 +205,8 @@ gl::Error Framebuffer9::readPixelsImpl(const gl::Rectangle &area,
packParams.outputPitch = static_cast<GLuint>(outputPitch);
packParams.pack = pack;
PackPixels(packParams, sourceFormatInfo, d3dFormatInfo.fastCopyFunctions, colorReadFunction,
inputPitch, source, pixels);
PackPixels(packParams, *d3dFormatInfo.info, d3dFormatInfo.fastCopyFunctions, inputPitch, source,
pixels);
systemSurface->UnlockRect();
SafeRelease(systemSurface);
......
......@@ -13,6 +13,7 @@
#include "image_util/imageformats.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/Format.h"
#include <string.h>
......@@ -170,9 +171,8 @@ PackPixelsParams::PackPixelsParams(const gl::Rectangle &areaIn,
}
void PackPixels(const PackPixelsParams &params,
const gl::InternalFormat &sourceFormatInfo,
const angle::Format &sourceFormat,
const FastCopyFunctionMap &fastCopyFunctionsMap,
ColorReadFunction colorReadFunction,
int inputPitchIn,
const uint8_t *sourceIn,
uint8_t *destWithoutOffset)
......@@ -188,18 +188,20 @@ void PackPixels(const PackPixelsParams &params,
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
for (int y = 0; y < params.area.height; ++y)
{
memcpy(destWithOffset + y * params.outputPitch, source + y * inputPitch,
params.area.width * sourceFormatInfo.pixelBytes);
params.area.width * sourceGLInfo.pixelBytes);
}
return;
}
ASSERT(sourceFormatInfo.pixelBytes > 0);
ASSERT(sourceGLInfo.pixelBytes > 0);
gl::FormatType formatType(params.format, params.type);
ColorCopyFunction fastCopyFunc = GetFastCopyFunction(fastCopyFunctionsMap, formatType);
......@@ -215,7 +217,7 @@ void PackPixels(const PackPixelsParams &params,
{
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;
fastCopyFunc(src, dest);
}
......@@ -231,12 +233,14 @@ void PackPixels(const PackPixelsParams &params,
sizeof(temp) >= sizeof(gl::ColorI),
"Unexpected size of gl::Color struct.");
const auto &colorReadFunction = sourceFormat.colorReadFunction;
for (int y = 0; y < params.area.height; ++y)
{
for (int x = 0; x < params.area.width; ++x)
{
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
// will not allow the copy otherwise.
......
......@@ -16,6 +16,11 @@
#include "libANGLE/angletypes.h"
namespace angle
{
struct Format;
}
namespace gl
{
struct FormatType;
......@@ -61,9 +66,8 @@ struct PackPixelsParams
};
void PackPixels(const PackPixelsParams &params,
const gl::InternalFormat &sourceFormatInfo,
const angle::Format &sourceFormat,
const FastCopyFunctionMap &fastCopyFunctionsMap,
ColorReadFunction colorReadFunction,
int inputPitch,
const uint8_t *source,
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