diff options
Diffstat (limited to 'libs/hwui')
| -rw-r--r-- | libs/hwui/Caches.cpp | 17 | ||||
| -rw-r--r-- | libs/hwui/Layer.h | 3 | ||||
| -rw-r--r-- | libs/hwui/OpenGLRenderer.cpp | 28 | ||||
| -rw-r--r-- | libs/hwui/Texture.h | 10 | ||||
| -rw-r--r-- | libs/hwui/TextureCache.cpp | 17 |
5 files changed, 59 insertions, 16 deletions
diff --git a/libs/hwui/Caches.cpp b/libs/hwui/Caches.cpp index d18a5b0..e7085b0 100644 --- a/libs/hwui/Caches.cpp +++ b/libs/hwui/Caches.cpp @@ -399,9 +399,20 @@ bool Caches::setScissor(GLint x, GLint y, GLint width, GLint height) { if (scissorEnabled && (x != mScissorX || y != mScissorY || width != mScissorWidth || height != mScissorHeight)) { - if (x < 0) x = 0; - if (y < 0) y = 0; - + if (x < 0) { + width += x; + x = 0; + } + if (y < 0) { + height += y; + y = 0; + } + if (width < 0) { + width = 0; + } + if (height < 0) { + height = 0; + } glScissor(x, y, width, height); mScissorX = x; diff --git a/libs/hwui/Layer.h b/libs/hwui/Layer.h index 69be317..448e3da 100644 --- a/libs/hwui/Layer.h +++ b/libs/hwui/Layer.h @@ -209,6 +209,9 @@ struct Layer { } inline void allocateTexture(GLenum format, GLenum storage) { +#if DEBUG_LAYERS + ALOGD(" Allocate layer: %dx%d", getWidth(), getHeight()); +#endif glTexImage2D(renderTarget, 0, format, getWidth(), getHeight(), 0, format, storage, NULL); } diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp index 89cefe0..b6be5b3 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 @@ -895,12 +895,6 @@ void OpenGLRenderer::composeLayer(sp<Snapshot> current, sp<Snapshot> previous) { void OpenGLRenderer::drawTextureLayer(Layer* layer, const Rect& rect) { float alpha = layer->getAlpha() / 255.0f; - mat4& transform = layer->getTransform(); - if (!transform.isIdentity()) { - save(0); - mSnapshot->transform->multiply(transform); - } - setupDraw(); if (layer->getRenderTarget() == GL_TEXTURE_2D) { setupDrawWithTexture(); @@ -937,10 +931,6 @@ void OpenGLRenderer::drawTextureLayer(Layer* layer, const Rect& rect) { glDrawArrays(GL_TRIANGLE_STRIP, 0, gMeshCount); finishDrawTexture(); - - if (!transform.isIdentity()) { - restore(); - } } void OpenGLRenderer::composeLayerRect(Layer* layer, const Rect& rect, bool swap) { @@ -2792,12 +2782,24 @@ status_t OpenGLRenderer::drawLayer(Layer* layer, float x, float y, SkPaint* pain return DrawGlInfo::kStatusDone; } + mat4* transform = NULL; + if (layer->isTextureLayer()) { + transform = &layer->getTransform(); + if (!transform->isIdentity()) { + save(0); + mSnapshot->transform->multiply(*transform); + } + } + Rect transformed; Rect clip; const bool rejected = quickRejectNoScissor(x, y, x + layer->layer.getWidth(), y + layer->layer.getHeight(), transformed, clip); if (rejected) { + if (transform && !transform->isIdentity()) { + restore(); + } return DrawGlInfo::kStatusDone; } @@ -2858,6 +2860,10 @@ status_t OpenGLRenderer::drawLayer(Layer* layer, float x, float y, SkPaint* pain } } + if (transform && !transform->isIdentity()) { + restore(); + } + return DrawGlInfo::kStatusDrew; } 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..10d112a 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" @@ -216,8 +217,15 @@ void TextureCache::generateTexture(SkBitmap* bitmap, Texture* texture, bool rege return; } + // We could also enable mipmapping if both bitmap dimensions are powers + // of 2 but we'd have to deal with size changes. Let's keep this simple + const bool canMipMap = Caches::getInstance().extensions.hasNPot(); + + // 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 && canMipMap && texture->mipMap && !bitmap->hasHardwareMipMap()); if (!regenerate) { glGenTextures(1, &texture->id); @@ -261,6 +269,13 @@ void TextureCache::generateTexture(SkBitmap* bitmap, Texture* texture, bool rege break; } + if (canMipMap) { + texture->mipMap = bitmap->hasHardwareMipMap(); + if (texture->mipMap) { + glGenerateMipmap(GL_TEXTURE_2D); + } + } + if (!regenerate) { texture->setFilter(GL_NEAREST); texture->setWrap(GL_CLAMP_TO_EDGE); |
