Previous code only consider that info.srcOffset is 0.
Fix some minor logical error.
+
Make the format convertor consider pixel stride.
Change-Id: I439f14f3350ff1360b853680ba73c93fac4a2def
Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
info.srcExtent2D.height != (createInfo.size.height / (1 << info.level)));
auto* sourceBuffer = reinterpret_cast<uint8_t*>(source.memorySource.memory);
+ auto sourceStride = info.srcStride;
std::vector<uint8_t> tempBuffer;
+
if(mGlAbstraction->TextureRequiresConverting(srcFormat, destFormat, isSubImage))
{
// Convert RGB to RGBA if necessary.
- texture->TryConvertPixelData(source.memorySource.memory, info.srcFormat, createInfo.format, info.srcSize, info.srcExtent2D.width, info.srcExtent2D.height, tempBuffer);
- sourceBuffer = &tempBuffer[0];
- srcFormat = destFormat;
- srcType = GLES::GLTextureFormatType(createInfo.format).type;
+ if(texture->TryConvertPixelData(source.memorySource.memory, info.srcFormat, createInfo.format, info.srcSize, info.srcStride, info.srcExtent2D.width, info.srcExtent2D.height, tempBuffer))
+ {
+ sourceBuffer = &tempBuffer[0];
+ sourceStride = 0u; // Converted buffer compacted. make stride as 0.
+ srcFormat = destFormat;
+ srcType = GLES::GLTextureFormatType(createInfo.format).type;
+ }
}
// Calculate the maximum mipmap level for the texture
}
mGlAbstraction->PixelStorei(GL_UNPACK_ALIGNMENT, 1);
- mGlAbstraction->PixelStorei(GL_UNPACK_ROW_LENGTH, info.srcStride);
+ mGlAbstraction->PixelStorei(GL_UNPACK_ROW_LENGTH, sourceStride);
mCurrentContext->BindTexture(bindTarget, texture->GetTextureTypeId(), texture->GetGLTexture());
// TODO: using PBO with GLES3, this is just naive
// oldschool way
- char* stagingBuffer = reinterpret_cast<char*>(malloc(info.srcSize));
- std::copy(&reinterpret_cast<char*>(source.memorySource.memory)[info.srcOffset],
- reinterpret_cast<char*>(source.memorySource.memory) + info.srcSize,
- stagingBuffer);
+ uint8_t* stagingBuffer = reinterpret_cast<uint8_t*>(malloc(info.srcSize));
+
+ uint8_t* srcMemory = &reinterpret_cast<uint8_t*>(source.memorySource.memory)[info.srcOffset];
+
+ std::copy(srcMemory, srcMemory + info.srcSize, stagingBuffer);
mTextureUploadTotalCPUMemoryUsed += info.srcSize;
/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
void (*pConversionWriteFunc)(const void*, uint32_t, uint32_t, uint32_t, uint32_t, void*);
};
-inline void WriteRGB32ToRGBA32(const void* pData, uint32_t sizeInBytes, uint32_t width, uint32_t height, uint32_t rowStride, void* pOutput)
+inline void WriteRGB32ToRGBA32(const void* __restrict__ pData, uint32_t sizeInBytes, uint32_t width, uint32_t height, uint32_t rowStride, void* __restrict__ pOutput)
{
- auto inData = reinterpret_cast<const uint8_t*>(pData);
- auto outData = reinterpret_cast<uint8_t*>(pOutput);
- auto outIdx = 0u;
- for(auto i = 0u; i < sizeInBytes; i += 3)
+ const uint8_t* __restrict__ inData = reinterpret_cast<const uint8_t*>(pData);
+ uint8_t* __restrict__ outData = reinterpret_cast<uint8_t*>(pOutput);
+ if(rowStride == 0u)
{
- outData[outIdx] = inData[i];
- outData[outIdx + 1] = inData[i + 1];
- outData[outIdx + 2] = inData[i + 2];
- outData[outIdx + 3] = 0xff;
- outIdx += 4;
+ rowStride = width;
+ }
+ for(auto y = 0u; y < height; ++y)
+ {
+ auto inIdx = 0u;
+ auto outIdx = 0u;
+ for(auto x = 0u; x < width; ++x)
+ {
+ outData[outIdx] = inData[inIdx];
+ outData[outIdx + 1] = inData[inIdx + 1];
+ outData[outIdx + 2] = inData[inIdx + 2];
+ outData[outIdx + 3] = 0xff;
+ outIdx += 4;
+ inIdx += 3;
+ }
+ inData += rowStride * 3u;
+ outData += width * 4u;
}
}
* This function tests whether format is supported by the driver. If possible it applies
* format conversion to suitable supported pixel format.
*/
-bool Texture::TryConvertPixelData(const void* pData, Graphics::Format srcFormat, Graphics::Format destFormat, uint32_t sizeInBytes, uint32_t width, uint32_t height, std::vector<uint8_t>& outputBuffer)
+bool Texture::TryConvertPixelData(const void* pData, Graphics::Format srcFormat, Graphics::Format destFormat, uint32_t sizeInBytes, uint32_t inStride, uint32_t width, uint32_t height, std::vector<uint8_t>& outputBuffer)
{
// No need to convert
if(srcFormat == destFormat)
}
auto begin = reinterpret_cast<const uint8_t*>(pData);
- outputBuffer = std::move(it->pConversionFunc(begin, sizeInBytes, width, height, 0u));
+ outputBuffer = std::move(it->pConversionFunc(begin, sizeInBytes, width, height, inStride));
return !outputBuffer.empty();
}
#define DALI_GRAPHICS_GLES_TEXTURE_H
/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
/**
* @param pData Input data
* @param sizeInBytes Size of the input data in bytes
- * @param width Width of the output buffer
- * @param height height of the output buffer
+ * @param inStride Stride of the input data.
+ * @param width Width of the input/output buffer
+ * @param height Height of the intput/output buffer
* @param outputBuffer The buffer to write to
+ * @note output Buffer will be packed without stride.
* @return true if converted, or false otherwise
*/
- bool TryConvertPixelData(const void* pData, Graphics::Format srcFormat, Graphics::Format destFormat, uint32_t sizeInBytes, uint32_t width, uint32_t height, std::vector<uint8_t>& outputBuffer);
+ bool TryConvertPixelData(const void* pData, Graphics::Format srcFormat, Graphics::Format destFormat, uint32_t sizeInBytes, uint32_t inStride, uint32_t width, uint32_t height, std::vector<uint8_t>& outputBuffer);
bool InitializeNativeImage();