Flutter iOS Embedder
ios_context_metal_skia.mm
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
6 
7 #include "flutter/common/graphics/persistent_cache.h"
8 #include "flutter/fml/logging.h"
9 #import "flutter/shell/platform/darwin/graphics/FlutterDarwinContextMetalSkia.h"
11 #include "third_party/skia/include/gpu/GrContextOptions.h"
12 
13 namespace flutter {
14 
15 IOSContextMetalSkia::IOSContextMetalSkia(MsaaSampleCount msaa_samples) : IOSContext(msaa_samples) {
16  darwin_context_metal_ = fml::scoped_nsobject<FlutterDarwinContextMetalSkia>{
17  [[FlutterDarwinContextMetalSkia alloc] initWithDefaultMTLDevice]};
18 }
19 
21 
22 fml::scoped_nsobject<FlutterDarwinContextMetalSkia> IOSContextMetalSkia::GetDarwinContext() const {
23  return darwin_context_metal_;
24 }
25 
28 }
29 
30 sk_sp<GrDirectContext> IOSContextMetalSkia::GetMainContext() const {
31  return darwin_context_metal_.get().mainContext;
32 }
33 
34 sk_sp<GrDirectContext> IOSContextMetalSkia::GetResourceContext() const {
35  return darwin_context_metal_.get().resourceContext;
36 }
37 
38 // |IOSContext|
39 sk_sp<GrDirectContext> IOSContextMetalSkia::CreateResourceContext() {
40  return darwin_context_metal_.get().resourceContext;
41 }
42 
43 // |IOSContext|
44 std::unique_ptr<GLContextResult> IOSContextMetalSkia::MakeCurrent() {
45  // This only makes sense for context that need to be bound to a specific thread.
46  return std::make_unique<GLContextDefaultResult>(true);
47 }
48 
49 // |IOSContext|
50 std::unique_ptr<Texture> IOSContextMetalSkia::CreateExternalTexture(
51  int64_t texture_id,
52  fml::scoped_nsobject<NSObject<FlutterTexture>> texture) {
53  return std::make_unique<IOSExternalTextureMetal>(
54  fml::scoped_nsobject<FlutterDarwinExternalTextureMetal>{
55  [[darwin_context_metal_ createExternalTextureWithIdentifier:texture_id
56  texture:texture] retain]});
57 }
58 
59 } // namespace flutter
flutter::IOSRenderingBackend::kSkia
@ kSkia
flutter::IOSContextMetalSkia::GetResourceContext
sk_sp< GrDirectContext > GetResourceContext() const
Definition: ios_context_metal_skia.mm:34
flutter::IOSContextMetalSkia::GetMainContext
sk_sp< GrDirectContext > GetMainContext() const override
Accessor for the Skia context associated with IOSSurfaces and the raster thread.
Definition: ios_context_metal_skia.mm:30
flutter::IOSContextMetalSkia::GetBackend
IOSRenderingBackend GetBackend() const override
Get the rendering backend used by this context.
Definition: ios_context_metal_skia.mm:26
flutter::IOSContextMetalSkia::GetDarwinContext
fml::scoped_nsobject< FlutterDarwinContextMetalSkia > GetDarwinContext() const
Definition: ios_context_metal_skia.mm:22
flutter::IOSContext
Manages the lifetime of the on-screen and off-screen rendering contexts on iOS. On-screen contexts ar...
Definition: ios_context.h:40
ios_context_metal_skia.h
flutter::IOSRenderingBackend
IOSRenderingBackend
Definition: rendering_api_selection.h:19
flutter::IOSContextMetalSkia::IOSContextMetalSkia
IOSContextMetalSkia(MsaaSampleCount msaa_samples)
Definition: ios_context_metal_skia.mm:15
flutter
Definition: accessibility_bridge.h:28
ios_external_texture_metal.h
flutter::IOSContextMetalSkia::~IOSContextMetalSkia
~IOSContextMetalSkia()
texture_id
int64_t texture_id
Definition: texture_registrar_unittests.cc:24