Merge "Apply bilinear filtering on text only when necessary."
This commit is contained in:
@@ -437,8 +437,9 @@ void FontRenderer::initTextTexture() {
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, mCacheWidth, mCacheHeight, 0,
|
||||
GL_ALPHA, GL_UNSIGNED_BYTE, 0);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
mLinearFiltering = false;
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
@@ -156,8 +156,16 @@ public:
|
||||
DropShadow renderDropShadow(SkPaint* paint, const char *text, uint32_t startIndex,
|
||||
uint32_t len, int numGlyphs, uint32_t radius);
|
||||
|
||||
GLuint getTexture() {
|
||||
GLuint getTexture(bool linearFiltering = false) {
|
||||
checkInit();
|
||||
if (linearFiltering != mLinearFiltering) {
|
||||
mLinearFiltering = linearFiltering;
|
||||
const GLenum filtering = linearFiltering ? GL_LINEAR : GL_NEAREST;
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, mTextureId);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filtering);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filtering);
|
||||
}
|
||||
return mTextureId;
|
||||
}
|
||||
|
||||
@@ -252,6 +260,8 @@ protected:
|
||||
|
||||
bool mInitialized;
|
||||
|
||||
bool mLinearFiltering;
|
||||
|
||||
void computeGaussianWeights(float* weights, int32_t radius);
|
||||
void horizontalBlur(float* weights, int32_t radius, const uint8_t *source, uint8_t *dest,
|
||||
int32_t width, int32_t height);
|
||||
|
||||
@@ -53,6 +53,15 @@ void Matrix4::loadIdentity() {
|
||||
mSimpleMatrix = true;
|
||||
}
|
||||
|
||||
#define EPSILON 0.00001f
|
||||
#define almost(u, v) (fabs((u) - (v)) < EPSILON)
|
||||
|
||||
bool Matrix4::changesBounds() {
|
||||
return !(almost(data[0], 1.0f) && almost(data[1], 0.0f) && almost(data[2], 0.0f) &&
|
||||
almost(data[4], 0.0f) && almost(data[5], 1.0f) && almost(data[6], 0.0f) &&
|
||||
almost(data[8], 0.0f) && almost(data[9], 0.0f) && almost(data[10], 1.0f));
|
||||
}
|
||||
|
||||
void Matrix4::load(const float* v) {
|
||||
memcpy(data, v, sizeof(data));
|
||||
mSimpleMatrix = false;
|
||||
|
||||
@@ -103,6 +103,8 @@ public:
|
||||
multiply(u);
|
||||
}
|
||||
|
||||
bool changesBounds();
|
||||
|
||||
void copyTo(float* v) const;
|
||||
void copyTo(SkMatrix& v) const;
|
||||
|
||||
|
||||
@@ -767,8 +767,10 @@ void OpenGLRenderer::drawText(const char* text, int bytesCount, int count,
|
||||
GLuint textureUnit = 0;
|
||||
glActiveTexture(gTextureUnits[textureUnit]);
|
||||
|
||||
setupTextureAlpha8(fontRenderer.getTexture(), 0, 0, textureUnit, x, y, r, g, b, a,
|
||||
mode, false, true);
|
||||
// Assume that the modelView matrix does not force scales, rotates, etc.
|
||||
const bool linearFilter = mSnapshot->transform->changesBounds();
|
||||
setupTextureAlpha8(fontRenderer.getTexture(linearFilter), 0, 0, textureUnit,
|
||||
x, y, r, g, b, a, mode, false, true);
|
||||
|
||||
const Rect& clip = mSnapshot->getLocalClip();
|
||||
clearLayerRegions();
|
||||
|
||||
Reference in New Issue
Block a user