Removes getDisplay and getContext calls

TRAC #22000

Signed-off-by: Daniel Koch

Author:    Shannon Woods

git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1408 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/libGLESv2/Framebuffer.cpp b/src/libGLESv2/Framebuffer.cpp
index 84a0910..39abfe0 100644
--- a/src/libGLESv2/Framebuffer.cpp
+++ b/src/libGLESv2/Framebuffer.cpp
@@ -273,7 +273,6 @@
 
 GLenum Framebuffer::completeness()
 {
-    gl::Context *context = gl::getContext();
     int width = 0;
     int height = 0;
     int samples = -1;
@@ -313,8 +312,10 @@
                 return GL_FRAMEBUFFER_UNSUPPORTED;
             }
 
-            if ((gl::IsFloat32Format(internalformat) && !context->supportsFloat32RenderableTextures()) ||
-                (gl::IsFloat16Format(internalformat) && !context->supportsFloat16RenderableTextures()))
+            bool filtering, renderable;
+
+            if ((gl::IsFloat32Format(internalformat) && !mRenderer->getFloat32TextureSupport(&filtering, &renderable)) ||
+                (gl::IsFloat16Format(internalformat) && !mRenderer->getFloat16TextureSupport(&filtering, &renderable)))
             {
                 return GL_FRAMEBUFFER_UNSUPPORTED;
             }
@@ -365,7 +366,7 @@
             GLint internalformat = depthbuffer->getInternalFormat();
 
             // depth texture attachments require OES/ANGLE_depth_texture
-            if (!context->supportsDepthTextures())
+            if (!mRenderer->getDepthTextureSupport())
             {
                 return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
             }
@@ -425,7 +426,7 @@
 
             // texture stencil attachments come along as part
             // of OES_packed_depth_stencil + OES/ANGLE_depth_texture
-            if (!context->supportsDepthTextures())
+            if (!mRenderer->getDepthTextureSupport())
             {
                 return GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
             }
diff --git a/src/libGLESv2/ProgramBinary.cpp b/src/libGLESv2/ProgramBinary.cpp
index b3e1521..ed44c36 100644
--- a/src/libGLESv2/ProgramBinary.cpp
+++ b/src/libGLESv2/ProgramBinary.cpp
@@ -1318,8 +1318,8 @@
     }
 
     // Write the HLSL input/output declarations
+    const bool sm3 = mRenderer->getShaderModel3Support();
     Context *context = getContext();
-    const bool sm3 = context->supportsShaderModel3();
     const int maxVaryingVectors = context->getMaximumVaryingVectors();
 
     if (registers == maxVaryingVectors && fragmentShader->mUsesFragCoord)
@@ -1931,9 +1931,8 @@
         return false;
     }
 
-    Context *context = getContext();
-    const char *vertexProfile = context->supportsShaderModel3() ? "vs_3_0" : "vs_2_0";
-    const char *pixelProfile = context->supportsShaderModel3() ? "ps_3_0" : "ps_2_0";
+    const char *vertexProfile = mRenderer->getShaderModel3Support() ? "vs_3_0" : "vs_2_0";
+    const char *pixelProfile = mRenderer->getShaderModel3Support() ? "ps_3_0" : "ps_2_0";
 
     ID3D10Blob *vertexBinary = compileToBinary(infoLog, vertexHLSL.c_str(), vertexProfile, &mConstantTableVS);
     ID3D10Blob *pixelBinary = compileToBinary(infoLog, pixelHLSL.c_str(), pixelProfile, &mConstantTablePS);
@@ -1983,6 +1982,7 @@
         mDxFrontCCWLocation = getUniformLocation("dx_FrontCCW");
         mDxPointsOrLinesLocation = getUniformLocation("dx_PointsOrLines");
 
+        Context *context = getContext();
         context->markDxUniformsDirty();
 
         return true;
diff --git a/src/libGLESv2/Texture.cpp b/src/libGLESv2/Texture.cpp
index 396d456..08b4c4c 100644
--- a/src/libGLESv2/Texture.cpp
+++ b/src/libGLESv2/Texture.cpp
@@ -310,7 +310,7 @@
 
 GLint Texture::creationLevels(GLsizei width, GLsizei height) const
 {
-    if ((isPow2(width) && isPow2(height)) || getContext()->supportsNonPower2Texture())
+    if ((isPow2(width) && isPow2(height)) || mRenderer->getNonPower2TextureSupport())
     {
         return 0;   // Maximum number of levels
     }
@@ -627,9 +627,10 @@
     }
 
     bool mipmapping = isMipmapFiltered();
+    bool filtering, renderable;
 
-    if ((IsFloat32Format(getInternalFormat(0)) && !getContext()->supportsFloat32LinearFilter()) ||
-        (IsFloat16Format(getInternalFormat(0)) && !getContext()->supportsFloat16LinearFilter()))
+    if ((IsFloat32Format(getInternalFormat(0)) && !mRenderer->getFloat32TextureSupport(&filtering, &renderable)) ||
+        (IsFloat16Format(getInternalFormat(0)) && !mRenderer->getFloat16TextureSupport(&filtering, &renderable)))
     {
         if (mSamplerState.magFilter != GL_NEAREST ||
             (mSamplerState.minFilter != GL_NEAREST && mSamplerState.minFilter != GL_NEAREST_MIPMAP_NEAREST))
@@ -638,7 +639,7 @@
         }
     }
 
-    bool npotSupport = getContext()->supportsNonPower2Texture();
+    bool npotSupport = mRenderer->getNonPower2TextureSupport();
 
     if (!npotSupport)
     {
@@ -797,7 +798,7 @@
 
 void Texture2D::generateMipmaps()
 {
-    if (!getContext()->supportsNonPower2Texture())
+    if (!mRenderer->getNonPower2TextureSupport())
     {
         if (!isPow2(mImageArray[0].getWidth()) || !isPow2(mImageArray[0].getHeight()))
         {
@@ -1072,9 +1073,10 @@
     int size = mImageArray[0][0].getWidth();
 
     bool mipmapping = isMipmapFiltered();
+    bool filtering, renderable;
 
-    if ((gl::ExtractType(getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0)) == GL_FLOAT && !getContext()->supportsFloat32LinearFilter()) ||
-        (gl::ExtractType(getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0) == GL_HALF_FLOAT_OES) && !getContext()->supportsFloat16LinearFilter()))
+    if ((gl::ExtractType(getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0)) == GL_FLOAT && !mRenderer->getFloat32TextureSupport(&filtering, &renderable)) ||
+        (gl::ExtractType(getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0) == GL_HALF_FLOAT_OES) && !mRenderer->getFloat16TextureSupport(&filtering, &renderable)))
     {
         if (mSamplerState.magFilter != GL_NEAREST ||
             (mSamplerState.minFilter != GL_NEAREST && mSamplerState.minFilter != GL_NEAREST_MIPMAP_NEAREST))
@@ -1083,7 +1085,7 @@
         }
     }
 
-    if (!isPow2(size) && !getContext()->supportsNonPower2Texture())
+    if (!isPow2(size) && !mRenderer->getNonPower2TextureSupport())
     {
         if (mSamplerState.wrapS != GL_CLAMP_TO_EDGE || mSamplerState.wrapT != GL_CLAMP_TO_EDGE || mipmapping)
         {
@@ -1415,7 +1417,7 @@
         return error(GL_INVALID_OPERATION);
     }
 
-    if (!getContext()->supportsNonPower2Texture())
+    if (!mRenderer->getNonPower2TextureSupport())
     {
         if (!isPow2(mImageArray[0][0].getWidth()))
         {
diff --git a/src/libGLESv2/renderer/Image.cpp b/src/libGLESv2/renderer/Image.cpp
index 716d4cb..f3ffba4 100644
--- a/src/libGLESv2/renderer/Image.cpp
+++ b/src/libGLESv2/renderer/Image.cpp
@@ -210,6 +210,8 @@
 
     mDirty = false;
 
+    mRenderer = NULL;
+
     mD3DPool = D3DPOOL_SYSTEMMEM;
     mD3DFormat = D3DFMT_UNKNOWN;
     mActualFormat = GL_NONE;
@@ -277,6 +279,9 @@
         mD3DFormat = renderer->ConvertTextureInternalFormat(internalformat);
         mActualFormat = dx2es::GetEquivalentFormat(mD3DFormat);
 
+        ASSERT(dynamic_cast<rx::Renderer9*>(renderer) != NULL); // D3D9_REPLACE
+        mRenderer = static_cast<rx::Renderer9*>(renderer); // D3D9_REPLACE
+
         if (mSurface)
         {
             mSurface->Release();
@@ -309,8 +314,8 @@
         GLsizei requestHeight = mHeight;
         MakeValidSize(true, IsCompressed(mInternalFormat), &requestWidth, &requestHeight, &levelToFetch);
 
-        // D3D9_REPLACE
-        IDirect3DDevice9 *device = getDisplay()->getRenderer9()->getDevice();
+        IDirect3DDevice9 *device = mRenderer->getDevice(); // D3D9_REPLACE
+
         HRESULT result = device->CreateTexture(requestWidth, requestHeight, levelToFetch + 1, NULL, d3dFormat,
                                                     poolToUse, &newTexture, NULL);
 
@@ -437,7 +442,8 @@
         rect.bottom = yoffset + height;
 
         POINT point = {rect.left, rect.top};
-        IDirect3DDevice9 *device = getDisplay()->getRenderer9()->getDevice();  // D3D9_REPLACE
+
+        IDirect3DDevice9 *device = mRenderer->getDevice(); // D3D9_REPLACE
 
         if (mD3DPool == D3DPOOL_MANAGED)
         {
@@ -986,7 +992,8 @@
         return error(GL_OUT_OF_MEMORY);
     }
 
-    IDirect3DDevice9 *device = getDisplay()->getRenderer9()->getDevice(); // D3D9_REPLACE
+    IDirect3DDevice9 *device = mRenderer->getDevice(); // D3D9_REPLACE
+
     IDirect3DSurface9 *renderTargetData = NULL;
     D3DSURFACE_DESC description;
     renderTarget->GetDesc(&description);
diff --git a/src/libGLESv2/renderer/Image.h b/src/libGLESv2/renderer/Image.h
index 192c447..a30dc71 100644
--- a/src/libGLESv2/renderer/Image.h
+++ b/src/libGLESv2/renderer/Image.h
@@ -121,6 +121,8 @@
 
     bool mDirty;
 
+    rx::Renderer9 *mRenderer;
+
     D3DPOOL mD3DPool;   // can only be D3DPOOL_SYSTEMMEM or D3DPOOL_MANAGED since it needs to be lockable.
     D3DFORMAT mD3DFormat;
     GLenum mActualFormat;