2012-09-04 12:55:44 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 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.
|
|
|
|
*/
|
|
|
|
|
2012-08-14 16:44:52 -04:00
|
|
|
#include <SkGlyph.h>
|
2012-09-04 12:55:44 -07:00
|
|
|
|
2013-06-04 18:00:09 -07:00
|
|
|
#include "../Caches.h"
|
2013-04-04 12:27:54 -07:00
|
|
|
#include "../Debug.h"
|
2013-04-08 19:40:31 -07:00
|
|
|
#include "../Extensions.h"
|
|
|
|
#include "../PixelBuffer.h"
|
2017-11-03 10:12:19 -07:00
|
|
|
#include "CacheTexture.h"
|
|
|
|
#include "FontUtil.h"
|
2012-09-04 12:55:44 -07:00
|
|
|
|
|
|
|
namespace android {
|
|
|
|
namespace uirenderer {
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CacheBlock
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Insert new block into existing linked list of blocks. Blocks are sorted in increasing-width
|
|
|
|
* order, except for the final block (the remainder space at the right, since we fill from the
|
|
|
|
* left).
|
|
|
|
*/
|
2012-09-04 18:58:46 -07:00
|
|
|
CacheBlock* CacheBlock::insertBlock(CacheBlock* head, CacheBlock* newBlock) {
|
2012-09-04 12:55:44 -07:00
|
|
|
#if DEBUG_FONT_RENDERER
|
2017-11-03 10:12:19 -07:00
|
|
|
ALOGD("insertBlock: this, x, y, w, h = %p, %d, %d, %d, %d", newBlock, newBlock->mX,
|
|
|
|
newBlock->mY, newBlock->mWidth, newBlock->mHeight);
|
2012-09-04 12:55:44 -07:00
|
|
|
#endif
|
2012-09-04 15:22:57 -07:00
|
|
|
|
2012-09-04 18:58:46 -07:00
|
|
|
CacheBlock* currBlock = head;
|
2015-01-05 15:51:13 -08:00
|
|
|
CacheBlock* prevBlock = nullptr;
|
2012-09-04 15:22:57 -07:00
|
|
|
|
2012-09-04 12:55:44 -07:00
|
|
|
while (currBlock && currBlock->mY != TEXTURE_BORDER_SIZE) {
|
|
|
|
if (newBlock->mWidth < currBlock->mWidth) {
|
|
|
|
newBlock->mNext = currBlock;
|
|
|
|
newBlock->mPrev = prevBlock;
|
|
|
|
currBlock->mPrev = newBlock;
|
2012-09-04 15:22:57 -07:00
|
|
|
|
2012-09-04 12:55:44 -07:00
|
|
|
if (prevBlock) {
|
|
|
|
prevBlock->mNext = newBlock;
|
|
|
|
return head;
|
|
|
|
} else {
|
|
|
|
return newBlock;
|
|
|
|
}
|
|
|
|
}
|
2012-09-04 15:22:57 -07:00
|
|
|
|
2012-09-04 12:55:44 -07:00
|
|
|
prevBlock = currBlock;
|
|
|
|
currBlock = currBlock->mNext;
|
|
|
|
}
|
2012-09-04 15:22:57 -07:00
|
|
|
|
2012-09-04 12:55:44 -07:00
|
|
|
// new block larger than all others - insert at end (but before the remainder space, if there)
|
|
|
|
newBlock->mNext = currBlock;
|
|
|
|
newBlock->mPrev = prevBlock;
|
2012-09-04 15:22:57 -07:00
|
|
|
|
2012-09-04 12:55:44 -07:00
|
|
|
if (currBlock) {
|
|
|
|
currBlock->mPrev = newBlock;
|
|
|
|
}
|
2012-09-04 15:22:57 -07:00
|
|
|
|
2012-09-04 12:55:44 -07:00
|
|
|
if (prevBlock) {
|
|
|
|
prevBlock->mNext = newBlock;
|
|
|
|
return head;
|
|
|
|
} else {
|
|
|
|
return newBlock;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-04 18:58:46 -07:00
|
|
|
CacheBlock* CacheBlock::removeBlock(CacheBlock* head, CacheBlock* blockToRemove) {
|
2012-09-04 12:55:44 -07:00
|
|
|
#if DEBUG_FONT_RENDERER
|
2017-11-03 10:12:19 -07:00
|
|
|
ALOGD("removeBlock: this, x, y, w, h = %p, %d, %d, %d, %d", blockToRemove, blockToRemove->mX,
|
|
|
|
blockToRemove->mY, blockToRemove->mWidth, blockToRemove->mHeight);
|
2012-09-04 12:55:44 -07:00
|
|
|
#endif
|
2012-09-04 15:22:57 -07:00
|
|
|
|
2012-09-04 12:55:44 -07:00
|
|
|
CacheBlock* newHead = head;
|
|
|
|
CacheBlock* nextBlock = blockToRemove->mNext;
|
|
|
|
CacheBlock* prevBlock = blockToRemove->mPrev;
|
2012-09-04 15:22:57 -07:00
|
|
|
|
2012-09-04 12:55:44 -07:00
|
|
|
if (prevBlock) {
|
2017-07-18 16:28:28 -07:00
|
|
|
// If this doesn't hold, we have a use-after-free below.
|
|
|
|
LOG_ALWAYS_FATAL_IF(head == blockToRemove,
|
2017-11-03 10:12:19 -07:00
|
|
|
"removeBlock: head should not have a previous block");
|
2012-09-04 12:55:44 -07:00
|
|
|
prevBlock->mNext = nextBlock;
|
|
|
|
} else {
|
|
|
|
newHead = nextBlock;
|
|
|
|
}
|
2012-09-04 15:22:57 -07:00
|
|
|
|
2012-09-04 12:55:44 -07:00
|
|
|
if (nextBlock) {
|
|
|
|
nextBlock->mPrev = prevBlock;
|
|
|
|
}
|
2012-09-04 15:22:57 -07:00
|
|
|
|
2012-09-04 12:55:44 -07:00
|
|
|
delete blockToRemove;
|
2012-09-04 15:22:57 -07:00
|
|
|
|
2012-09-04 12:55:44 -07:00
|
|
|
return newHead;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CacheTexture
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-03-13 15:07:52 -07:00
|
|
|
CacheTexture::CacheTexture(uint16_t width, uint16_t height, GLenum format, uint32_t maxQuadCount)
|
|
|
|
: mTexture(Caches::getInstance())
|
2015-11-10 12:19:17 -08:00
|
|
|
, mWidth(width)
|
|
|
|
, mHeight(height)
|
2015-03-13 15:07:52 -07:00
|
|
|
, mFormat(format)
|
|
|
|
, mMaxQuadCount(maxQuadCount)
|
|
|
|
, mCaches(Caches::getInstance()) {
|
|
|
|
mTexture.blend = true;
|
|
|
|
|
2017-11-03 10:12:19 -07:00
|
|
|
mCacheBlocks =
|
|
|
|
new CacheBlock(TEXTURE_BORDER_SIZE, TEXTURE_BORDER_SIZE,
|
|
|
|
getWidth() - TEXTURE_BORDER_SIZE, getHeight() - TEXTURE_BORDER_SIZE);
|
2013-04-08 19:40:31 -07:00
|
|
|
|
|
|
|
// OpenGL ES 3.0+ lets us specify the row length for unpack operations such
|
|
|
|
// as glTexSubImage2D(). This allows us to upload a sub-rectangle of a texture.
|
|
|
|
// With OpenGL ES 2.0 we have to upload entire stripes instead.
|
2015-02-05 10:12:38 -08:00
|
|
|
mHasUnpackRowLength = mCaches.extensions().hasUnpackRowLength();
|
2013-03-19 15:24:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
CacheTexture::~CacheTexture() {
|
|
|
|
releaseMesh();
|
2015-03-13 15:07:52 -07:00
|
|
|
releasePixelBuffer();
|
2013-03-19 15:24:36 -07:00
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CacheTexture::reset() {
|
|
|
|
// Delete existing cache blocks
|
2015-01-05 15:51:13 -08:00
|
|
|
while (mCacheBlocks != nullptr) {
|
2013-03-19 15:24:36 -07:00
|
|
|
CacheBlock* tmpBlock = mCacheBlocks;
|
|
|
|
mCacheBlocks = mCacheBlocks->mNext;
|
|
|
|
delete tmpBlock;
|
|
|
|
}
|
|
|
|
mNumGlyphs = 0;
|
|
|
|
mCurrentQuad = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CacheTexture::init() {
|
|
|
|
// reset, then create a new remainder space to start again
|
|
|
|
reset();
|
2017-11-03 10:12:19 -07:00
|
|
|
mCacheBlocks =
|
|
|
|
new CacheBlock(TEXTURE_BORDER_SIZE, TEXTURE_BORDER_SIZE,
|
|
|
|
getWidth() - TEXTURE_BORDER_SIZE, getHeight() - TEXTURE_BORDER_SIZE);
|
2013-03-19 15:24:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void CacheTexture::releaseMesh() {
|
|
|
|
delete[] mMesh;
|
|
|
|
}
|
|
|
|
|
2015-03-13 15:07:52 -07:00
|
|
|
void CacheTexture::releasePixelBuffer() {
|
|
|
|
if (mPixelBuffer) {
|
|
|
|
delete mPixelBuffer;
|
|
|
|
mPixelBuffer = nullptr;
|
2013-03-19 15:24:36 -07:00
|
|
|
}
|
2015-11-10 12:19:17 -08:00
|
|
|
mTexture.deleteTexture();
|
2013-03-19 15:24:36 -07:00
|
|
|
mDirty = false;
|
|
|
|
mCurrentQuad = 0;
|
|
|
|
}
|
|
|
|
|
2015-03-13 15:07:52 -07:00
|
|
|
void CacheTexture::setLinearFiltering(bool linearFiltering) {
|
|
|
|
mTexture.setFilter(linearFiltering ? GL_LINEAR : GL_NEAREST);
|
2013-04-08 19:40:31 -07:00
|
|
|
}
|
|
|
|
|
2013-03-19 15:24:36 -07:00
|
|
|
void CacheTexture::allocateMesh() {
|
|
|
|
if (!mMesh) {
|
|
|
|
mMesh = new TextureVertex[mMaxQuadCount * 4];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-13 15:07:52 -07:00
|
|
|
void CacheTexture::allocatePixelBuffer() {
|
|
|
|
if (!mPixelBuffer) {
|
|
|
|
mPixelBuffer = PixelBuffer::create(mFormat, getWidth(), getHeight());
|
2013-03-19 15:24:36 -07:00
|
|
|
}
|
|
|
|
|
Linear blending, step 1
NOTE: Linear blending is currently disabled in this CL as the
feature is still a work in progress
Android currently performs all blending (any kind of linear math
on colors really) on gamma-encoded colors. Since Android assumes
that the default color space is sRGB, all bitmaps and colors
are encoded with the sRGB Opto-Electronic Conversion Function
(OECF, which can be approximated with a power function). Since
the power curve is not linear, our linear math is incorrect.
The result is that we generate colors that tend to be too dark;
this affects blending but also anti-aliasing, gradients, blurs,
etc.
The solution is to convert gamma-encoded colors back to linear
space before doing any math on them, using the sRGB Electo-Optical
Conversion Function (EOCF). This is achieved in different
ways in different parts of the pipeline:
- Using hardware conversions when sampling from OpenGL textures
or writing into OpenGL frame buffers
- Using software conversion functions, to translate app-supplied
colors to and from sRGB
- Using Skia's color spaces
Any type of processing on colors must roughly ollow these steps:
[sRGB input]->EOCF->[linear data]->[processing]->OECF->[sRGB output]
For the sRGB color space, the conversion functions are defined as
follows:
OECF(linear) :=
linear <= 0.0031308 ? linear * 12.92 : (pow(linear, 1/2.4) * 1.055) - 0.055
EOCF(srgb) :=
srgb <= 0.04045 ? srgb / 12.92 : pow((srgb + 0.055) / 1.055, 2.4)
The EOCF is simply the reciprocal of the OECF.
While it is highly recommended to use the exact sRGB conversion
functions everywhere possible, it is sometimes useful or beneficial
to rely on approximations:
- pow(x,2.2) and pow(x,1/2.2)
- x^2 and sqrt(x)
The latter is particularly useful in fragment shaders (for instance
to apply dithering in sRGB space), especially if the sqrt() can be
replaced with an inversesqrt().
Here is a fairly exhaustive list of modifications implemented
in this CL:
- Set TARGET_ENABLE_LINEAR_BLENDING := false in BoardConfig.mk
to disable linear blending. This is only for GLES 2.0 GPUs
with no hardware sRGB support. This flag is currently assumed
to be false (see note above)
- sRGB writes are disabled when entering a functor (WebView).
This will need to be fixed at some point
- Skia bitmaps are created with the sRGB color space
- Bitmaps using a 565 config are expanded to 888
- Linear blending is disabled when entering a functor
- External textures are not properly sampled (see below)
- Gradients are interpolated in linear space
- Texture-based dithering was replaced with analytical dithering
- Dithering is done in the quantization color space, which is
why we must do EOCF(OECF(color)+dither)
- Text is now gamma corrected differently depending on the luminance
of the source pixel. The asumption is that a bright pixel will be
blended on a dark background and the other way around. The source
alpha is gamma corrected to thicken dark on bright and thin
bright on dark to match the intended design of fonts. This also
matches the behavior of popular design/drawing applications
- Removed the asset atlas. It did not contain anything useful and
could not be sampled in sRGB without a yet-to-be-defined GL
extension
- The last column of color matrices is converted to linear space
because its value are added to linear colors
Missing features:
- Resource qualifier?
- Regeneration of goldeng images for automated tests
- Handle alpha8/grey8 properly
- Disable sRGB write for layers with external textures
Test: Manual testing while work in progress
Bug: 29940137
Change-Id: I6a07b15ab49b554377cd33a36b6d9971a15e9a0b
2016-09-28 17:34:42 -07:00
|
|
|
GLint internalFormat = mFormat;
|
|
|
|
if (mFormat == GL_RGBA) {
|
|
|
|
internalFormat = mCaches.rgbaInternalFormat();
|
|
|
|
}
|
|
|
|
|
|
|
|
mTexture.resize(mWidth, mHeight, internalFormat, mFormat);
|
2015-11-10 12:19:17 -08:00
|
|
|
mTexture.setFilter(getLinearFiltering() ? GL_LINEAR : GL_NEAREST);
|
|
|
|
mTexture.setWrap(GL_CLAMP_TO_EDGE);
|
2013-03-19 15:24:36 -07:00
|
|
|
}
|
|
|
|
|
2013-04-08 19:40:31 -07:00
|
|
|
bool CacheTexture::upload() {
|
|
|
|
const Rect& dirtyRect = mDirtyRect;
|
|
|
|
|
2016-02-15 16:09:40 +08:00
|
|
|
// align the x direction to 32 and y direction to 4 for better performance
|
|
|
|
uint32_t x = (((uint32_t)dirtyRect.left) & (~0x1F));
|
|
|
|
uint32_t y = (((uint32_t)dirtyRect.top) & (~0x3));
|
|
|
|
uint32_t r = ((((uint32_t)dirtyRect.right) + 0x1F) & (~0x1F)) - x;
|
|
|
|
uint32_t b = ((((uint32_t)dirtyRect.bottom) + 0x3) & (~0x3)) - y;
|
|
|
|
uint32_t width = (r > getWidth() ? getWidth() : r);
|
|
|
|
uint32_t height = (b > getHeight() ? getHeight() : b);
|
2013-04-08 19:40:31 -07:00
|
|
|
|
|
|
|
// The unpack row length only needs to be specified when a new
|
|
|
|
// texture is bound
|
2013-09-24 18:44:54 -07:00
|
|
|
if (mHasUnpackRowLength) {
|
2015-03-13 15:07:52 -07:00
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, getWidth());
|
2016-02-15 16:09:40 +08:00
|
|
|
} else {
|
|
|
|
x = 0;
|
|
|
|
width = getWidth();
|
2013-04-08 19:40:31 -07:00
|
|
|
}
|
|
|
|
|
2015-03-13 15:07:52 -07:00
|
|
|
mPixelBuffer->upload(x, y, width, height);
|
2013-04-08 19:40:31 -07:00
|
|
|
setDirty(false);
|
|
|
|
|
2013-09-24 18:44:54 -07:00
|
|
|
return mHasUnpackRowLength;
|
2013-04-08 19:40:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void CacheTexture::setDirty(bool dirty) {
|
|
|
|
mDirty = dirty;
|
|
|
|
if (!dirty) {
|
|
|
|
mDirtyRect.setEmpty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-04 18:58:46 -07:00
|
|
|
bool CacheTexture::fitBitmap(const SkGlyph& glyph, uint32_t* retOriginX, uint32_t* retOriginY) {
|
2013-06-25 14:25:17 -07:00
|
|
|
switch (glyph.fMaskFormat) {
|
|
|
|
case SkMask::kA8_Format:
|
2013-08-12 14:38:44 -07:00
|
|
|
case SkMask::kBW_Format:
|
2013-06-25 14:25:17 -07:00
|
|
|
if (mFormat != GL_ALPHA) {
|
|
|
|
#if DEBUG_FONT_RENDERER
|
2013-08-12 14:38:44 -07:00
|
|
|
ALOGD("fitBitmap: texture format %x is inappropriate for monochromatic glyphs",
|
2017-11-03 10:12:19 -07:00
|
|
|
mFormat);
|
2013-06-25 14:25:17 -07:00
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SkMask::kARGB32_Format:
|
|
|
|
if (mFormat != GL_RGBA) {
|
|
|
|
#if DEBUG_FONT_RENDERER
|
2013-08-12 14:38:44 -07:00
|
|
|
ALOGD("fitBitmap: texture format %x is inappropriate for colour glyphs", mFormat);
|
2013-06-25 14:25:17 -07:00
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
#if DEBUG_FONT_RENDERER
|
|
|
|
ALOGD("fitBitmap: unknown glyph format %x encountered", glyph.fMaskFormat);
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-13 15:07:52 -07:00
|
|
|
if (glyph.fHeight + TEXTURE_BORDER_SIZE * 2 > getHeight()) {
|
2012-09-04 12:55:44 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t glyphW = glyph.fWidth + TEXTURE_BORDER_SIZE;
|
|
|
|
uint16_t glyphH = glyph.fHeight + TEXTURE_BORDER_SIZE;
|
2012-09-04 15:22:57 -07:00
|
|
|
|
2012-09-04 12:55:44 -07:00
|
|
|
// roundedUpW equals glyphW to the next multiple of CACHE_BLOCK_ROUNDING_SIZE.
|
|
|
|
// This columns for glyphs that are close but not necessarily exactly the same size. It trades
|
|
|
|
// off the loss of a few pixels for some glyphs against the ability to store more glyphs
|
|
|
|
// of varying sizes in one block.
|
2012-09-04 18:58:46 -07:00
|
|
|
uint16_t roundedUpW = (glyphW + CACHE_BLOCK_ROUNDING_SIZE - 1) & -CACHE_BLOCK_ROUNDING_SIZE;
|
2012-09-04 15:22:57 -07:00
|
|
|
|
2012-09-04 18:58:46 -07:00
|
|
|
CacheBlock* cacheBlock = mCacheBlocks;
|
2012-09-04 12:55:44 -07:00
|
|
|
while (cacheBlock) {
|
|
|
|
// Store glyph in this block iff: it fits the block's remaining space and:
|
|
|
|
// it's the remainder space (mY == 0) or there's only enough height for this one glyph
|
|
|
|
// or it's within ROUNDING_SIZE of the block width
|
|
|
|
if (roundedUpW <= cacheBlock->mWidth && glyphH <= cacheBlock->mHeight &&
|
2017-11-03 10:12:19 -07:00
|
|
|
(cacheBlock->mY == TEXTURE_BORDER_SIZE ||
|
|
|
|
(cacheBlock->mWidth - roundedUpW < CACHE_BLOCK_ROUNDING_SIZE))) {
|
2012-09-04 12:55:44 -07:00
|
|
|
if (cacheBlock->mHeight - glyphH < glyphH) {
|
|
|
|
// Only enough space for this glyph - don't bother rounding up the width
|
|
|
|
roundedUpW = glyphW;
|
|
|
|
}
|
2012-09-04 15:22:57 -07:00
|
|
|
|
2012-09-04 12:55:44 -07:00
|
|
|
*retOriginX = cacheBlock->mX;
|
|
|
|
*retOriginY = cacheBlock->mY;
|
2012-09-04 15:22:57 -07:00
|
|
|
|
2012-09-04 12:55:44 -07:00
|
|
|
// If this is the remainder space, create a new cache block for this column. Otherwise,
|
|
|
|
// adjust the info about this column.
|
|
|
|
if (cacheBlock->mY == TEXTURE_BORDER_SIZE) {
|
|
|
|
uint16_t oldX = cacheBlock->mX;
|
|
|
|
// Adjust remainder space dimensions
|
|
|
|
cacheBlock->mWidth -= roundedUpW;
|
|
|
|
cacheBlock->mX += roundedUpW;
|
2012-09-04 15:22:57 -07:00
|
|
|
|
2015-03-13 15:07:52 -07:00
|
|
|
if (getHeight() - glyphH >= glyphH) {
|
2012-09-04 12:55:44 -07:00
|
|
|
// There's enough height left over to create a new CacheBlock
|
2017-11-03 10:12:19 -07:00
|
|
|
CacheBlock* newBlock =
|
|
|
|
new CacheBlock(oldX, glyphH + TEXTURE_BORDER_SIZE, roundedUpW,
|
|
|
|
getHeight() - glyphH - TEXTURE_BORDER_SIZE);
|
2012-09-04 12:55:44 -07:00
|
|
|
#if DEBUG_FONT_RENDERER
|
|
|
|
ALOGD("fitBitmap: Created new block: this, x, y, w, h = %p, %d, %d, %d, %d",
|
2017-11-03 10:12:19 -07:00
|
|
|
newBlock, newBlock->mX, newBlock->mY, newBlock->mWidth,
|
|
|
|
newBlock->mHeight);
|
2012-09-04 12:55:44 -07:00
|
|
|
#endif
|
|
|
|
mCacheBlocks = CacheBlock::insertBlock(mCacheBlocks, newBlock);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Insert into current column and adjust column dimensions
|
|
|
|
cacheBlock->mY += glyphH;
|
|
|
|
cacheBlock->mHeight -= glyphH;
|
|
|
|
#if DEBUG_FONT_RENDERER
|
|
|
|
ALOGD("fitBitmap: Added to existing block: this, x, y, w, h = %p, %d, %d, %d, %d",
|
2017-11-03 10:12:19 -07:00
|
|
|
cacheBlock, cacheBlock->mX, cacheBlock->mY, cacheBlock->mWidth,
|
|
|
|
cacheBlock->mHeight);
|
2012-09-04 12:55:44 -07:00
|
|
|
#endif
|
|
|
|
}
|
2012-09-04 15:22:57 -07:00
|
|
|
|
2015-07-07 18:42:17 -07:00
|
|
|
if (cacheBlock->mHeight < std::min(glyphH, glyphW)) {
|
2012-09-04 12:55:44 -07:00
|
|
|
// If remaining space in this block is too small to be useful, remove it
|
|
|
|
mCacheBlocks = CacheBlock::removeBlock(mCacheBlocks, cacheBlock);
|
|
|
|
}
|
2012-09-04 15:22:57 -07:00
|
|
|
|
2012-09-04 12:55:44 -07:00
|
|
|
mDirty = true;
|
2012-09-21 08:40:46 -07:00
|
|
|
const Rect r(*retOriginX - TEXTURE_BORDER_SIZE, *retOriginY - TEXTURE_BORDER_SIZE,
|
2017-11-03 10:12:19 -07:00
|
|
|
*retOriginX + glyphW, *retOriginY + glyphH);
|
2012-09-21 08:40:46 -07:00
|
|
|
mDirtyRect.unionWith(r);
|
2012-09-04 15:22:57 -07:00
|
|
|
mNumGlyphs++;
|
|
|
|
|
2012-09-04 12:55:44 -07:00
|
|
|
#if DEBUG_FONT_RENDERER
|
|
|
|
ALOGD("fitBitmap: current block list:");
|
|
|
|
mCacheBlocks->output();
|
|
|
|
#endif
|
2012-09-04 15:22:57 -07:00
|
|
|
|
2012-09-04 12:55:44 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
cacheBlock = cacheBlock->mNext;
|
|
|
|
}
|
|
|
|
#if DEBUG_FONT_RENDERER
|
|
|
|
ALOGD("fitBitmap: returning false for glyph of size %d, %d", glyphW, glyphH);
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-08 11:09:34 -07:00
|
|
|
uint32_t CacheTexture::calculateFreeMemory() const {
|
|
|
|
CacheBlock* cacheBlock = mCacheBlocks;
|
|
|
|
uint32_t free = 0;
|
|
|
|
// currently only two formats are supported: GL_ALPHA or GL_RGBA;
|
|
|
|
uint32_t bpp = mFormat == GL_RGBA ? 4 : 1;
|
|
|
|
while (cacheBlock) {
|
|
|
|
free += bpp * cacheBlock->mWidth * cacheBlock->mHeight;
|
|
|
|
cacheBlock = cacheBlock->mNext;
|
|
|
|
}
|
|
|
|
return free;
|
|
|
|
}
|
|
|
|
|
2017-11-03 10:12:19 -07:00
|
|
|
}; // namespace uirenderer
|
|
|
|
}; // namespace android
|