Moves TextureStorage class to its own file in the Renderer directory

TRAC #21909

Author: Shannon Woods
Signed-off-by: Daniel Koch

git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1363 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/build_angle.gypi b/src/build_angle.gypi
index 6f316ac..f115edc 100644
--- a/src/build_angle.gypi
+++ b/src/build_angle.gypi
@@ -259,6 +259,8 @@
             'libGLESv2/renderer/ShaderCache.h',
             'libGLESv2/renderer/SwapChain.cpp',
             'libGLESv2/renderer/SwapChain.h',
+            'libGLESv2/renderer/TextureStorage.cpp',
+            'libGLESv2/renderer/TextureStorage.h',
             'libGLESv2/ResourceManager.cpp',
             'libGLESv2/ResourceManager.h',
             'libGLESv2/Shader.cpp',
diff --git a/src/libGLESv2/Texture.cpp b/src/libGLESv2/Texture.cpp
index 6de9317..66718cb 100644
--- a/src/libGLESv2/Texture.cpp
+++ b/src/libGLESv2/Texture.cpp
@@ -24,8 +24,6 @@
 
 namespace gl
 {
-unsigned int TextureStorage::mCurrentTextureSerial = 1;
-
 static inline DWORD GetTextureUsage(D3DFORMAT d3dfmt, GLenum glusage, bool forceRenderable)
 {
     DWORD d3dusage = 0;
@@ -219,53 +217,6 @@
 }
 }
 
-TextureStorage::TextureStorage(DWORD usage)
-    : mD3DUsage(usage),
-      mD3DPool(getDisplay()->getRenderer()->getTexturePool(usage)), // D3D9_REPLACE
-      mTextureSerial(issueTextureSerial()),
-      mLodOffset(0)
-{
-}
-
-TextureStorage::~TextureStorage()
-{
-}
-
-bool TextureStorage::isRenderTarget() const
-{
-    return (mD3DUsage & (D3DUSAGE_RENDERTARGET | D3DUSAGE_DEPTHSTENCIL)) != 0;
-}
-
-bool TextureStorage::isManaged() const
-{
-    return (mD3DPool == D3DPOOL_MANAGED);
-}
-
-D3DPOOL TextureStorage::getPool() const
-{
-    return mD3DPool;
-}
-
-DWORD TextureStorage::getUsage() const
-{
-    return mD3DUsage;
-}
-
-unsigned int TextureStorage::getTextureSerial() const
-{
-    return mTextureSerial;
-}
-
-unsigned int TextureStorage::issueTextureSerial()
-{
-    return mCurrentTextureSerial++;
-}
-
-int TextureStorage::getLodOffset() const
-{
-    return mLodOffset;
-}
-
 Texture::Texture(GLuint id) : RefCountObject(id)
 {
     mSamplerState.minFilter = GL_NEAREST_MIPMAP_LINEAR;
@@ -689,70 +640,6 @@
     return true;
 }
 
-TextureStorage2D::TextureStorage2D(IDirect3DTexture9 *surfaceTexture) : TextureStorage(D3DUSAGE_RENDERTARGET), mRenderTargetSerial(RenderbufferStorage::issueSerial())
-{
-    mTexture = surfaceTexture;
-}
-
-TextureStorage2D::TextureStorage2D(int levels, D3DFORMAT format, DWORD usage, int width, int height)
-    : TextureStorage(usage), mRenderTargetSerial(RenderbufferStorage::issueSerial())
-{
-    mTexture = NULL;
-    // if the width or height is not positive this should be treated as an incomplete texture
-    // we handle that here by skipping the d3d texture creation
-    if (width > 0 && height > 0)
-    {
-        IDirect3DDevice9 *device = getDisplay()->getRenderer()->getDevice(); // D3D9_REPLACE
-        MakeValidSize(false, dx::IsCompressedFormat(format), &width, &height, &mLodOffset);
-        HRESULT result = device->CreateTexture(width, height, levels ? levels + mLodOffset : 0, getUsage(), format, getPool(), &mTexture, NULL);
-
-        if (FAILED(result))
-        {
-            ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
-            error(GL_OUT_OF_MEMORY);
-        }
-    }
-}
-
-TextureStorage2D::~TextureStorage2D()
-{
-    if (mTexture)
-    {
-        mTexture->Release();
-    }
-}
-
-// Increments refcount on surface.
-// caller must Release() the returned surface
-IDirect3DSurface9 *TextureStorage2D::getSurfaceLevel(int level, bool dirty)
-{
-    IDirect3DSurface9 *surface = NULL;
-
-    if (mTexture)
-    {
-        HRESULT result = mTexture->GetSurfaceLevel(level + mLodOffset, &surface);
-        ASSERT(SUCCEEDED(result));
-
-        // With managed textures the driver needs to be informed of updates to the lower mipmap levels
-        if (level != 0 && isManaged() && dirty)
-        {
-            mTexture->AddDirtyRect(NULL);
-        }
-    }
-
-    return surface;
-}
-
-IDirect3DBaseTexture9 *TextureStorage2D::getBaseTexture() const
-{
-    return mTexture;
-}
-
-unsigned int TextureStorage2D::getRenderTargetSerial(GLenum target) const
-{
-    return mRenderTargetSerial;
-}
-
 Texture2D::Texture2D(GLuint id) : Texture(id)
 {
     mTexStorage = NULL;
@@ -1394,67 +1281,6 @@
     return mTexStorage;
 }
 
-TextureStorageCubeMap::TextureStorageCubeMap(int levels, D3DFORMAT format, DWORD usage, int size)
-    : TextureStorage(usage), mFirstRenderTargetSerial(RenderbufferStorage::issueCubeSerials())
-{
-    mTexture = NULL;
-    // if the size is not positive this should be treated as an incomplete texture
-    // we handle that here by skipping the d3d texture creation
-    if (size > 0)
-    {
-        IDirect3DDevice9 *device = getDisplay()->getRenderer()->getDevice(); // D3D9_REPLACE
-        int height = size;
-        MakeValidSize(false, dx::IsCompressedFormat(format), &size, &height, &mLodOffset);
-        HRESULT result = device->CreateCubeTexture(size, levels ? levels + mLodOffset : 0, getUsage(), format, getPool(), &mTexture, NULL);
-
-        if (FAILED(result))
-        {
-            ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
-            error(GL_OUT_OF_MEMORY);
-        }
-    }
-}
-
-TextureStorageCubeMap::~TextureStorageCubeMap()
-{
-    if (mTexture)
-    {
-        mTexture->Release();
-    }
-}
-
-// Increments refcount on surface.
-// caller must Release() the returned surface
-IDirect3DSurface9 *TextureStorageCubeMap::getCubeMapSurface(GLenum faceTarget, int level, bool dirty)
-{
-    IDirect3DSurface9 *surface = NULL;
-
-    if (mTexture)
-    {
-        D3DCUBEMAP_FACES face = es2dx::ConvertCubeFace(faceTarget);
-        HRESULT result = mTexture->GetCubeMapSurface(face, level + mLodOffset, &surface);
-        ASSERT(SUCCEEDED(result));
-
-        // With managed textures the driver needs to be informed of updates to the lower mipmap levels
-        if (level != 0 && isManaged() && dirty)
-        {
-            mTexture->AddDirtyRect(face, NULL);
-        }
-    }
-
-    return surface;
-}
-
-IDirect3DBaseTexture9 *TextureStorageCubeMap::getBaseTexture() const
-{
-    return mTexture;
-}
-
-unsigned int TextureStorageCubeMap::getRenderTargetSerial(GLenum target) const
-{
-    return mFirstRenderTargetSerial + TextureCubeMap::faceIndex(target);
-}
-
 TextureCubeMap::TextureCubeMap(GLuint id) : Texture(id)
 {
     mTexStorage = NULL;
diff --git a/src/libGLESv2/Texture.h b/src/libGLESv2/Texture.h
index 1ed053d..293d5e2 100644
--- a/src/libGLESv2/Texture.h
+++ b/src/libGLESv2/Texture.h
@@ -20,6 +20,7 @@
 #include "common/debug.h"
 #include "common/RefCountObject.h"
 #include "libGLESv2/renderer/Image.h"
+#include "libGLESv2/renderer/TextureStorage.h"
 #include "libGLESv2/Renderbuffer.h"
 #include "libGLESv2/utilities.h"
 
@@ -54,38 +55,6 @@
     int lodOffset;
 };
 
-
-
-class TextureStorage
-{
-  public:
-    explicit TextureStorage(DWORD usage);
-
-    virtual ~TextureStorage();
-
-    bool isRenderTarget() const;
-    bool isManaged() const;
-    D3DPOOL getPool() const;
-    DWORD getUsage() const;
-    unsigned int getTextureSerial() const;
-    virtual unsigned int getRenderTargetSerial(GLenum target) const = 0;
-    int getLodOffset() const;
-
-  protected:
-    int mLodOffset;
-
-  private:
-    DISALLOW_COPY_AND_ASSIGN(TextureStorage);
-
-    const DWORD mD3DUsage;
-    const D3DPOOL mD3DPool;
-
-    const unsigned int mTextureSerial;
-    static unsigned int issueTextureSerial();
-
-    static unsigned int mCurrentTextureSerial;
-};
-
 class Texture : public RefCountObject
 {
   public:
@@ -170,26 +139,6 @@
     virtual TextureStorage *getStorage(bool renderTarget) = 0;
 };
 
-class TextureStorage2D : public TextureStorage
-{
-  public:
-    explicit TextureStorage2D(IDirect3DTexture9 *surfaceTexture);
-    TextureStorage2D(int levels, D3DFORMAT format, DWORD usage, int width, int height);
-
-    virtual ~TextureStorage2D();
-
-    IDirect3DSurface9 *getSurfaceLevel(int level, bool dirty);
-    IDirect3DBaseTexture9 *getBaseTexture() const;
-
-    virtual unsigned int getRenderTargetSerial(GLenum target) const;
-
-  private:
-    DISALLOW_COPY_AND_ASSIGN(TextureStorage2D);
-
-    IDirect3DTexture9 *mTexture;
-    const unsigned int mRenderTargetSerial;
-};
-
 class Texture2D : public Texture
 {
   public:
@@ -258,25 +207,6 @@
     unsigned int mProxyRefs;
 };
 
-class TextureStorageCubeMap : public TextureStorage
-{
-  public:
-    TextureStorageCubeMap(int levels, D3DFORMAT format, DWORD usage, int size);
-
-    virtual ~TextureStorageCubeMap();
-
-    IDirect3DSurface9 *getCubeMapSurface(GLenum faceTarget, int level, bool dirty);
-    IDirect3DBaseTexture9 *getBaseTexture() const;
-
-    virtual unsigned int getRenderTargetSerial(GLenum target) const;
-
-  private:
-    DISALLOW_COPY_AND_ASSIGN(TextureStorageCubeMap);
-
-    IDirect3DCubeTexture9 *mTexture;
-    const unsigned int mFirstRenderTargetSerial;
-};
-
 class TextureCubeMap : public Texture
 {
   public:
diff --git a/src/libGLESv2/libGLESv2.vcxproj b/src/libGLESv2/libGLESv2.vcxproj
index 766fb92..88edaeb 100644
--- a/src/libGLESv2/libGLESv2.vcxproj
+++ b/src/libGLESv2/libGLESv2.vcxproj
@@ -248,6 +248,7 @@
     <ClCompile Include="renderer\Renderer9.cpp" />

     <ClCompile Include="renderer\Image.cpp" />

     <ClCompile Include="renderer\SwapChain.cpp" />

+    <ClCompile Include="renderer\TextureStorage.cpp" />

     <ClCompile Include="ResourceManager.cpp" />

     <ClCompile Include="Shader.cpp" />

     <ClCompile Include="Texture.cpp" />

@@ -281,6 +282,7 @@
     <ClInclude Include="renderer\Renderer9.h" />

     <ClInclude Include="renderer\ShaderCache.h" />

     <ClInclude Include="renderer\SwapChain.h" />

+    <ClInclude Include="renderer\TextureStorage.h" />

     <ClInclude Include="resource.h" />

     <ClInclude Include="ResourceManager.h" />

     <ClInclude Include="Shader.h" />

diff --git a/src/libGLESv2/libGLESv2.vcxproj.filters b/src/libGLESv2/libGLESv2.vcxproj.filters
index 7e7c110..036a030 100644
--- a/src/libGLESv2/libGLESv2.vcxproj.filters
+++ b/src/libGLESv2/libGLESv2.vcxproj.filters
@@ -92,6 +92,9 @@
     <ClCompile Include="renderer\Image.cpp">

       <Filter>Renderer</Filter>

     </ClCompile>

+    <ClCompile Include="renderer\TextureStorage.cpp">

+      <Filter>Renderer</Filter>

+    </ClCompile>

   </ItemGroup>

   <ItemGroup>

     <ClInclude Include="BinaryStream.h">

@@ -191,6 +194,9 @@
     <ClInclude Include="renderer\Image.h">

       <Filter>Renderer</Filter>

     </ClInclude>

+    <ClInclude Include="renderer\TextureStorage.h">

+      <Filter>Renderer</Filter>

+    </ClInclude>

   </ItemGroup>

   <ItemGroup>

     <None Include="libGLESv2.def">

diff --git a/src/libGLESv2/renderer/TextureStorage.cpp b/src/libGLESv2/renderer/TextureStorage.cpp
new file mode 100644
index 0000000..b20c370
--- /dev/null
+++ b/src/libGLESv2/renderer/TextureStorage.cpp
@@ -0,0 +1,192 @@
+//
+// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+
+// TextureStorage.cpp: Implements the abstract gl::TextureStorage class and its concrete derived
+// classes TextureStorage2D and TextureStorageCubeMap, which act as the interface to the
+// D3D-side texture.
+
+#include "libGLESv2/main.h"
+#include "libGLESv2/renderer/TextureStorage.h"
+
+#include "common/debug.h"
+
+namespace gl
+{
+unsigned int TextureStorage::mCurrentTextureSerial = 1;
+
+TextureStorage::TextureStorage(DWORD usage)
+    : mD3DUsage(usage),
+      mD3DPool(getDisplay()->getRenderer()->getTexturePool(usage)), // D3D9_REPLACE
+      mTextureSerial(issueTextureSerial()),
+      mLodOffset(0)
+{
+}
+
+TextureStorage::~TextureStorage()
+{
+}
+
+bool TextureStorage::isRenderTarget() const
+{
+    return (mD3DUsage & (D3DUSAGE_RENDERTARGET | D3DUSAGE_DEPTHSTENCIL)) != 0;
+}
+
+bool TextureStorage::isManaged() const
+{
+    return (mD3DPool == D3DPOOL_MANAGED);
+}
+
+D3DPOOL TextureStorage::getPool() const
+{
+    return mD3DPool;
+}
+
+DWORD TextureStorage::getUsage() const
+{
+    return mD3DUsage;
+}
+
+unsigned int TextureStorage::getTextureSerial() const
+{
+    return mTextureSerial;
+}
+
+unsigned int TextureStorage::issueTextureSerial()
+{
+    return mCurrentTextureSerial++;
+}
+
+int TextureStorage::getLodOffset() const
+{
+    return mLodOffset;
+}
+
+TextureStorage2D::TextureStorage2D(IDirect3DTexture9 *surfaceTexture) : TextureStorage(D3DUSAGE_RENDERTARGET), mRenderTargetSerial(RenderbufferStorage::issueSerial())
+{
+    mTexture = surfaceTexture;
+}
+
+TextureStorage2D::TextureStorage2D(int levels, D3DFORMAT format, DWORD usage, int width, int height)
+    : TextureStorage(usage), mRenderTargetSerial(RenderbufferStorage::issueSerial())
+{
+    mTexture = NULL;
+    // if the width or height is not positive this should be treated as an incomplete texture
+    // we handle that here by skipping the d3d texture creation
+    if (width > 0 && height > 0)
+    {
+        IDirect3DDevice9 *device = getDisplay()->getRenderer()->getDevice(); // D3D9_REPLACE
+        MakeValidSize(false, dx::IsCompressedFormat(format), &width, &height, &mLodOffset);
+        HRESULT result = device->CreateTexture(width, height, levels ? levels + mLodOffset : 0, getUsage(), format, getPool(), &mTexture, NULL);
+
+        if (FAILED(result))
+        {
+            ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
+            error(GL_OUT_OF_MEMORY);
+        }
+    }
+}
+
+TextureStorage2D::~TextureStorage2D()
+{
+    if (mTexture)
+    {
+        mTexture->Release();
+    }
+}
+
+// Increments refcount on surface.
+// caller must Release() the returned surface
+IDirect3DSurface9 *TextureStorage2D::getSurfaceLevel(int level, bool dirty)
+{
+    IDirect3DSurface9 *surface = NULL;
+
+    if (mTexture)
+    {
+        HRESULT result = mTexture->GetSurfaceLevel(level + mLodOffset, &surface);
+        ASSERT(SUCCEEDED(result));
+
+        // With managed textures the driver needs to be informed of updates to the lower mipmap levels
+        if (level != 0 && isManaged() && dirty)
+        {
+            mTexture->AddDirtyRect(NULL);
+        }
+    }
+
+    return surface;
+}
+
+IDirect3DBaseTexture9 *TextureStorage2D::getBaseTexture() const
+{
+    return mTexture;
+}
+
+unsigned int TextureStorage2D::getRenderTargetSerial(GLenum target) const
+{
+    return mRenderTargetSerial;
+}
+
+TextureStorageCubeMap::TextureStorageCubeMap(int levels, D3DFORMAT format, DWORD usage, int size)
+    : TextureStorage(usage), mFirstRenderTargetSerial(RenderbufferStorage::issueCubeSerials())
+{
+    mTexture = NULL;
+    // if the size is not positive this should be treated as an incomplete texture
+    // we handle that here by skipping the d3d texture creation
+    if (size > 0)
+    {
+        IDirect3DDevice9 *device = getDisplay()->getRenderer()->getDevice(); // D3D9_REPLACE
+        int height = size;
+        MakeValidSize(false, dx::IsCompressedFormat(format), &size, &height, &mLodOffset);
+        HRESULT result = device->CreateCubeTexture(size, levels ? levels + mLodOffset : 0, getUsage(), format, getPool(), &mTexture, NULL);
+
+        if (FAILED(result))
+        {
+            ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
+            error(GL_OUT_OF_MEMORY);
+        }
+    }
+}
+
+TextureStorageCubeMap::~TextureStorageCubeMap()
+{
+    if (mTexture)
+    {
+        mTexture->Release();
+    }
+}
+
+// Increments refcount on surface.
+// caller must Release() the returned surface
+IDirect3DSurface9 *TextureStorageCubeMap::getCubeMapSurface(GLenum faceTarget, int level, bool dirty)
+{
+    IDirect3DSurface9 *surface = NULL;
+
+    if (mTexture)
+    {
+        D3DCUBEMAP_FACES face = es2dx::ConvertCubeFace(faceTarget);
+        HRESULT result = mTexture->GetCubeMapSurface(face, level + mLodOffset, &surface);
+        ASSERT(SUCCEEDED(result));
+
+        // With managed textures the driver needs to be informed of updates to the lower mipmap levels
+        if (level != 0 && isManaged() && dirty)
+        {
+            mTexture->AddDirtyRect(face, NULL);
+        }
+    }
+
+    return surface;
+}
+
+IDirect3DBaseTexture9 *TextureStorageCubeMap::getBaseTexture() const
+{
+    return mTexture;
+}
+
+unsigned int TextureStorageCubeMap::getRenderTargetSerial(GLenum target) const
+{
+    return mFirstRenderTargetSerial + TextureCubeMap::faceIndex(target);
+}
+
+}
\ No newline at end of file
diff --git a/src/libGLESv2/renderer/TextureStorage.h b/src/libGLESv2/renderer/TextureStorage.h
new file mode 100644
index 0000000..472ef3d
--- /dev/null
+++ b/src/libGLESv2/renderer/TextureStorage.h
@@ -0,0 +1,95 @@
+//
+// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+
+// TextureStorage.h: Defines the abstract gl::TextureStorage class and its concrete derived
+// classes TextureStorage2D and TextureStorageCubeMap, which act as the interface to the
+// D3D-side texture.
+
+#ifndef LIBGLESV2_TEXTURESTORAGE_H_
+#define LIBGLESV2_TEXTURESTORAGE_H_
+
+#define GL_APICALL
+#include <GLES2/gl2.h>
+#include <d3d9.h>
+
+#include "common/debug.h"
+
+namespace gl
+{
+
+class TextureStorage
+{
+  public:
+    explicit TextureStorage(DWORD usage);
+
+    virtual ~TextureStorage();
+
+    bool isRenderTarget() const;
+    bool isManaged() const;
+    D3DPOOL getPool() const;
+    DWORD getUsage() const;
+    unsigned int getTextureSerial() const;
+    virtual unsigned int getRenderTargetSerial(GLenum target) const = 0;
+    int getLodOffset() const;
+
+  protected:
+    int mLodOffset;
+
+  private:
+    DISALLOW_COPY_AND_ASSIGN(TextureStorage);
+
+    const DWORD mD3DUsage;
+    const D3DPOOL mD3DPool;
+
+    const unsigned int mTextureSerial;
+    static unsigned int issueTextureSerial();
+
+    static unsigned int mCurrentTextureSerial;
+};
+
+class TextureStorage2D : public TextureStorage
+{
+  public:
+    explicit TextureStorage2D(IDirect3DTexture9 *surfaceTexture);
+    TextureStorage2D(int levels, D3DFORMAT format, DWORD usage, int width, int height);
+
+    virtual ~TextureStorage2D();
+
+    IDirect3DSurface9 *getSurfaceLevel(int level, bool dirty);
+    IDirect3DBaseTexture9 *getBaseTexture() const;
+
+    virtual unsigned int getRenderTargetSerial(GLenum target) const;
+
+  private:
+    DISALLOW_COPY_AND_ASSIGN(TextureStorage2D);
+
+    IDirect3DTexture9 *mTexture;
+    const unsigned int mRenderTargetSerial;
+};
+
+class TextureStorageCubeMap : public TextureStorage
+{
+  public:
+    TextureStorageCubeMap(int levels, D3DFORMAT format, DWORD usage, int size);
+
+    virtual ~TextureStorageCubeMap();
+
+    IDirect3DSurface9 *getCubeMapSurface(GLenum faceTarget, int level, bool dirty);
+    IDirect3DBaseTexture9 *getBaseTexture() const;
+
+    virtual unsigned int getRenderTargetSerial(GLenum target) const;
+
+  private:
+    DISALLOW_COPY_AND_ASSIGN(TextureStorageCubeMap);
+
+    IDirect3DCubeTexture9 *mTexture;
+    const unsigned int mFirstRenderTargetSerial;
+};
+
+}
+
+#endif // LIBGLESV2_TEXTURESTORAGE_H_
+