Commit ede18442 by Geoff Lang

Updated Image9 to use gl::Errors for staging texture manipulation.

BUG=angle:520 Change-Id: I527a2bcadbf1abb05bd461d35ddbd7e28d487639 Reviewed-on: https://chromium-review.googlesource.com/221396Reviewed-by: 's avatarBrandon Jones <bajones@chromium.org> Reviewed-by: 's avatarShannon Woods <shannonwoods@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 922a9fb3
...@@ -100,11 +100,21 @@ Image9 *Image9::makeImage9(Image *img) ...@@ -100,11 +100,21 @@ Image9 *Image9::makeImage9(Image *img)
gl::Error Image9::generateMipmap(Image9 *dest, Image9 *source) gl::Error Image9::generateMipmap(Image9 *dest, Image9 *source)
{ {
IDirect3DSurface9 *sourceSurface = source->getSurface(); IDirect3DSurface9 *sourceSurface = NULL;
ASSERT(sourceSurface); gl::Error error = source->getSurface(&sourceSurface);
if (error.isError())
{
return error;
}
IDirect3DSurface9 *destSurface = NULL;
error = dest->getSurface(&destSurface);
if (error.isError())
{
return error;
}
IDirect3DSurface9 *destSurface = dest->getSurface(); error = generateMip(destSurface, sourceSurface);
gl::Error error = generateMip(destSurface, sourceSurface);
if (error.isError()) if (error.isError())
{ {
return error; return error;
...@@ -195,11 +205,11 @@ bool Image9::redefine(rx::Renderer *renderer, GLenum target, GLenum internalform ...@@ -195,11 +205,11 @@ bool Image9::redefine(rx::Renderer *renderer, GLenum target, GLenum internalform
return false; return false;
} }
void Image9::createSurface() gl::Error Image9::createSurface()
{ {
if(mSurface) if (mSurface)
{ {
return; return gl::Error(GL_NO_ERROR);
} }
IDirect3DTexture9 *newTexture = NULL; IDirect3DTexture9 *newTexture = NULL;
...@@ -222,8 +232,7 @@ void Image9::createSurface() ...@@ -222,8 +232,7 @@ void Image9::createSurface()
if (FAILED(result)) if (FAILED(result))
{ {
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY); ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
ERR("Creating image surface failed."); return gl::Error(GL_OUT_OF_MEMORY, "Failed to create image surface, result: 0x%X.", result);
return gl::error(GL_OUT_OF_MEMORY);
} }
newTexture->GetSurfaceLevel(levelToFetch, &newSurface); newTexture->GetSurfaceLevel(levelToFetch, &newSurface);
...@@ -241,35 +250,51 @@ void Image9::createSurface() ...@@ -241,35 +250,51 @@ void Image9::createSurface()
D3DLOCKED_RECT lockedRect; D3DLOCKED_RECT lockedRect;
result = newSurface->LockRect(&lockedRect, &entireRect, 0); result = newSurface->LockRect(&lockedRect, &entireRect, 0);
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
if (FAILED(result))
{
return gl::Error(GL_OUT_OF_MEMORY, "Failed to lock image surface, result: 0x%X.", result);
}
d3dFormatInfo.dataInitializerFunction(mWidth, mHeight, 1, reinterpret_cast<uint8_t*>(lockedRect.pBits), d3dFormatInfo.dataInitializerFunction(mWidth, mHeight, 1, reinterpret_cast<uint8_t*>(lockedRect.pBits),
lockedRect.Pitch, 0); lockedRect.Pitch, 0);
result = newSurface->UnlockRect(); result = newSurface->UnlockRect();
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
if (FAILED(result))
{
return gl::Error(GL_OUT_OF_MEMORY, "Failed to unlock image surface, result: 0x%X.", result);
}
} }
} }
mSurface = newSurface; mSurface = newSurface;
mDirty = false; mDirty = false;
mD3DPool = poolToUse; mD3DPool = poolToUse;
return gl::Error(GL_NO_ERROR);
} }
HRESULT Image9::lock(D3DLOCKED_RECT *lockedRect, const RECT *rect) gl::Error Image9::lock(D3DLOCKED_RECT *lockedRect, const RECT &rect)
{ {
createSurface(); gl::Error error = createSurface();
if (error.isError())
HRESULT result = D3DERR_INVALIDCALL; {
return error;
}
if (mSurface) if (mSurface)
{ {
result = mSurface->LockRect(lockedRect, rect, 0); HRESULT result = mSurface->LockRect(lockedRect, &rect, 0);
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
if (FAILED(result))
{
return gl::Error(GL_OUT_OF_MEMORY, "Failed to lock image surface, result: 0x%X.", result);
}
mDirty = true; mDirty = true;
} }
return result; return gl::Error(GL_NO_ERROR);
} }
void Image9::unlock() void Image9::unlock()
...@@ -298,11 +323,16 @@ bool Image9::isDirty() const ...@@ -298,11 +323,16 @@ bool Image9::isDirty() const
return (mSurface || d3d9::GetTextureFormatInfo(mInternalFormat).dataInitializerFunction != NULL) && mDirty; return (mSurface || d3d9::GetTextureFormatInfo(mInternalFormat).dataInitializerFunction != NULL) && mDirty;
} }
IDirect3DSurface9 *Image9::getSurface() gl::Error Image9::getSurface(IDirect3DSurface9 **outSurface)
{ {
createSurface(); gl::Error error = createSurface();
if (error.isError())
{
return error;
}
return mSurface; *outSurface = mSurface;
return gl::Error(GL_NO_ERROR);
} }
gl::Error Image9::setManagedSurface2D(TextureStorage *storage, int level) gl::Error Image9::setManagedSurface2D(TextureStorage *storage, int level)
...@@ -356,7 +386,11 @@ gl::Error Image9::setManagedSurface(IDirect3DSurface9 *surface) ...@@ -356,7 +386,11 @@ gl::Error Image9::setManagedSurface(IDirect3DSurface9 *surface)
gl::Error Image9::copyToStorage(TextureStorage *storage, const gl::ImageIndex &index, const gl::Box &region) gl::Error Image9::copyToStorage(TextureStorage *storage, const gl::ImageIndex &index, const gl::Box &region)
{ {
ASSERT(getSurface() != NULL); gl::Error error = createSurface();
if (error.isError())
{
return error;
}
IDirect3DSurface9 *destSurface = NULL; IDirect3DSurface9 *destSurface = NULL;
...@@ -380,7 +414,7 @@ gl::Error Image9::copyToStorage(TextureStorage *storage, const gl::ImageIndex &i ...@@ -380,7 +414,7 @@ gl::Error Image9::copyToStorage(TextureStorage *storage, const gl::ImageIndex &i
} }
} }
gl::Error error = copyToSurface(destSurface, region.x, region.y, region.width, region.height); error = copyToSurface(destSurface, region.x, region.y, region.width, region.height);
SafeRelease(destSurface); SafeRelease(destSurface);
return error; return error;
} }
...@@ -390,7 +424,13 @@ gl::Error Image9::copyToSurface(IDirect3DSurface9 *destSurface, GLint xoffset, G ...@@ -390,7 +424,13 @@ gl::Error Image9::copyToSurface(IDirect3DSurface9 *destSurface, GLint xoffset, G
ASSERT(width > 0 && height > 0); ASSERT(width > 0 && height > 0);
ASSERT(destSurface); ASSERT(destSurface);
IDirect3DSurface9 *sourceSurface = getSurface(); IDirect3DSurface9 *sourceSurface = NULL;
gl::Error error = getSurface(&sourceSurface);
if (error.isError())
{
return error;
}
ASSERT(sourceSurface && sourceSurface != destSurface); ASSERT(sourceSurface && sourceSurface != destSurface);
RECT rect; RECT rect;
...@@ -459,10 +499,10 @@ gl::Error Image9::loadData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei ...@@ -459,10 +499,10 @@ gl::Error Image9::loadData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei
}; };
D3DLOCKED_RECT locked; D3DLOCKED_RECT locked;
HRESULT result = lock(&locked, &lockRect); gl::Error error = lock(&locked, lockRect);
if (FAILED(result)) if (error.isError())
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Failed to lock internal texture for loading data, result: 0x%X.", result); return error;
} }
d3dFormatInfo.loadFunction(width, height, depth, d3dFormatInfo.loadFunction(width, height, depth,
...@@ -498,10 +538,10 @@ gl::Error Image9::loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset ...@@ -498,10 +538,10 @@ gl::Error Image9::loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset
}; };
D3DLOCKED_RECT locked; D3DLOCKED_RECT locked;
HRESULT result = lock(&locked, &lockRect); gl::Error error = lock(&locked, lockRect);
if (FAILED(result)) if (error.isError())
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Failed to lock internal texture for loading data, result: 0x%X.", result); return error;
} }
d3d9FormatInfo.loadFunction(width, height, depth, d3d9FormatInfo.loadFunction(width, height, depth,
...@@ -566,14 +606,13 @@ gl::Error Image9::copy(GLint xoffset, GLint yoffset, GLint zoffset, const gl::Re ...@@ -566,14 +606,13 @@ gl::Error Image9::copy(GLint xoffset, GLint yoffset, GLint zoffset, const gl::Re
} }
D3DLOCKED_RECT destLock = {0}; D3DLOCKED_RECT destLock = {0};
result = lock(&destLock, &destRect); gl::Error error = lock(&destLock, destRect);
if (error.isError())
if (FAILED(result))
{ {
renderTargetData->UnlockRect(); renderTargetData->UnlockRect();
SafeRelease(renderTargetData); SafeRelease(renderTargetData);
SafeRelease(surface); SafeRelease(surface);
return gl::Error(GL_OUT_OF_MEMORY, "Failed to lock the destination surface (rectangle might be invalid), result: 0x%X.", result); return error;
} }
ASSERT(destLock.pBits && sourceLock.pBits); ASSERT(destLock.pBits && sourceLock.pBits);
......
...@@ -40,7 +40,6 @@ class Image9 : public ImageD3D ...@@ -40,7 +40,6 @@ class Image9 : public ImageD3D
D3DFORMAT getD3DFormat() const; D3DFORMAT getD3DFormat() const;
virtual bool isDirty() const; virtual bool isDirty() const;
IDirect3DSurface9 *getSurface();
virtual gl::Error setManagedSurface2D(TextureStorage *storage, int level); virtual gl::Error setManagedSurface2D(TextureStorage *storage, int level);
virtual gl::Error setManagedSurfaceCube(TextureStorage *storage, int face, int level); virtual gl::Error setManagedSurfaceCube(TextureStorage *storage, int face, int level);
...@@ -58,11 +57,13 @@ class Image9 : public ImageD3D ...@@ -58,11 +57,13 @@ class Image9 : public ImageD3D
private: private:
DISALLOW_COPY_AND_ASSIGN(Image9); DISALLOW_COPY_AND_ASSIGN(Image9);
void createSurface(); gl::Error getSurface(IDirect3DSurface9 **outSurface);
gl::Error createSurface();
gl::Error setManagedSurface(IDirect3DSurface9 *surface); gl::Error setManagedSurface(IDirect3DSurface9 *surface);
gl::Error copyToSurface(IDirect3DSurface9 *dest, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height); gl::Error copyToSurface(IDirect3DSurface9 *dest, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height);
HRESULT lock(D3DLOCKED_RECT *lockedRect, const RECT *rect); gl::Error lock(D3DLOCKED_RECT *lockedRect, const RECT &rect);
void unlock(); void unlock();
Renderer9 *mRenderer; Renderer9 *mRenderer;
......
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