2010-07-21 21:33:20 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2010-10-27 18:57:51 -07:00
|
|
|
#ifndef ANDROID_HWUI_FONT_RENDERER_H
|
|
|
|
#define ANDROID_HWUI_FONT_RENDERER_H
|
2010-07-21 21:33:20 -07:00
|
|
|
|
2013-01-08 11:15:30 -08:00
|
|
|
#include <utils/LruCache.h>
|
2010-07-21 21:33:20 -07:00
|
|
|
#include <utils/Vector.h>
|
|
|
|
|
|
|
|
#include <SkPaint.h>
|
|
|
|
|
|
|
|
#include <GLES2/gl2.h>
|
|
|
|
|
2012-09-04 12:55:44 -07:00
|
|
|
#include "font/FontUtil.h"
|
|
|
|
#include "font/CacheTexture.h"
|
|
|
|
#include "font/CachedGlyphInfo.h"
|
|
|
|
#include "font/Font.h"
|
2013-03-19 11:32:41 -07:00
|
|
|
#include "utils/SortedList.h"
|
2013-01-08 11:15:30 -08:00
|
|
|
#include "Matrix.h"
|
2010-07-23 00:28:00 -07:00
|
|
|
#include "Properties.h"
|
2010-07-22 13:08:20 -07:00
|
|
|
|
2013-02-13 16:14:17 -08:00
|
|
|
namespace RSC {
|
|
|
|
class Element;
|
|
|
|
class RS;
|
|
|
|
class ScriptIntrinsicBlur;
|
|
|
|
}
|
|
|
|
|
2010-07-21 21:33:20 -07:00
|
|
|
namespace android {
|
|
|
|
namespace uirenderer {
|
|
|
|
|
2011-06-01 14:52:00 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Renderer
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-07-21 21:33:20 -07:00
|
|
|
class FontRenderer {
|
|
|
|
public:
|
|
|
|
FontRenderer();
|
|
|
|
~FontRenderer();
|
|
|
|
|
2011-12-16 15:44:59 -08:00
|
|
|
void flushLargeCaches();
|
2010-07-21 21:33:20 -07:00
|
|
|
|
2010-08-26 20:35:23 -07:00
|
|
|
void setGammaTable(const uint8_t* gammaTable) {
|
|
|
|
mGammaTable = gammaTable;
|
|
|
|
}
|
|
|
|
|
2013-01-08 11:15:30 -08:00
|
|
|
void setFont(SkPaint* paint, const mat4& matrix);
|
Optimize interactions with glyph cache
There are two fixes here:
- precaching: instead of caching-then-drawing whenever there is a new
glyph, we cache at DisplayList record time. Then when we finally draw that
DisplayList, we just upload the affected texture(s) once, instead of once
per change. This is a huge savings in upload time, especially when there are
larger glyphs being used by the app.
- packing: Previously, glyphs would line up horizontally on each cache line, leaving
potentially tons of space vertically, especially when smaller glyphs got put into cache
lines intended for large glyphs (which can happen when an app uses lots of unique
glyphs, a common case with, for example, chinese/japanese/korean languages). The new
approach packs glyphs vertically as well as horizontally to use the space more efficiently
and provide space for more glyphs in these situations.
Change-Id: I84338aa25db208c7bf13f3f92b4d05ed40c33527
2012-08-09 13:39:02 -07:00
|
|
|
|
2013-01-08 11:15:30 -08:00
|
|
|
void precache(SkPaint* paint, const char* text, int numGlyphs, const mat4& matrix);
|
Optimize interactions with glyph cache
There are two fixes here:
- precaching: instead of caching-then-drawing whenever there is a new
glyph, we cache at DisplayList record time. Then when we finally draw that
DisplayList, we just upload the affected texture(s) once, instead of once
per change. This is a huge savings in upload time, especially when there are
larger glyphs being used by the app.
- packing: Previously, glyphs would line up horizontally on each cache line, leaving
potentially tons of space vertically, especially when smaller glyphs got put into cache
lines intended for large glyphs (which can happen when an app uses lots of unique
glyphs, a common case with, for example, chinese/japanese/korean languages). The new
approach packs glyphs vertically as well as horizontally to use the space more efficiently
and provide space for more glyphs in these situations.
Change-Id: I84338aa25db208c7bf13f3f92b4d05ed40c33527
2012-08-09 13:39:02 -07:00
|
|
|
|
2012-01-18 12:39:17 -08:00
|
|
|
// bounds is an out parameter
|
|
|
|
bool renderPosText(SkPaint* paint, const Rect* clip, const char *text, uint32_t startIndex,
|
|
|
|
uint32_t len, int numGlyphs, int x, int y, const float* positions, Rect* bounds);
|
2012-02-28 18:17:02 -08:00
|
|
|
// bounds is an out parameter
|
|
|
|
bool renderTextOnPath(SkPaint* paint, const Rect* clip, const char *text, uint32_t startIndex,
|
|
|
|
uint32_t len, int numGlyphs, SkPath* path, float hOffset, float vOffset, Rect* bounds);
|
2010-07-21 21:33:20 -07:00
|
|
|
|
2010-08-06 14:49:04 -07:00
|
|
|
struct DropShadow {
|
2010-08-13 19:39:53 -07:00
|
|
|
DropShadow() { };
|
|
|
|
|
|
|
|
DropShadow(const DropShadow& dropShadow):
|
|
|
|
width(dropShadow.width), height(dropShadow.height),
|
|
|
|
image(dropShadow.image), penX(dropShadow.penX),
|
|
|
|
penY(dropShadow.penY) {
|
|
|
|
}
|
|
|
|
|
2010-08-06 14:49:04 -07:00
|
|
|
uint32_t width;
|
|
|
|
uint32_t height;
|
|
|
|
uint8_t* image;
|
|
|
|
int32_t penX;
|
|
|
|
int32_t penY;
|
|
|
|
};
|
|
|
|
|
|
|
|
// After renderDropShadow returns, the called owns the memory in DropShadow.image
|
|
|
|
// and is responsible for releasing it when it's done with it
|
|
|
|
DropShadow renderDropShadow(SkPaint* paint, const char *text, uint32_t startIndex,
|
2012-07-19 22:48:17 -07:00
|
|
|
uint32_t len, int numGlyphs, uint32_t radius, const float* positions);
|
2010-08-06 14:49:04 -07:00
|
|
|
|
2010-10-04 14:14:11 -07:00
|
|
|
GLuint getTexture(bool linearFiltering = false) {
|
2010-07-21 21:33:20 -07:00
|
|
|
checkInit();
|
2012-05-14 14:00:27 -07:00
|
|
|
|
2012-09-04 16:42:01 -07:00
|
|
|
mCurrentCacheTexture->setLinearFiltering(linearFiltering);
|
|
|
|
mLinearFiltering = linearFiltering;
|
2012-05-14 14:00:27 -07:00
|
|
|
|
2012-09-04 16:42:01 -07:00
|
|
|
return mCurrentCacheTexture->getTextureId();
|
2010-11-10 11:59:15 -08:00
|
|
|
}
|
|
|
|
|
2011-12-05 16:35:38 -08:00
|
|
|
uint32_t getCacheSize() const {
|
|
|
|
uint32_t size = 0;
|
2012-08-15 15:54:54 -07:00
|
|
|
for (uint32_t i = 0; i < mCacheTextures.size(); i++) {
|
|
|
|
CacheTexture* cacheTexture = mCacheTextures[i];
|
2012-09-04 16:42:01 -07:00
|
|
|
if (cacheTexture && cacheTexture->getTexture()) {
|
|
|
|
size += cacheTexture->getWidth() * cacheTexture->getHeight();
|
2012-08-15 15:54:54 -07:00
|
|
|
}
|
2011-12-05 16:35:38 -08:00
|
|
|
}
|
|
|
|
return size;
|
2010-11-10 11:59:15 -08:00
|
|
|
}
|
|
|
|
|
2012-09-04 15:22:57 -07:00
|
|
|
private:
|
2010-07-21 21:33:20 -07:00
|
|
|
friend class Font;
|
|
|
|
|
2010-08-26 20:35:23 -07:00
|
|
|
const uint8_t* mGammaTable;
|
|
|
|
|
2011-12-14 15:22:56 -08:00
|
|
|
void allocateTextureMemory(CacheTexture* cacheTexture);
|
2011-12-16 15:44:59 -08:00
|
|
|
void deallocateTextureMemory(CacheTexture* cacheTexture);
|
2011-12-05 16:35:38 -08:00
|
|
|
void initTextTexture();
|
2012-02-28 18:17:02 -08:00
|
|
|
CacheTexture* createCacheTexture(int width, int height, bool allocate);
|
2011-12-05 16:35:38 -08:00
|
|
|
void cacheBitmap(const SkGlyph& glyph, CachedGlyphInfo* cachedGlyph,
|
2012-08-30 09:06:46 -07:00
|
|
|
uint32_t *retOriginX, uint32_t *retOriginY, bool precaching);
|
2012-08-15 15:54:54 -07:00
|
|
|
CacheTexture* cacheBitmapInTexture(const SkGlyph& glyph, uint32_t* startX, uint32_t* startY);
|
2010-07-21 21:33:20 -07:00
|
|
|
|
|
|
|
void flushAllAndInvalidate();
|
|
|
|
void initVertexArrayBuffers();
|
|
|
|
|
|
|
|
void checkInit();
|
2012-01-18 12:39:17 -08:00
|
|
|
void initRender(const Rect* clip, Rect* bounds);
|
|
|
|
void finishRender();
|
2010-07-21 21:33:20 -07:00
|
|
|
|
|
|
|
void issueDrawCommand();
|
2012-02-28 18:17:02 -08:00
|
|
|
void appendMeshQuadNoClip(float x1, float y1, float u1, float v1,
|
|
|
|
float x2, float y2, float u2, float v2,
|
|
|
|
float x3, float y3, float u3, float v3,
|
|
|
|
float x4, float y4, float u4, float v4, CacheTexture* texture);
|
2011-12-12 19:03:35 -08:00
|
|
|
void appendMeshQuad(float x1, float y1, float u1, float v1,
|
|
|
|
float x2, float y2, float u2, float v2,
|
|
|
|
float x3, float y3, float u3, float v3,
|
2011-12-05 16:35:38 -08:00
|
|
|
float x4, float y4, float u4, float v4, CacheTexture* texture);
|
2012-02-28 18:17:02 -08:00
|
|
|
void appendRotatedMeshQuad(float x1, float y1, float u1, float v1,
|
|
|
|
float x2, float y2, float u2, float v2,
|
|
|
|
float x3, float y3, float u3, float v3,
|
|
|
|
float x4, float y4, float u4, float v4, CacheTexture* texture);
|
2010-07-21 21:33:20 -07:00
|
|
|
|
2012-09-04 15:22:57 -07:00
|
|
|
void removeFont(const Font* font);
|
|
|
|
|
2012-11-16 00:03:17 +09:00
|
|
|
void updateDrawParams();
|
2012-09-04 15:22:57 -07:00
|
|
|
void checkTextureUpdate();
|
|
|
|
|
|
|
|
void setTextureDirty() {
|
|
|
|
mUploadTexture = true;
|
|
|
|
}
|
|
|
|
|
2011-12-05 16:35:38 -08:00
|
|
|
uint32_t mSmallCacheWidth;
|
|
|
|
uint32_t mSmallCacheHeight;
|
2012-08-31 13:54:03 -07:00
|
|
|
uint32_t mLargeCacheWidth;
|
|
|
|
uint32_t mLargeCacheHeight;
|
2010-07-21 21:33:20 -07:00
|
|
|
|
2012-08-15 15:54:54 -07:00
|
|
|
Vector<CacheTexture*> mCacheTextures;
|
2010-07-21 21:33:20 -07:00
|
|
|
|
2010-07-22 13:08:20 -07:00
|
|
|
Font* mCurrentFont;
|
2013-01-08 11:15:30 -08:00
|
|
|
LruCache<Font::FontDescription, Font*> mActiveFonts;
|
2010-07-21 21:33:20 -07:00
|
|
|
|
2011-12-05 16:35:38 -08:00
|
|
|
CacheTexture* mCurrentCacheTexture;
|
|
|
|
|
2010-07-21 21:33:20 -07:00
|
|
|
bool mUploadTexture;
|
|
|
|
|
|
|
|
// Pointer to vertex data to speed up frame to frame work
|
2012-09-04 15:22:57 -07:00
|
|
|
float* mTextMesh;
|
2010-07-21 21:33:20 -07:00
|
|
|
uint32_t mCurrentQuadIndex;
|
2012-11-16 00:03:17 +09:00
|
|
|
uint32_t mLastQuadIndex;
|
2010-07-21 21:33:20 -07:00
|
|
|
uint32_t mMaxNumberOfQuads;
|
|
|
|
|
|
|
|
uint32_t mIndexBufferID;
|
|
|
|
|
2010-07-22 13:08:20 -07:00
|
|
|
const Rect* mClip;
|
2010-10-27 18:57:51 -07:00
|
|
|
Rect* mBounds;
|
|
|
|
bool mDrawn;
|
2010-07-22 13:08:20 -07:00
|
|
|
|
2010-07-21 21:33:20 -07:00
|
|
|
bool mInitialized;
|
2010-08-02 17:52:30 -07:00
|
|
|
|
2010-10-04 14:14:11 -07:00
|
|
|
bool mLinearFiltering;
|
|
|
|
|
2013-03-19 11:32:41 -07:00
|
|
|
struct TextBatch {
|
|
|
|
TextBatch(): offset(NULL), count(0), texture(NULL) {
|
|
|
|
}
|
|
|
|
|
|
|
|
TextBatch(uint16_t* offset, uint32_t count, CacheTexture* texture):
|
|
|
|
offset(offset), count(count), texture(texture) {
|
|
|
|
}
|
|
|
|
|
|
|
|
static int compare(const TextBatch& lhs, const TextBatch& rhs) {
|
|
|
|
return lhs.texture->getTextureId() - rhs.texture->getTextureId();
|
|
|
|
}
|
|
|
|
|
|
|
|
friend inline int strictly_order_type(const TextBatch& lhs, const TextBatch& rhs) {
|
|
|
|
return compare(lhs, rhs) < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend inline int compare_type(const TextBatch& lhs, const TextBatch& rhs) {
|
|
|
|
return compare(lhs, rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t* offset;
|
|
|
|
uint32_t count;
|
|
|
|
CacheTexture* texture;
|
|
|
|
};
|
|
|
|
|
|
|
|
SortedList<TextBatch> mDrawBatch;
|
2012-11-16 00:03:17 +09:00
|
|
|
|
2013-02-13 16:14:17 -08:00
|
|
|
// RS constructs
|
|
|
|
sp<RSC::RS> mRs;
|
|
|
|
sp<const RSC::Element> mRsElement;
|
|
|
|
sp<RSC::ScriptIntrinsicBlur> mRsScript;
|
|
|
|
|
2012-09-04 15:22:57 -07:00
|
|
|
static void computeGaussianWeights(float* weights, int32_t radius);
|
|
|
|
static void horizontalBlur(float* weights, int32_t radius, const uint8_t *source, uint8_t *dest,
|
2010-08-13 19:39:53 -07:00
|
|
|
int32_t width, int32_t height);
|
2012-09-04 15:22:57 -07:00
|
|
|
static void verticalBlur(float* weights, int32_t radius, const uint8_t *source, uint8_t *dest,
|
2010-08-13 19:39:53 -07:00
|
|
|
int32_t width, int32_t height);
|
2013-02-13 16:14:17 -08:00
|
|
|
|
|
|
|
// the input image handle may have its pointer replaced (to avoid copies)
|
|
|
|
void blurImage(uint8_t** image, int32_t width, int32_t height, int32_t radius);
|
2010-07-21 21:33:20 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
}; // namespace uirenderer
|
|
|
|
}; // namespace android
|
|
|
|
|
2010-10-27 18:57:51 -07:00
|
|
|
#endif // ANDROID_HWUI_FONT_RENDERER_H
|