Updated mipmap generation to return Error objects.
BUG=angle:520
Change-Id: Ic4e57148d031d6c452b3054efad98f6e730c7691
Reviewed-on: https://chromium-review.googlesource.com/221394
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Tested-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/libGLESv2/renderer/Renderer.h b/src/libGLESv2/renderer/Renderer.h
index 79cff6a..6ef8d64 100644
--- a/src/libGLESv2/renderer/Renderer.h
+++ b/src/libGLESv2/renderer/Renderer.h
@@ -208,7 +208,7 @@
// Image operations
virtual Image *createImage() = 0;
- virtual void generateMipmap(Image *dest, Image *source) = 0;
+ virtual gl::Error generateMipmap(Image *dest, Image *source) = 0;
virtual TextureStorage *createTextureStorage2D(SwapChain *swapChain) = 0;
virtual TextureStorage *createTextureStorage2D(GLenum internalformat, bool renderTarget, GLsizei width, GLsizei height, int levels) = 0;
virtual TextureStorage *createTextureStorageCube(GLenum internalformat, bool renderTarget, int size, int levels) = 0;
diff --git a/src/libGLESv2/renderer/TextureImpl.h b/src/libGLESv2/renderer/TextureImpl.h
index ef47582..b4f9729 100644
--- a/src/libGLESv2/renderer/TextureImpl.h
+++ b/src/libGLESv2/renderer/TextureImpl.h
@@ -55,7 +55,7 @@
virtual gl::Error copySubImage(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source) = 0;
virtual gl::Error storage(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth) = 0;
- virtual void generateMipmaps() = 0;
+ virtual gl::Error generateMipmaps() = 0;
virtual void bindTexImage(egl::Surface *surface) = 0;
virtual void releaseTexImage() = 0;
diff --git a/src/libGLESv2/renderer/d3d/TextureD3D.cpp b/src/libGLESv2/renderer/d3d/TextureD3D.cpp
index 1028b1b..bdea186 100644
--- a/src/libGLESv2/renderer/d3d/TextureD3D.cpp
+++ b/src/libGLESv2/renderer/d3d/TextureD3D.cpp
@@ -337,13 +337,13 @@
return getImage(getImageIndex(0, 0));
}
-void TextureD3D::generateMipmaps()
+gl::Error TextureD3D::generateMipmaps()
{
GLint mipCount = mipLevels();
if (mipCount == 1)
{
- return; // no-op
+ return gl::Error(GL_NO_ERROR); // no-op
}
// Set up proper mipmap chain in our Image array.
@@ -366,12 +366,20 @@
Image *image = getImage(srcIndex);
gl::Rectangle area(0, 0, image->getWidth(), image->getHeight());
- image->copy(0, 0, 0, area, srcIndex, mTexStorage);
+ gl::Error error = image->copy(0, 0, 0, area, srcIndex, mTexStorage);
+ if (error.isError())
+ {
+ return error;
+ }
}
}
else
{
- updateStorage();
+ gl::Error error = updateStorage();
+ if (error.isError())
+ {
+ return error;
+ }
}
}
@@ -389,15 +397,25 @@
if (renderableStorage)
{
// GPU-side mipmapping
- mTexStorage->generateMipmap(sourceIndex, destIndex);
+ gl::Error error = mTexStorage->generateMipmap(sourceIndex, destIndex);
+ if (error.isError())
+ {
+ return error;
+ }
}
else
{
// CPU-side mipmapping
- mRenderer->generateMipmap(getImage(destIndex), getImage(sourceIndex));
+ gl::Error error = mRenderer->generateMipmap(getImage(destIndex), getImage(sourceIndex));
+ if (error.isError())
+ {
+ return error;
+ }
}
}
}
+
+ return gl::Error(GL_NO_ERROR);
}
bool TextureD3D::isBaseImageZeroSize() const
diff --git a/src/libGLESv2/renderer/d3d/TextureD3D.h b/src/libGLESv2/renderer/d3d/TextureD3D.h
index 67e84f4..3d1bc82 100644
--- a/src/libGLESv2/renderer/d3d/TextureD3D.h
+++ b/src/libGLESv2/renderer/d3d/TextureD3D.h
@@ -59,7 +59,7 @@
virtual gl::ImageIndex getImageIndex(GLint mip, GLint layer) const = 0;
virtual bool isValidIndex(const gl::ImageIndex &index) const = 0;
- virtual void generateMipmaps();
+ virtual gl::Error generateMipmaps();
TextureStorage *getStorage();
Image *getBaseLevelImage() const;
diff --git a/src/libGLESv2/renderer/d3d/TextureStorage.h b/src/libGLESv2/renderer/d3d/TextureStorage.h
index b537016..1c5b784 100644
--- a/src/libGLESv2/renderer/d3d/TextureStorage.h
+++ b/src/libGLESv2/renderer/d3d/TextureStorage.h
@@ -43,7 +43,7 @@
virtual int getLevelCount() const = 0;
virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT) = 0;
- virtual void generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex) = 0;
+ virtual gl::Error generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex) = 0;
virtual gl::Error copyToStorage(TextureStorage *destStorage) = 0;
virtual gl::Error setData(const gl::ImageIndex &index, Image *image, const gl::Box *destBox, GLenum type,
diff --git a/src/libGLESv2/renderer/d3d/d3d11/Image11.cpp b/src/libGLESv2/renderer/d3d/d3d11/Image11.cpp
index a8196f6..2e4f925 100644
--- a/src/libGLESv2/renderer/d3d/d3d11/Image11.cpp
+++ b/src/libGLESv2/renderer/d3d/d3d11/Image11.cpp
@@ -47,7 +47,7 @@
return static_cast<rx::Image11*>(img);
}
-void Image11::generateMipmap(Image11 *dest, Image11 *src)
+gl::Error Image11::generateMipmap(Image11 *dest, Image11 *src)
{
ASSERT(src->getDXGIFormat() == dest->getDXGIFormat());
ASSERT(src->getWidth() == 1 || src->getWidth() / 2 == dest->getWidth());
@@ -60,18 +60,15 @@
HRESULT destMapResult = dest->map(D3D11_MAP_WRITE, &destMapped);
if (FAILED(destMapResult))
{
- ERR("Failed to map destination image for mip map generation. HRESULT:0x%X", destMapResult);
- return;
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to map destination image for mipmap generation, result: 0x%X", destMapResult);
}
D3D11_MAPPED_SUBRESOURCE srcMapped;
HRESULT srcMapResult = src->map(D3D11_MAP_READ, &srcMapped);
if (FAILED(srcMapResult))
{
- ERR("Failed to map source image for mip map generation. HRESULT:0x%X", srcMapResult);
-
dest->unmap();
- return;
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to map source image for mip map generation, result: 0x%X", srcMapResult);
}
const uint8_t *sourceData = reinterpret_cast<const uint8_t*>(srcMapped.pData);
@@ -85,6 +82,8 @@
src->unmap();
dest->markDirty();
+
+ return gl::Error(GL_NO_ERROR);
}
bool Image11::isDirty() const
diff --git a/src/libGLESv2/renderer/d3d/d3d11/Image11.h b/src/libGLESv2/renderer/d3d/d3d11/Image11.h
index 30005ff..1458b5d 100644
--- a/src/libGLESv2/renderer/d3d/d3d11/Image11.h
+++ b/src/libGLESv2/renderer/d3d/d3d11/Image11.h
@@ -34,7 +34,7 @@
static Image11 *makeImage11(Image *img);
- static void generateMipmap(Image11 *dest, Image11 *src);
+ static gl::Error generateMipmap(Image11 *dest, Image11 *src);
virtual bool isDirty() const;
diff --git a/src/libGLESv2/renderer/d3d/d3d11/Renderer11.cpp b/src/libGLESv2/renderer/d3d/d3d11/Renderer11.cpp
index d632429..50b84eb 100644
--- a/src/libGLESv2/renderer/d3d/d3d11/Renderer11.cpp
+++ b/src/libGLESv2/renderer/d3d/d3d11/Renderer11.cpp
@@ -2659,11 +2659,11 @@
return new Image11();
}
-void Renderer11::generateMipmap(Image *dest, Image *src)
+gl::Error Renderer11::generateMipmap(Image *dest, Image *src)
{
Image11 *dest11 = Image11::makeImage11(dest);
Image11 *src11 = Image11::makeImage11(src);
- Image11::generateMipmap(dest11, src11);
+ return Image11::generateMipmap(dest11, src11);
}
TextureStorage *Renderer11::createTextureStorage2D(SwapChain *swapChain)
diff --git a/src/libGLESv2/renderer/d3d/d3d11/Renderer11.h b/src/libGLESv2/renderer/d3d/d3d11/Renderer11.h
index 9cf6fb1..6087e8c 100644
--- a/src/libGLESv2/renderer/d3d/d3d11/Renderer11.h
+++ b/src/libGLESv2/renderer/d3d/d3d11/Renderer11.h
@@ -152,7 +152,7 @@
// Image operations
virtual Image *createImage();
- virtual void generateMipmap(Image *dest, Image *source);
+ virtual gl::Error generateMipmap(Image *dest, Image *source);
virtual TextureStorage *createTextureStorage2D(SwapChain *swapChain);
virtual TextureStorage *createTextureStorage2D(GLenum internalformat, bool renderTarget, GLsizei width, GLsizei height, int levels);
virtual TextureStorage *createTextureStorageCube(GLenum internalformat, bool renderTarget, int size, int levels);
diff --git a/src/libGLESv2/renderer/d3d/d3d11/TextureStorage11.cpp b/src/libGLESv2/renderer/d3d/d3d11/TextureStorage11.cpp
index 07bd7dd..6998231 100644
--- a/src/libGLESv2/renderer/d3d/d3d11/TextureStorage11.cpp
+++ b/src/libGLESv2/renderer/d3d/d3d11/TextureStorage11.cpp
@@ -388,7 +388,7 @@
return gl::Error(GL_NO_ERROR);
}
-void TextureStorage11::generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex)
+gl::Error TextureStorage11::generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex)
{
ASSERT(sourceIndex.layerIndex == destIndex.layerIndex);
@@ -398,14 +398,14 @@
gl::Error error = getRenderTarget(sourceIndex, &source);
if (error.isError())
{
- return;
+ return error;
}
RenderTarget *dest = NULL;
error = getRenderTarget(destIndex, &dest);
if (error.isError())
{
- return;
+ return error;
}
ID3D11ShaderResourceView *sourceSRV = RenderTarget11::makeRenderTarget11(source)->getShaderResourceView();
@@ -418,8 +418,8 @@
gl::Extents destSize(dest->getWidth(), dest->getHeight(), dest->getDepth());
Blit11 *blitter = mRenderer->getBlitter();
- blitter->copyTexture(sourceSRV, sourceArea, sourceSize, destRTV, destArea, destSize, NULL,
- gl::GetInternalFormatInfo(source->getInternalFormat()).format, GL_LINEAR);
+ return blitter->copyTexture(sourceSRV, sourceArea, sourceSize, destRTV, destArea, destSize, NULL,
+ gl::GetInternalFormatInfo(source->getInternalFormat()).format, GL_LINEAR);
}
void TextureStorage11::verifySwizzleExists(GLenum swizzleRed, GLenum swizzleGreen, GLenum swizzleBlue, GLenum swizzleAlpha)
diff --git a/src/libGLESv2/renderer/d3d/d3d11/TextureStorage11.h b/src/libGLESv2/renderer/d3d/d3d11/TextureStorage11.h
index 3ec2be6..21598a8 100644
--- a/src/libGLESv2/renderer/d3d/d3d11/TextureStorage11.h
+++ b/src/libGLESv2/renderer/d3d/d3d11/TextureStorage11.h
@@ -45,7 +45,7 @@
virtual gl::Error getSRV(const gl::SamplerState &samplerState, ID3D11ShaderResourceView **outSRV);
virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT) = 0;
- virtual void generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex);
+ virtual gl::Error generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex);
virtual int getTopLevel() const;
virtual bool isRenderTarget() const;
diff --git a/src/libGLESv2/renderer/d3d/d3d9/Image9.cpp b/src/libGLESv2/renderer/d3d/d3d9/Image9.cpp
index a059fcb..f582245 100644
--- a/src/libGLESv2/renderer/d3d/d3d9/Image9.cpp
+++ b/src/libGLESv2/renderer/d3d/d3d9/Image9.cpp
@@ -36,15 +36,23 @@
SafeRelease(mSurface);
}
-void Image9::generateMip(IDirect3DSurface9 *destSurface, IDirect3DSurface9 *sourceSurface)
+gl::Error Image9::generateMip(IDirect3DSurface9 *destSurface, IDirect3DSurface9 *sourceSurface)
{
D3DSURFACE_DESC destDesc;
HRESULT result = destSurface->GetDesc(&destDesc);
ASSERT(SUCCEEDED(result));
+ if (FAILED(result))
+ {
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to query the source surface description for mipmap generation, result: 0x%X.", result);
+ }
D3DSURFACE_DESC sourceDesc;
result = sourceSurface->GetDesc(&sourceDesc);
ASSERT(SUCCEEDED(result));
+ if (FAILED(result))
+ {
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to query the destination surface description for mipmap generation, result: 0x%X.", result);
+ }
ASSERT(sourceDesc.Format == destDesc.Format);
ASSERT(sourceDesc.Width == 1 || sourceDesc.Width / 2 == destDesc.Width);
@@ -56,22 +64,32 @@
D3DLOCKED_RECT sourceLocked = {0};
result = sourceSurface->LockRect(&sourceLocked, NULL, D3DLOCK_READONLY);
ASSERT(SUCCEEDED(result));
+ if (FAILED(result))
+ {
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to lock the source surface for mipmap generation, result: 0x%X.", result);
+ }
D3DLOCKED_RECT destLocked = {0};
result = destSurface->LockRect(&destLocked, NULL, 0);
ASSERT(SUCCEEDED(result));
+ if (FAILED(result))
+ {
+ sourceSurface->UnlockRect();
+ return gl::Error(GL_OUT_OF_MEMORY, "Failed to lock the destination surface for mipmap generation, result: 0x%X.", result);
+ }
const uint8_t *sourceData = reinterpret_cast<const uint8_t*>(sourceLocked.pBits);
uint8_t *destData = reinterpret_cast<uint8_t*>(destLocked.pBits);
- if (sourceData && destData)
- {
- d3dFormatInfo.mipGenerationFunction(sourceDesc.Width, sourceDesc.Height, 1, sourceData, sourceLocked.Pitch, 0,
- destData, destLocked.Pitch, 0);
- }
+ ASSERT(sourceData && destData);
+
+ d3dFormatInfo.mipGenerationFunction(sourceDesc.Width, sourceDesc.Height, 1, sourceData, sourceLocked.Pitch, 0,
+ destData, destLocked.Pitch, 0);
destSurface->UnlockRect();
sourceSurface->UnlockRect();
+
+ return gl::Error(GL_NO_ERROR);
}
Image9 *Image9::makeImage9(Image *img)
@@ -80,16 +98,21 @@
return static_cast<rx::Image9*>(img);
}
-void Image9::generateMipmap(Image9 *dest, Image9 *source)
+gl::Error Image9::generateMipmap(Image9 *dest, Image9 *source)
{
IDirect3DSurface9 *sourceSurface = source->getSurface();
- if (sourceSurface == NULL)
- return gl::error(GL_OUT_OF_MEMORY);
+ ASSERT(sourceSurface);
IDirect3DSurface9 *destSurface = dest->getSurface();
- generateMip(destSurface, sourceSurface);
+ gl::Error error = generateMip(destSurface, sourceSurface);
+ if (error.isError())
+ {
+ return error;
+ }
dest->markDirty();
+
+ return gl::Error(GL_NO_ERROR);
}
gl::Error Image9::copyLockableSurfaces(IDirect3DSurface9 *dest, IDirect3DSurface9 *source)
diff --git a/src/libGLESv2/renderer/d3d/d3d9/Image9.h b/src/libGLESv2/renderer/d3d/d3d9/Image9.h
index c0a4384..953932f 100644
--- a/src/libGLESv2/renderer/d3d/d3d9/Image9.h
+++ b/src/libGLESv2/renderer/d3d/d3d9/Image9.h
@@ -31,8 +31,8 @@
static Image9 *makeImage9(Image *img);
- static void generateMipmap(Image9 *dest, Image9 *source);
- static void generateMip(IDirect3DSurface9 *destSurface, IDirect3DSurface9 *sourceSurface);
+ static gl::Error generateMipmap(Image9 *dest, Image9 *source);
+ static gl::Error generateMip(IDirect3DSurface9 *destSurface, IDirect3DSurface9 *sourceSurface);
static gl::Error copyLockableSurfaces(IDirect3DSurface9 *dest, IDirect3DSurface9 *source);
virtual bool redefine(Renderer *renderer, GLenum target, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, bool forceRelease);
diff --git a/src/libGLESv2/renderer/d3d/d3d9/Renderer9.cpp b/src/libGLESv2/renderer/d3d/d3d9/Renderer9.cpp
index eacfd81..5776908 100644
--- a/src/libGLESv2/renderer/d3d/d3d9/Renderer9.cpp
+++ b/src/libGLESv2/renderer/d3d/d3d9/Renderer9.cpp
@@ -3037,11 +3037,11 @@
return new Image9();
}
-void Renderer9::generateMipmap(Image *dest, Image *src)
+gl::Error Renderer9::generateMipmap(Image *dest, Image *src)
{
Image9 *src9 = Image9::makeImage9(src);
Image9 *dst9 = Image9::makeImage9(dest);
- Image9::generateMipmap(dst9, src9);
+ return Image9::generateMipmap(dst9, src9);
}
TextureStorage *Renderer9::createTextureStorage2D(SwapChain *swapChain)
diff --git a/src/libGLESv2/renderer/d3d/d3d9/Renderer9.h b/src/libGLESv2/renderer/d3d/d3d9/Renderer9.h
index 120987c..7cf0b1e 100644
--- a/src/libGLESv2/renderer/d3d/d3d9/Renderer9.h
+++ b/src/libGLESv2/renderer/d3d/d3d9/Renderer9.h
@@ -154,7 +154,7 @@
// Image operations
virtual Image *createImage();
- virtual void generateMipmap(Image *dest, Image *source);
+ virtual gl::Error generateMipmap(Image *dest, Image *source);
virtual TextureStorage *createTextureStorage2D(SwapChain *swapChain);
virtual TextureStorage *createTextureStorage2D(GLenum internalformat, bool renderTarget, GLsizei width, GLsizei height, int levels);
virtual TextureStorage *createTextureStorageCube(GLenum internalformat, bool renderTarget, int size, int levels);
diff --git a/src/libGLESv2/renderer/d3d/d3d9/TextureStorage9.cpp b/src/libGLESv2/renderer/d3d/d3d9/TextureStorage9.cpp
index f1a8135..479e05e 100644
--- a/src/libGLESv2/renderer/d3d/d3d9/TextureStorage9.cpp
+++ b/src/libGLESv2/renderer/d3d/d3d9/TextureStorage9.cpp
@@ -194,13 +194,13 @@
return gl::Error(GL_NO_ERROR);
}
-void TextureStorage9_2D::generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex)
+gl::Error TextureStorage9_2D::generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex)
{
IDirect3DSurface9 *upper = NULL;
gl::Error error = getSurfaceLevel(sourceIndex.mipIndex, false, &upper);
if (error.isError())
{
- return;
+ return error;
}
IDirect3DSurface9 *lower = NULL;
@@ -208,14 +208,16 @@
if (error.isError())
{
SafeRelease(upper);
- return;
+ return error;
}
ASSERT(upper && lower);
- mRenderer->boxFilter(upper, lower);
+ error = mRenderer->boxFilter(upper, lower);
SafeRelease(upper);
SafeRelease(lower);
+
+ return error;
}
gl::Error TextureStorage9_2D::getBaseTexture(IDirect3DBaseTexture9 **outTexture)
@@ -369,13 +371,13 @@
return gl::Error(GL_NO_ERROR);
}
-void TextureStorage9_Cube::generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex)
+gl::Error TextureStorage9_Cube::generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex)
{
IDirect3DSurface9 *upper = NULL;
gl::Error error = getCubeMapSurface(sourceIndex.type, sourceIndex.mipIndex, false, &upper);
if (error.isError())
{
- return;
+ return error;
}
IDirect3DSurface9 *lower = NULL;
@@ -383,14 +385,16 @@
if (error.isError())
{
SafeRelease(upper);
- return;
+ return error;
}
ASSERT(upper && lower);
- mRenderer->boxFilter(upper, lower);
+ error = mRenderer->boxFilter(upper, lower);
SafeRelease(upper);
SafeRelease(lower);
+
+ return error;
}
gl::Error TextureStorage9_Cube::getBaseTexture(IDirect3DBaseTexture9 **outTexture)
diff --git a/src/libGLESv2/renderer/d3d/d3d9/TextureStorage9.h b/src/libGLESv2/renderer/d3d/d3d9/TextureStorage9.h
index 0f717bd..1d124d5 100644
--- a/src/libGLESv2/renderer/d3d/d3d9/TextureStorage9.h
+++ b/src/libGLESv2/renderer/d3d/d3d9/TextureStorage9.h
@@ -35,7 +35,6 @@
virtual gl::Error getBaseTexture(IDirect3DBaseTexture9 **outTexture) = 0;
virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT) = 0;
- virtual void generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex) = 0;
virtual int getTopLevel() const;
virtual bool isRenderTarget() const;
@@ -75,7 +74,7 @@
gl::Error getSurfaceLevel(int level, bool dirty, IDirect3DSurface9 **outSurface);
virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT);
virtual gl::Error getBaseTexture(IDirect3DBaseTexture9 **outTexture);
- virtual void generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex);
+ virtual gl::Error generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex);
virtual gl::Error copyToStorage(TextureStorage *destStorage);
private:
@@ -96,7 +95,7 @@
gl::Error getCubeMapSurface(GLenum faceTarget, int level, bool dirty, IDirect3DSurface9 **outSurface);
virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT);
virtual gl::Error getBaseTexture(IDirect3DBaseTexture9 **outTexture);
- virtual void generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex);
+ virtual gl::Error generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex);
virtual gl::Error copyToStorage(TextureStorage *destStorage);
private: