Commit 63837d51 by Geoff Lang

Defer the creation of Blit9's geometry and return Errors if it fails.

BUG=angle:520 Change-Id: I5e51fec38c513419beea5ff612a6ec2fb0e81a26 Reviewed-on: https://chromium-review.googlesource.com/218768Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent cbc7f050
...@@ -46,10 +46,16 @@ const size_t g_shaderSize[] = ...@@ -46,10 +46,16 @@ const size_t g_shaderSize[] =
namespace rx namespace rx
{ {
Blit9::Blit9(rx::Renderer9 *renderer) Blit9::Blit9(rx::Renderer9 *renderer)
: mRenderer(renderer), mQuadVertexBuffer(NULL), mQuadVertexDeclaration(NULL), mSavedStateBlock(NULL), mSavedRenderTarget(NULL), mSavedDepthStencil(NULL) : mRenderer(renderer),
mGeometryLoaded(false),
mQuadVertexBuffer(NULL),
mQuadVertexDeclaration(NULL),
mSavedStateBlock(NULL),
mSavedRenderTarget(NULL),
mSavedDepthStencil(NULL)
{ {
initGeometry();
memset(mCompiledShaders, 0, sizeof(mCompiledShaders)); memset(mCompiledShaders, 0, sizeof(mCompiledShaders));
} }
...@@ -65,8 +71,13 @@ Blit9::~Blit9() ...@@ -65,8 +71,13 @@ Blit9::~Blit9()
} }
} }
void Blit9::initGeometry() gl::Error Blit9::initialize()
{ {
if (mGeometryLoaded)
{
return gl::Error(GL_NO_ERROR);
}
static const float quad[] = static const float quad[] =
{ {
-1, -1, -1, -1,
...@@ -82,7 +93,7 @@ void Blit9::initGeometry() ...@@ -82,7 +93,7 @@ void Blit9::initGeometry()
if (FAILED(result)) if (FAILED(result))
{ {
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY); ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
return gl::error(GL_OUT_OF_MEMORY); return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal blit vertex shader, result: 0x%X.", result);
} }
void *lockPtr = NULL; void *lockPtr = NULL;
...@@ -91,7 +102,8 @@ void Blit9::initGeometry() ...@@ -91,7 +102,8 @@ void Blit9::initGeometry()
if (FAILED(result) || lockPtr == NULL) if (FAILED(result) || lockPtr == NULL)
{ {
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY); ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
return gl::error(GL_OUT_OF_MEMORY); SafeRelease(mQuadVertexBuffer);
return gl::Error(GL_OUT_OF_MEMORY, "Failed to lock internal blit vertex shader, result: 0x%X.", result);
} }
memcpy(lockPtr, quad, sizeof(quad)); memcpy(lockPtr, quad, sizeof(quad));
...@@ -108,8 +120,12 @@ void Blit9::initGeometry() ...@@ -108,8 +120,12 @@ void Blit9::initGeometry()
if (FAILED(result)) if (FAILED(result))
{ {
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY); ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
return gl::error(GL_OUT_OF_MEMORY); SafeRelease(mQuadVertexBuffer);
return gl::Error(GL_OUT_OF_MEMORY, "Failed to lock internal blit vertex declaration, result: 0x%X.", result);
} }
mGeometryLoaded = true;
return gl::Error(GL_NO_ERROR);
} }
template <class D3DShaderType> template <class D3DShaderType>
...@@ -174,8 +190,14 @@ RECT Blit9::getSurfaceRect(IDirect3DSurface9 *surface) const ...@@ -174,8 +190,14 @@ RECT Blit9::getSurfaceRect(IDirect3DSurface9 *surface) const
gl::Error Blit9::boxFilter(IDirect3DSurface9 *source, IDirect3DSurface9 *dest) gl::Error Blit9::boxFilter(IDirect3DSurface9 *source, IDirect3DSurface9 *dest)
{ {
gl::Error error = initialize();
if (error.isError())
{
return error;
}
IDirect3DTexture9 *texture = NULL; IDirect3DTexture9 *texture = NULL;
gl::Error error = copySurfaceToTexture(source, getSurfaceRect(source), &texture); error = copySurfaceToTexture(source, getSurfaceRect(source), &texture);
if (error.isError()) if (error.isError())
{ {
return error; return error;
...@@ -208,11 +230,17 @@ gl::Error Blit9::boxFilter(IDirect3DSurface9 *source, IDirect3DSurface9 *dest) ...@@ -208,11 +230,17 @@ gl::Error Blit9::boxFilter(IDirect3DSurface9 *source, IDirect3DSurface9 *dest)
gl::Error Blit9::copy2D(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, TextureStorage *storage, GLint level) gl::Error Blit9::copy2D(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, TextureStorage *storage, GLint level)
{ {
gl::Error error = initialize();
if (error.isError())
{
return error;
}
gl::FramebufferAttachment *colorbuffer = framebuffer->getColorbuffer(0); gl::FramebufferAttachment *colorbuffer = framebuffer->getColorbuffer(0);
ASSERT(colorbuffer); ASSERT(colorbuffer);
RenderTarget9 *renderTarget9 = NULL; RenderTarget9 *renderTarget9 = NULL;
gl::Error error = d3d9::GetAttachmentRenderTarget(colorbuffer, &renderTarget9); error = d3d9::GetAttachmentRenderTarget(colorbuffer, &renderTarget9);
if (error.isError()) if (error.isError())
{ {
return error; return error;
...@@ -236,11 +264,17 @@ gl::Error Blit9::copy2D(gl::Framebuffer *framebuffer, const RECT &sourceRect, GL ...@@ -236,11 +264,17 @@ gl::Error Blit9::copy2D(gl::Framebuffer *framebuffer, const RECT &sourceRect, GL
gl::Error Blit9::copyCube(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, TextureStorage *storage, GLenum target, GLint level) gl::Error Blit9::copyCube(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, TextureStorage *storage, GLenum target, GLint level)
{ {
gl::Error error = initialize();
if (error.isError())
{
return error;
}
gl::FramebufferAttachment *colorbuffer = framebuffer->getColorbuffer(0); gl::FramebufferAttachment *colorbuffer = framebuffer->getColorbuffer(0);
ASSERT(colorbuffer); ASSERT(colorbuffer);
RenderTarget9 *renderTarget9 = NULL; RenderTarget9 *renderTarget9 = NULL;
gl::Error error = d3d9::GetAttachmentRenderTarget(colorbuffer, &renderTarget9); error = d3d9::GetAttachmentRenderTarget(colorbuffer, &renderTarget9);
if (error.isError()) if (error.isError())
{ {
return error; return error;
...@@ -295,8 +329,14 @@ gl::Error Blit9::copy(IDirect3DSurface9 *source, const RECT &sourceRect, GLenum ...@@ -295,8 +329,14 @@ gl::Error Blit9::copy(IDirect3DSurface9 *source, const RECT &sourceRect, GLenum
gl::Error Blit9::formatConvert(IDirect3DSurface9 *source, const RECT &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, IDirect3DSurface9 *dest) gl::Error Blit9::formatConvert(IDirect3DSurface9 *source, const RECT &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, IDirect3DSurface9 *dest)
{ {
gl::Error error = initialize();
if (error.isError())
{
return error;
}
IDirect3DTexture9 *texture = NULL; IDirect3DTexture9 *texture = NULL;
gl::Error error = copySurfaceToTexture(source, sourceRect, &texture); error = copySurfaceToTexture(source, sourceRect, &texture);
if (error.isError()) if (error.isError())
{ {
return error; return error;
......
...@@ -30,6 +30,8 @@ class Blit9 ...@@ -30,6 +30,8 @@ class Blit9
explicit Blit9(Renderer9 *renderer); explicit Blit9(Renderer9 *renderer);
~Blit9(); ~Blit9();
gl::Error initialize();
// Copy from source surface to dest surface. // Copy from source surface to dest surface.
// sourceRect, xoffset, yoffset are in D3D coordinates (0,0 in upper-left) // sourceRect, xoffset, yoffset are in D3D coordinates (0,0 in upper-left)
gl::Error copy2D(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, TextureStorage *storage, GLint level); gl::Error copy2D(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, TextureStorage *storage, GLint level);
...@@ -47,11 +49,10 @@ class Blit9 ...@@ -47,11 +49,10 @@ class Blit9
private: private:
rx::Renderer9 *mRenderer; rx::Renderer9 *mRenderer;
bool mGeometryLoaded;
IDirect3DVertexBuffer9 *mQuadVertexBuffer; IDirect3DVertexBuffer9 *mQuadVertexBuffer;
IDirect3DVertexDeclaration9 *mQuadVertexDeclaration; IDirect3DVertexDeclaration9 *mQuadVertexDeclaration;
void initGeometry();
gl::Error setFormatConvertShaders(GLenum destFormat); gl::Error setFormatConvertShaders(GLenum destFormat);
gl::Error copy(IDirect3DSurface9 *source, const RECT &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, IDirect3DSurface9 *dest); gl::Error copy(IDirect3DSurface9 *source, const RECT &sourceRect, GLenum destFormat, GLint xoffset, GLint yoffset, IDirect3DSurface9 *dest);
......
...@@ -395,8 +395,11 @@ void Renderer9::initializeDevice() ...@@ -395,8 +395,11 @@ void Renderer9::initializeDevice()
mSceneStarted = false; mSceneStarted = false;
ASSERT(!mBlit && !mVertexDataManager && !mIndexDataManager); ASSERT(!mBlit);
mBlit = new Blit9(this); mBlit = new Blit9(this);
mBlit->initialize();
ASSERT(!mVertexDataManager && !mIndexDataManager);
mVertexDataManager = new rx::VertexDataManager(this); mVertexDataManager = new rx::VertexDataManager(this);
mIndexDataManager = new rx::IndexDataManager(this); mIndexDataManager = new rx::IndexDataManager(this);
} }
......
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