Migrate skottiekit to GrDirectContext
Change-Id: I6767070f63ba19a61ac6766254b9e524b7bbc8a3 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/326901 Reviewed-by: Kevin Lubick <kjlubick@google.com> Commit-Queue: Adlai Holler <adlai@google.com>
This commit is contained in:
parent
e07f2b2191
commit
dd09d6e2ef
@ -214,8 +214,7 @@ SkImageInfo toSkImageInfo(const SimpleImageInfo& sii) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SK_GL
|
#ifdef SK_GL
|
||||||
// TODO: Migrate this to GrDirectContext.
|
sk_sp<GrDirectContext> MakeGrContext(EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context)
|
||||||
sk_sp<GrContext> MakeGrContext(EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context)
|
|
||||||
{
|
{
|
||||||
EMSCRIPTEN_RESULT r = emscripten_webgl_make_context_current(context);
|
EMSCRIPTEN_RESULT r = emscripten_webgl_make_context_current(context);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
@ -224,12 +223,10 @@ sk_sp<GrContext> MakeGrContext(EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context)
|
|||||||
}
|
}
|
||||||
// setup GrDirectContext
|
// setup GrDirectContext
|
||||||
auto interface = GrGLMakeNativeInterface();
|
auto interface = GrGLMakeNativeInterface();
|
||||||
// setup contexts
|
return GrDirectContext::MakeGL(interface);
|
||||||
sk_sp<GrContext> grContext(GrDirectContext::MakeGL(interface));
|
|
||||||
return grContext;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sk_sp<SkSurface> MakeOnScreenGLSurface(sk_sp<GrContext> grContext, int width, int height) {
|
sk_sp<SkSurface> MakeOnScreenGLSurface(sk_sp<GrDirectContext> grContext, int width, int height) {
|
||||||
glClearColor(0, 0, 0, 0);
|
glClearColor(0, 0, 0, 0);
|
||||||
glClearStencil(0);
|
glClearStencil(0);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||||
@ -257,7 +254,7 @@ sk_sp<SkSurface> MakeOnScreenGLSurface(sk_sp<GrContext> grContext, int width, in
|
|||||||
return surface;
|
return surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
sk_sp<SkSurface> MakeRenderTarget(sk_sp<GrContext> grContext, int width, int height) {
|
sk_sp<SkSurface> MakeRenderTarget(sk_sp<GrDirectContext> grContext, int width, int height) {
|
||||||
SkImageInfo info = SkImageInfo::MakeN32(width, height, SkAlphaType::kPremul_SkAlphaType);
|
SkImageInfo info = SkImageInfo::MakeN32(width, height, SkAlphaType::kPremul_SkAlphaType);
|
||||||
|
|
||||||
sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(grContext.get(),
|
sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(grContext.get(),
|
||||||
@ -268,7 +265,7 @@ sk_sp<SkSurface> MakeRenderTarget(sk_sp<GrContext> grContext, int width, int hei
|
|||||||
return surface;
|
return surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
sk_sp<SkSurface> MakeRenderTarget(sk_sp<GrContext> grContext, SimpleImageInfo sii) {
|
sk_sp<SkSurface> MakeRenderTarget(sk_sp<GrDirectContext> grContext, SimpleImageInfo sii) {
|
||||||
sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(grContext.get(),
|
sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(grContext.get(),
|
||||||
SkBudgeted::kYes,
|
SkBudgeted::kYes,
|
||||||
toSkImageInfo(sii), 0,
|
toSkImageInfo(sii), 0,
|
||||||
@ -290,32 +287,34 @@ sk_sp<SkSurface> MakeRenderTarget(sk_sp<GrContext> grContext, SimpleImageInfo si
|
|||||||
// types Pi, Pf"). But, we can just pretend they are numbers and cast them to be pointers and
|
// types Pi, Pf"). But, we can just pretend they are numbers and cast them to be pointers and
|
||||||
// the compiler is happy.
|
// the compiler is happy.
|
||||||
EMSCRIPTEN_BINDINGS(Skottie) {
|
EMSCRIPTEN_BINDINGS(Skottie) {
|
||||||
#ifdef SK_GL
|
#ifdef SK_GL
|
||||||
function("currentContext", &emscripten_webgl_get_current_context);
|
function("currentContext", &emscripten_webgl_get_current_context);
|
||||||
function("setCurrentContext", &emscripten_webgl_make_context_current);
|
function("setCurrentContext", &emscripten_webgl_make_context_current);
|
||||||
function("MakeGrContext", &MakeGrContext);
|
function("MakeGrContext", &MakeGrContext);
|
||||||
function("MakeOnScreenGLSurface", &MakeOnScreenGLSurface);
|
function("MakeOnScreenGLSurface", &MakeOnScreenGLSurface);
|
||||||
function("MakeRenderTarget", select_overload<sk_sp<SkSurface>(sk_sp<GrContext>, int, int)>(&MakeRenderTarget));
|
function("MakeRenderTarget",
|
||||||
function("MakeRenderTarget", select_overload<sk_sp<SkSurface>(sk_sp<GrContext>, SimpleImageInfo)>(&MakeRenderTarget));
|
select_overload<sk_sp<SkSurface>(sk_sp<GrDirectContext>, int, int)>(&MakeRenderTarget));
|
||||||
|
function("MakeRenderTarget",
|
||||||
|
select_overload<sk_sp<SkSurface>(sk_sp<GrDirectContext>, SimpleImageInfo)>(&MakeRenderTarget));
|
||||||
|
|
||||||
constant("gpu", true);
|
constant("gpu", true);
|
||||||
|
|
||||||
class_<GrContext>("GrContext")
|
class_<GrDirectContext>("GrDirectContext")
|
||||||
.smart_ptr<sk_sp<GrContext>>("sk_sp<GrContext>");
|
.smart_ptr<sk_sp<GrDirectContext>>("sk_sp<GrDirectContext>");
|
||||||
// .function("getResourceCacheLimitBytes", optional_override([](GrContext& self)->size_t {
|
// .function("getResourceCacheLimitBytes", optional_override([](GrDirectContext& self)->size_t {
|
||||||
// int maxResources = 0;// ignored
|
// int maxResources = 0;// ignored
|
||||||
// size_t currMax = 0;
|
// size_t currMax = 0;
|
||||||
// self.getResourceCacheLimits(&maxResources, &currMax);
|
// self.getResourceCacheLimits(&maxResources, &currMax);
|
||||||
// return currMax;
|
// return currMax;
|
||||||
// }))
|
// }))
|
||||||
// .function("getResourceCacheUsageBytes", optional_override([](GrContext& self)->size_t {
|
// .function("getResourceCacheUsageBytes", optional_override([](GrDirectContext& self)->size_t {
|
||||||
// int usedResources = 0;// ignored
|
// int usedResources = 0;// ignored
|
||||||
// size_t currUsage = 0;
|
// size_t currUsage = 0;
|
||||||
// self.getResourceCacheUsage(&usedResources, &currUsage);
|
// self.getResourceCacheUsage(&usedResources, &currUsage);
|
||||||
// return currUsage;
|
// return currUsage;
|
||||||
// }))
|
// }))
|
||||||
// .function("releaseResourcesAndAbandonContext", &GrContext::releaseResourcesAndAbandonContext)
|
// .function("releaseResourcesAndAbandonContext", &GrDirectContext::releaseResourcesAndAbandonContext)
|
||||||
// .function("setResourceCacheLimitBytes", optional_override([](GrContext& self, size_t maxResourceBytes)->void {
|
// .function("setResourceCacheLimitBytes", optional_override([](GrDirectContext& self, size_t maxResourceBytes) {
|
||||||
// int maxResources = 0;
|
// int maxResources = 0;
|
||||||
// size_t currMax = 0; // ignored
|
// size_t currMax = 0; // ignored
|
||||||
// self.getResourceCacheLimits(&maxResources, &currMax);
|
// self.getResourceCacheLimits(&maxResources, &currMax);
|
||||||
|
Loading…
Reference in New Issue
Block a user