Abstracted image locking/unlocking.

TRAC #18714 Signed-off-by: Daniel Koch Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@827 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent dff362f5
...@@ -107,6 +107,32 @@ void Image::createSurface() ...@@ -107,6 +107,32 @@ void Image::createSurface()
mSurface = newSurface; mSurface = newSurface;
} }
HRESULT Image::lock(D3DLOCKED_RECT *lockedRect, const RECT *rect)
{
createSurface();
HRESULT result = D3DERR_INVALIDCALL;
if (mSurface)
{
result = mSurface->LockRect(lockedRect, rect, 0);
ASSERT(SUCCEEDED(result));
mDirty = true;
}
return result;
}
void Image::unlock()
{
if (mSurface)
{
HRESULT result = mSurface->UnlockRect();
ASSERT(SUCCEEDED(result));
}
}
bool Image::isRenderable() const bool Image::isRenderable() const
{ {
switch(getD3DFormat()) switch(getD3DFormat())
...@@ -1125,14 +1151,12 @@ void Texture::setImage(GLint unpackAlignment, const void *pixels, Image *image) ...@@ -1125,14 +1151,12 @@ void Texture::setImage(GLint unpackAlignment, const void *pixels, Image *image)
image->getSurface()->GetDesc(&description); image->getSurface()->GetDesc(&description);
D3DLOCKED_RECT locked; D3DLOCKED_RECT locked;
HRESULT result = image->getSurface()->LockRect(&locked, NULL, 0); HRESULT result = image->lock(&locked, NULL);
ASSERT(SUCCEEDED(result));
if (SUCCEEDED(result)) if (SUCCEEDED(result))
{ {
loadImageData(0, 0, image->getWidth(), image->getHeight(), image->getFormat(), image->getType(), unpackAlignment, pixels, locked.Pitch, locked.pBits, &description); loadImageData(0, 0, image->getWidth(), image->getHeight(), image->getFormat(), image->getType(), unpackAlignment, pixels, locked.Pitch, locked.pBits, &description);
image->getSurface()->UnlockRect(); image->unlock();
} }
image->markDirty(); image->markDirty();
...@@ -1147,16 +1171,14 @@ void Texture::setCompressedImage(GLsizei imageSize, const void *pixels, Image *i ...@@ -1147,16 +1171,14 @@ void Texture::setCompressedImage(GLsizei imageSize, const void *pixels, Image *i
if (pixels != NULL && image->getSurface() != NULL) if (pixels != NULL && image->getSurface() != NULL)
{ {
D3DLOCKED_RECT locked; D3DLOCKED_RECT locked;
HRESULT result = image->getSurface()->LockRect(&locked, NULL, 0); HRESULT result = image->lock(&locked, NULL);
ASSERT(SUCCEEDED(result));
if (SUCCEEDED(result)) if (SUCCEEDED(result))
{ {
int inputPitch = ComputeCompressedPitch(image->getWidth(), image->getFormat()); int inputPitch = ComputeCompressedPitch(image->getWidth(), image->getFormat());
int inputSize = ComputeCompressedSize(image->getWidth(), image->getHeight(), image->getFormat()); int inputSize = ComputeCompressedSize(image->getWidth(), image->getHeight(), image->getFormat());
loadCompressedImageData(0, 0, image->getWidth(), image->getHeight(), -inputPitch, static_cast<const char*>(pixels) + inputSize - inputPitch, locked.Pitch, locked.pBits); loadCompressedImageData(0, 0, image->getWidth(), image->getHeight(), -inputPitch, static_cast<const char*>(pixels) + inputSize - inputPitch, locked.Pitch, locked.pBits);
image->getSurface()->UnlockRect(); image->unlock();
} }
image->markDirty(); image->markDirty();
...@@ -1192,14 +1214,12 @@ bool Texture::subImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei heig ...@@ -1192,14 +1214,12 @@ bool Texture::subImage(GLint xoffset, GLint yoffset, GLsizei width, GLsizei heig
image->getSurface()->GetDesc(&description); image->getSurface()->GetDesc(&description);
D3DLOCKED_RECT locked; D3DLOCKED_RECT locked;
HRESULT result = image->getSurface()->LockRect(&locked, NULL, 0); HRESULT result = image->lock(&locked, NULL);
ASSERT(SUCCEEDED(result));
if (SUCCEEDED(result)) if (SUCCEEDED(result))
{ {
loadImageData(xoffset, transformPixelYOffset(yoffset, height, image->getHeight()), width, height, format, type, unpackAlignment, pixels, locked.Pitch, locked.pBits, &description); loadImageData(xoffset, transformPixelYOffset(yoffset, height, image->getHeight()), width, height, format, type, unpackAlignment, pixels, locked.Pitch, locked.pBits, &description);
image->getSurface()->UnlockRect(); image->unlock();
} }
image->markDirty(); image->markDirty();
...@@ -1223,9 +1243,7 @@ bool Texture::subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GL ...@@ -1223,9 +1243,7 @@ bool Texture::subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GL
return false; return false;
} }
image->createSurface(); if (pixels != NULL)
if (pixels != NULL && image->getSurface() != NULL)
{ {
RECT updateRegion; RECT updateRegion;
updateRegion.left = xoffset; updateRegion.left = xoffset;
...@@ -1234,16 +1252,14 @@ bool Texture::subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GL ...@@ -1234,16 +1252,14 @@ bool Texture::subImageCompressed(GLint xoffset, GLint yoffset, GLsizei width, GL
updateRegion.top = yoffset; updateRegion.top = yoffset;
D3DLOCKED_RECT locked; D3DLOCKED_RECT locked;
HRESULT result = image->getSurface()->LockRect(&locked, &updateRegion, 0); HRESULT result = image->lock(&locked, &updateRegion);
ASSERT(SUCCEEDED(result));
if (SUCCEEDED(result)) if (SUCCEEDED(result))
{ {
int inputPitch = ComputeCompressedPitch(width, format); int inputPitch = ComputeCompressedPitch(width, format);
int inputSize = ComputeCompressedSize(width, height, format); int inputSize = ComputeCompressedSize(width, height, format);
loadCompressedImageData(xoffset, transformPixelYOffset(yoffset, height, image->getHeight()), width, height, -inputPitch, static_cast<const char*>(pixels) + inputSize - inputPitch, locked.Pitch, locked.pBits); loadCompressedImageData(xoffset, transformPixelYOffset(yoffset, height, image->getHeight()), width, height, -inputPitch, static_cast<const char*>(pixels) + inputSize - inputPitch, locked.Pitch, locked.pBits);
image->getSurface()->UnlockRect(); image->unlock();
} }
image->markDirty(); image->markDirty();
...@@ -1314,7 +1330,7 @@ void Texture::copyToImage(Image *image, GLint xoffset, GLint yoffset, GLint x, G ...@@ -1314,7 +1330,7 @@ void Texture::copyToImage(Image *image, GLint xoffset, GLint yoffset, GLint x, G
} }
D3DLOCKED_RECT destLock = {0}; D3DLOCKED_RECT destLock = {0};
result = image->getSurface()->LockRect(&destLock, &destRect, 0); result = image->lock(&destLock, &destRect);
if (FAILED(result)) if (FAILED(result))
{ {
...@@ -1423,7 +1439,7 @@ void Texture::copyToImage(Image *image, GLint xoffset, GLint yoffset, GLint x, G ...@@ -1423,7 +1439,7 @@ void Texture::copyToImage(Image *image, GLint xoffset, GLint yoffset, GLint x, G
} }
} }
image->getSurface()->UnlockRect(); image->unlock();
renderTargetData->UnlockRect(); renderTargetData->UnlockRect();
} }
...@@ -1905,7 +1921,7 @@ void Texture2D::updateTexture() ...@@ -1905,7 +1921,7 @@ void Texture2D::updateTexture()
{ {
Image *image = &mImageArray[level]; Image *image = &mImageArray[level];
if (image->getSurface() && image->isDirty()) if (image->isDirty())
{ {
commitRect(level, 0, 0, mImageArray[level].getWidth(), mImageArray[level].getHeight()); commitRect(level, 0, 0, mImageArray[level].getWidth(), mImageArray[level].getHeight());
} }
...@@ -2362,7 +2378,7 @@ void TextureCubeMap::updateTexture() ...@@ -2362,7 +2378,7 @@ void TextureCubeMap::updateTexture()
{ {
Image *image = &mImageArray[face][level]; Image *image = &mImageArray[face][level];
if (image->getSurface() && image->isDirty()) if (image->isDirty())
{ {
commitRect(face, level, 0, 0, image->getWidth(), image->getHeight()); commitRect(face, level, 0, 0, image->getWidth(), image->getHeight());
} }
......
...@@ -54,6 +54,9 @@ class Image ...@@ -54,6 +54,9 @@ class Image
void markDirty() {mDirty = true;} void markDirty() {mDirty = true;}
void markClean() {mDirty = false;} void markClean() {mDirty = false;}
HRESULT lock(D3DLOCKED_RECT *lockedRect, const RECT *rect);
void unlock();
bool isRenderable() const; bool isRenderable() const;
D3DFORMAT getD3DFormat() const; D3DFORMAT getD3DFormat() const;
...@@ -61,7 +64,7 @@ class Image ...@@ -61,7 +64,7 @@ class Image
GLsizei getHeight() const {return mHeight;} GLsizei getHeight() const {return mHeight;}
GLenum getFormat() const {return mFormat;} GLenum getFormat() const {return mFormat;}
GLenum getType() const {return mType;} GLenum getType() const {return mType;}
bool isDirty() const {return mDirty;} bool isDirty() const {return mSurface && mDirty;}
IDirect3DSurface9 *getSurface() {return mSurface;} IDirect3DSurface9 *getSurface() {return mSurface;}
private: private:
......
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