Skip to content

Commit 58e6c23

Browse files
bsalomonjason-simmons
authored andcommitted
Modernize GrContext creation (#4640)
1 parent 76d4928 commit 58e6c23

File tree

6 files changed

+19
-34
lines changed

6 files changed

+19
-34
lines changed

content_handler/vulkan_surface_producer.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ bool VulkanSurfaceProducer::Initialize(scenic_lib::Session* mozart_session) {
103103
logical_device_->ReleaseDeviceOwnership();
104104
application_->ReleaseInstanceOwnership();
105105

106-
context_.reset(GrContext::Create(
107-
kVulkan_GrBackend,
108-
reinterpret_cast<GrBackendContext>(backend_context_.get())));
106+
context_ = GrContext::MakeVulkan(backend_context);
109107

110108
context_->setResourceCacheLimits(vulkan::kGrCacheMaxCount,
111109
vulkan::kGrCacheMaxByteSize);

lib/ui/painting/resource_context.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ ResourceContext::~ResourceContext() {
2424
g_mutex.Unlock();
2525
}
2626

27-
void ResourceContext::Set(GrContext* context) {
27+
void ResourceContext::Set(sk_sp<GrContext> context) {
2828
FXL_DCHECK(!g_context);
29-
g_context = context;
29+
g_context = context.release();
3030
}
3131

3232
GrContext* ResourceContext::Get() {

lib/ui/painting/resource_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ResourceContext {
1515
/**
1616
* Globally set the GrContext singleton instance.
1717
*/
18-
static void Set(GrContext* context);
18+
static void Set(sk_sp<GrContext> context);
1919

2020
/**
2121
* Acquire a GrContext wrapping ResourceContext that's also an exclusive mutex

shell/common/platform_view.cc

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void PlatformView::CreateEngine() {
4747
void PlatformView::DispatchPlatformMessage(
4848
fxl::RefPtr<blink::PlatformMessage> message) {
4949
blink::Threads::UI()->PostTask(
50-
[ engine = engine_->GetWeakPtr(), message = std::move(message) ] {
50+
[engine = engine_->GetWeakPtr(), message = std::move(message)] {
5151
if (engine) {
5252
engine->DispatchPlatformMessage(message);
5353
}
@@ -58,7 +58,7 @@ void PlatformView::DispatchSemanticsAction(int32_t id,
5858
blink::SemanticsAction action,
5959
std::vector<uint8_t> args) {
6060
blink::Threads::UI()->PostTask(
61-
[ engine = engine_->GetWeakPtr(), id, action, args = std::move(args) ] {
61+
[engine = engine_->GetWeakPtr(), id, action, args = std::move(args)] {
6262
if (engine) {
6363
engine->DispatchSemanticsAction(
6464
id, static_cast<blink::SemanticsAction>(action), std::move(args));
@@ -67,7 +67,7 @@ void PlatformView::DispatchSemanticsAction(int32_t id,
6767
}
6868

6969
void PlatformView::SetSemanticsEnabled(bool enabled) {
70-
blink::Threads::UI()->PostTask([ engine = engine_->GetWeakPtr(), enabled ] {
70+
blink::Threads::UI()->PostTask([engine = engine_->GetWeakPtr(), enabled] {
7171
if (engine)
7272
engine->SetSemanticsEnabled(enabled);
7373
});
@@ -81,18 +81,14 @@ void PlatformView::NotifyCreated(std::unique_ptr<Surface> surface,
8181
fxl::Closure caller_continuation) {
8282
fxl::AutoResetWaitableEvent latch;
8383

84-
auto ui_continuation = fxl::MakeCopyable([
85-
this, //
86-
surface = std::move(surface), //
87-
caller_continuation, //
88-
&latch
89-
]() mutable {
90-
auto gpu_continuation = fxl::MakeCopyable([
91-
this, //
92-
surface = std::move(surface), //
93-
caller_continuation, //
94-
&latch
95-
]() mutable {
84+
auto ui_continuation = fxl::MakeCopyable([this, //
85+
surface = std::move(surface), //
86+
caller_continuation, //
87+
&latch]() mutable {
88+
auto gpu_continuation = fxl::MakeCopyable([this, //
89+
surface = std::move(surface), //
90+
caller_continuation, //
91+
&latch]() mutable {
9692
// Runs on the GPU Thread. So does the Caller Continuation.
9793
rasterizer_->Setup(std::move(surface), caller_continuation, &latch);
9894
});
@@ -195,10 +191,8 @@ void PlatformView::SetupResourceContextOnIOThreadPerform(
195191
// that feature, which will cause texture uploads to do CPU YUV conversion.
196192
options.fDisableGpuYUVConversion = true;
197193

198-
blink::ResourceContext::Set(GrContext::Create(
199-
GrBackend::kOpenGL_GrBackend,
200-
reinterpret_cast<GrBackendContext>(GrGLCreateNativeInterface()),
201-
options));
194+
blink::ResourceContext::Set(
195+
GrContext::MakeGL(GrGLMakeNativeInterface(), options));
202196

203197
// Do not cache textures created by the image decoder. These textures should
204198
// be deleted when they are no longer referenced by an SkImage.

shell/gpu/gpu_surface_gl.cc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,10 @@ GPUSurfaceGL::GPUSurfaceGL(GPUSurfaceGLDelegate* delegate)
3030
return;
3131
}
3232

33-
auto backend_context =
34-
reinterpret_cast<GrBackendContext>(GrGLCreateNativeInterface());
35-
3633
GrContextOptions options;
3734
options.fAvoidStencilBuffers = true;
3835

39-
auto context = sk_sp<GrContext>(
40-
GrContext::Create(kOpenGL_GrBackend, backend_context, options));
36+
auto context = GrContext::MakeGL(GrGLMakeNativeInterface(), options);
4137

4238
if (context == nullptr) {
4339
FXL_LOG(ERROR) << "Failed to setup Skia Gr context.";
@@ -80,7 +76,6 @@ static GrPixelConfig FirstSupportedConfig(GrContext* context) {
8076
if (context->caps()->isConfigRenderable((x), false)) { \
8177
return (x); \
8278
}
83-
8479
RETURN_IF_RENDERABLE(kRGBA_8888_GrPixelConfig);
8580
RETURN_IF_RENDERABLE(kRGBA_4444_GrPixelConfig);
8681
RETURN_IF_RENDERABLE(kRGB_565_GrPixelConfig);

vulkan/vulkan_window.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ bool VulkanWindow::CreateSkiaGrContext() {
103103
return false;
104104
}
105105

106-
sk_sp<GrContext> context(GrContext::Create(
107-
kVulkan_GrBackend,
108-
reinterpret_cast<GrBackendContext>(backend_context.get())));
106+
sk_sp<GrContext> context = GrContext::MakeVulkan(backend_context);
109107

110108
if (context == nullptr) {
111109
return false;

0 commit comments

Comments
 (0)