Commit 2f1cd4a3 by Geoff Lang

Defer the creation of textures in TextureStorage9 and use Error objects.

BUG=angle:520 Change-Id: I5db70189d95babef14d48548054af4c7ff2bfc47 Reviewed-on: https://chromium-review.googlesource.com/219334Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 553c6bee
......@@ -250,8 +250,13 @@ gl::Error Blit9::copy2D(gl::Framebuffer *framebuffer, const RECT &sourceRect, GL
IDirect3DSurface9 *source = renderTarget9->getSurface();
ASSERT(source);
IDirect3DSurface9 *destSurface = NULL;
TextureStorage9_2D *storage9 = TextureStorage9_2D::makeTextureStorage9_2D(storage);
IDirect3DSurface9 *destSurface = storage9->getSurfaceLevel(level, true);
error = storage9->getSurfaceLevel(level, true, &destSurface);
if (error.isError())
{
return error;
}
ASSERT(destSurface);
gl::Error result = copy(source, sourceRect, destFormat, xoffset, yoffset, destSurface);
......@@ -284,8 +289,13 @@ gl::Error Blit9::copyCube(gl::Framebuffer *framebuffer, const RECT &sourceRect,
IDirect3DSurface9 *source = renderTarget9->getSurface();
ASSERT(source);
IDirect3DSurface9 *destSurface = NULL;
TextureStorage9_Cube *storage9 = TextureStorage9_Cube::makeTextureStorage9_Cube(storage);
IDirect3DSurface9 *destSurface = storage9->getCubeMapSurface(target, level, true);
error = storage9->getCubeMapSurface(target, level, true, &destSurface);
if (error.isError())
{
return error;
}
ASSERT(destSurface);
gl::Error result = copy(source, sourceRect, destFormat, xoffset, yoffset, destSurface);
......
......@@ -284,14 +284,26 @@ IDirect3DSurface9 *Image9::getSurface()
gl::Error Image9::setManagedSurface2D(TextureStorage *storage, int level)
{
IDirect3DSurface9 *surface = NULL;
TextureStorage9_2D *storage9 = TextureStorage9_2D::makeTextureStorage9_2D(storage);
return setManagedSurface(storage9->getSurfaceLevel(level, false));
gl::Error error = storage9->getSurfaceLevel(level, false, &surface);
if (error.isError())
{
return error;
}
return setManagedSurface(surface);
}
gl::Error Image9::setManagedSurfaceCube(TextureStorage *storage, int face, int level)
{
IDirect3DSurface9 *surface = NULL;
TextureStorage9_Cube *storage9 = TextureStorage9_Cube::makeTextureStorage9_Cube(storage);
return setManagedSurface(storage9->getCubeMapSurface(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, level, false));
gl::Error error = storage9->getCubeMapSurface(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, level, false, &surface);
if (error.isError())
{
return error;
}
return setManagedSurface(surface);
}
gl::Error Image9::setManagedSurface(IDirect3DSurface9 *surface)
......@@ -328,13 +340,21 @@ gl::Error Image9::copyToStorage(TextureStorage *storage, const gl::ImageIndex &i
if (index.type == GL_TEXTURE_2D)
{
TextureStorage9_2D *storage9 = TextureStorage9_2D::makeTextureStorage9_2D(storage);
destSurface = storage9->getSurfaceLevel(index.mipIndex, true);
gl::Error error = storage9->getSurfaceLevel(index.mipIndex, true, &destSurface);
if (error.isError())
{
return error;
}
}
else
{
ASSERT(gl::IsCubemapTextureTarget(index.type));
TextureStorage9_Cube *storage9 = TextureStorage9_Cube::makeTextureStorage9_Cube(storage);
destSurface = storage9->getCubeMapSurface(index.type, index.mipIndex, true);
gl::Error error = storage9->getCubeMapSurface(index.type, index.mipIndex, true, &destSurface);
if (error.isError())
{
return error;
}
}
gl::Error error = copyToSurface(destSurface, region.x, region.y, region.width, region.height);
......
......@@ -731,7 +731,12 @@ gl::Error Renderer9::setTexture(gl::SamplerType type, int index, gl::Texture *te
if (texStorage)
{
TextureStorage9 *storage9 = TextureStorage9::makeTextureStorage9(texStorage);
d3dTexture = storage9->getBaseTexture();
gl::Error error = storage9->getBaseTexture(&d3dTexture);
if (error.isError())
{
return error;
}
}
// If we get NULL back from getBaseTexture here, something went wrong
// in the texture class and we're unexpectedly missing the d3d texture
......
......@@ -33,7 +33,7 @@ class TextureStorage9 : public TextureStorage
D3DPOOL getPool() const;
DWORD getUsage() const;
virtual IDirect3DBaseTexture9 *getBaseTexture() const = 0;
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;
......@@ -47,6 +47,11 @@ class TextureStorage9 : public TextureStorage
protected:
int mTopLevel;
size_t mMipLevels;
size_t mTextureWidth;
size_t mTextureHeight;
D3DFORMAT mTextureFormat;
Renderer9 *mRenderer;
TextureStorage9(Renderer *renderer, DWORD usage);
......@@ -67,17 +72,15 @@ class TextureStorage9_2D : public TextureStorage9
static TextureStorage9_2D *makeTextureStorage9_2D(TextureStorage *storage);
IDirect3DSurface9 *getSurfaceLevel(int level, bool dirty);
gl::Error getSurfaceLevel(int level, bool dirty, IDirect3DSurface9 **outSurface);
virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT);
virtual IDirect3DBaseTexture9 *getBaseTexture() const;
virtual gl::Error getBaseTexture(IDirect3DBaseTexture9 **outTexture);
virtual void generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex);
virtual gl::Error copyToStorage(TextureStorage *destStorage);
private:
DISALLOW_COPY_AND_ASSIGN(TextureStorage9_2D);
void initializeRenderTarget();
IDirect3DTexture9 *mTexture;
RenderTarget9 *mRenderTarget;
};
......@@ -90,17 +93,15 @@ class TextureStorage9_Cube : public TextureStorage9
static TextureStorage9_Cube *makeTextureStorage9_Cube(TextureStorage *storage);
IDirect3DSurface9 *getCubeMapSurface(GLenum faceTarget, int level, bool dirty);
gl::Error getCubeMapSurface(GLenum faceTarget, int level, bool dirty, IDirect3DSurface9 **outSurface);
virtual gl::Error getRenderTarget(const gl::ImageIndex &index, RenderTarget **outRT);
virtual IDirect3DBaseTexture9 *getBaseTexture() const;
virtual gl::Error getBaseTexture(IDirect3DBaseTexture9 **outTexture);
virtual void generateMipmap(const gl::ImageIndex &sourceIndex, const gl::ImageIndex &destIndex);
virtual gl::Error copyToStorage(TextureStorage *destStorage);
private:
DISALLOW_COPY_AND_ASSIGN(TextureStorage9_Cube);
void initializeRenderTarget();
static const size_t CUBE_FACE_COUNT = 6;
IDirect3DCubeTexture9 *mTexture;
......
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