diff options
author | Romain Guy <romainguy@google.com> | 2012-10-16 19:05:48 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-10-16 19:05:49 -0700 |
commit | 1b85122bd22c4528679ae8bd67077dfc2fdf1847 (patch) | |
tree | 4664b577e4dfdd34b63e6004961c8c7d2f3e1e0b /libs | |
parent | e13ae648504661ca158d15aa415568e351b380c4 (diff) | |
parent | 713e1bb9df6bdfc21bd5c40d1a6ecf6c822a4be5 (diff) | |
download | frameworks_base-1b85122bd22c4528679ae8bd67077dfc2fdf1847.zip frameworks_base-1b85122bd22c4528679ae8bd67077dfc2fdf1847.tar.gz frameworks_base-1b85122bd22c4528679ae8bd67077dfc2fdf1847.tar.bz2 |
Merge "Add API to enable mipmaps on Bitmap Bug #7353771" into jb-mr1-dev
Diffstat (limited to 'libs')
-rw-r--r-- | libs/hwui/OpenGLRenderer.cpp | 2 | ||||
-rw-r--r-- | libs/hwui/Texture.h | 10 | ||||
-rw-r--r-- | libs/hwui/TextureCache.cpp | 15 | ||||
-rw-r--r-- | libs/hwui/TextureCache.h | 1 |
4 files changed, 25 insertions, 3 deletions
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index 89cefe0..406d5e9 100644 --- a/libs/hwui/OpenGLRenderer.cpp +++ b/libs/hwui/OpenGLRenderer.cpp @@ -49,7 +49,7 @@ namespace uirenderer { #define ALPHA_THRESHOLD 0 -#define FILTER(paint) (paint && paint->isFilterBitmap() ? GL_LINEAR : GL_NEAREST) +#define FILTER(paint) (!paint || paint->isFilterBitmap() ? GL_LINEAR : GL_NEAREST) /////////////////////////////////////////////////////////////////////////////// // Globals diff --git a/libs/hwui/Texture.h b/libs/hwui/Texture.h index 03e2172..8d88bdc 100644 --- a/libs/hwui/Texture.h +++ b/libs/hwui/Texture.h @@ -36,6 +36,8 @@ struct Texture { minFilter = GL_NEAREST; magFilter = GL_NEAREST; + mipMap = false; + firstFilter = true; firstWrap = true; @@ -83,6 +85,8 @@ struct Texture { glBindTexture(renderTarget, id); } + if (mipMap && min == GL_LINEAR) min = GL_LINEAR_MIPMAP_LINEAR; + glTexParameteri(renderTarget, GL_TEXTURE_MIN_FILTER, min); glTexParameteri(renderTarget, GL_TEXTURE_MAG_FILTER, mag); } @@ -116,7 +120,12 @@ struct Texture { * Optional, size of the original bitmap. */ uint32_t bitmapSize; + /** + * Indicates whether this texture will use trilinear filtering. + */ + bool mipMap; +private: /** * Last wrap modes set on this texture. Defaults to GL_CLAMP_TO_EDGE. */ @@ -129,7 +138,6 @@ struct Texture { GLenum minFilter; GLenum magFilter; -private: bool firstFilter; bool firstWrap; }; // struct Texture diff --git a/libs/hwui/TextureCache.cpp b/libs/hwui/TextureCache.cpp index 4d16bb4..431367a 100644 --- a/libs/hwui/TextureCache.cpp +++ b/libs/hwui/TextureCache.cpp @@ -22,6 +22,7 @@ #include <utils/threads.h> +#include "Caches.h" #include "TextureCache.h" #include "Properties.h" @@ -73,6 +74,8 @@ void TextureCache::init() { INIT_LOGD(" Maximum texture dimension is %d pixels", mMaxTextureSize); mDebugEnabled = readDebugLevel() & kDebugCaches; + + mHasNPot = Caches::getInstance().extensions.hasNPot(); } /////////////////////////////////////////////////////////////////////////////// @@ -216,8 +219,11 @@ void TextureCache::generateTexture(SkBitmap* bitmap, Texture* texture, bool rege return; } + // If the texture had mipmap enabled but not anymore, + // force a glTexImage2D to discard the mipmap levels const bool resize = !regenerate || bitmap->width() != int(texture->width) || - bitmap->height() != int(texture->height); + bitmap->height() != int(texture->height) || + (regenerate && mHasNPot && texture->mipMap && !bitmap->hasHardwareMipMap()); if (!regenerate) { glGenTextures(1, &texture->id); @@ -261,6 +267,13 @@ void TextureCache::generateTexture(SkBitmap* bitmap, Texture* texture, bool rege break; } + if (mHasNPot) { + texture->mipMap = bitmap->hasHardwareMipMap(); + if (texture->mipMap) { + glGenerateMipmap(GL_TEXTURE_2D); + } + } + if (!regenerate) { texture->setFilter(GL_NEAREST); texture->setWrap(GL_CLAMP_TO_EDGE); diff --git a/libs/hwui/TextureCache.h b/libs/hwui/TextureCache.h index 31a2e3d..8e19092 100644 --- a/libs/hwui/TextureCache.h +++ b/libs/hwui/TextureCache.h @@ -138,6 +138,7 @@ private: float mFlushRate; + bool mHasNPot; bool mDebugEnabled; Vector<SkBitmap*> mGarbage; |