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.
|
|
|
|
*/
|
|
|
|
|
2015-01-27 15:46:35 -08:00
|
|
|
#include "FontRenderer.h"
|
|
|
|
|
2016-07-06 16:10:09 -07:00
|
|
|
#include "BakedOpDispatcher.h"
|
|
|
|
#include "BakedOpRenderer.h"
|
|
|
|
#include "BakedOpState.h"
|
2015-01-27 15:46:35 -08:00
|
|
|
#include "Caches.h"
|
|
|
|
#include "Debug.h"
|
|
|
|
#include "Extensions.h"
|
2015-03-13 15:07:52 -07:00
|
|
|
#include "Glop.h"
|
|
|
|
#include "GlopBuilder.h"
|
2015-01-27 15:46:35 -08:00
|
|
|
#include "PixelBuffer.h"
|
|
|
|
#include "Rect.h"
|
2017-11-03 10:12:19 -07:00
|
|
|
#include "font/Font.h"
|
2015-01-27 15:46:35 -08:00
|
|
|
#include "renderstate/RenderState.h"
|
|
|
|
#include "utils/Blur.h"
|
|
|
|
#include "utils/Timing.h"
|
2010-07-21 21:33:20 -07:00
|
|
|
|
2017-02-09 10:38:34 +08:00
|
|
|
#include <RenderScript.h>
|
2012-08-14 16:44:52 -04:00
|
|
|
#include <SkGlyph.h>
|
2010-07-21 21:33:20 -07:00
|
|
|
#include <SkUtils.h>
|
2010-07-23 00:28:00 -07:00
|
|
|
#include <utils/Log.h>
|
2017-11-03 10:12:19 -07:00
|
|
|
#include <algorithm>
|
2010-07-23 00:28:00 -07:00
|
|
|
|
2010-07-21 21:33:20 -07:00
|
|
|
namespace android {
|
|
|
|
namespace uirenderer {
|
|
|
|
|
2013-02-13 16:14:17 -08:00
|
|
|
// blur inputs smaller than this constant will bypass renderscript
|
|
|
|
#define RS_MIN_INPUT_CUTOFF 10000
|
|
|
|
|
2013-06-25 14:25:17 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// TextSetupFunctor
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-04-03 09:37:49 -07:00
|
|
|
void TextDrawFunctor::draw(CacheTexture& texture, bool linearFiltering) {
|
2015-06-01 10:35:35 -07:00
|
|
|
int textureFillFlags = TextureFillFlags::None;
|
|
|
|
if (texture.getFormat() == GL_ALPHA) {
|
|
|
|
textureFillFlags |= TextureFillFlags::IsAlphaMaskTexture;
|
|
|
|
}
|
2015-03-13 15:07:52 -07:00
|
|
|
if (linearFiltering) {
|
2015-06-01 10:35:35 -07:00
|
|
|
textureFillFlags |= TextureFillFlags::ForceFilter;
|
2015-03-13 15:07:52 -07:00
|
|
|
}
|
2017-11-03 10:12:19 -07:00
|
|
|
int transformFlags =
|
|
|
|
pureTranslate ? TransformFlags::MeshIgnoresCanvasTransform : TransformFlags::None;
|
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
|
|
|
#ifdef ANDROID_ENABLE_LINEAR_BLENDING
|
|
|
|
bool gammaCorrection = true;
|
|
|
|
#else
|
|
|
|
bool gammaCorrection = false;
|
|
|
|
#endif
|
2015-03-13 15:07:52 -07:00
|
|
|
Glop glop;
|
2015-11-19 13:02:43 -08:00
|
|
|
GlopBuilder(renderer->renderState(), renderer->caches(), &glop)
|
|
|
|
.setRoundRectClipState(bakedState->roundRectClipState)
|
|
|
|
.setMeshTexturedIndexedQuads(texture.mesh(), texture.meshElementCount())
|
|
|
|
.setFillTexturePaint(texture.getTexture(), textureFillFlags, paint, bakedState->alpha)
|
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
|
|
|
.setGammaCorrection(gammaCorrection)
|
2015-11-19 13:02:43 -08:00
|
|
|
.setTransform(bakedState->computedState.transform, transformFlags)
|
2015-12-08 17:21:58 -08:00
|
|
|
.setModelViewIdentityEmptyBounds()
|
2015-11-19 13:02:43 -08:00
|
|
|
.build();
|
2015-12-03 12:16:56 -08:00
|
|
|
// Note: don't pass dirty bounds here, so user must manage passing dirty bounds to renderer
|
|
|
|
renderer->renderGlop(nullptr, clip, glop);
|
2013-06-25 14:25:17 -07:00
|
|
|
}
|
|
|
|
|
2010-07-21 21:33:20 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// FontRenderer
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-01-19 14:38:29 -08:00
|
|
|
static bool sLogFontRendererCreate = true;
|
|
|
|
|
2015-09-22 14:22:29 -07:00
|
|
|
FontRenderer::FontRenderer(const uint8_t* gammaTable)
|
|
|
|
: mGammaTable(gammaTable)
|
2015-02-27 17:04:20 -08:00
|
|
|
, mCurrentFont(nullptr)
|
|
|
|
, mActiveFonts(LruCache<Font::FontDescription, Font*>::kUnlimitedCapacity)
|
|
|
|
, mCurrentCacheTexture(nullptr)
|
|
|
|
, mUploadTexture(false)
|
|
|
|
, mFunctor(nullptr)
|
|
|
|
, mClip(nullptr)
|
|
|
|
, mBounds(nullptr)
|
|
|
|
, mDrawn(false)
|
|
|
|
, mInitialized(false)
|
|
|
|
, mLinearFiltering(false) {
|
2011-01-21 21:14:15 -08:00
|
|
|
if (sLogFontRendererCreate) {
|
|
|
|
INIT_LOGD("Creating FontRenderer");
|
|
|
|
}
|
2010-07-23 00:28:00 -07:00
|
|
|
|
2017-07-17 09:55:02 -07:00
|
|
|
auto deviceInfo = DeviceInfo::get();
|
2017-08-14 14:22:56 -07:00
|
|
|
auto displayInfo = deviceInfo->displayInfo();
|
2017-07-17 09:55:02 -07:00
|
|
|
int maxTextureSize = deviceInfo->maxTextureSize();
|
2010-07-23 00:28:00 -07:00
|
|
|
|
2017-08-14 14:22:56 -07:00
|
|
|
// Adjust cache size based on Pixel's desnsity.
|
|
|
|
constexpr float PIXEL_DENSITY = 2.6;
|
|
|
|
const float densityRatio = displayInfo.density / PIXEL_DENSITY;
|
|
|
|
|
2017-07-17 09:55:02 -07:00
|
|
|
// TODO: Most devices are hardcoded with this configuration, does it need to be dynamic?
|
2017-08-14 14:22:56 -07:00
|
|
|
mSmallCacheWidth =
|
|
|
|
OffscreenBuffer::computeIdealDimension(std::min(1024, maxTextureSize) * densityRatio);
|
|
|
|
mSmallCacheHeight =
|
|
|
|
OffscreenBuffer::computeIdealDimension(std::min(1024, maxTextureSize) * densityRatio);
|
|
|
|
mLargeCacheWidth =
|
|
|
|
OffscreenBuffer::computeIdealDimension(std::min(2048, maxTextureSize) * densityRatio);
|
|
|
|
mLargeCacheHeight =
|
|
|
|
OffscreenBuffer::computeIdealDimension(std::min(1024, maxTextureSize) * densityRatio);
|
2012-09-04 12:55:44 -07:00
|
|
|
|
2012-08-31 13:54:03 -07:00
|
|
|
if (sLogFontRendererCreate) {
|
|
|
|
INIT_LOGD(" Text cache sizes, in pixels: %i x %i, %i x %i, %i x %i, %i x %i",
|
2017-11-03 10:12:19 -07:00
|
|
|
mSmallCacheWidth, mSmallCacheHeight, mLargeCacheWidth, mLargeCacheHeight >> 1,
|
|
|
|
mLargeCacheWidth, mLargeCacheHeight >> 1, mLargeCacheWidth, mLargeCacheHeight);
|
2010-07-23 00:28:00 -07:00
|
|
|
}
|
2011-01-19 14:38:29 -08:00
|
|
|
|
|
|
|
sLogFontRendererCreate = false;
|
2010-07-21 21:33:20 -07:00
|
|
|
}
|
|
|
|
|
2015-07-29 16:48:58 -07:00
|
|
|
void clearCacheTextures(std::vector<CacheTexture*>& cacheTextures) {
|
2013-06-25 14:25:17 -07:00
|
|
|
for (uint32_t i = 0; i < cacheTextures.size(); i++) {
|
|
|
|
delete cacheTextures[i];
|
2010-07-21 21:33:20 -07:00
|
|
|
}
|
2013-06-25 14:25:17 -07:00
|
|
|
cacheTextures.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
FontRenderer::~FontRenderer() {
|
|
|
|
clearCacheTextures(mACacheTextures);
|
|
|
|
clearCacheTextures(mRGBACacheTextures);
|
2010-07-21 21:33:20 -07:00
|
|
|
|
2013-01-08 11:15:30 -08:00
|
|
|
LruCache<Font::FontDescription, Font*>::Iterator it(mActiveFonts);
|
|
|
|
while (it.next()) {
|
|
|
|
delete it.value();
|
2010-07-21 21:33:20 -07:00
|
|
|
}
|
2013-01-08 11:15:30 -08:00
|
|
|
mActiveFonts.clear();
|
2010-07-21 21:33:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void FontRenderer::flushAllAndInvalidate() {
|
2013-03-19 15:24:36 -07:00
|
|
|
issueDrawCommand();
|
2012-05-14 15:19:58 -07:00
|
|
|
|
2013-01-08 11:15:30 -08:00
|
|
|
LruCache<Font::FontDescription, Font*>::Iterator it(mActiveFonts);
|
|
|
|
while (it.next()) {
|
|
|
|
it.value()->invalidateTextureCache();
|
2010-07-21 21:33:20 -07:00
|
|
|
}
|
2012-05-14 15:19:58 -07:00
|
|
|
|
2013-06-25 14:25:17 -07:00
|
|
|
for (uint32_t i = 0; i < mACacheTextures.size(); i++) {
|
|
|
|
mACacheTextures[i]->init();
|
2016-09-09 18:02:07 -07:00
|
|
|
|
|
|
|
#ifdef BUGREPORT_FONT_CACHE_USAGE
|
|
|
|
mHistoryTracker.glyphsCleared(mACacheTextures[i]);
|
|
|
|
#endif
|
2013-06-25 14:25:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < mRGBACacheTextures.size(); i++) {
|
|
|
|
mRGBACacheTextures[i]->init();
|
2016-09-09 18:02:07 -07:00
|
|
|
#ifdef BUGREPORT_FONT_CACHE_USAGE
|
|
|
|
mHistoryTracker.glyphsCleared(mRGBACacheTextures[i]);
|
|
|
|
#endif
|
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
|
|
|
}
|
2014-08-28 18:45:27 -07:00
|
|
|
|
|
|
|
mDrawn = false;
|
2010-07-21 21:33:20 -07:00
|
|
|
}
|
|
|
|
|
2015-07-29 16:48:58 -07:00
|
|
|
void FontRenderer::flushLargeCaches(std::vector<CacheTexture*>& cacheTextures) {
|
2012-08-15 15:54:54 -07:00
|
|
|
// Start from 1; don't deallocate smallest/default texture
|
2013-06-25 14:25:17 -07:00
|
|
|
for (uint32_t i = 1; i < cacheTextures.size(); i++) {
|
|
|
|
CacheTexture* cacheTexture = cacheTextures[i];
|
2013-04-08 19:40:31 -07:00
|
|
|
if (cacheTexture->getPixelBuffer()) {
|
2012-08-15 15:54:54 -07:00
|
|
|
cacheTexture->init();
|
2016-09-09 18:02:07 -07:00
|
|
|
#ifdef BUGREPORT_FONT_CACHE_USAGE
|
|
|
|
mHistoryTracker.glyphsCleared(cacheTexture);
|
|
|
|
#endif
|
2013-01-08 11:15:30 -08:00
|
|
|
LruCache<Font::FontDescription, Font*>::Iterator it(mActiveFonts);
|
|
|
|
while (it.next()) {
|
|
|
|
it.value()->invalidateTextureCache(cacheTexture);
|
2011-12-16 15:44:59 -08:00
|
|
|
}
|
2015-03-13 15:07:52 -07:00
|
|
|
cacheTexture->releasePixelBuffer();
|
2011-12-16 15:44:59 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-25 14:25:17 -07:00
|
|
|
void FontRenderer::flushLargeCaches() {
|
|
|
|
flushLargeCaches(mACacheTextures);
|
|
|
|
flushLargeCaches(mRGBACacheTextures);
|
|
|
|
}
|
|
|
|
|
2015-07-29 16:48:58 -07:00
|
|
|
CacheTexture* FontRenderer::cacheBitmapInTexture(std::vector<CacheTexture*>& cacheTextures,
|
2017-11-03 10:12:19 -07:00
|
|
|
const SkGlyph& glyph, uint32_t* startX,
|
|
|
|
uint32_t* startY) {
|
2013-06-25 14:25:17 -07:00
|
|
|
for (uint32_t i = 0; i < cacheTextures.size(); i++) {
|
|
|
|
if (cacheTextures[i]->fitBitmap(glyph, startX, startY)) {
|
|
|
|
return cacheTextures[i];
|
2012-08-15 15:54:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Could not fit glyph into current cache textures
|
2015-01-05 15:51:13 -08:00
|
|
|
return nullptr;
|
2012-08-15 15:54:54 -07:00
|
|
|
}
|
|
|
|
|
2011-12-05 16:35:38 -08:00
|
|
|
void FontRenderer::cacheBitmap(const SkGlyph& glyph, CachedGlyphInfo* cachedGlyph,
|
2017-11-03 10:12:19 -07:00
|
|
|
uint32_t* retOriginX, uint32_t* retOriginY, bool precaching) {
|
2012-08-15 13:15:16 -07:00
|
|
|
checkInit();
|
2013-02-28 12:15:35 -08:00
|
|
|
|
|
|
|
// If the glyph bitmap is empty let's assum the glyph is valid
|
|
|
|
// so we can avoid doing extra work later on
|
|
|
|
if (glyph.fWidth == 0 || glyph.fHeight == 0) {
|
|
|
|
cachedGlyph->mIsValid = true;
|
2015-01-05 15:51:13 -08:00
|
|
|
cachedGlyph->mCacheTexture = nullptr;
|
2013-02-28 12:15:35 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-05 16:35:38 -08:00
|
|
|
cachedGlyph->mIsValid = false;
|
2013-02-28 12:15:35 -08:00
|
|
|
|
2013-06-25 14:25:17 -07:00
|
|
|
// choose an appropriate cache texture list for this glyph format
|
|
|
|
SkMask::Format format = static_cast<SkMask::Format>(glyph.fMaskFormat);
|
2015-07-29 16:48:58 -07:00
|
|
|
std::vector<CacheTexture*>* cacheTextures = nullptr;
|
2013-06-25 14:25:17 -07:00
|
|
|
switch (format) {
|
|
|
|
case SkMask::kA8_Format:
|
2013-08-12 14:38:44 -07:00
|
|
|
case SkMask::kBW_Format:
|
2013-06-25 14:25:17 -07:00
|
|
|
cacheTextures = &mACacheTextures;
|
|
|
|
break;
|
|
|
|
case SkMask::kARGB32_Format:
|
|
|
|
cacheTextures = &mRGBACacheTextures;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
#if DEBUG_FONT_RENDERER
|
|
|
|
ALOGD("getCacheTexturesForFormat: unknown SkMask format %x", format);
|
|
|
|
#endif
|
2017-11-03 10:12:19 -07:00
|
|
|
return;
|
2013-06-25 14:25:17 -07:00
|
|
|
}
|
|
|
|
|
2010-07-21 21:33:20 -07:00
|
|
|
// If the glyph is too tall, don't cache it
|
2012-08-15 15:54:54 -07:00
|
|
|
if (glyph.fHeight + TEXTURE_BORDER_SIZE * 2 >
|
2017-11-03 10:12:19 -07:00
|
|
|
(*cacheTextures)[cacheTextures->size() - 1]->getHeight()) {
|
|
|
|
ALOGE("Font size too large to fit in cache. width, height = %i, %i", (int)glyph.fWidth,
|
|
|
|
(int)glyph.fHeight);
|
2011-12-05 16:35:38 -08:00
|
|
|
return;
|
2010-07-21 21:33:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now copy the bitmap into the cache texture
|
|
|
|
uint32_t startX = 0;
|
|
|
|
uint32_t startY = 0;
|
|
|
|
|
2013-06-25 14:25:17 -07:00
|
|
|
CacheTexture* cacheTexture = cacheBitmapInTexture(*cacheTextures, glyph, &startX, &startY);
|
2010-07-21 21:33:20 -07:00
|
|
|
|
2012-08-15 15:54:54 -07:00
|
|
|
if (!cacheTexture) {
|
2012-08-30 09:06:46 -07:00
|
|
|
if (!precaching) {
|
|
|
|
// If the new glyph didn't fit and we are not just trying to precache it,
|
|
|
|
// clear out the cache and try again
|
|
|
|
flushAllAndInvalidate();
|
2013-06-25 14:25:17 -07:00
|
|
|
cacheTexture = cacheBitmapInTexture(*cacheTextures, glyph, &startX, &startY);
|
2012-08-30 09:06:46 -07:00
|
|
|
}
|
2010-07-21 21:33:20 -07:00
|
|
|
|
2012-08-15 15:54:54 -07:00
|
|
|
if (!cacheTexture) {
|
2012-08-30 09:06:46 -07:00
|
|
|
// either the glyph didn't fit or we're precaching and will cache it when we draw
|
2011-12-05 16:35:38 -08:00
|
|
|
return;
|
2010-07-21 21:33:20 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-15 15:54:54 -07:00
|
|
|
cachedGlyph->mCacheTexture = cacheTexture;
|
2011-12-05 16:35:38 -08:00
|
|
|
|
2010-07-21 21:33:20 -07:00
|
|
|
*retOriginX = startX;
|
|
|
|
*retOriginY = startY;
|
|
|
|
|
|
|
|
uint32_t endX = startX + glyph.fWidth;
|
|
|
|
uint32_t endY = startY + glyph.fHeight;
|
|
|
|
|
2012-09-04 16:42:01 -07:00
|
|
|
uint32_t cacheWidth = cacheTexture->getWidth();
|
2010-07-21 21:33:20 -07:00
|
|
|
|
2013-04-08 19:40:31 -07:00
|
|
|
if (!cacheTexture->getPixelBuffer()) {
|
2015-01-29 09:45:09 -08:00
|
|
|
Caches::getInstance().textureState().activateTexture(0);
|
2011-12-05 16:35:38 -08:00
|
|
|
// Large-glyph texture memory is allocated only as needed
|
2015-03-13 15:07:52 -07:00
|
|
|
cacheTexture->allocatePixelBuffer();
|
2011-12-05 16:35:38 -08:00
|
|
|
}
|
2013-03-19 15:24:36 -07:00
|
|
|
if (!cacheTexture->mesh()) {
|
|
|
|
cacheTexture->allocateMesh();
|
|
|
|
}
|
2012-05-14 15:19:58 -07:00
|
|
|
|
2013-04-08 19:40:31 -07:00
|
|
|
uint8_t* cacheBuffer = cacheTexture->getPixelBuffer()->map();
|
2017-11-03 10:12:19 -07:00
|
|
|
uint8_t* bitmapBuffer = (uint8_t*)glyph.fImage;
|
2013-06-25 14:25:17 -07:00
|
|
|
int srcStride = glyph.rowBytes();
|
2013-03-05 12:16:27 -08:00
|
|
|
|
2013-06-25 14:25:17 -07:00
|
|
|
// Copy the glyph image, taking the mask format into account
|
2013-02-05 14:38:40 -08:00
|
|
|
switch (format) {
|
|
|
|
case SkMask::kA8_Format: {
|
2017-11-03 10:12:19 -07:00
|
|
|
uint32_t row =
|
|
|
|
(startY - TEXTURE_BORDER_SIZE) * cacheWidth + startX - TEXTURE_BORDER_SIZE;
|
2013-06-25 14:25:17 -07:00
|
|
|
// write leading border line
|
|
|
|
memset(&cacheBuffer[row], 0, glyph.fWidth + 2 * TEXTURE_BORDER_SIZE);
|
|
|
|
// write glyph data
|
2013-02-05 14:38:40 -08:00
|
|
|
if (mGammaTable) {
|
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
|
|
|
for (uint32_t cacheY = startY, bY = 0; cacheY < endY; cacheY++, bY += srcStride) {
|
2013-03-05 12:16:27 -08:00
|
|
|
row = cacheY * cacheWidth;
|
|
|
|
cacheBuffer[row + startX - TEXTURE_BORDER_SIZE] = 0;
|
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
|
|
|
for (uint32_t cacheX = startX, bX = 0; cacheX < endX; cacheX++, bX++) {
|
2013-02-05 14:38:40 -08:00
|
|
|
uint8_t tempCol = bitmapBuffer[bY + bX];
|
2013-03-05 12:16:27 -08:00
|
|
|
cacheBuffer[row + cacheX] = mGammaTable[tempCol];
|
2013-02-05 14:38:40 -08:00
|
|
|
}
|
2013-03-05 12:16:27 -08:00
|
|
|
cacheBuffer[row + endX + TEXTURE_BORDER_SIZE - 1] = 0;
|
2013-02-05 14:38:40 -08:00
|
|
|
}
|
|
|
|
} else {
|
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
|
|
|
for (uint32_t cacheY = startY, bY = 0; cacheY < endY; cacheY++, bY += srcStride) {
|
2013-03-05 12:16:27 -08:00
|
|
|
row = cacheY * cacheWidth;
|
|
|
|
memcpy(&cacheBuffer[row + startX], &bitmapBuffer[bY], glyph.fWidth);
|
|
|
|
cacheBuffer[row + startX - TEXTURE_BORDER_SIZE] = 0;
|
|
|
|
cacheBuffer[row + endX + TEXTURE_BORDER_SIZE - 1] = 0;
|
2013-02-05 14:38:40 -08:00
|
|
|
}
|
2012-07-13 18:25:35 -07:00
|
|
|
}
|
2013-06-25 14:25:17 -07:00
|
|
|
// write trailing border line
|
|
|
|
row = (endY + TEXTURE_BORDER_SIZE - 1) * cacheWidth + startX - TEXTURE_BORDER_SIZE;
|
|
|
|
memset(&cacheBuffer[row], 0, glyph.fWidth + 2 * TEXTURE_BORDER_SIZE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SkMask::kARGB32_Format: {
|
|
|
|
// prep data lengths
|
|
|
|
const size_t formatSize = PixelBuffer::formatSize(GL_RGBA);
|
|
|
|
const size_t borderSize = formatSize * TEXTURE_BORDER_SIZE;
|
|
|
|
size_t rowSize = formatSize * glyph.fWidth;
|
|
|
|
// prep advances
|
|
|
|
size_t dstStride = formatSize * cacheWidth;
|
|
|
|
// prep indices
|
|
|
|
// - we actually start one row early, and then increment before first copy
|
|
|
|
uint8_t* src = &bitmapBuffer[0 - srcStride];
|
|
|
|
uint8_t* dst = &cacheBuffer[cacheTexture->getOffset(startX, startY - 1)];
|
|
|
|
uint8_t* dstEnd = &cacheBuffer[cacheTexture->getOffset(startX, endY - 1)];
|
|
|
|
uint8_t* dstL = dst - borderSize;
|
|
|
|
uint8_t* dstR = dst + rowSize;
|
|
|
|
// write leading border line
|
|
|
|
memset(dstL, 0, rowSize + 2 * borderSize);
|
|
|
|
// write glyph data
|
|
|
|
while (dst < dstEnd) {
|
2017-11-03 10:12:19 -07:00
|
|
|
memset(dstL += dstStride, 0, borderSize); // leading border column
|
|
|
|
memcpy(dst += dstStride, src += srcStride, rowSize); // glyph data
|
|
|
|
memset(dstR += dstStride, 0, borderSize); // trailing border column
|
2013-06-25 14:25:17 -07:00
|
|
|
}
|
|
|
|
// write trailing border line
|
2013-09-19 15:38:21 -07:00
|
|
|
memset(dstL += dstStride, 0, rowSize + 2 * borderSize);
|
2013-02-05 14:38:40 -08:00
|
|
|
break;
|
2012-07-13 18:25:35 -07:00
|
|
|
}
|
2013-02-05 14:38:40 -08:00
|
|
|
case SkMask::kBW_Format: {
|
2014-11-10 15:23:43 -08:00
|
|
|
uint32_t cacheX = 0, cacheY = 0;
|
2017-11-03 10:12:19 -07:00
|
|
|
uint32_t row =
|
|
|
|
(startY - TEXTURE_BORDER_SIZE) * cacheWidth + startX - TEXTURE_BORDER_SIZE;
|
|
|
|
static const uint8_t COLORS[2] = {0, 255};
|
2013-06-25 14:25:17 -07:00
|
|
|
// write leading border line
|
|
|
|
memset(&cacheBuffer[row], 0, glyph.fWidth + 2 * TEXTURE_BORDER_SIZE);
|
|
|
|
// write glyph data
|
2013-02-05 14:38:40 -08:00
|
|
|
for (cacheY = startY; cacheY < endY; cacheY++) {
|
|
|
|
cacheX = startX;
|
2013-06-25 14:25:17 -07:00
|
|
|
int rowBytes = srcStride;
|
2013-02-05 14:38:40 -08:00
|
|
|
uint8_t* buffer = bitmapBuffer;
|
|
|
|
|
2013-03-05 12:16:27 -08:00
|
|
|
row = cacheY * cacheWidth;
|
|
|
|
cacheBuffer[row + startX - TEXTURE_BORDER_SIZE] = 0;
|
2013-02-05 14:38:40 -08:00
|
|
|
while (--rowBytes >= 0) {
|
|
|
|
uint8_t b = *buffer++;
|
|
|
|
for (int8_t mask = 7; mask >= 0 && cacheX < endX; mask--) {
|
|
|
|
cacheBuffer[cacheY * cacheWidth + cacheX++] = COLORS[(b >> mask) & 0x1];
|
|
|
|
}
|
|
|
|
}
|
2013-03-05 12:16:27 -08:00
|
|
|
cacheBuffer[row + endX + TEXTURE_BORDER_SIZE - 1] = 0;
|
2013-02-05 14:38:40 -08:00
|
|
|
|
2013-06-25 14:25:17 -07:00
|
|
|
bitmapBuffer += srcStride;
|
2012-07-13 18:25:35 -07:00
|
|
|
}
|
2013-06-25 14:25:17 -07:00
|
|
|
// write trailing border line
|
|
|
|
row = (endY + TEXTURE_BORDER_SIZE - 1) * cacheWidth + startX - TEXTURE_BORDER_SIZE;
|
|
|
|
memset(&cacheBuffer[row], 0, glyph.fWidth + 2 * TEXTURE_BORDER_SIZE);
|
2013-02-05 14:38:40 -08:00
|
|
|
break;
|
2010-07-21 21:33:20 -07:00
|
|
|
}
|
2013-02-05 14:38:40 -08:00
|
|
|
default:
|
2013-06-25 14:25:17 -07:00
|
|
|
ALOGW("Unknown glyph format: 0x%x", format);
|
2013-02-05 14:38:40 -08:00
|
|
|
break;
|
2010-07-21 21:33:20 -07:00
|
|
|
}
|
2012-02-28 18:17:02 -08:00
|
|
|
|
2011-12-05 16:35:38 -08:00
|
|
|
cachedGlyph->mIsValid = true;
|
2016-09-09 18:02:07 -07:00
|
|
|
|
|
|
|
#ifdef BUGREPORT_FONT_CACHE_USAGE
|
|
|
|
mHistoryTracker.glyphUploaded(cacheTexture, startX, startY, glyph.fWidth, glyph.fHeight);
|
|
|
|
#endif
|
2010-07-21 21:33:20 -07:00
|
|
|
}
|
|
|
|
|
2013-06-25 14:25:17 -07:00
|
|
|
CacheTexture* FontRenderer::createCacheTexture(int width, int height, GLenum format,
|
2017-11-03 10:12:19 -07:00
|
|
|
bool allocate) {
|
2015-01-27 15:46:35 -08:00
|
|
|
CacheTexture* cacheTexture = new CacheTexture(width, height, format, kMaxNumberOfQuads);
|
2012-05-14 15:19:58 -07:00
|
|
|
|
2011-12-14 15:22:56 -08:00
|
|
|
if (allocate) {
|
2015-01-29 09:45:09 -08:00
|
|
|
Caches::getInstance().textureState().activateTexture(0);
|
2015-03-13 15:07:52 -07:00
|
|
|
cacheTexture->allocatePixelBuffer();
|
2013-03-19 15:24:36 -07:00
|
|
|
cacheTexture->allocateMesh();
|
2011-12-14 15:22:56 -08:00
|
|
|
}
|
2012-05-14 15:19:58 -07:00
|
|
|
|
2011-12-14 15:22:56 -08:00
|
|
|
return cacheTexture;
|
2011-12-05 16:35:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void FontRenderer::initTextTexture() {
|
2013-06-25 14:25:17 -07:00
|
|
|
clearCacheTextures(mACacheTextures);
|
|
|
|
clearCacheTextures(mRGBACacheTextures);
|
2012-05-14 15:19:58 -07:00
|
|
|
|
2011-12-05 16:35:38 -08:00
|
|
|
mUploadTexture = false;
|
2017-11-03 10:12:19 -07:00
|
|
|
mACacheTextures.push_back(
|
|
|
|
createCacheTexture(mSmallCacheWidth, mSmallCacheHeight, GL_ALPHA, true));
|
|
|
|
mACacheTextures.push_back(
|
|
|
|
createCacheTexture(mLargeCacheWidth, mLargeCacheHeight >> 1, GL_ALPHA, false));
|
|
|
|
mACacheTextures.push_back(
|
|
|
|
createCacheTexture(mLargeCacheWidth, mLargeCacheHeight >> 1, GL_ALPHA, false));
|
|
|
|
mACacheTextures.push_back(
|
|
|
|
createCacheTexture(mLargeCacheWidth, mLargeCacheHeight, GL_ALPHA, false));
|
|
|
|
mRGBACacheTextures.push_back(
|
|
|
|
createCacheTexture(mSmallCacheWidth, mSmallCacheHeight, GL_RGBA, false));
|
|
|
|
mRGBACacheTextures.push_back(
|
|
|
|
createCacheTexture(mLargeCacheWidth, mLargeCacheHeight >> 1, GL_RGBA, false));
|
2013-06-25 14:25:17 -07:00
|
|
|
mCurrentCacheTexture = mACacheTextures[0];
|
2010-07-21 21:33:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// We don't want to allocate anything unless we actually draw text
|
|
|
|
void FontRenderer::checkInit() {
|
|
|
|
if (mInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
initTextTexture();
|
|
|
|
|
|
|
|
mInitialized = true;
|
|
|
|
}
|
|
|
|
|
2015-07-29 16:48:58 -07:00
|
|
|
void checkTextureUpdateForCache(Caches& caches, std::vector<CacheTexture*>& cacheTextures,
|
2017-11-03 10:12:19 -07:00
|
|
|
bool& resetPixelStore, GLuint& lastTextureId) {
|
2013-06-25 14:25:17 -07:00
|
|
|
for (uint32_t i = 0; i < cacheTextures.size(); i++) {
|
|
|
|
CacheTexture* cacheTexture = cacheTextures[i];
|
2013-04-08 19:40:31 -07:00
|
|
|
if (cacheTexture->isDirty() && cacheTexture->getPixelBuffer()) {
|
2012-09-04 16:42:01 -07:00
|
|
|
if (cacheTexture->getTextureId() != lastTextureId) {
|
|
|
|
lastTextureId = cacheTexture->getTextureId();
|
2015-01-29 09:45:09 -08:00
|
|
|
caches.textureState().activateTexture(0);
|
|
|
|
caches.textureState().bindTexture(lastTextureId);
|
2013-04-04 12:27:54 -07:00
|
|
|
}
|
|
|
|
|
2013-04-08 19:40:31 -07:00
|
|
|
if (cacheTexture->upload()) {
|
|
|
|
resetPixelStore = true;
|
2011-12-13 22:00:19 -08:00
|
|
|
}
|
2010-07-23 14:45:49 -07:00
|
|
|
}
|
2010-07-21 21:33:20 -07:00
|
|
|
}
|
2013-06-25 14:25:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void FontRenderer::checkTextureUpdate() {
|
|
|
|
if (!mUploadTexture) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Caches& caches = Caches::getInstance();
|
|
|
|
GLuint lastTextureId = 0;
|
|
|
|
|
|
|
|
bool resetPixelStore = false;
|
|
|
|
|
|
|
|
// Iterate over all the cache textures and see which ones need to be updated
|
|
|
|
checkTextureUpdateForCache(caches, mACacheTextures, resetPixelStore, lastTextureId);
|
|
|
|
checkTextureUpdateForCache(caches, mRGBACacheTextures, resetPixelStore, lastTextureId);
|
2010-07-21 21:33:20 -07:00
|
|
|
|
2013-04-08 19:40:31 -07:00
|
|
|
// Unbind any PBO we might have used to update textures
|
2015-01-29 09:45:09 -08:00
|
|
|
caches.pixelBufferState().unbind();
|
2013-04-08 19:40:31 -07:00
|
|
|
|
2013-04-04 12:27:54 -07:00
|
|
|
// Reset to default unpack row length to avoid affecting texture
|
|
|
|
// uploads in other parts of the renderer
|
2013-04-08 19:40:31 -07:00
|
|
|
if (resetPixelStore) {
|
2013-04-04 12:27:54 -07:00
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
|
|
|
}
|
|
|
|
|
2010-07-23 14:45:49 -07:00
|
|
|
mUploadTexture = false;
|
|
|
|
}
|
|
|
|
|
2015-07-29 16:48:58 -07:00
|
|
|
void FontRenderer::issueDrawCommand(std::vector<CacheTexture*>& cacheTextures) {
|
2015-01-27 15:46:35 -08:00
|
|
|
if (!mFunctor) return;
|
|
|
|
|
2013-03-19 15:24:36 -07:00
|
|
|
bool first = true;
|
2013-06-25 14:25:17 -07:00
|
|
|
for (uint32_t i = 0; i < cacheTextures.size(); i++) {
|
|
|
|
CacheTexture* texture = cacheTextures[i];
|
2013-03-19 15:24:36 -07:00
|
|
|
if (texture->canDraw()) {
|
|
|
|
if (first) {
|
2015-03-13 15:07:52 -07:00
|
|
|
checkTextureUpdate();
|
2013-03-19 15:24:36 -07:00
|
|
|
first = false;
|
2015-02-27 17:04:20 -08:00
|
|
|
mDrawn = true;
|
2013-03-19 15:24:36 -07:00
|
|
|
}
|
2012-11-16 00:03:17 +09:00
|
|
|
|
2015-04-03 09:37:49 -07:00
|
|
|
mFunctor->draw(*texture, mLinearFiltering);
|
2013-03-19 15:24:36 -07:00
|
|
|
|
|
|
|
texture->resetMesh();
|
|
|
|
}
|
2012-11-16 00:03:17 +09:00
|
|
|
}
|
2013-06-25 14:25:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void FontRenderer::issueDrawCommand() {
|
|
|
|
issueDrawCommand(mACacheTextures);
|
|
|
|
issueDrawCommand(mRGBACacheTextures);
|
2010-07-21 21:33:20 -07:00
|
|
|
}
|
|
|
|
|
2017-11-03 10:12:19 -07:00
|
|
|
void FontRenderer::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-05 16:35:38 -08:00
|
|
|
if (texture != mCurrentCacheTexture) {
|
|
|
|
// Now use the new texture id
|
|
|
|
mCurrentCacheTexture = texture;
|
|
|
|
}
|
2010-07-22 13:08:20 -07:00
|
|
|
|
2017-11-03 10:12:19 -07:00
|
|
|
mCurrentCacheTexture->addQuad(x1, y1, u1, v1, x2, y2, u2, v2, x3, y3, u3, v3, x4, y4, u4, v4);
|
2012-02-28 18:17:02 -08:00
|
|
|
}
|
|
|
|
|
2017-11-03 10:12:19 -07:00
|
|
|
void FontRenderer::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,
|
|
|
|
float x4, float y4, float u4, float v4, CacheTexture* texture) {
|
|
|
|
if (mClip && (x1 > mClip->right || y1 < mClip->top || x2 < mClip->left || y4 > mClip->bottom)) {
|
2012-02-28 18:17:02 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
appendMeshQuadNoClip(x1, y1, u1, v1, x2, y2, u2, v2, x3, y3, u3, v3, x4, y4, u4, v4, texture);
|
2010-07-21 21:33:20 -07:00
|
|
|
|
2010-10-27 18:57:51 -07:00
|
|
|
if (mBounds) {
|
2015-07-07 18:42:17 -07:00
|
|
|
mBounds->left = std::min(mBounds->left, x1);
|
|
|
|
mBounds->top = std::min(mBounds->top, y3);
|
|
|
|
mBounds->right = std::max(mBounds->right, x3);
|
|
|
|
mBounds->bottom = std::max(mBounds->bottom, y1);
|
2010-10-27 18:57:51 -07:00
|
|
|
}
|
|
|
|
|
2013-03-19 15:24:36 -07:00
|
|
|
if (mCurrentCacheTexture->endOfMesh()) {
|
2010-07-21 21:33:20 -07:00
|
|
|
issueDrawCommand();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-03 10:12:19 -07:00
|
|
|
void FontRenderer::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) {
|
2012-02-28 18:17:02 -08:00
|
|
|
appendMeshQuadNoClip(x1, y1, u1, v1, x2, y2, u2, v2, x3, y3, u3, v3, x4, y4, u4, v4, texture);
|
|
|
|
|
|
|
|
if (mBounds) {
|
2015-07-07 18:42:17 -07:00
|
|
|
mBounds->left = std::min(mBounds->left, std::min(x1, std::min(x2, std::min(x3, x4))));
|
|
|
|
mBounds->top = std::min(mBounds->top, std::min(y1, std::min(y2, std::min(y3, y4))));
|
|
|
|
mBounds->right = std::max(mBounds->right, std::max(x1, std::max(x2, std::max(x3, x4))));
|
|
|
|
mBounds->bottom = std::max(mBounds->bottom, std::max(y1, std::max(y2, std::max(y3, y4))));
|
2012-02-28 18:17:02 -08:00
|
|
|
}
|
|
|
|
|
2013-03-19 15:24:36 -07:00
|
|
|
if (mCurrentCacheTexture->endOfMesh()) {
|
2012-02-28 18:17:02 -08:00
|
|
|
issueDrawCommand();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-01 17:56:52 -07:00
|
|
|
void FontRenderer::setFont(const SkPaint* paint, const SkMatrix& matrix) {
|
2013-01-08 11:15:30 -08:00
|
|
|
mCurrentFont = Font::create(this, paint, matrix);
|
2010-07-21 21:33:20 -07:00
|
|
|
}
|
2010-10-01 16:36:14 -07:00
|
|
|
|
2017-11-03 10:12:19 -07:00
|
|
|
FontRenderer::DropShadow FontRenderer::renderDropShadow(const SkPaint* paint, const glyph_t* glyphs,
|
|
|
|
int numGlyphs, float radius,
|
|
|
|
const float* positions) {
|
2010-08-13 19:39:53 -07:00
|
|
|
checkInit();
|
|
|
|
|
2013-04-08 19:40:31 -07:00
|
|
|
DropShadow image;
|
|
|
|
image.width = 0;
|
|
|
|
image.height = 0;
|
2015-01-05 15:51:13 -08:00
|
|
|
image.image = nullptr;
|
2013-04-08 19:40:31 -07:00
|
|
|
image.penX = 0;
|
|
|
|
image.penY = 0;
|
|
|
|
|
2010-08-13 19:39:53 -07:00
|
|
|
if (!mCurrentFont) {
|
|
|
|
return image;
|
|
|
|
}
|
2010-08-06 14:49:04 -07:00
|
|
|
|
2011-12-13 22:00:19 -08:00
|
|
|
mDrawn = false;
|
2015-01-05 15:51:13 -08:00
|
|
|
mClip = nullptr;
|
|
|
|
mBounds = nullptr;
|
2011-11-28 09:35:09 -08:00
|
|
|
|
2010-08-06 14:49:04 -07:00
|
|
|
Rect bounds;
|
2016-02-05 20:10:50 -08:00
|
|
|
mCurrentFont->measure(paint, glyphs, numGlyphs, &bounds, positions);
|
2011-11-28 09:35:09 -08:00
|
|
|
|
2014-05-21 11:25:22 -04:00
|
|
|
uint32_t intRadius = Blur::convertRadiusToInt(radius);
|
2017-11-03 10:12:19 -07:00
|
|
|
uint32_t paddedWidth = (uint32_t)(bounds.right - bounds.left) + 2 * intRadius;
|
|
|
|
uint32_t paddedHeight = (uint32_t)(bounds.top - bounds.bottom) + 2 * intRadius;
|
2011-11-28 09:35:09 -08:00
|
|
|
|
2013-04-08 19:40:31 -07:00
|
|
|
uint32_t maxSize = Caches::getInstance().maxTextureSize;
|
|
|
|
if (paddedWidth > maxSize || paddedHeight > maxSize) {
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
2013-02-13 16:14:17 -08:00
|
|
|
// Align buffers for renderscript usage
|
|
|
|
if (paddedWidth & (RS_CPU_ALLOCATION_ALIGNMENT - 1)) {
|
|
|
|
paddedWidth += RS_CPU_ALLOCATION_ALIGNMENT - paddedWidth % RS_CPU_ALLOCATION_ALIGNMENT;
|
2010-08-06 14:49:04 -07:00
|
|
|
}
|
2013-02-13 16:14:17 -08:00
|
|
|
int size = paddedWidth * paddedHeight;
|
2017-11-03 10:12:19 -07:00
|
|
|
uint8_t* dataBuffer = (uint8_t*)memalign(RS_CPU_ALLOCATION_ALIGNMENT, size);
|
2013-03-28 18:10:43 -07:00
|
|
|
|
2013-02-13 16:14:17 -08:00
|
|
|
memset(dataBuffer, 0, size);
|
|
|
|
|
2014-05-21 11:25:22 -04:00
|
|
|
int penX = intRadius - bounds.left;
|
|
|
|
int penY = intRadius - bounds.bottom;
|
2010-08-06 14:49:04 -07:00
|
|
|
|
2013-02-22 10:41:36 -08:00
|
|
|
if ((bounds.right > bounds.left) && (bounds.top > bounds.bottom)) {
|
|
|
|
// text has non-whitespace, so draw and blur to create the shadow
|
|
|
|
// NOTE: bounds.isEmpty() can't be used here, since vertical coordinates are inverted
|
|
|
|
// TODO: don't draw pure whitespace in the first place, and avoid needing this check
|
2017-11-03 10:12:19 -07:00
|
|
|
mCurrentFont->render(paint, glyphs, numGlyphs, penX, penY, Font::BITMAP, dataBuffer,
|
|
|
|
paddedWidth, paddedHeight, nullptr, positions);
|
2013-02-22 10:41:36 -08:00
|
|
|
|
2013-04-08 19:40:31 -07:00
|
|
|
// Unbind any PBO we might have used
|
2015-01-29 09:45:09 -08:00
|
|
|
Caches::getInstance().pixelBufferState().unbind();
|
2013-04-08 19:40:31 -07:00
|
|
|
|
2013-02-22 10:41:36 -08:00
|
|
|
blurImage(&dataBuffer, paddedWidth, paddedHeight, radius);
|
|
|
|
}
|
2010-08-06 14:49:04 -07:00
|
|
|
|
|
|
|
image.width = paddedWidth;
|
|
|
|
image.height = paddedHeight;
|
|
|
|
image.image = dataBuffer;
|
|
|
|
image.penX = penX;
|
|
|
|
image.penY = penY;
|
2011-12-13 22:00:19 -08:00
|
|
|
|
2010-08-06 14:49:04 -07:00
|
|
|
return image;
|
|
|
|
}
|
2010-07-21 21:33:20 -07:00
|
|
|
|
2015-04-03 09:37:49 -07:00
|
|
|
void FontRenderer::initRender(const Rect* clip, Rect* bounds, TextDrawFunctor* functor) {
|
2010-07-21 21:33:20 -07:00
|
|
|
checkInit();
|
|
|
|
|
2010-10-27 18:57:51 -07:00
|
|
|
mDrawn = false;
|
|
|
|
mBounds = bounds;
|
2013-03-20 16:31:12 -07:00
|
|
|
mFunctor = functor;
|
2010-07-22 13:08:20 -07:00
|
|
|
mClip = clip;
|
2012-01-18 12:39:17 -08:00
|
|
|
}
|
2011-11-28 09:35:09 -08:00
|
|
|
|
2012-01-18 12:39:17 -08:00
|
|
|
void FontRenderer::finishRender() {
|
2015-01-05 15:51:13 -08:00
|
|
|
mBounds = nullptr;
|
|
|
|
mClip = nullptr;
|
2010-07-21 21:33:20 -07:00
|
|
|
|
2013-03-19 15:24:36 -07:00
|
|
|
issueDrawCommand();
|
2012-01-18 12:39:17 -08:00
|
|
|
}
|
|
|
|
|
2016-02-05 20:10:50 -08:00
|
|
|
void FontRenderer::precache(const SkPaint* paint, const glyph_t* glyphs, int numGlyphs,
|
2017-11-03 10:12:19 -07:00
|
|
|
const SkMatrix& matrix) {
|
2013-01-08 11:15:30 -08:00
|
|
|
Font* font = Font::create(this, paint, matrix);
|
2016-02-05 20:10:50 -08:00
|
|
|
font->precache(paint, glyphs, numGlyphs);
|
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-04-08 19:40:31 -07:00
|
|
|
void FontRenderer::endPrecaching() {
|
|
|
|
checkTextureUpdate();
|
|
|
|
}
|
|
|
|
|
2016-02-05 20:10:50 -08:00
|
|
|
bool FontRenderer::renderPosText(const SkPaint* paint, const Rect* clip, const glyph_t* glyphs,
|
2017-11-03 10:12:19 -07:00
|
|
|
int numGlyphs, int x, int y, const float* positions, Rect* bounds,
|
|
|
|
TextDrawFunctor* functor, bool forceFinish) {
|
2012-01-18 12:39:17 -08:00
|
|
|
if (!mCurrentFont) {
|
|
|
|
ALOGE("No font set");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-20 16:31:12 -07:00
|
|
|
initRender(clip, bounds, functor);
|
2016-02-05 20:10:50 -08:00
|
|
|
mCurrentFont->render(paint, glyphs, numGlyphs, x, y, positions);
|
2013-03-04 10:19:31 -08:00
|
|
|
|
|
|
|
if (forceFinish) {
|
|
|
|
finishRender();
|
|
|
|
}
|
2010-10-27 18:57:51 -07:00
|
|
|
|
2012-02-28 18:17:02 -08:00
|
|
|
return mDrawn;
|
|
|
|
}
|
|
|
|
|
2016-02-05 20:10:50 -08:00
|
|
|
bool FontRenderer::renderTextOnPath(const SkPaint* paint, const Rect* clip, const glyph_t* glyphs,
|
2017-11-03 10:12:19 -07:00
|
|
|
int numGlyphs, const SkPath* path, float hOffset, float vOffset,
|
|
|
|
Rect* bounds, TextDrawFunctor* functor) {
|
2012-02-28 18:17:02 -08:00
|
|
|
if (!mCurrentFont) {
|
|
|
|
ALOGE("No font set");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-25 14:25:17 -07:00
|
|
|
initRender(clip, bounds, functor);
|
2016-02-05 20:10:50 -08:00
|
|
|
mCurrentFont->render(paint, glyphs, numGlyphs, path, hOffset, vOffset);
|
2012-02-28 18:17:02 -08:00
|
|
|
finishRender();
|
|
|
|
|
2010-10-27 18:57:51 -07:00
|
|
|
return mDrawn;
|
2010-07-21 21:33:20 -07:00
|
|
|
}
|
|
|
|
|
2014-05-21 11:25:22 -04:00
|
|
|
void FontRenderer::blurImage(uint8_t** image, int32_t width, int32_t height, float radius) {
|
|
|
|
uint32_t intRadius = Blur::convertRadiusToInt(radius);
|
2016-04-19 18:13:21 -07:00
|
|
|
if (width * height * intRadius >= RS_MIN_INPUT_CUTOFF && radius <= 25.0f) {
|
2017-11-03 10:12:19 -07:00
|
|
|
uint8_t* outImage = (uint8_t*)memalign(RS_CPU_ALLOCATION_ALIGNMENT, width * height);
|
2013-03-28 18:10:43 -07:00
|
|
|
|
2015-01-05 15:51:13 -08:00
|
|
|
if (mRs == nullptr) {
|
2013-03-28 18:10:43 -07:00
|
|
|
mRs = new RSC::RS();
|
2013-12-13 12:57:36 -08:00
|
|
|
// a null path is OK because there are no custom kernels used
|
|
|
|
// hence nothing gets cached by RS
|
|
|
|
if (!mRs->init("", RSC::RS_INIT_LOW_LATENCY | RSC::RS_INIT_SYNCHRONOUS)) {
|
2013-11-14 15:52:22 +08:00
|
|
|
mRs.clear();
|
2013-03-28 18:10:43 -07:00
|
|
|
ALOGE("blur RS failed to init");
|
2013-11-14 15:52:22 +08:00
|
|
|
} else {
|
|
|
|
mRsElement = RSC::Element::A_8(mRs);
|
|
|
|
mRsScript = RSC::ScriptIntrinsicBlur::create(mRs, mRsElement);
|
2013-03-28 18:10:43 -07:00
|
|
|
}
|
|
|
|
}
|
2015-01-05 15:51:13 -08:00
|
|
|
if (mRs != nullptr) {
|
2013-11-14 15:52:22 +08:00
|
|
|
RSC::sp<const RSC::Type> t = RSC::Type::create(mRs, mRsElement, width, height, 0);
|
2017-11-03 10:12:19 -07:00
|
|
|
RSC::sp<RSC::Allocation> ain = RSC::Allocation::createTyped(
|
|
|
|
mRs, t, RS_ALLOCATION_MIPMAP_NONE,
|
|
|
|
RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_SHARED, *image);
|
|
|
|
RSC::sp<RSC::Allocation> aout = RSC::Allocation::createTyped(
|
|
|
|
mRs, t, RS_ALLOCATION_MIPMAP_NONE,
|
|
|
|
RS_ALLOCATION_USAGE_SCRIPT | RS_ALLOCATION_USAGE_SHARED, outImage);
|
2013-11-14 15:52:22 +08:00
|
|
|
|
|
|
|
mRsScript->setRadius(radius);
|
|
|
|
mRsScript->setInput(ain);
|
|
|
|
mRsScript->forEach(aout);
|
|
|
|
|
|
|
|
// replace the original image's pointer, avoiding a copy back to the original buffer
|
|
|
|
free(*image);
|
|
|
|
*image = outImage;
|
2013-02-13 16:14:17 -08:00
|
|
|
|
2013-11-14 15:52:22 +08:00
|
|
|
return;
|
|
|
|
}
|
2013-02-13 16:14:17 -08:00
|
|
|
}
|
2011-12-12 19:03:35 -08:00
|
|
|
|
2014-12-22 17:16:56 -08:00
|
|
|
std::unique_ptr<float[]> gaussian(new float[2 * intRadius + 1]);
|
2015-04-14 16:23:15 +02:00
|
|
|
Blur::generateGaussianWeights(gaussian.get(), radius);
|
2011-12-12 19:03:35 -08:00
|
|
|
|
2014-12-22 17:16:56 -08:00
|
|
|
std::unique_ptr<uint8_t[]> scratch(new uint8_t[width * height]);
|
|
|
|
Blur::horizontal(gaussian.get(), intRadius, *image, scratch.get(), width, height);
|
|
|
|
Blur::vertical(gaussian.get(), intRadius, scratch.get(), *image, width, height);
|
2010-08-02 17:52:30 -07:00
|
|
|
}
|
|
|
|
|
2015-07-29 16:48:58 -07:00
|
|
|
static uint32_t calculateCacheSize(const std::vector<CacheTexture*>& cacheTextures) {
|
2013-04-08 19:40:31 -07:00
|
|
|
uint32_t size = 0;
|
2013-06-25 14:25:17 -07:00
|
|
|
for (uint32_t i = 0; i < cacheTextures.size(); i++) {
|
|
|
|
CacheTexture* cacheTexture = cacheTextures[i];
|
2013-04-08 19:40:31 -07:00
|
|
|
if (cacheTexture && cacheTexture->getPixelBuffer()) {
|
|
|
|
size += cacheTexture->getPixelBuffer()->getSize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2016-09-08 11:09:34 -07:00
|
|
|
static uint32_t calculateFreeCacheSize(const std::vector<CacheTexture*>& cacheTextures) {
|
|
|
|
uint32_t size = 0;
|
|
|
|
for (uint32_t i = 0; i < cacheTextures.size(); i++) {
|
|
|
|
CacheTexture* cacheTexture = cacheTextures[i];
|
|
|
|
if (cacheTexture && cacheTexture->getPixelBuffer()) {
|
|
|
|
size += cacheTexture->calculateFreeMemory();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<CacheTexture*>& FontRenderer::cacheTexturesForFormat(GLenum format) const {
|
2013-06-25 14:25:17 -07:00
|
|
|
switch (format) {
|
|
|
|
case GL_ALPHA: {
|
2016-09-08 11:09:34 -07:00
|
|
|
return mACacheTextures;
|
2013-06-25 14:25:17 -07:00
|
|
|
}
|
|
|
|
case GL_RGBA: {
|
2016-09-08 11:09:34 -07:00
|
|
|
return mRGBACacheTextures;
|
2013-06-25 14:25:17 -07:00
|
|
|
}
|
|
|
|
default: {
|
2016-09-08 11:09:34 -07:00
|
|
|
LOG_ALWAYS_FATAL("Unsupported format: %d", format);
|
|
|
|
// Impossible to hit this, but the compiler doesn't know that
|
|
|
|
return *(new std::vector<CacheTexture*>());
|
2013-06-25 14:25:17 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-08 11:09:34 -07:00
|
|
|
static void dumpTextures(String8& log, const char* tag,
|
2017-11-03 10:12:19 -07:00
|
|
|
const std::vector<CacheTexture*>& cacheTextures) {
|
2016-09-08 11:09:34 -07:00
|
|
|
for (uint32_t i = 0; i < cacheTextures.size(); i++) {
|
|
|
|
CacheTexture* cacheTexture = cacheTextures[i];
|
|
|
|
if (cacheTexture && cacheTexture->getPixelBuffer()) {
|
|
|
|
uint32_t free = cacheTexture->calculateFreeMemory();
|
|
|
|
uint32_t total = cacheTexture->getPixelBuffer()->getSize();
|
|
|
|
log.appendFormat(" %-4s texture %d %8d / %8d\n", tag, i, total - free, total);
|
2013-06-25 14:25:17 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-08 11:09:34 -07:00
|
|
|
void FontRenderer::dumpMemoryUsage(String8& log) const {
|
|
|
|
const uint32_t sizeA8 = getCacheSize(GL_ALPHA);
|
|
|
|
const uint32_t usedA8 = sizeA8 - getFreeCacheSize(GL_ALPHA);
|
|
|
|
const uint32_t sizeRGBA = getCacheSize(GL_RGBA);
|
|
|
|
const uint32_t usedRGBA = sizeRGBA - getFreeCacheSize(GL_RGBA);
|
|
|
|
log.appendFormat(" FontRenderer A8 %8d / %8d\n", usedA8, sizeA8);
|
|
|
|
dumpTextures(log, "A8", cacheTexturesForFormat(GL_ALPHA));
|
|
|
|
log.appendFormat(" FontRenderer RGBA %8d / %8d\n", usedRGBA, sizeRGBA);
|
|
|
|
dumpTextures(log, "RGBA", cacheTexturesForFormat(GL_RGBA));
|
|
|
|
log.appendFormat(" FontRenderer total %8d / %8d\n", usedA8 + usedRGBA, sizeA8 + sizeRGBA);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t FontRenderer::getCacheSize(GLenum format) const {
|
|
|
|
return calculateCacheSize(cacheTexturesForFormat(format));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t FontRenderer::getFreeCacheSize(GLenum format) const {
|
|
|
|
return calculateFreeCacheSize(cacheTexturesForFormat(format));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t FontRenderer::getSize() const {
|
|
|
|
return getCacheSize(GL_ALPHA) + getCacheSize(GL_RGBA);
|
|
|
|
}
|
|
|
|
|
2017-11-03 10:12:19 -07:00
|
|
|
}; // namespace uirenderer
|
|
|
|
}; // namespace android
|