Skip to content

Commit

Permalink
Modernize GrContext creation (flutter#4640)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsalomon authored and jason-simmons committed Feb 6, 2018
1 parent 76d4928 commit 58e6c23
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 34 deletions.
4 changes: 1 addition & 3 deletions content_handler/vulkan_surface_producer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<GrBackendContext>(backend_context_.get())));
context_ = GrContext::MakeVulkan(backend_context);

context_->setResourceCacheLimits(vulkan::kGrCacheMaxCount,
vulkan::kGrCacheMaxByteSize);
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/painting/resource_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ ResourceContext::~ResourceContext() {
g_mutex.Unlock();
}

void ResourceContext::Set(GrContext* context) {
void ResourceContext::Set(sk_sp<GrContext> context) {
FXL_DCHECK(!g_context);
g_context = context;
g_context = context.release();
}

GrContext* ResourceContext::Get() {
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/painting/resource_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ResourceContext {
/**
* Globally set the GrContext singleton instance.
*/
static void Set(GrContext* context);
static void Set(sk_sp<GrContext> context);

/**
* Acquire a GrContext wrapping ResourceContext that's also an exclusive mutex
Expand Down
32 changes: 13 additions & 19 deletions shell/common/platform_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void PlatformView::CreateEngine() {
void PlatformView::DispatchPlatformMessage(
fxl::RefPtr<blink::PlatformMessage> message) {
blink::Threads::UI()->PostTask(
[ engine = engine_->GetWeakPtr(), message = std::move(message) ] {
[engine = engine_->GetWeakPtr(), message = std::move(message)] {
if (engine) {
engine->DispatchPlatformMessage(message);
}
Expand All @@ -58,7 +58,7 @@ void PlatformView::DispatchSemanticsAction(int32_t id,
blink::SemanticsAction action,
std::vector<uint8_t> 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<blink::SemanticsAction>(action), std::move(args));
Expand All @@ -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);
});
Expand All @@ -81,18 +81,14 @@ void PlatformView::NotifyCreated(std::unique_ptr<Surface> 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);
});
Expand Down Expand Up @@ -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<GrBackendContext>(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.
Expand Down
7 changes: 1 addition & 6 deletions shell/gpu/gpu_surface_gl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,10 @@ GPUSurfaceGL::GPUSurfaceGL(GPUSurfaceGLDelegate* delegate)
return;
}

auto backend_context =
reinterpret_cast<GrBackendContext>(GrGLCreateNativeInterface());

GrContextOptions options;
options.fAvoidStencilBuffers = true;

auto context = sk_sp<GrContext>(
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.";
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions vulkan/vulkan_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ bool VulkanWindow::CreateSkiaGrContext() {
return false;
}

sk_sp<GrContext> context(GrContext::Create(
kVulkan_GrBackend,
reinterpret_cast<GrBackendContext>(backend_context.get())));
sk_sp<GrContext> context = GrContext::MakeVulkan(backend_context);

if (context == nullptr) {
return false;
Expand Down

0 comments on commit 58e6c23

Please sign in to comment.