get genmipmap function in the struct

BUG=
R=bsalomon@google.com, reed@google.com

Author: humper@google.com

Review URL: https://chromiumcodereview.appspot.com/20436002

git-svn-id: http://skia.googlecode.com/svn/trunk@10393 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/gpu/GrTexture.h b/include/gpu/GrTexture.h
index a870818..acb7ade 100644
--- a/include/gpu/GrTexture.h
+++ b/include/gpu/GrTexture.h
@@ -43,6 +43,14 @@
     bool isSetFlag(GrTextureFlags flags) const {
         return 0 != (fDesc.fFlags & flags);
     }
+    
+    void dirtyMipMaps(bool mipMapsDirty) {
+        fMipMapsDirty = mipMapsDirty;
+    }
+    
+    bool mipMapsAreDirty() const {
+        return fMipMapsDirty;
+    }
 
     /**
      *  Approximate number of bytes used by the texture
@@ -136,7 +144,8 @@
 
     GrTexture(GrGpu* gpu, bool isWrapped, const GrTextureDesc& desc)
     : INHERITED(gpu, isWrapped, desc)
-    , fRenderTarget(NULL) {
+    , fRenderTarget(NULL) 
+    , fMipMapsDirty(true) {
 
         // only make sense if alloc size is pow2
         fShiftFixedX = 31 - SkCLZ(fDesc.fWidth);
@@ -155,6 +164,8 @@
     // for this texture if the texture is power of two sized.
     int                 fShiftFixedX;
     int                 fShiftFixedY;
+    
+    bool                fMipMapsDirty;
 
     virtual void internal_dispose() const SK_OVERRIDE;
 
diff --git a/include/gpu/gl/GrGLFunctions.h b/include/gpu/gl/GrGLFunctions.h
index c29c14f..b30ef3a 100644
--- a/include/gpu/gl/GrGLFunctions.h
+++ b/include/gpu/gl/GrGLFunctions.h
@@ -94,6 +94,7 @@
     typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLFrontFaceProc)(GrGLenum mode);
     typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLGenBuffersProc)(GrGLsizei n, GrGLuint* buffers);
     typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLGenFramebuffersProc)(GrGLsizei n, GrGLuint *framebuffers);
+    typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLGenerateMipmapProc)(GrGLenum target);
     typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLGenQueriesProc)(GrGLsizei n, GrGLuint *ids);
     typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLGenRenderbuffersProc)(GrGLsizei n, GrGLuint *renderbuffers);
     typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GrGLGenTexturesProc)(GrGLsizei n, GrGLuint* textures);
diff --git a/include/gpu/gl/GrGLInterface.h b/include/gpu/gl/GrGLInterface.h
index 6cc8e17..6a51adc 100644
--- a/include/gpu/gl/GrGLInterface.h
+++ b/include/gpu/gl/GrGLInterface.h
@@ -189,6 +189,7 @@
     GLPtr<GrGLFrontFaceProc> fFrontFace;
     GLPtr<GrGLGenBuffersProc> fGenBuffers;
     GLPtr<GrGLGenFramebuffersProc> fGenFramebuffers;
+    GLPtr<GrGLGenerateMipmapProc> fGenerateMipmap;
     GLPtr<GrGLGenQueriesProc> fGenQueries;
     GLPtr<GrGLGenRenderbuffersProc> fGenRenderbuffers;
     GLPtr<GrGLGenTexturesProc> fGenTextures;
diff --git a/src/gpu/gl/GrGLCreateNullInterface.cpp b/src/gpu/gl/GrGLCreateNullInterface.cpp
index aa9b93c..0d539c9 100644
--- a/src/gpu/gl/GrGLCreateNullInterface.cpp
+++ b/src/gpu/gl/GrGLCreateNullInterface.cpp
@@ -109,6 +109,8 @@
     }
 }
 
+GrGLvoid GR_GL_FUNCTION_TYPE nullGLGenerateMipmap(GrGLenum target) {}
+
 GrGLvoid GR_GL_FUNCTION_TYPE nullGLBufferData(GrGLenum target,
                                               GrGLsizeiptr size,
                                               const GrGLvoid* data,
@@ -306,6 +308,7 @@
         interface->fFlush = noOpGLFlush;
         interface->fFrontFace = noOpGLFrontFace;
         interface->fGenBuffers = nullGLGenBuffers;
+        interface->fGenerateMipmap = nullGLGenerateMipmap;
         interface->fGenQueries = noOpGLGenIds;
         interface->fGenTextures = noOpGLGenIds;
         interface->fGenVertexArrays = noOpGLGenIds;
diff --git a/src/gpu/gl/GrGLInterface.cpp b/src/gpu/gl/GrGLInterface.cpp
index f5cef11..72d7934 100644
--- a/src/gpu/gl/GrGLInterface.cpp
+++ b/src/gpu/gl/GrGLInterface.cpp
@@ -78,6 +78,9 @@
         NULL == fGenBuffers ||
         NULL == fGenTextures ||
         NULL == fGetBufferParameteriv ||
+#ifndef SKIA_IGNORE_GPU_MIPMAPS
+        NULL == fGenerateMipmap ||
+#endif
         NULL == fGetError ||
         NULL == fGetIntegerv ||
         NULL == fGetProgramInfoLog ||
diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp
index 5b9609b..149025a 100644
--- a/src/gpu/gl/GrGpuGL.cpp
+++ b/src/gpu/gl/GrGpuGL.cpp
@@ -526,9 +526,14 @@
     desc.fTextureID = glTex->textureID();
     desc.fOrigin = glTex->origin();
 
-    return this->uploadTexData(desc, false,
-                               left, top, width, height,
-                               config, buffer, rowBytes);
+    if (this->uploadTexData(desc, false,
+                            left, top, width, height,
+                            config, buffer, rowBytes)) {
+        texture->dirtyMipMaps(true);
+        return true;
+    } else {
+        return false;
+    }
 }
 
 namespace {
@@ -1547,6 +1552,11 @@
     if (NULL == bound || !bound->isEmpty()) {
         rt->flagAsNeedingResolve(bound);
     }
+    
+    GrTexture *texture = rt->asTexture();
+    if (texture) {
+        texture->dirtyMipMaps(true);
+    }
 }
 
 GrGLenum gPrimitiveType2GLMode[] = {
@@ -2006,7 +2016,21 @@
     bool setAll = timestamp < this->getResetTimestamp();
     GrGLTexture::TexParams newTexParams;
 
-    newTexParams.fFilter = (params.filterMode() == GrTextureParams::kNone_FilterMode) ? GR_GL_NEAREST : GR_GL_LINEAR;
+    static GrGLenum glFilterModes[] = {
+        GR_GL_NEAREST,
+        GR_GL_LINEAR,
+        GR_GL_LINEAR_MIPMAP_LINEAR
+    };
+    newTexParams.fFilter = glFilterModes[params.filterMode()];
+    
+#ifndef SKIA_IGNORE_GPU_MIPMAPS
+    if (params.filterMode() == GrTextureParams::kMipMap_FilterMode && 
+        texture->mipMapsAreDirty()) {
+//        GL_CALL(Hint(GR_GL_GENERATE_MIPMAP_HINT,GR_GL_NICEST));
+        GL_CALL(GenerateMipmap(GR_GL_TEXTURE_2D));
+        texture->dirtyMipMaps(false);
+    }
+#endif
 
     newTexParams.fWrapS = tile_to_gl_wrap(params.getTileModeX());
     newTexParams.fWrapT = tile_to_gl_wrap(params.getTileModeY());
diff --git a/src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp b/src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp
index 77248a0..cfd181a 100644
--- a/src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp
+++ b/src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp
@@ -62,6 +62,7 @@
         interface->fFlush = glFlush;
         interface->fFrontFace = glFrontFace;
         interface->fGenBuffers = glGenBuffers;
+        interface->fGenerateMipmap = glGenerateMipmap;
         interface->fGenTextures = glGenTextures;
         interface->fGenVertexArrays = glGenVertexArraysOES;
         interface->fGetBufferParameteriv = glGetBufferParameteriv;
diff --git a/src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp b/src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp
index 1b9f5c2..d74e395 100644
--- a/src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp
+++ b/src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp
@@ -77,6 +77,7 @@
         GET_PROC(Flush);
         GET_PROC(FrontFace);
         GET_PROC(GenBuffers);
+        GET_PROC(GenerateMipmap);
         GET_PROC(GenTextures);
         interface->fGenVertexArrays =
             (GrGLGenVertexArraysProc) eglGetProcAddress("glGenVertexArraysOES");
diff --git a/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp b/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp
index 0666fdd..d517aa8 100644
--- a/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp
+++ b/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp
@@ -523,6 +523,9 @@
     debugGenObjs(GrDebugGL::kBuffer_ObjTypes, n, ids);
 }
 
+GrGLvoid GR_GL_FUNCTION_TYPE debugGLGenerateMipmap(GrGLenum level) {
+}
+
 GrGLvoid GR_GL_FUNCTION_TYPE debugGLGenFramebuffers(GrGLsizei n,
                                                     GrGLuint* ids) {
     debugGenObjs(GrDebugGL::kFrameBuffer_ObjTypes, n, ids);
@@ -824,6 +827,7 @@
     interface->fFinish = noOpGLFinish;
     interface->fFlush = noOpGLFlush;
     interface->fFrontFace = noOpGLFrontFace;
+    interface->fGenerateMipmap = debugGLGenerateMipmap;
     interface->fGenBuffers = debugGLGenBuffers;
     interface->fGenQueries = noOpGLGenIds;
     interface->fGenTextures = debugGLGenTextures;
diff --git a/src/gpu/gl/iOS/GrGLCreateNativeInterface_iOS.cpp b/src/gpu/gl/iOS/GrGLCreateNativeInterface_iOS.cpp
index e83ccdd..62a39e3 100644
--- a/src/gpu/gl/iOS/GrGLCreateNativeInterface_iOS.cpp
+++ b/src/gpu/gl/iOS/GrGLCreateNativeInterface_iOS.cpp
@@ -54,6 +54,7 @@
         interface->fFlush = glFlush;
         interface->fFrontFace = glFrontFace;
         interface->fGenBuffers = glGenBuffers;
+        interface->fGenerateMipmap = glGenerateMipmap;
         interface->fGetBufferParameteriv = glGetBufferParameteriv;
         interface->fGetError = glGetError;
         interface->fGetIntegerv = glGetIntegerv;
diff --git a/src/gpu/gl/mac/GrGLCreateNativeInterface_mac.cpp b/src/gpu/gl/mac/GrGLCreateNativeInterface_mac.cpp
index 1455d1f..eb0e87e 100644
--- a/src/gpu/gl/mac/GrGLCreateNativeInterface_mac.cpp
+++ b/src/gpu/gl/mac/GrGLCreateNativeInterface_mac.cpp
@@ -110,6 +110,7 @@
         GET_PROC(Flush);
         GET_PROC(FrontFace);
         GET_PROC(GenBuffers);
+        GET_PROC(GenerateMipmap);
         GET_PROC(GenQueries);
         GET_PROC(GetBufferParameteriv);
         GET_PROC(GetError);
diff --git a/src/gpu/gl/mesa/GrGLCreateMesaInterface.cpp b/src/gpu/gl/mesa/GrGLCreateMesaInterface.cpp
index 55f4409..1ffcbcd 100644
--- a/src/gpu/gl/mesa/GrGLCreateMesaInterface.cpp
+++ b/src/gpu/gl/mesa/GrGLCreateMesaInterface.cpp
@@ -89,6 +89,7 @@
         GR_GL_GET_PROC(Flush);
         GR_GL_GET_PROC(FrontFace);
         GR_GL_GET_PROC(GenBuffers);
+        GR_GL_GET_PROC(GenerateMipmap);
         GR_GL_GET_PROC(GenQueries);
         GR_GL_GET_PROC(GetBufferParameteriv);
         GR_GL_GET_PROC(GetError);
diff --git a/src/gpu/gl/unix/GrGLCreateNativeInterface_unix.cpp b/src/gpu/gl/unix/GrGLCreateNativeInterface_unix.cpp
index 00bff3f..3d35006 100644
--- a/src/gpu/gl/unix/GrGLCreateNativeInterface_unix.cpp
+++ b/src/gpu/gl/unix/GrGLCreateNativeInterface_unix.cpp
@@ -89,6 +89,7 @@
         interface->fFlush = glFlush;
         interface->fFrontFace = glFrontFace;
         GR_GL_GET_PROC(GenBuffers);
+        GR_GL_GET_PROC(GenerateMipmap);
         GR_GL_GET_PROC(GetBufferParameteriv);
         interface->fGetError = glGetError;
         interface->fGetIntegerv = glGetIntegerv;
diff --git a/src/gpu/gl/win/GrGLCreateNativeInterface_win.cpp b/src/gpu/gl/win/GrGLCreateNativeInterface_win.cpp
index 28ef2ef..53b1edd 100644
--- a/src/gpu/gl/win/GrGLCreateNativeInterface_win.cpp
+++ b/src/gpu/gl/win/GrGLCreateNativeInterface_win.cpp
@@ -152,6 +152,7 @@
         WGL_SET_PROC(EnableVertexAttribArray);
         WGL_SET_PROC(EndQuery);
         WGL_SET_PROC(GenBuffers);
+        WGL_SET_PROC(GenerateMipmap);
         WGL_SET_PROC(GenQueries);
         WGL_SET_PROC(GetBufferParameteriv);
         WGL_SET_PROC(GetQueryiv);