I'm trying to integrate Skia into a framework that does it's own GL drawing. For this I need Skia to render into a texture, either one it creates or one provide to it. I've tried both approached and don't seem to get any results.
The first approach is to render to a texture I've already created and bound to the GL context. I then do this with skia:
const GrGLInterface* interface = nullptr;
GrContext* context = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)interface);
GrBackendRenderTargetDesc desc;
desc.fWidth = 400;
desc.fHeight = 300;
desc.fConfig = kSkia8888_GrPixelConfig;
desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
desc.fSampleCnt = 1;
desc.fStencilBits = 0;
desc.fRenderTargetHandle = 0;
sk_sp<SkSurface> surface = SkSurface::MakeFromBackendRenderTarget(context, desc, NULL);
SkCanvas* canvas = surface->getCanvas();
canvas->clear(SK_ColorWHITE);
canvas->flush();
context->flush();
I'm assuming this is enough to color the surface white (I've cleared it to green). But it doesn't appear to do anything to the buffer. (Note, I've also tried drawing the sample star in my code, but it doesn't do anything either).
The second approach is letting Skia create the texture and then get the handle to that.
const GrGLInterface* interface = nullptr;
GrContext* context = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)interface);
SkImageInfo info = SkImageInfo::MakeN32Premul(400,300);
sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info);
SkCanvas* canvas = surface->getCanvas();
canvas->clear(SK_ColorWHITE);
canvas->flush();
context->flush();
sk_sp<SkImage> image = surface->makeImageSnapshot();
GrBackendObject handle = image->getTextureHandle(true);
SkImage* rawImage = image.release();
surface.release(); //temporary for now, to prevent texture release
return handle;
I then bind the returned handle to GL and copy it to my output buffer. The result is always just black.
What am I doing wrong? I'd prefer for the first approach to work, to output to my own buffers, but if I can see anything n the second one I'd use that at least for now.