From 58e6c23ecee152a8df2d13ca874a03640f25fcda Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Tue, 6 Feb 2018 16:45:31 -0500 Subject: [PATCH] Modernize GrContext creation (#4640) --- content_handler/vulkan_surface_producer.cc | 4 +-- lib/ui/painting/resource_context.cc | 4 +-- lib/ui/painting/resource_context.h | 2 +- shell/common/platform_view.cc | 32 +++++++++------------- shell/gpu/gpu_surface_gl.cc | 7 +---- vulkan/vulkan_window.cc | 4 +-- 6 files changed, 19 insertions(+), 34 deletions(-) diff --git a/content_handler/vulkan_surface_producer.cc b/content_handler/vulkan_surface_producer.cc index fc674066d1..f30d5bfdf2 100644 --- a/content_handler/vulkan_surface_producer.cc +++ b/content_handler/vulkan_surface_producer.cc @@ -103,9 +103,7 @@ bool VulkanSurfaceProducer::Initialize(scenic_lib::Session* mozart_session) { logical_device_->ReleaseDeviceOwnership(); application_->ReleaseInstanceOwnership(); - context_.reset(GrContext::Create( - kVulkan_GrBackend, - reinterpret_cast(backend_context_.get()))); + context_ = GrContext::MakeVulkan(backend_context); context_->setResourceCacheLimits(vulkan::kGrCacheMaxCount, vulkan::kGrCacheMaxByteSize); diff --git a/lib/ui/painting/resource_context.cc b/lib/ui/painting/resource_context.cc index bc8118a546..7ec6a90f34 100644 --- a/lib/ui/painting/resource_context.cc +++ b/lib/ui/painting/resource_context.cc @@ -24,9 +24,9 @@ ResourceContext::~ResourceContext() { g_mutex.Unlock(); } -void ResourceContext::Set(GrContext* context) { +void ResourceContext::Set(sk_sp context) { FXL_DCHECK(!g_context); - g_context = context; + g_context = context.release(); } GrContext* ResourceContext::Get() { diff --git a/lib/ui/painting/resource_context.h b/lib/ui/painting/resource_context.h index 047c34ce42..627b2053c2 100644 --- a/lib/ui/painting/resource_context.h +++ b/lib/ui/painting/resource_context.h @@ -15,7 +15,7 @@ class ResourceContext { /** * Globally set the GrContext singleton instance. */ - static void Set(GrContext* context); + static void Set(sk_sp context); /** * Acquire a GrContext wrapping ResourceContext that's also an exclusive mutex diff --git a/shell/common/platform_view.cc b/shell/common/platform_view.cc index 37321372e5..2d5715a173 100644 --- a/shell/common/platform_view.cc +++ b/shell/common/platform_view.cc @@ -47,7 +47,7 @@ void PlatformView::CreateEngine() { void PlatformView::DispatchPlatformMessage( fxl::RefPtr message) { blink::Threads::UI()->PostTask( - [ engine = engine_->GetWeakPtr(), message = std::move(message) ] { + [engine = engine_->GetWeakPtr(), message = std::move(message)] { if (engine) { engine->DispatchPlatformMessage(message); } @@ -58,7 +58,7 @@ void PlatformView::DispatchSemanticsAction(int32_t id, blink::SemanticsAction action, std::vector args) { blink::Threads::UI()->PostTask( - [ engine = engine_->GetWeakPtr(), id, action, args = std::move(args) ] { + [engine = engine_->GetWeakPtr(), id, action, args = std::move(args)] { if (engine) { engine->DispatchSemanticsAction( id, static_cast(action), std::move(args)); @@ -67,7 +67,7 @@ void PlatformView::DispatchSemanticsAction(int32_t id, } void PlatformView::SetSemanticsEnabled(bool enabled) { - blink::Threads::UI()->PostTask([ engine = engine_->GetWeakPtr(), enabled ] { + blink::Threads::UI()->PostTask([engine = engine_->GetWeakPtr(), enabled] { if (engine) engine->SetSemanticsEnabled(enabled); }); @@ -81,18 +81,14 @@ void PlatformView::NotifyCreated(std::unique_ptr surface, fxl::Closure caller_continuation) { fxl::AutoResetWaitableEvent latch; - auto ui_continuation = fxl::MakeCopyable([ - this, // - surface = std::move(surface), // - caller_continuation, // - &latch - ]() mutable { - auto gpu_continuation = fxl::MakeCopyable([ - this, // - surface = std::move(surface), // - caller_continuation, // - &latch - ]() mutable { + auto ui_continuation = fxl::MakeCopyable([this, // + surface = std::move(surface), // + caller_continuation, // + &latch]() mutable { + auto gpu_continuation = fxl::MakeCopyable([this, // + surface = std::move(surface), // + caller_continuation, // + &latch]() mutable { // Runs on the GPU Thread. So does the Caller Continuation. rasterizer_->Setup(std::move(surface), caller_continuation, &latch); }); @@ -195,10 +191,8 @@ void PlatformView::SetupResourceContextOnIOThreadPerform( // that feature, which will cause texture uploads to do CPU YUV conversion. options.fDisableGpuYUVConversion = true; - blink::ResourceContext::Set(GrContext::Create( - GrBackend::kOpenGL_GrBackend, - reinterpret_cast(GrGLCreateNativeInterface()), - options)); + blink::ResourceContext::Set( + GrContext::MakeGL(GrGLMakeNativeInterface(), options)); // Do not cache textures created by the image decoder. These textures should // be deleted when they are no longer referenced by an SkImage. diff --git a/shell/gpu/gpu_surface_gl.cc b/shell/gpu/gpu_surface_gl.cc index ee28c97f79..36c2b80976 100644 --- a/shell/gpu/gpu_surface_gl.cc +++ b/shell/gpu/gpu_surface_gl.cc @@ -30,14 +30,10 @@ GPUSurfaceGL::GPUSurfaceGL(GPUSurfaceGLDelegate* delegate) return; } - auto backend_context = - reinterpret_cast(GrGLCreateNativeInterface()); - GrContextOptions options; options.fAvoidStencilBuffers = true; - auto context = sk_sp( - GrContext::Create(kOpenGL_GrBackend, backend_context, options)); + auto context = GrContext::MakeGL(GrGLMakeNativeInterface(), options); if (context == nullptr) { FXL_LOG(ERROR) << "Failed to setup Skia Gr context."; @@ -80,7 +76,6 @@ static GrPixelConfig FirstSupportedConfig(GrContext* context) { if (context->caps()->isConfigRenderable((x), false)) { \ return (x); \ } - RETURN_IF_RENDERABLE(kRGBA_8888_GrPixelConfig); RETURN_IF_RENDERABLE(kRGBA_4444_GrPixelConfig); RETURN_IF_RENDERABLE(kRGB_565_GrPixelConfig); diff --git a/vulkan/vulkan_window.cc b/vulkan/vulkan_window.cc index 00c57ac002..907a15a097 100644 --- a/vulkan/vulkan_window.cc +++ b/vulkan/vulkan_window.cc @@ -103,9 +103,7 @@ bool VulkanWindow::CreateSkiaGrContext() { return false; } - sk_sp context(GrContext::Create( - kVulkan_GrBackend, - reinterpret_cast(backend_context.get()))); + sk_sp context = GrContext::MakeVulkan(backend_context); if (context == nullptr) { return false; -- GitLab