I am trying to apply a text using canvas->drawString() function. It is part of an android application where the surface is created using the java code. A media decoder is using that surface to render a video. After rendering each frame I am retrieving that surface in CPP. From there I am getting the canvas and calling draw operation on that. So basically the text is expected to appear on top of the video.
But when I call drawString() function like below, it does not render anything on the screen.
canvas->drawString(text, textPosX, textPosY, font, p);
But if somehow if I use the canvas for some other draw operation before text rendering, then it renders the text. For example, if I use the following code to draw a rectangle (which will hardly be visible in the screen), it renders the text.
pp.setImageFilter(SkImageFilters::Blur(0.0, 0.0, nullptr));
canvas->drawRect(SkRect::MakeWH(1, 1), pp);
Please note that if I do not set the image filter, I can see few filled rectangles, one for each character in the text, which is probably the boundary of those characters.
Somehow, probably this issue is linked with the way I am retrieving the surface. I am doing the following things.
1. Create GL interface using GrGLMakeNativeInterface function.
2. Create GrDirectContext using GrDirectContext::MakeGL from the GL interface.
3. Create GrBackendRenderTarget using GrDirectContext.
4. Create SkSurface using the output of step 3.
These steps are supposed to be executed for every frame of input video. But to optimise the performance I am running step 1 and 2 only once and using their values in the subsequently in loop because these two are costly operations. 3 and 4 are anyway run in loop. With this set up the issue mentioned above is observed. But if I execute step 2 also every time and only optimise step 1, it works fine.
What could be the reason for it?