Commit d2b50a0b by Jamie Madill Committed by Commit Bot

Move ReadPixels logic to helper methods.

These routines were pretty much duplicated between D3D9 and D3D11. Since I was going to have to rewrite them again for Vulkan, I figured it would be best to move them into a common location and clean them up a bit. BUG=angleproject:1319 Change-Id: I15d39b052daf3e1020dbd0880f01ae84f3686a0a Reviewed-on: https://chromium-review.googlesource.com/349630Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 6e4d1d21
......@@ -20,14 +20,28 @@ namespace gl
// can decide the true, sized, internal format. The ES2FormatMap determines the internal format for all valid
// format and type combinations.
typedef std::pair<GLenum, GLenum> FormatTypePair;
typedef std::pair<FormatTypePair, GLenum> FormatPair;
typedef std::map<FormatTypePair, GLenum> FormatMap;
typedef std::pair<FormatType, GLenum> FormatPair;
typedef std::map<FormatType, GLenum> FormatMap;
FormatType::FormatType() : format(GL_NONE), type(GL_NONE)
{
}
FormatType::FormatType(GLenum format_, GLenum type_) : format(format_), type(type_)
{
}
bool FormatType::operator<(const FormatType &other) const
{
if (format != other.format)
return format < other.format;
return type < other.type;
}
// A helper function to insert data into the format map with fewer characters.
static inline void InsertFormatMapping(FormatMap *map, GLenum format, GLenum type, GLenum internalFormat)
{
map->insert(FormatPair(FormatTypePair(format, type), internalFormat));
map->insert(FormatPair(FormatType(format, type), internalFormat));
}
FormatMap BuildFormatMap()
......@@ -799,7 +813,7 @@ GLenum GetSizedInternalFormat(GLenum internalFormat, GLenum type)
}
static const FormatMap formatMap = BuildFormatMap();
auto iter = formatMap.find(FormatTypePair(internalFormat, type));
auto iter = formatMap.find(FormatType(internalFormat, type));
if (iter != formatMap.end())
{
return iter->second;
......
......@@ -20,6 +20,19 @@
namespace gl
{
struct FormatType final
{
FormatType();
FormatType(GLenum format_, GLenum type_);
FormatType(const FormatType &other) = default;
FormatType &operator=(const FormatType &other) = default;
bool operator<(const FormatType &other) const;
GLenum format;
GLenum type;
};
struct Type
{
Type();
......
......@@ -6,17 +6,17 @@
// copyimage.cpp: Defines image copying functions
#include "libANGLE/renderer/d3d/copyimage.h"
#include "libANGLE/renderer/copyimage.h"
namespace rx
{
void CopyBGRA8ToRGBA8(const uint8_t *source, uint8_t *dest)
{
uint32_t argb = *reinterpret_cast<const uint32_t*>(source);
*reinterpret_cast<uint32_t*>(dest) = (argb & 0xFF00FF00) | // Keep alpha and green
(argb & 0x00FF0000) >> 16 | // Move red to blue
(argb & 0x000000FF) << 16; // Move blue to red
uint32_t argb = *reinterpret_cast<const uint32_t *>(source);
*reinterpret_cast<uint32_t *>(dest) = (argb & 0xFF00FF00) | // Keep alpha and green
(argb & 0x00FF0000) >> 16 | // Move red to blue
(argb & 0x000000FF) << 16; // Move blue to red
}
}
} // namespace rx
......@@ -28,8 +28,8 @@ void CopyPixel(const uint8_t *source, uint8_t *dest);
void CopyBGRA8ToRGBA8(const uint8_t *source, uint8_t *dest);
}
} // namespace rx
#include "copyimage.inl"
#endif // LIBANGLE_RENDERER_D3D_COPYIMAGE_H_
#endif // LIBANGLE_RENDERER_D3D_COPYIMAGE_H_
......@@ -11,6 +11,7 @@
#include <memory>
#include "common/MemoryBuffer.h"
#include "libANGLE/renderer/renderer_utils.h"
#include "libANGLE/renderer/d3d/IndexDataManager.h"
#include "libANGLE/renderer/d3d/VertexDataManager.h"
#include "libANGLE/renderer/d3d/d3d11/Renderer11.h"
......@@ -39,27 +40,6 @@ enum class CopyResult
} // anonymous namespace
PackPixelsParams::PackPixelsParams()
: format(GL_NONE), type(GL_NONE), outputPitch(0), packBuffer(nullptr), offset(0)
{
}
PackPixelsParams::PackPixelsParams(const gl::Rectangle &areaIn,
GLenum formatIn,
GLenum typeIn,
GLuint outputPitchIn,
const gl::PixelPackState &packIn,
ptrdiff_t offsetIn)
: area(areaIn),
format(formatIn),
type(typeIn),
outputPitch(outputPitchIn),
packBuffer(packIn.pixelBuffer.get()),
pack(packIn.alignment, packIn.reverseRowOrder),
offset(offsetIn)
{
}
namespace gl_d3d11
{
......
......@@ -22,6 +22,7 @@ class FramebufferAttachment;
namespace rx
{
struct PackPixelsParams;
class Renderer11;
struct SourceIndexData;
struct TranslatedAttribute;
......@@ -40,21 +41,6 @@ enum BufferUsage
BUFFER_USAGE_COUNT,
};
struct PackPixelsParams
{
PackPixelsParams();
PackPixelsParams(const gl::Rectangle &area, GLenum format, GLenum type, GLuint outputPitch,
const gl::PixelPackState &pack, ptrdiff_t offset);
gl::Rectangle area;
GLenum format;
GLenum type;
GLuint outputPitch;
gl::Buffer *packBuffer;
gl::PixelPackState pack;
ptrdiff_t offset;
};
typedef size_t DataRevision;
class Buffer11 : public BufferD3D
......
......@@ -21,6 +21,7 @@
#include "libANGLE/FramebufferAttachment.h"
#include "libANGLE/histogram_macros.h"
#include "libANGLE/Program.h"
#include "libANGLE/renderer/renderer_utils.h"
#include "libANGLE/renderer/d3d/CompilerD3D.h"
#include "libANGLE/renderer/d3d/d3d11/Blit11.h"
#include "libANGLE/renderer/d3d/d3d11/Buffer11.h"
......@@ -3756,79 +3757,17 @@ gl::Error Renderer11::packPixels(const TextureHelper11 &textureHelper,
return gl::Error(GL_OUT_OF_MEMORY, "Failed to map internal texture for reading, result: 0x%X.", hr);
}
uint8_t *source;
int inputPitch;
if (params.pack.reverseRowOrder)
{
source = static_cast<uint8_t*>(mapping.pData) + mapping.RowPitch * (params.area.height - 1);
inputPitch = -static_cast<int>(mapping.RowPitch);
}
else
{
source = static_cast<uint8_t*>(mapping.pData);
inputPitch = static_cast<int>(mapping.RowPitch);
}
uint8_t *source = static_cast<uint8_t *>(mapping.pData);
int inputPitch = static_cast<int>(mapping.RowPitch);
const auto &angleFormatInfo = d3d11::GetANGLEFormatSet(textureHelper.getANGLEFormat());
const gl::InternalFormat &sourceFormatInfo =
gl::GetInternalFormatInfo(angleFormatInfo.glInternalFormat);
if (sourceFormatInfo.format == params.format && sourceFormatInfo.type == params.type)
{
uint8_t *dest = pixelsOut + params.offset;
for (int y = 0; y < params.area.height; y++)
{
memcpy(dest + y * params.outputPitch, source + y * inputPitch, params.area.width * sourceFormatInfo.pixelBytes);
}
}
else
{
const d3d11::DXGIFormat &dxgiFormatInfo =
d3d11::GetDXGIFormatInfo(textureHelper.getFormat());
ColorCopyFunction fastCopyFunc =
dxgiFormatInfo.getFastCopyFunction(params.format, params.type);
GLenum sizedDestInternalFormat = gl::GetSizedInternalFormat(params.format, params.type);
const gl::InternalFormat &destFormatInfo = gl::GetInternalFormatInfo(sizedDestInternalFormat);
if (fastCopyFunc)
{
// Fast copy is possible through some special function
for (int y = 0; y < params.area.height; y++)
{
for (int x = 0; x < params.area.width; x++)
{
uint8_t *dest = pixelsOut + params.offset + y * params.outputPitch + x * destFormatInfo.pixelBytes;
const uint8_t *src = source + y * inputPitch + x * sourceFormatInfo.pixelBytes;
const auto &dxgiFormatInfo = d3d11::GetDXGIFormatInfo(textureHelper.getFormat());
ColorReadFunction colorReadFunction = angleFormatInfo.colorReadFunction;
fastCopyFunc(src, dest);
}
}
}
else
{
ColorReadFunction colorReadFunction = angleFormatInfo.colorReadFunction;
ColorWriteFunction colorWriteFunction = GetColorWriteFunction(params.format, params.type);
uint8_t temp[16]; // Maximum size of any Color<T> type used.
static_assert(sizeof(temp) >= sizeof(gl::ColorF) &&
sizeof(temp) >= sizeof(gl::ColorUI) &&
sizeof(temp) >= sizeof(gl::ColorI),
"Unexpected size of gl::Color struct.");
for (int y = 0; y < params.area.height; y++)
{
for (int x = 0; x < params.area.width; x++)
{
uint8_t *dest = pixelsOut + params.offset + y * params.outputPitch + x * destFormatInfo.pixelBytes;
const uint8_t *src = source + y * inputPitch + x * sourceFormatInfo.pixelBytes;
// readFunc and writeFunc will be using the same type of color, CopyTexImage
// will not allow the copy otherwise.
colorReadFunction(src, temp);
colorWriteFunction(temp, dest);
}
}
}
}
PackPixels(params, sourceFormatInfo, dxgiFormatInfo.fastCopyFunctions, colorReadFunction,
inputPitch, source, pixelsOut);
mDeviceContext->Unmap(readResource, 0);
......
......@@ -10,7 +10,7 @@
#include "libANGLE/renderer/d3d/d3d11/formatutils11.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/d3d/copyimage.h"
#include "libANGLE/renderer/copyimage.h"
#include "libANGLE/renderer/d3d/d3d11/copyvertex.h"
#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
#include "libANGLE/renderer/d3d/d3d11/Renderer11.h"
......@@ -39,15 +39,25 @@ struct D3D11FastCopyFormat
}
};
typedef std::multimap<DXGI_FORMAT, D3D11FastCopyFormat> D3D11FastCopyMap;
static D3D11FastCopyMap BuildFastCopyMap()
static const FastCopyFunctionMap &GetFastCopyFunctionMap(DXGI_FORMAT dxgiFormat)
{
D3D11FastCopyMap map;
map.insert(std::make_pair(DXGI_FORMAT_B8G8R8A8_UNORM, D3D11FastCopyFormat(GL_RGBA, GL_UNSIGNED_BYTE, CopyBGRA8ToRGBA8)));
return map;
switch (dxgiFormat)
{
case DXGI_FORMAT_B8G8R8A8_UNORM:
{
static FastCopyFunctionMap fastCopyMap;
if (fastCopyMap.empty())
{
fastCopyMap[gl::FormatType(GL_RGBA, GL_UNSIGNED_BYTE)] = CopyBGRA8ToRGBA8;
}
return fastCopyMap;
}
default:
{
static FastCopyFunctionMap emptyMap;
return emptyMap;
}
}
}
struct DXGIColorFormatInfo
......@@ -225,12 +235,6 @@ static bool RequiresFeatureLevel(D3D_FEATURE_LEVEL featureLevel)
return featureLevel >= requiredFeatureLevel;
}
ColorCopyFunction DXGIFormat::getFastCopyFunction(GLenum format, GLenum type) const
{
FastCopyFunctionMap::const_iterator iter = fastCopyFunctions.find(std::make_pair(format, type));
return (iter != fastCopyFunctions.end()) ? iter->second : NULL;
}
void AddDXGIFormat(DXGIFormatInfoMap *map,
DXGI_FORMAT dxgiFormat,
GLenum componentType,
......@@ -260,14 +264,7 @@ void AddDXGIFormat(DXGIFormatInfoMap *map,
}
info.componentType = componentType;
static const D3D11FastCopyMap fastCopyMap = BuildFastCopyMap();
std::pair<D3D11FastCopyMap::const_iterator, D3D11FastCopyMap::const_iterator> fastCopyIter = fastCopyMap.equal_range(dxgiFormat);
for (D3D11FastCopyMap::const_iterator i = fastCopyIter.first; i != fastCopyIter.second; i++)
{
info.fastCopyFunctions.insert(std::make_pair(std::make_pair(i->second.destFormat, i->second.destType), i->second.copyFunction));
}
info.fastCopyFunctions = GetFastCopyFunctionMap(dxgiFormat);
info.nativeMipmapSupport = nativeMipmapSupport;
map->insert(std::make_pair(dxgiFormat, info));
......
......@@ -15,6 +15,7 @@
#include "common/platform.h"
#include "libANGLE/angletypes.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/renderer_utils.h"
#include "libANGLE/renderer/d3d/formatutilsD3D.h"
namespace rx
......@@ -24,7 +25,6 @@ struct Renderer11DeviceCaps;
namespace d3d11
{
typedef std::map<std::pair<GLenum, GLenum>, ColorCopyFunction> FastCopyFunctionMap;
typedef bool (*NativeMipmapGenerationSupportFunction)(D3D_FEATURE_LEVEL);
struct DXGIFormat
......@@ -45,8 +45,6 @@ struct DXGIFormat
FastCopyFunctionMap fastCopyFunctions;
NativeMipmapGenerationSupportFunction nativeMipmapSupport;
ColorCopyFunction getFastCopyFunction(GLenum format, GLenum type) const;
};
// This structure is problematic because a resource is associated with multiple DXGI formats.
......
......@@ -7,6 +7,7 @@
# Code generation for texture format map
#
from datetime import date
import json
import math
import pprint
......@@ -39,7 +40,7 @@ enum ANGLEFormat
template_texture_format_table_autogen_cpp = """// GENERATED FILE - DO NOT EDIT.
// Generated by gen_texture_format_table.py using data from texture_format_data.json
//
// Copyright 2015 The ANGLE Project Authors. All rights reserved.
// Copyright {copyright_year} The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
......@@ -49,10 +50,10 @@ template_texture_format_table_autogen_cpp = """// GENERATED FILE - DO NOT EDIT.
#include "libANGLE/renderer/d3d/d3d11/texture_format_table.h"
#include "libANGLE/renderer/copyimage.h"
#include "libANGLE/renderer/d3d/d3d11/formatutils11.h"
#include "libANGLE/renderer/d3d/d3d11/load_functions_table.h"
#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
#include "libANGLE/renderer/d3d/copyimage.h"
#include "libANGLE/renderer/d3d/generatemip.h"
#include "libANGLE/renderer/d3d/loadimage.h"
......@@ -516,6 +517,7 @@ with open('texture_format_map.json') as texture_format_map_file:
texture_format_cases = parse_json_into_switch_texture_format_string(json_map, json_data)
angle_format_cases = parse_json_into_switch_angle_format_string(json_data)
output_cpp = template_texture_format_table_autogen_cpp.format(
copyright_year=date.today().year,
texture_format_info_cases=texture_format_cases,
angle_format_info_cases=angle_format_cases)
with open('texture_format_table_autogen.cpp', 'wt') as out_file:
......
......@@ -14,6 +14,7 @@
#include "common/angleutils.h"
#include "common/platform.h"
#include "libANGLE/renderer/renderer_utils.h"
#include "libANGLE/renderer/d3d/formatutilsD3D.h"
#include "libANGLE/renderer/d3d/d3d11/texture_format_table_autogen.h"
......
// GENERATED FILE - DO NOT EDIT.
// Generated by gen_texture_format_table.py using data from texture_format_data.json
//
// Copyright 2015 The ANGLE Project Authors. All rights reserved.
// Copyright 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
......@@ -11,10 +11,10 @@
#include "libANGLE/renderer/d3d/d3d11/texture_format_table.h"
#include "libANGLE/renderer/copyimage.h"
#include "libANGLE/renderer/d3d/d3d11/formatutils11.h"
#include "libANGLE/renderer/d3d/d3d11/load_functions_table.h"
#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
#include "libANGLE/renderer/d3d/copyimage.h"
#include "libANGLE/renderer/d3d/generatemip.h"
#include "libANGLE/renderer/d3d/loadimage.h"
......
......@@ -13,6 +13,7 @@
#include "libANGLE/Texture.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/ContextImpl.h"
#include "libANGLE/renderer/renderer_utils.h"
#include "libANGLE/renderer/d3d/TextureD3D.h"
#include "libANGLE/renderer/d3d/d3d9/Renderer9.h"
#include "libANGLE/renderer/d3d/d3d9/RenderTarget9.h"
......@@ -187,72 +188,27 @@ gl::Error Framebuffer9::readPixelsImpl(const gl::Rectangle &area,
return gl::Error(GL_OUT_OF_MEMORY, "Failed to lock internal render target.");
}
uint8_t *source;
int inputPitch;
if (pack.reverseRowOrder)
{
source = reinterpret_cast<uint8_t*>(lock.pBits) + lock.Pitch * (rect.bottom - rect.top - 1);
inputPitch = -lock.Pitch;
}
else
{
source = reinterpret_cast<uint8_t*>(lock.pBits);
inputPitch = lock.Pitch;
}
uint8_t *source = reinterpret_cast<uint8_t *>(lock.pBits);
int inputPitch = lock.Pitch;
const d3d9::D3DFormat &d3dFormatInfo = d3d9::GetD3DFormatInfo(desc.Format);
const gl::InternalFormat &sourceFormatInfo = gl::GetInternalFormatInfo(d3dFormatInfo.internalFormat);
if (sourceFormatInfo.format == format && sourceFormatInfo.type == type)
{
// Direct copy possible
for (int y = 0; y < rect.bottom - rect.top; y++)
{
memcpy(pixels + y * outputPitch, source + y * inputPitch, (rect.right - rect.left) * sourceFormatInfo.pixelBytes);
}
}
else
{
const d3d9::D3DFormat &sourceD3DFormatInfo = d3d9::GetD3DFormatInfo(desc.Format);
ColorCopyFunction fastCopyFunc = sourceD3DFormatInfo.getFastCopyFunction(format, type);
GLenum sizedDestInternalFormat = gl::GetSizedInternalFormat(format, type);
const gl::InternalFormat &destFormatInfo = gl::GetInternalFormatInfo(sizedDestInternalFormat);
if (fastCopyFunc)
{
// Fast copy is possible through some special function
for (int y = 0; y < rect.bottom - rect.top; y++)
{
for (int x = 0; x < rect.right - rect.left; x++)
{
uint8_t *dest = pixels + y * outputPitch + x * destFormatInfo.pixelBytes;
const uint8_t *src = source + y * inputPitch + x * sourceFormatInfo.pixelBytes;
fastCopyFunc(src, dest);
}
}
}
else
{
ColorReadFunction colorReadFunction = sourceD3DFormatInfo.colorReadFunction;
ColorWriteFunction colorWriteFunction = GetColorWriteFunction(format, type);
uint8_t temp[sizeof(gl::ColorF)];
for (int y = 0; y < rect.bottom - rect.top; y++)
{
for (int x = 0; x < rect.right - rect.left; x++)
{
uint8_t *dest = pixels + y * outputPitch + x * destFormatInfo.pixelBytes;
const uint8_t *src = source + y * inputPitch + x * sourceFormatInfo.pixelBytes;
// readFunc and writeFunc will be using the same type of color, CopyTexImage
// will not allow the copy otherwise.
colorReadFunction(src, temp);
colorWriteFunction(temp, dest);
}
}
}
}
gl::FormatType formatType(format, type);
ColorReadFunction colorReadFunction = d3dFormatInfo.colorReadFunction;
// TODO(jmadill): Maybe we can avoid a copy of pack parameters here?
PackPixelsParams packParams;
packParams.area.x = rect.left;
packParams.area.y = rect.top;
packParams.area.width = rect.right - rect.left;
packParams.area.height = rect.bottom - rect.top;
packParams.format = format;
packParams.type = type;
packParams.outputPitch = static_cast<GLuint>(outputPitch);
packParams.pack = pack;
PackPixels(packParams, sourceFormatInfo, d3dFormatInfo.fastCopyFunctions, colorReadFunction,
inputPitch, source, pixels);
systemSurface->UnlockRect();
SafeRelease(systemSurface);
......@@ -454,4 +410,4 @@ GLenum Framebuffer9::getRenderTargetImplementationFormat(RenderTargetD3D *render
return d3dFormatInfo.internalFormat;
}
}
} // namespace rx
......@@ -7,8 +7,9 @@
// formatutils9.cpp: Queries for GL image formats and their translations to D3D9
// formats.
#include "libANGLE/renderer/d3d/copyimage.h"
#include "libANGLE/renderer/d3d/d3d9/formatutils9.h"
#include "libANGLE/renderer/copyimage.h"
#include "libANGLE/renderer/d3d/d3d9/Renderer9.h"
#include "libANGLE/renderer/d3d/d3d9/vertexconversion.h"
#include "libANGLE/renderer/d3d/generatemip.h"
......@@ -39,15 +40,25 @@ struct D3D9FastCopyFormat
}
};
typedef std::multimap<D3DFORMAT, D3D9FastCopyFormat> D3D9FastCopyMap;
static D3D9FastCopyMap BuildFastCopyMap()
static const FastCopyFunctionMap &GetFastCopyFunctionMap(D3DFORMAT d3dFormat)
{
D3D9FastCopyMap map;
map.insert(std::make_pair(D3DFMT_A8R8G8B8, D3D9FastCopyFormat(GL_RGBA, GL_UNSIGNED_BYTE, CopyBGRA8ToRGBA8)));
return map;
switch (d3dFormat)
{
case D3DFMT_A8R8G8B8:
{
static FastCopyFunctionMap fastCopyMap;
if (fastCopyMap.empty())
{
fastCopyMap[gl::FormatType(GL_RGBA, GL_UNSIGNED_BYTE)] = CopyBGRA8ToRGBA8;
}
return fastCopyMap;
}
default:
{
static FastCopyFunctionMap emptyMap;
return emptyMap;
}
}
}
// A map to determine the pixel size and mip generation function of a given D3D format
......@@ -71,12 +82,6 @@ D3DFormat::D3DFormat()
{
}
ColorCopyFunction D3DFormat::getFastCopyFunction(GLenum format, GLenum type) const
{
FastCopyFunctionMap::const_iterator iter = fastCopyFunctions.find(std::make_pair(format, type));
return (iter != fastCopyFunctions.end()) ? iter->second : NULL;
}
static inline void InsertD3DFormatInfo(D3D9FormatInfoMap *map, D3DFORMAT format, GLuint bits, GLuint blockWidth,
GLuint blockHeight, GLuint redBits, GLuint greenBits, GLuint blueBits,
GLuint alphaBits, GLuint lumBits, GLuint depthBits, GLuint stencilBits,
......@@ -97,13 +102,7 @@ static inline void InsertD3DFormatInfo(D3D9FormatInfoMap *map, D3DFORMAT format,
info.internalFormat = internalFormat;
info.mipGenerationFunction = mipFunc;
info.colorReadFunction = colorReadFunc;
static const D3D9FastCopyMap fastCopyMap = BuildFastCopyMap();
std::pair<D3D9FastCopyMap::const_iterator, D3D9FastCopyMap::const_iterator> fastCopyIter = fastCopyMap.equal_range(format);
for (D3D9FastCopyMap::const_iterator i = fastCopyIter.first; i != fastCopyIter.second; i++)
{
info.fastCopyFunctions.insert(std::make_pair(std::make_pair(i->second.destFormat, i->second.destType), i->second.copyFunction));
}
info.fastCopyFunctions = GetFastCopyFunctionMap(format);
map->insert(std::make_pair(format, info));
}
......
......@@ -15,6 +15,7 @@
#include "common/platform.h"
#include "libANGLE/angletypes.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/renderer_utils.h"
#include "libANGLE/renderer/d3d/formatutilsD3D.h"
namespace rx
......@@ -25,8 +26,6 @@ class Renderer9;
namespace d3d9
{
typedef std::map<std::pair<GLenum, GLenum>, ColorCopyFunction> FastCopyFunctionMap;
struct D3DFormat
{
D3DFormat();
......@@ -50,8 +49,8 @@ struct D3DFormat
ColorReadFunction colorReadFunction;
FastCopyFunctionMap fastCopyFunctions;
ColorCopyFunction getFastCopyFunction(GLenum format, GLenum type) const;
};
const D3DFormat &GetD3DFormatInfo(D3DFORMAT format);
struct VertexFormat
......
......@@ -15,9 +15,15 @@
#include <cstddef>
#include <stdint.h>
namespace rx
#include <map>
namespace gl
{
struct FormatType;
}
namespace rx
{
typedef void (*MipGenerationFunction)(size_t sourceWidth, size_t sourceHeight, size_t sourceDepth,
const uint8_t *sourceData, size_t sourceRowPitch, size_t sourceDepthPitch,
uint8_t *destData, size_t destRowPitch, size_t destDepthPitch);
......@@ -29,10 +35,6 @@ typedef void (*LoadImageFunction)(size_t width, size_t height, size_t depth,
typedef void (*InitializeTextureDataFunction)(size_t width, size_t height, size_t depth,
uint8_t *output, size_t outputRowPitch, size_t outputDepthPitch);
typedef void (*ColorReadFunction)(const uint8_t *source, uint8_t *dest);
typedef void (*ColorWriteFunction)(const uint8_t *source, uint8_t *dest);
typedef void (*ColorCopyFunction)(const uint8_t *source, uint8_t *dest);
typedef void (*VertexCopyFunction)(const uint8_t *input, size_t stride, size_t count, uint8_t *output);
enum VertexConversionType
......@@ -42,9 +44,6 @@ enum VertexConversionType
VERTEX_CONVERT_GPU = 2,
VERTEX_CONVERT_BOTH = 3
};
ColorWriteFunction GetColorWriteFunction(GLenum format, GLenum type);
}
} // namespace rx
#endif // LIBANGLE_RENDERER_D3D_FORMATUTILSD3D_H_
......@@ -10,8 +10,8 @@
#ifndef LIBANGLE_RENDERER_D3D_GENERATEMIP_H_
#define LIBANGLE_RENDERER_D3D_GENERATEMIP_H_
#include "libANGLE/renderer/d3d/imageformats.h"
#include "libANGLE/angletypes.h"
#include "libANGLE/renderer/imageformats.h"
namespace rx
{
......
......@@ -6,8 +6,8 @@
// loadimage.h: Defines image loading functions
#ifndef LIBANGLE_RENDERER_D3D_LOADIMAGE_H_
#define LIBANGLE_RENDERER_D3D_LOADIMAGE_H_
#ifndef LIBANGLE_RENDERER_LOADIMAGE_H_
#define LIBANGLE_RENDERER_LOADIMAGE_H_
#include "libANGLE/angletypes.h"
......@@ -198,4 +198,4 @@ inline const T *OffsetDataPointer(const uint8_t *data, size_t y, size_t z, size_
#include "loadimage.inl"
#endif // LIBANGLE_RENDERER_D3D_LOADIMAGE_H_
#endif // LIBANGLE_RENDERER_LOADIMAGE_H_
......@@ -8,8 +8,8 @@
#include "libANGLE/renderer/d3d/loadimage_etc.h"
#include "libANGLE/renderer/imageformats.h"
#include "libANGLE/renderer/d3d/loadimage.h"
#include "libANGLE/renderer/d3d/imageformats.h"
namespace rx
{
......
//
// Copyright (c) 2015 The ANGLE Project Authors. All rights reserved.
// Copyright 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// renderer_utils:
// Helper methods pertaining to most or all back-ends.
//
// formatutils9.cpp: Queries for GL image formats and their translations to D3D
// formats.
#include "libANGLE/renderer/d3d/formatutilsD3D.h"
#include <map>
#include "libANGLE/renderer/renderer_utils.h"
#include "common/debug.h"
#include "libANGLE/renderer/d3d/imageformats.h"
#include "libANGLE/renderer/d3d/copyimage.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/copyimage.h"
#include "libANGLE/renderer/imageformats.h"
namespace rx
{
typedef std::pair<GLenum, GLenum> FormatTypePair;
typedef std::pair<FormatTypePair, ColorWriteFunction> FormatWriteFunctionPair;
typedef std::map<FormatTypePair, ColorWriteFunction> FormatWriteFunctionMap;
namespace
{
typedef std::pair<gl::FormatType, ColorWriteFunction> FormatWriteFunctionPair;
typedef std::map<gl::FormatType, ColorWriteFunction> FormatWriteFunctionMap;
static inline void InsertFormatWriteFunctionMapping(FormatWriteFunctionMap *map, GLenum format, GLenum type,
static inline void InsertFormatWriteFunctionMapping(FormatWriteFunctionMap *map,
GLenum format,
GLenum type,
ColorWriteFunction writeFunc)
{
map->insert(FormatWriteFunctionPair(FormatTypePair(format, type), writeFunc));
map->insert(FormatWriteFunctionPair(gl::FormatType(format, type), writeFunc));
}
static FormatWriteFunctionMap BuildFormatWriteFunctionMap()
{
FormatWriteFunctionMap map;
// clang-format off
// | Format | Type | Color write function |
InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_UNSIGNED_BYTE, WriteColor<R8G8B8A8, GLfloat> );
InsertFormatWriteFunctionMapping(&map, GL_RGBA, GL_BYTE, WriteColor<R8G8B8A8S, GLfloat> );
......@@ -135,14 +137,112 @@ static FormatWriteFunctionMap BuildFormatWriteFunctionMap()
InsertFormatWriteFunctionMapping(&map, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL );
InsertFormatWriteFunctionMapping(&map, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, NULL );
// clang-format on
return map;
}
} // anonymous namespace
ColorWriteFunction GetColorWriteFunction(GLenum format, GLenum type)
PackPixelsParams::PackPixelsParams()
: format(GL_NONE), type(GL_NONE), outputPitch(0), packBuffer(nullptr), offset(0)
{
}
PackPixelsParams::PackPixelsParams(const gl::Rectangle &areaIn,
GLenum formatIn,
GLenum typeIn,
GLuint outputPitchIn,
const gl::PixelPackState &packIn,
ptrdiff_t offsetIn)
: area(areaIn),
format(formatIn),
type(typeIn),
outputPitch(outputPitchIn),
packBuffer(packIn.pixelBuffer.get()),
pack(packIn.alignment, packIn.reverseRowOrder),
offset(offsetIn)
{
}
void PackPixels(const PackPixelsParams &params,
const gl::InternalFormat &sourceFormatInfo,
const FastCopyFunctionMap &fastCopyFunctionsMap,
ColorReadFunction colorReadFunction,
int inputPitchIn,
const uint8_t *sourceIn,
uint8_t *destWithoutOffset)
{
uint8_t *destWithOffset = destWithoutOffset + params.offset;
const uint8_t *source = sourceIn;
int inputPitch = inputPitchIn;
if (params.pack.reverseRowOrder)
{
source += inputPitch * (params.area.height - 1);
inputPitch = -inputPitch;
}
if (sourceFormatInfo.format == params.format && sourceFormatInfo.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);
}
return;
}
gl::FormatType formatType(params.format, params.type);
ColorCopyFunction fastCopyFunc = GetFastCopyFunction(fastCopyFunctionsMap, formatType);
GLenum sizedDestInternalFormat = gl::GetSizedInternalFormat(formatType.format, formatType.type);
const auto &destFormatInfo = gl::GetInternalFormatInfo(sizedDestInternalFormat);
if (fastCopyFunc)
{
// Fast copy is possible through some special function
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;
fastCopyFunc(src, dest);
}
}
return;
}
ColorWriteFunction colorWriteFunction = GetColorWriteFunction(formatType);
// Maximum size of any Color<T> type used.
uint8_t temp[16];
static_assert(sizeof(temp) >= sizeof(gl::ColorF) && sizeof(temp) >= sizeof(gl::ColorUI) &&
sizeof(temp) >= sizeof(gl::ColorI),
"Unexpected size of gl::Color struct.");
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;
// readFunc and writeFunc will be using the same type of color, CopyTexImage
// will not allow the copy otherwise.
colorReadFunction(src, temp);
colorWriteFunction(temp, dest);
}
}
}
ColorWriteFunction GetColorWriteFunction(const gl::FormatType &formatType)
{
static const FormatWriteFunctionMap formatTypeMap = BuildFormatWriteFunctionMap();
FormatWriteFunctionMap::const_iterator iter = formatTypeMap.find(FormatTypePair(format, type));
auto iter = formatTypeMap.find(formatType);
ASSERT(iter != formatTypeMap.end());
if (iter != formatTypeMap.end())
{
......@@ -150,8 +250,15 @@ ColorWriteFunction GetColorWriteFunction(GLenum format, GLenum type)
}
else
{
return NULL;
return nullptr;
}
}
ColorCopyFunction GetFastCopyFunction(const FastCopyFunctionMap &fastCopyFunctions,
const gl::FormatType &formatType)
{
auto iter = fastCopyFunctions.find(formatType);
return (iter != fastCopyFunctions.end()) ? iter->second : nullptr;
}
} // namespace rx
//
// Copyright 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// renderer_utils:
// Helper methods pertaining to most or all back-ends.
//
#ifndef LIBANGLE_RENDERER_RENDERER_UTILS_H_
#define LIBANGLE_RENDERER_RENDERER_UTILS_H_
#include <cstdint>
#include <map>
#include "libANGLE/angletypes.h"
namespace gl
{
struct FormatType;
struct InternalFormat;
}
namespace rx
{
typedef void (*ColorReadFunction)(const uint8_t *source, uint8_t *dest);
typedef void (*ColorWriteFunction)(const uint8_t *source, uint8_t *dest);
typedef void (*ColorCopyFunction)(const uint8_t *source, uint8_t *dest);
typedef std::map<gl::FormatType, ColorCopyFunction> FastCopyFunctionMap;
struct PackPixelsParams
{
PackPixelsParams();
PackPixelsParams(const gl::Rectangle &area,
GLenum format,
GLenum type,
GLuint outputPitch,
const gl::PixelPackState &pack,
ptrdiff_t offset);
gl::Rectangle area;
GLenum format;
GLenum type;
GLuint outputPitch;
gl::Buffer *packBuffer;
gl::PixelPackState pack;
ptrdiff_t offset;
};
void PackPixels(const PackPixelsParams &params,
const gl::InternalFormat &sourceFormatInfo,
const FastCopyFunctionMap &fastCopyFunctionsMap,
ColorReadFunction colorReadFunction,
int inputPitch,
const uint8_t *source,
uint8_t *destination);
ColorWriteFunction GetColorWriteFunction(const gl::FormatType &formatType);
ColorCopyFunction GetFastCopyFunction(const FastCopyFunctionMap &fastCopyFunctions,
const gl::FormatType &formatType);
} // namespace rx
#endif // LIBANGLE_RENDERER_RENDERER_UTILS_H_
......@@ -166,6 +166,12 @@
'libANGLE/renderer/TextureImpl.h',
'libANGLE/renderer/TransformFeedbackImpl.h',
'libANGLE/renderer/VertexArrayImpl.h',
'libANGLE/renderer/copyimage.cpp',
'libANGLE/renderer/copyimage.h',
'libANGLE/renderer/copyimage.inl',
'libANGLE/renderer/imageformats.h',
'libANGLE/renderer/renderer_utils.cpp',
'libANGLE/renderer/renderer_utils.h',
'libANGLE/validationEGL.cpp',
'libANGLE/validationEGL.h',
'libANGLE/validationES.cpp',
......@@ -183,9 +189,6 @@
'libANGLE/renderer/d3d/BufferD3D.h',
'libANGLE/renderer/d3d/CompilerD3D.cpp',
'libANGLE/renderer/d3d/CompilerD3D.h',
'libANGLE/renderer/d3d/copyimage.cpp',
'libANGLE/renderer/d3d/copyimage.h',
'libANGLE/renderer/d3d/copyimage.inl',
'libANGLE/renderer/d3d/DeviceD3D.cpp',
'libANGLE/renderer/d3d/DeviceD3D.h',
'libANGLE/renderer/d3d/DisplayD3D.cpp',
......@@ -194,7 +197,6 @@
'libANGLE/renderer/d3d/DynamicHLSL.h',
'libANGLE/renderer/d3d/EGLImageD3D.cpp',
'libANGLE/renderer/d3d/EGLImageD3D.h',
'libANGLE/renderer/d3d/formatutilsD3D.cpp',
'libANGLE/renderer/d3d/formatutilsD3D.h',
'libANGLE/renderer/d3d/FramebufferD3D.cpp',
'libANGLE/renderer/d3d/FramebufferD3D.h',
......@@ -204,7 +206,6 @@
'libANGLE/renderer/d3d/HLSLCompiler.h',
'libANGLE/renderer/d3d/ImageD3D.cpp',
'libANGLE/renderer/d3d/ImageD3D.h',
'libANGLE/renderer/d3d/imageformats.h',
'libANGLE/renderer/d3d/IndexBuffer.cpp',
'libANGLE/renderer/d3d/IndexBuffer.h',
'libANGLE/renderer/d3d/IndexDataManager.cpp',
......
......@@ -8,7 +8,7 @@
#include "test_utils/ANGLETest.h"
#include "libANGLE/renderer/d3d/imageformats.h"
#include "libANGLE/renderer/imageformats.h"
using namespace angle;
......
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