/* Shared object (not in loop) */
sk_sp<SkTypeface> _typeface = SkTypeface::MakeFromFile( FileUtils::getInstance()->fullPathForFilename( "font.ttf" ).c_str() );
_typefacePaint.setAntiAlias( true );
_typefacePaint.setColor( SK_ColorWHITE );
_typefacePaint.setStyle( SkPaint::kFill_Style );
_typefacePaint.setSubpixelText( true );
_typefacePaint.setTypeface( _typeface );
SkRect textBounds;
(void)_typefacePaint.measureText( text.c_str(), text.size(), &textBounds );
float canvasWidth = textBounds.width();
SkPaint::FontMetrics metrics;
_typefacePaint.getFontMetrics( &metrics );
float canvasHeight = metrics.fAscent * (-1) + metrics.fDescent;
bitmap.allocPixels( SkImageInfo::MakeN32Premul( canvasWidth, canvasHeight ) );
bitmap.eraseColor( SK_ColorTRANSPARENT );
SkCanvas canvas( bitmap );
canvas.drawText( text.c_str(),
text.size(),
textPositionX,
textPositionY,
_typefacePaint );
auto pixels = bitmap.getPixels();
//Create some object here from pixels data ...
/* Drawing loop: end */
__________________________________________________________
So it works really slow on mobile devices(iOS, Android, Windows Phone).
Is there way to rasterise faster?
Thanks!
--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/d/optout.
I'm not sure I have the picture of what you are doing. Can you post some working code using https://fiddle.skia.org/? The more information you can share with us the easier it is to diagnose.
Yes, you should be able to use the GPU. Rather than using SkBitmap, try using SkSurface. If you allocate one as: sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(...), it will be GPU backed, and then you can get the canvas via surface->getCanvas() to draw your text.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss+unsubscribe@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss+unsubscribe@googlegroups.com.
auto tf = SkTypeface::MakeFromFile( FileUtils::getInstance()->fullPathForFilename( "NotoSans-Regular.ttf" ).c_str() );
SkPaint paint;
paint.setTextSize( 82.5f );
paint.setAntiAlias( true );
paint.setColor( SK_ColorWHITE );
paint.setStyle( SkPaint::kFill_Style );
paint.setSubpixelText( true );
paint.setTypeface( tf );
SkRect textBounds;
(void)paint.measureText( str.c_str(), str.size(), &textBounds );
auto canvasWidth = textBounds.width();
SkPaint::FontMetrics metrics;
paint.getFontMetrics( &metrics );
auto canvasHeight = metrics.fAscent * (-1) + metrics.fDescent;
auto curIntf = GrGLCreateNativeInterface();
auto curContext = GrContext::Create( kOpenGL_GrBackend, (GrBackendContext) curIntf);
SkImageInfo info = SkImageInfo::MakeN32Premul( SkScalarCeilToInt( canvasWidth ), SkScalarCeilToInt( canvasHeight ) );
sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget( curContext, SkBudgeted::kNo, info );
__________
And after that I have my openGL view affected on iOS (pictures attached).
void GrGLGpu::setScratchTextureUnit() {
// Bind the last texture unit since it is the least likely to be used by GrGLProgram.
int lastUnitIdx = fHWBoundTextureUniqueIDs.count() - 1;
if (lastUnitIdx != fHWActiveTextureUnitIdx) {
GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + lastUnitIdx));
fHWActiveTextureUnitIdx = lastUnitIdx;
}
// clear out the this field so that if a program does use this unit it will rebind the correct
// texture.
fHWBoundTextureUniqueIDs[lastUnitIdx] = SK_InvalidUniqueID;
}
Yes, you should be able to use the GPU. Rather than using SkBitmap, try using SkSurface. If you allocate one as: sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(...), it will be GPU backed, and then you can get the canvas via surface->getCanvas() to draw your text.
auto curIntf = GrGLCreateNativeInterface();
auto curContext = GrContext::Create( kOpenGL_GrBackend, (GrBackendContext) curIntf );
GLint activeTexture;
glGetIntegerv(GL_ACTIVE_TEXTURE, &activeTexture);
3. Create surface, and draw on canvas:
sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget( curContext, .., .., .. );
std::string str("012345678901234567890123456789");
auto tf = SkTypeface::MakeFromFile( ... );
SkPaint paint;
paint.setTextSize( 52.5f );
paint.setAntiAlias( true );
paint.setColor( SK_ColorWHITE );
paint.setStyle( SkPaint::kFill_Style );
paint.setSubpixelText( true );
paint.setTypeface( tf );
SkRect textBounds;
(void)paint.measureText( str.c_str(), str.size(), &textBounds );
auto canvasWidth = textBounds.width();
SkPaint::FontMetrics metrics;
paint.getFontMetrics( &metrics );
auto canvasHeight = metrics.fAscent * (-1) + metrics.fDescent;
setSkiaContextAsCurrent(); /* Makes own Skia active */
SkImageInfo info = SkImageInfo::MakeN32Premul( SkScalarCeilToInt( canvasWidth ), SkScalarCeilToInt( canvasHeight ) );
sk_sp<SkSurface> surface =
SkSurface::MakeRenderTarget( curContext,
SkBudgeted::kNo,
info,
0,
GrSurfaceOrigin::kTopLeft_GrSurfaceOrigin,
nullptr );
auto canvas = surface->getCanvas();
auto baseLinePositionY = metrics.fAscent * (-1);
canvas->drawText(...);
/* сreate pixel array from canvas */
setGLViewContextAsCurrent(); /* Make GLView context active */
This is an instance of a general problem where Skia rendering changes OpenGL state. You either have to give Skia its own OpenGL context or assume that the OpenGL state has been modified after using Skia and respecify the state (in this example using glActiveTexture(GL_TEXTURE<n>)) when you transition from Skia rendering to your own OpenGL rendering. Also, Skia needs to know when you've change OpenGL state which is communicated by calling GrContext::resetContext() before resuming Skia rendering.Briam